compassmock/src/hooks/use-mobile.ts
Nicholai 0d1b4714dc
fix(ui): sidebar layout and mobile improvements (#71)
- Fix mobile state initialization bug that caused flickering
  (undefined -> false instead of !!undefined)
- Increase mobile sidebar width from 18rem to 20rem with 85vw max
- Add mobile-specific larger touch targets (44px min height)
- Increase icon and text sizes on mobile for better usability
- Fix collapsed sidebar button centering by reducing padding
- Remove fragile manual translate offsets on lg buttons
- Improve animation performance with will-change and ease-out
- Hide collapsed text instead of translating off-screen

Co-authored-by: Nicholai <nicholaivogelfilms@gmail.com>
2026-02-12 15:16:03 -07:00

20 lines
547 B
TypeScript
Executable File

import * as React from "react"
const MOBILE_BREAKPOINT = 768
export function useIsMobile() {
const [isMobile, setIsMobile] = React.useState<boolean>(false)
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
}