open-swe/ui/src/lib/useIsMobile.ts
Johannes du Plessis 0b6806c4ba
fix: make git panel a full-screen overlay on mobile widths (#1559)
At mobile widths the resizable git panel collided with the chat column's
360px min-width, overflowing the viewport. Treat mobile (<768px) like the
sidebar: the git panel becomes a full-screen overlay the user navigates to
and back from, while desktop keeps the inline resizable panel.

Co-authored-by: open-swe[bot] <open-swe@users.noreply.github.com>
2026-06-17 09:24:28 -07:00

25 lines
870 B
TypeScript

import { useEffect, useState } from "react"
// Matches the `max-md:` Tailwind breakpoint (md = 768px) used across the UI, so
// JS-driven layout decisions stay in sync with the CSS responsive utilities.
export const MOBILE_MEDIA_QUERY = "(max-width: 767px)"
function readIsMobile(): boolean {
if (typeof window === "undefined") return false
return window.matchMedia(MOBILE_MEDIA_QUERY).matches
}
/** Reactive flag that tracks whether the viewport is at mobile width. */
export function useIsMobile(): boolean {
const [isMobile, setIsMobile] = useState<boolean>(readIsMobile)
useEffect(() => {
const media = window.matchMedia(MOBILE_MEDIA_QUERY)
const onChange = () => setIsMobile(media.matches)
onChange()
media.addEventListener("change", onChange)
return () => media.removeEventListener("change", onChange)
}, [])
return isMobile
}