import { useEffect, useRef } from "react"; import { Button } from "./Button"; export function ConfirmDialog({ open, title, body, confirmLabel = "Confirm", danger = false, busy = false, onConfirm, onCancel, }: { open: boolean; title: string; body: string; confirmLabel?: string; danger?: boolean; busy?: boolean; onConfirm: () => void; onCancel: () => void; }) { const cancelRef = useRef(null); useEffect(() => { if (!open) return; cancelRef.current?.focus(); const onKey = (e: KeyboardEvent) => { if (e.key === "Escape") onCancel(); }; window.addEventListener("keydown", onKey); return () => window.removeEventListener("keydown", onKey); }, [open, onCancel]); if (!open) return null; return (
{ if (e.target === e.currentTarget) onCancel(); }} >

{title}

{body}

); }