// @flow strict import * as React from 'react'; import {TEXT_COLORS} from '../../types/typography'; import classify from '../../utils/classify'; import {Button} from '../Button'; import {Icon} from '../Icon'; import type {ModalProps} from '../Modal'; import {Modal} from '../Modal'; import css from './Dialog.module.css'; type FooterClassNames = $ReadOnly<{ wrapper?: string, actions?: string, }>; export const DIALOG_SEMANTIC = Object.freeze({ neutral: 'neutral', success: 'success', information: 'information', warning: 'warning', danger: 'danger', }); export type DialogSemanticType = $Values; export type DialogHeaderProps = { children?: React.Node, className?: string, }; export type DialogFooterProps = { children?: React.Node, classNames?: FooterClassNames, }; export type DialogBodyProps = { children?: React.Node, className?: string, }; export type DialogPropsBase = { ...ModalProps, }; export type DialogProps = { ...DialogPropsBase, semantic?: DialogSemanticType, iconName?: string, }; export type BasicDialogProps = { ...DialogProps, heading?: React.Node, body?: React.Node, confirmText?: string, abortText?: string, handleConfirm?: (event: SyntheticEvent<>) => mixed, handleAbort?: (event: SyntheticEvent<>) => mixed, }; const DialogIcon = ({ semantic, iconName, }: { semantic: DialogSemanticType, iconName: string, }) => { switch (semantic) { case DIALOG_SEMANTIC.neutral: return ( ); case DIALOG_SEMANTIC.success: return ( ); case DIALOG_SEMANTIC.information: return ( ); case DIALOG_SEMANTIC.warning: return ( ); case DIALOG_SEMANTIC.danger: return ( ); default: return ( ); } }; export const DialogHeader = ({ children, className, }: DialogHeaderProps): React.Node => ( <> {React.Children.count(children) > 0 && (
{children}
)} ); export const DialogBody = ({ children, className, }: DialogBodyProps): React.Node => (
{children}
); export const DialogFooter = ({ children, classNames, }: DialogFooterProps): React.Node => ( <> {React.Children.count(children) > 0 && (
{children}
)} ); export const Dialog = ({ children, isOpen = false, hideBackdrop = false, onClose, tapOutsideToClose = false, iconName = '', semantic = 'neutral', classNames, ...restDialogProps }: DialogProps): React.Node => (
{children}
); export const BasicDialog = ({ heading, body, confirmText, abortText, handleConfirm, handleAbort, ...restDialogProps }: BasicDialogProps): React.Node => ( {!!heading && {heading}} {!!body && {body}} {!!abortText && ( )} {!!confirmText && ( )} );