'use client'; import React, { type ReactNode, type KeyboardEvent as ReactKeyboardEvent, } from 'react'; import { Box } from './Box'; import { Text } from './Text'; import { Heading } from './Heading'; import { Button } from './Button'; interface ModalProps { title: string; description?: string; children?: ReactNode; primaryActionLabel?: string; secondaryActionLabel?: string; onPrimaryAction?: () => void | Promise; onSecondaryAction?: () => void; onOpenChange?: (open: boolean) => void; isOpen: boolean; } export function Modal({ title, description, children, primaryActionLabel, secondaryActionLabel, onPrimaryAction, onSecondaryAction, onOpenChange, isOpen, }: 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 ( {title} {description && ( {description} )} {children} {(primaryActionLabel || secondaryActionLabel) && ( {secondaryActionLabel && ( )} {primaryActionLabel && ( )} )} ); }