siakad-itm/resources/js/hooks/use-mobile.ts
Yoga Pangestu 8f692c44c7
Some checks failed
tests / ci (pull_request) Has been cancelled
refactor: update component imports and improve styling
- Refactored imports in Select, Separator, Sheet, Sidebar, Skeleton, Sonner, Toggle, and Tooltip components to use new radix-ui package.
- Enhanced styling for various components, including SelectTrigger, SelectContent, and TooltipContent for better visual consistency.
- Introduced a new hook `useIsMobile` to manage mobile state detection.
- Adjusted class names and styles for better responsiveness and accessibility across components.
- Added support for custom spacing in ToggleGroup component.
2026-08-03 15:19:17 +07:00

20 lines
565 B
TypeScript

import * as React from "react"
const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(undefined)
React.useEffect(() => {
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`)
const onChange = () => {
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
}
mql.addEventListener("change", onChange)
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT)
return () => mql.removeEventListener("change", onChange)
}, [])
return !!isMobile
}