"use client"; import { createPortal } from "react-dom"; import { ReactNode } from "react"; const MAX_WIDTH_MAP = { sm: "max-w-sm", md: "max-w-md", lg: "max-w-lg", xl: "max-w-xl", "2xl": "max-w-2xl", "3xl": "max-w-3xl", } as const; interface ModalProps { isOpen: boolean; onClose: () => void; title?: string; children: ReactNode; maxWidth?: keyof typeof MAX_WIDTH_MAP; /** Disable closing via backdrop click (e.g. while a form is submitting) */ disableClose?: boolean; } export function Modal({ isOpen, onClose, title, children, maxWidth = "2xl", disableClose = false }: ModalProps) { if (!isOpen) return null; return createPortal( <> {/* Backdrop */}
!disableClose && onClose()} /> {/* Container */}
{/* Header */} {title && (

{title}

)} {/* Body */} {children}
, document.body ); }