import React, { useEffect } from 'react'; export interface ActionDialogAction { label: string; onClick: () => void | Promise; variant?: 'primary' | 'secondary' | 'danger'; disabled?: boolean; autoFocus?: boolean; title?: string; } interface ActionDialogProps { open: boolean; title: string; children: React.ReactNode; actions: ActionDialogAction[]; onClose: () => void; } const backgroundByVariant: Record< NonNullable, string > = { primary: '#2563eb', secondary: '#e5e7eb', danger: '#dc2626', }; const colorByVariant: Record< NonNullable, string > = { primary: 'white', secondary: '#111827', danger: 'white', }; const ActionDialog: React.FC = ({ open, title, children, actions, onClose, }) => { useEffect(() => { if (!open) return; const handleKeyDown = (e: KeyboardEvent) => { if (e.key === 'Escape') { e.preventDefault(); onClose(); } }; window.addEventListener('keydown', handleKeyDown); return () => { window.removeEventListener('keydown', handleKeyDown); }; }, [open, onClose]); if (!open) return null; return (
{ if (e.target === e.currentTarget) { onClose(); } }} style={{ position: 'fixed', inset: 0, zIndex: 70, background: 'rgba(15, 23, 42, 0.55)', display: 'flex', alignItems: 'center', justifyContent: 'center', padding: '1rem', }} >

{title}

{children}
{actions.map((action) => { const variant = action.variant ?? 'secondary'; return ( ); })}
); }; export default ActionDialog;