import { useEffect, useRef } from 'react' import { X } from 'lucide-react' import { cn } from '../../utils/format' interface ModalProps { title: string onClose: () => void children: React.ReactNode /** Extra classes applied to the inner panel */ className?: string /** Width preset – defaults to 'md' */ size?: 'sm' | 'md' | 'lg' | 'xl' | 'full' } const sizeMap: Record, string> = { sm: 'max-w-sm', md: 'max-w-lg', lg: 'max-w-2xl', xl: 'max-w-4xl', full: 'max-w-full mx-4', } export default function Modal({ title, onClose, children, className, size = 'md' }: ModalProps) { const backdropRef = useRef(null) /* Close on Escape */ useEffect(() => { const handler = (e: KeyboardEvent) => { if (e.key === 'Escape') onClose() } window.addEventListener('keydown', handler) return () => window.removeEventListener('keydown', handler) }, [onClose]) /* Prevent scroll on body while modal is open */ useEffect(() => { document.body.style.overflow = 'hidden' return () => { document.body.style.overflow = '' } }, []) function handleBackdropClick(e: React.MouseEvent) { if (e.target === backdropRef.current) onClose() } return (
{/* Header */}
{/* Body */}
{children}
) }