import type { FC, ReactNode } from 'react'; import { useEffect, useRef } from 'react'; import { X } from 'lucide-react'; import { cn } from '../../lib/utils'; import { Button } from './Button'; interface ModalProps { isOpen: boolean; onClose: () => void; title: ReactNode; children: ReactNode; maxWidth?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full'; footer?: ReactNode; } const maxWidthClasses: Record, string> = { sm: 'max-w-sm', md: 'max-w-md', lg: 'max-w-lg', xl: 'max-w-xl', '2xl': 'max-w-2xl', full: 'max-w-[calc(100vw-2rem)]', }; export const Modal: FC = ({ isOpen, onClose, title, children, maxWidth = 'md', footer, }) => { const contentRef = useRef(null); useEffect(() => { if (!isOpen) return; const originalOverflow = document.body.style.overflow; document.body.style.overflow = 'hidden'; const handleKey = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose(); }; document.addEventListener('keydown', handleKey); return () => { document.body.style.overflow = originalOverflow; document.removeEventListener('keydown', handleKey); }; }, [isOpen, onClose]); if (!isOpen) return null; return (
); }; export default Modal;