import React, { useEffect } from 'react'; import { clsx } from 'clsx'; import { X } from 'lucide-react'; import { Button } from './Button'; export interface ModalProps { isOpen: boolean; onClose: () => void; title: string; children: React.ReactNode; size?: 'sm' | 'md' | 'lg' | 'xl'; showCloseButton?: boolean; closeOnOverlayClick?: boolean; className?: string; } export const Modal: React.FC = ({ isOpen, onClose, title, children, size = 'md', showCloseButton = true, closeOnOverlayClick = true, className }) => { // Handle escape key useEffect(() => { if (!isOpen) {return;} const handleEscape = (event: KeyboardEvent) => { if (event.key === 'Escape') { onClose(); } }; document.addEventListener('keydown', handleEscape); return () => document.removeEventListener('keydown', handleEscape); }, [isOpen, onClose]); // Prevent body scroll when modal is open useEffect(() => { if (isOpen) { document.body.style.overflow = 'hidden'; } else { document.body.style.overflow = 'unset'; } return () => { document.body.style.overflow = 'unset'; }; }, [isOpen]); if (!isOpen) {return null;} const sizeClasses = { sm: 'max-w-md', md: 'max-w-lg', lg: 'max-w-2xl', xl: 'max-w-4xl' }; const handleOverlayClick = (e: React.MouseEvent) => { if (closeOnOverlayClick && e.target === e.currentTarget) { onClose(); } }; return (
{/* Backdrop */} ); }; export default Modal;