import { X } from 'lucide-react' import { type ReactNode, useEffect } from 'react' import { cn } from '../lib/utils.js' import { Dialog, DialogContent, DialogTitle } from './ui/dialog.js' /** Slide-over panel for mobile navigation and sidebars. */ export function Sheet({ open, onClose, title, side = 'left', hideAt = 'md', children, }: { open: boolean onClose: () => void title: string side?: 'left' | 'right' hideAt?: 'md' | 'lg' children: ReactNode }) { useEffect(() => { if (!open || typeof window.matchMedia !== 'function') return const query = hideAt === 'lg' ? '(min-width: 64rem)' : '(min-width: 48rem)' const media = window.matchMedia(query) const closeAtDesktopBreakpoint = (event: MediaQueryListEvent | MediaQueryList) => { if (event.matches) onClose() } closeAtDesktopBreakpoint(media) media.addEventListener('change', closeAtDesktopBreakpoint) return () => media.removeEventListener('change', closeAtDesktopBreakpoint) }, [hideAt, onClose, open]) return ( { /* v8 ignore else -- @preserve this controlled sheet only acts on dismissal requests */ if (!next) onClose() }} >
{title}
{children}
) }