"use client"; import * as React from "react"; import { createPortal } from "react-dom"; import { motion, AnimatePresence } from "framer-motion"; import { X } from "lucide-react"; import { cn } from "../utils/cn"; interface ModalProps { isOpen: boolean; onClose: () => void; title: string; children: React.ReactNode; maxWidth?: string; } export function Modal({ isOpen, onClose, title, children, maxWidth = "max-w-lg", }: ModalProps) { const [mounted, setMounted] = React.useState(false); React.useEffect(() => { setMounted(true); return () => setMounted(false); }, []); // Close on escape key React.useEffect(() => { const handleEsc = (e: KeyboardEvent) => { if (e.key === "Escape") onClose(); }; window.addEventListener("keydown", handleEsc); return () => window.removeEventListener("keydown", handleEsc); }, [onClose]); if (!mounted) return null; return createPortal( {isOpen && ( <>

{title}

{children}
)}
, document.body, ); }