'use client'; import { useEffect, useRef } from 'react'; import { AnimatePresence, motion } from '@/lib/motion'; import { X } from 'lucide-react'; interface SlideOverProps { open: boolean; onClose: () => void; title: string; icon?: React.ReactNode; children: React.ReactNode; size?: 'form' | 'compact'; } const SIZE_CLASS = { form: 'w-full sm:w-[78vw] lg:w-[min(50vw,600px)] sm:max-w-[650px]', compact: 'w-full sm:w-[min(100%,380px)] sm:max-w-[380px]', }; export function SlideOver({ open, onClose, title, icon, children, size = 'form' }: SlideOverProps) { const panelRef = useRef(null); useEffect(() => { if (!open) return; const previousOverflow = document.body.style.overflow; document.body.style.overflow = 'hidden'; return () => { document.body.style.overflow = previousOverflow; }; }, [open]); useEffect(() => { if (!open) return; const onKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') onClose(); }; window.addEventListener('keydown', onKeyDown); return () => window.removeEventListener('keydown', onKeyDown); }, [open, onClose]); return ( {open && (
{ if (!open) return; const focusable = panelRef.current?.querySelector( 'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])' ); focusable?.focus(); }} >

{icon} {title}

{children}
)}
); }