import { useEffect } from 'react'; import styles from './Modal.module.css'; export interface ModalProps { open: boolean; title: string; children?: React.ReactNode; onClose: () => void; footer?: React.ReactNode; /** `lg` widens the dialog for long, document-like content. */ size?: 'md' | 'lg'; } export function Modal({ open, title, children, onClose, footer, size = 'md' }: ModalProps) { useEffect(() => { if (!open) return; const onKeyDown = (event: KeyboardEvent) => { if (event.key === 'Escape') onClose(); }; window.addEventListener('keydown', onKeyDown); return () => window.removeEventListener('keydown', onKeyDown); }, [open, onClose]); if (!open) return null; return (
event.stopPropagation()} >

{title}

{/* Long (lg) content scrolls; make it focusable so the keyboard can scroll it. */}
{children}
{footer &&
{footer}
}
); }