import React, { useEffect } from "react"; import { X } from "lucide-react"; interface ModalProps { isOpen: boolean; onClose: () => void; title: string; children: React.ReactNode; maxWidth?: "sm" | "md" | "lg" | "xl" | "2xl" | "4xl"; footer?: React.ReactNode; } export const Modal: React.FC = ({ isOpen, onClose, title, children, maxWidth = "lg", footer, }) => { useEffect(() => { const handleKeyDown = (e: KeyboardEvent) => { if (e.key === "Escape") { onClose(); } }; if (isOpen) { window.addEventListener("keydown", handleKeyDown); document.body.style.overflow = "hidden"; } return () => { window.removeEventListener("keydown", handleKeyDown); document.body.style.overflow = "unset"; }; }, [isOpen, onClose]); if (!isOpen) return null; const maxWidthStyles = { sm: "max-w-sm", md: "max-w-md", lg: "max-w-lg", xl: "max-w-xl", "2xl": "max-w-2xl", "4xl": "max-w-4xl", }; return (
e.stopPropagation()} >
{children}
{footer && (
{footer}
)}
); };