Add export method dialog, extract shared Dialog primitive

Add export dialog with download/clipboard options and optional
undo/redo history inclusion (default off). Extract shared Dialog
component to ui/dialog.tsx, consolidating open/close lifecycle,
backdrop click, and escape key handling from all 6 dialog components.
Update spec to reflect export method dialog and optional history.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Lukas
2026-03-27 14:57:31 +01:00
parent 4969ed069b
commit 209df13c32
10 changed files with 218 additions and 193 deletions

View File

@@ -0,0 +1,50 @@
import { type ReactNode, useEffect, useRef } from "react";
import { cn } from "../../lib/utils.js";
interface DialogProps {
open: boolean;
onClose: () => void;
className?: string;
children: ReactNode;
}
export function Dialog({ open, onClose, className, children }: DialogProps) {
const dialogRef = useRef<HTMLDialogElement>(null);
useEffect(() => {
const dialog = dialogRef.current;
if (!dialog) return;
if (open && !dialog.open) dialog.showModal();
else if (!open && dialog.open) dialog.close();
}, [open]);
useEffect(() => {
const dialog = dialogRef.current;
if (!dialog) return;
function handleCancel(e: Event) {
e.preventDefault();
onClose();
}
function handleBackdropClick(e: MouseEvent) {
if (e.target === dialog) onClose();
}
dialog.addEventListener("cancel", handleCancel);
dialog.addEventListener("mousedown", handleBackdropClick);
return () => {
dialog.removeEventListener("cancel", handleCancel);
dialog.removeEventListener("mousedown", handleBackdropClick);
};
}, [onClose]);
return (
<dialog
ref={dialogRef}
className={cn(
"m-auto rounded-lg border border-border bg-card text-foreground shadow-xl backdrop:bg-black/50",
className,
)}
>
<div className="p-6">{children}</div>
</dialog>
);
}