import React, { useEffect } from 'react'; import { FiX } from 'react-icons/fi'; export interface ModalProps { isOpen: boolean; onClose: () => void; title?: React.ReactNode; description?: React.ReactNode; size?: 'sm' | 'md' | 'lg' | 'xl' | '2xl' | 'full'; children: React.ReactNode; footer?: React.ReactNode; closeOnOverlayClick?: boolean; showCloseButton?: boolean; className?: string; } const sizeStyles = { sm: 'max-w-md', md: 'max-w-lg', lg: 'max-w-2xl', xl: 'max-w-4xl', '2xl': 'max-w-6xl', full: 'max-w-[95vw] h-[90vh]', }; export const Modal: React.FC = ({ isOpen, onClose, title, description, size = 'md', children, footer, closeOnOverlayClick = true, showCloseButton = true, className = '', }) => { // ESC key handler and body scroll lock useEffect(() => { if (!isOpen) return; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { onClose(); } }; const originalOverflow = document.body.style.overflow; document.body.style.overflow = 'hidden'; window.addEventListener('keydown', handleKeyDown); return () => { document.body.style.overflow = originalOverflow; window.removeEventListener('keydown', handleKeyDown); }; }, [isOpen, onClose]); if (!isOpen) return null; return (
{/* Backdrop */}
{ if (closeOnOverlayClick) onClose(); }} className="fixed inset-0 bg-slate-950/70 backdrop-blur-md transition-opacity animate-fadeIn" /> {/* Modal Dialog Card */}
{/* Header */} {(title || description || showCloseButton) && (
{title && (

{title}

)} {description && (

{description}

)}
{showCloseButton && ( )}
)} {/* Body Content */}
{children}
{/* Footer */} {footer && (
{footer}
)}
); };