"use client"; import { motion, AnimatePresence } from "framer-motion"; import { useEffect, useCallback, useRef, type ReactNode } from "react"; import { useFocusTrap } from "~/hooks/useFocusTrap.js"; interface AnimatedModalProps { open: boolean; onClose: () => void; children: ReactNode; className?: string; overlayClassName?: string; maxWidth?: string; disableBackdropClose?: boolean; } export function AnimatedModal({ open, onClose, children, className, overlayClassName, maxWidth = "max-w-xl", disableBackdropClose = false, }: AnimatedModalProps) { const panelRef = useRef(null); useFocusTrap(panelRef, open); const handleEscape = useCallback( (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }, [onClose], ); useEffect(() => { if (!open) return; document.addEventListener("keydown", handleEscape); return () => document.removeEventListener("keydown", handleEscape); }, [open, handleEscape]); return ( {open && (
{/* Overlay */}
)}
); }