"use client" import { useEffect, useRef } from "react" import { XIcon } from "lucide-react" import { motion, AnimatePresence } from "motion/react" interface FilterDrawerProps { isOpen: boolean onClose: () => void children: React.ReactNode } export function FilterDrawer({ isOpen, onClose, children }: FilterDrawerProps) { const drawerRef = useRef(null) // Close on Escape useEffect(() => { if (!isOpen) return const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") onClose() } document.addEventListener("keydown", handleKeyDown) return () => document.removeEventListener("keydown", handleKeyDown) }, [isOpen, onClose]) // Prevent body scroll when open useEffect(() => { if (isOpen) { document.body.style.overflow = "hidden" } else { document.body.style.overflow = "" } return () => { document.body.style.overflow = "" } }, [isOpen]) // Focus trap useEffect(() => { if (isOpen && drawerRef.current) { const firstFocusable = drawerRef.current.querySelector( 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])', ) firstFocusable?.focus() } }, [isOpen]) return ( {isOpen && ( <> {/* Backdrop */} {/* Drawer */}

Filters

{children}
)}
) }