import { ReactNode } from 'react'; import { Button } from '@@/buttons'; import { ButtonOptions, ModalType } from './types'; import { openModal } from './open-modal'; import { Modal, OnSubmit } from './Modal'; export interface DialogOptions { title?: ReactNode; message: ReactNode; modalType?: ModalType; buttons: Array>; } interface Props extends DialogOptions { onSubmit: OnSubmit; } export function Dialog({ buttons, message, title, onSubmit, modalType, }: Props) { const ariaLabel = requireString(title) || requireString(message) || 'Dialog'; return ( onSubmit()} aria-label={ariaLabel}> {title && } {message} {buttons.map((button, index) => ( ))} ); } function requireString(value: ReactNode) { return typeof value === 'string' ? value : undefined; } export async function openDialog(options: DialogOptions) { return openModal, T>(Dialog, options); }