import React, { type KeyboardEvent as ReactKeyboardEvent, type ReactNode, } from 'react'; import { Box } from './Box'; import { Button } from './Button'; import { Heading } from './Heading'; import { Stack } from './Stack'; import { Text } from './Text'; interface ModalProps { title: string; description?: string; icon?: ReactNode; children?: ReactNode; primaryActionLabel?: string; secondaryActionLabel?: string; onPrimaryAction?: () => void | Promise; onSecondaryAction?: () => void; onOpenChange?: (open: boolean) => void; isOpen: boolean; footer?: ReactNode; } export function Modal({ title, description, icon, children, primaryActionLabel, secondaryActionLabel, onPrimaryAction, onSecondaryAction, onOpenChange, isOpen, footer, }: ModalProps) { const handleKeyDown = (event: ReactKeyboardEvent) => { if (event.key === 'Escape') { if (onOpenChange) { onOpenChange(false); } return; } }; const handleBackdropClick = (event: React.MouseEvent) => { if (event.target === event.currentTarget && onOpenChange) { onOpenChange(false); } }; if (!isOpen) { return null; } return ( {icon && {icon}} {title} {description && ( {description} )} {children} {(primaryActionLabel || secondaryActionLabel || footer) && ( {(primaryActionLabel || secondaryActionLabel) && ( {secondaryActionLabel && ( )} {primaryActionLabel && ( )} )} {footer && ( {footer} )} )} ); }