"use client"; import { useEffect } from "react"; import { cn } from "@/lib/utils"; import { Sidebar } from "@/components/layout/Sidebar"; import { useTouchGesture } from "@/hooks/useTouchGesture"; interface MobileSidebarProps { isOpen: boolean; onClose: () => void; } /** * Slide-in drawer sidebar for mobile / tablet. * - Opens from the left as an overlay * - Swipe left or tap backdrop to close * - Traps focus while open and restores on close * - Locks body scroll while open */ export function MobileSidebar({ isOpen, onClose }: MobileSidebarProps) { // Swipe left on the drawer to close const swipeHandlers = useTouchGesture({ onSwipeLeft: onClose }); // Lock body scroll while drawer is open useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden"; } else { document.body.style.overflow = ""; } return () => { document.body.style.overflow = ""; }; }, [isOpen]); // Close on Escape useEffect(() => { if (!isOpen) return; const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; document.addEventListener("keydown", onKey); return () => document.removeEventListener("keydown", onKey); }, [isOpen, onClose]); return ( <> {/* Backdrop */}