"use client"; import { useEffect, useRef } from "react"; /* * A native , not a div with a fixed overlay. * * showModal() gives focus trapping, inert background, Escape and the top layer * for free — all four are things a hand-rolled overlay gets wrong, and the third * is the one staff will actually reach for. The only wiring needed is keeping * React state and the element's open state in step, and routing every close — * Escape, backdrop, button — through one onClose. */ export function Modal({ open, onClose, title, meta, footer, children, }: { open: boolean; onClose: () => void; title: string; meta?: React.ReactNode; footer?: React.ReactNode; children: React.ReactNode; }) { const ref = useRef(null); useEffect(() => { const el = ref.current; if (!el) return; if (open && !el.open) el.showModal(); if (!open && el.open) el.close(); }, [open]); return ( { e.preventDefault(); onClose(); }} /* Clicking the backdrop hits the dialog element itself, never a * child — so this closes on backdrop and not on content. */ onClick={(e) => { if (e.target === ref.current) onClose(); }} className="w-[min(44rem,94vw)] rounded border border-rule bg-panel p-0 text-ink shadow-lg backdrop:bg-[rgba(4,12,24,0.55)]" >

{title}

{meta && {meta}}
{children}
{footer && }
); }