import React, { useEffect, useRef } from 'react' import styles from './Modal.module.css' export interface ModalProps { open: boolean onClose: () => void title?: string children: React.ReactNode footer?: React.ReactNode width?: 'sm' | 'md' | 'lg' | 'xl' closeOnOverlayClick?: boolean } export const Modal: React.FC = ({ open, onClose, title, children, footer, width = 'md', closeOnOverlayClick = true }) => { const dialogRef = useRef(null) useEffect(() => { const dialog = dialogRef.current if (!dialog) return if (open) { dialog.showModal() } else { dialog.close() } }, [open]) const handleOverlayClick = (e: React.MouseEvent) => { if (closeOnOverlayClick && e.target === dialogRef.current) { onClose() } } if (!open) return null return (
{/* Header */} {title && (

{title}

)} {/* Body */}
{children}
{/* Footer */} {footer &&
{footer}
}
) } export default Modal