import { ComponentType, ReactNode } from 'react'; import { DialogButtonProps } from './dialog.doc'; import { ModalOptions } from './modal.doc'; export interface ModalShowOptions extends ModalOptions { /** * Whether to close modal on click outside of the modal element, defaults to * `true`. */ closeOnOutsideClick?: boolean; } export interface ModalShowOptionsWithButtons extends ModalShowOptions { buttons?: DialogButtonProps[]; } export interface ModalPromptOptions extends ModalShowOptions { initialValue?: string; placeholder?: string; } export interface ModalNoteOptions extends ModalShowOptions { placeholder?: string; } export interface DialogShowProps { /** * Should be an ReactNode, for example `` */ icon?: ReactNode; /** * Title of the dialog, should be an ReactNode */ title: ReactNode; /** * Content of the dialog, should be an ReactNode */ content: ReactNode; /** * Buttons to be shown in the dialog, each should be given a `value` with which * the promise will be resolved with to identify the clicked button. */ buttons?: DialogButtonProps[]; } export interface ModalContentProps { close(value?: T): void; } export interface IModalService { /** * The container for rendering modal DOM elements. */ readonly container: HTMLElement; /** * @observable */ readonly active: boolean; /** * Modals to be rendered within root component, should be put under theme provider. * * @observable */ readonly modals: ReactNode[]; /** * @param content Could be either a `ReactNode` or a component with * `ModalContentProps`, which provides a `close` handler for closing the * modal with specific value as result. */ show(content: ReactNode | ComponentType>>, options?: ModalShowOptions): Promise; showDialog(props: DialogShowProps, options: ModalShowOptions): Promise; /** * Show an alert dialog. */ alert(title: ReactNode, content: ReactNode, options: ModalShowOptions): Promise; /** * Show an info dialog. */ info(title: ReactNode, content: ReactNode, options: ModalShowOptions): Promise; /** * Show an success dialog. */ success(title: ReactNode, content: ReactNode, options: ModalShowOptions): Promise; /** * Show an error dialog. */ error(title: ReactNode, content: ReactNode, options: ModalShowOptions): Promise; /** * Show a confirm dialog. * @param modalOptions When undefined, `closeOnOutsideClick` defaults to `false` */ confirm(title: ReactNode, content: ReactNode, options: ModalShowOptions): Promise; /** * Show a prompt dialog */ prompt(title: ReactNode, options?: ModalPromptOptions): Promise; /** * Show a note dialog */ note(title: ReactNode, options?: ModalNoteOptions): Promise; /** * Show a warning dialog. */ warning(title: ReactNode, content: ReactNode, options: ModalShowOptions): Promise; }