import { useEffect, type ReactNode } from 'react' import { createPortal } from 'react-dom' type ModalProps = { open: boolean onClose: () => void title?: string children: ReactNode width?: number footer?: ReactNode } export function Modal({ open, onClose, title, children, width = 560, footer }: ModalProps) { useEffect(() => { if (!open) return const handleEsc = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } document.addEventListener('keydown', handleEsc) return () => document.removeEventListener('keydown', handleEsc) }, [open, onClose]) if (!open) return null return createPortal(
{/* Backdrop */}
{/* Modal content */}
{title && (

{title}

)}
{children}
{footer && (
{footer}
)}
, document.body, ) }