Skip to main content

Modal

Modal dialogs.

When To Use#

When requiring users to interact with the application, but without jumping to a new page and interrupting the user's workflow, you can use Modal to create a new floating layer over the current page to get user feedback or display information.

Examples#

import { Modal, useModal } from 'tailor-ui';

Basic#

Status bar and icon#

Large size#

Customized header#

Customized footer#

Without footer#

With button props#

onOpenComplete & onCloseComplete#

useModal Hooks#

You can use the useModal hooks to display Modal without render Modal component in your component.

Confirm#

Using callback#
Using promise#

With other status#

Set closable to true#
Manual to update and close#

API#

Modal#

PropertyDescriptionTypeDefault
titleThe modal dialog's titleReactNode
visibleWhether the modal dialog is visible or notboolean
closableCall onCancel when click the close (x) button or modal maskbooleantrue
statusShow the status bar and header icon in modal or null/undefined for no status bar'info' | 'success' | 'warning' | 'error' | null | undefined
sizeThe size of modal'md' | 'lg''md'
footerFooter content, set as footer={null} when you don't need default buttonsReactNode | nullConfirm and Cancel buttons
onOpenCompleteWhether to mount child components on onClose() => void
onCloseCompleteWhether to unmount child components on onClose() => void
confirmTextText of the Confirm buttonstringConfirm
cancelTextText of the Cancel buttonstringCancel
onConfirmSpecify a function that will be called when a user clicks the Confrim button(event: MouseEvent) => void
onCancelSpecify a function that will be called when a user clicks mask, close button on top right or Cancel button(event: MouseEvent) => void
confirmButtonPropsThe confirm button propsButtonProps
cancelButtonPropsThe cancel button propsButtonProps
contentStyleThe style of modal contentCSSProperties
footerStyleThe style of modal footerCSSProperties

Hooks#

const modal = useModal();
  • modal.confirm(options) => ReturnValue
  • modal.info(options) => ReturnValue
  • modal.success(options) => ReturnValue
  • modal.warning(options) => ReturnValue
  • modal.error(options) => ReturnValue

The ReturnValue can destructing by array or object:

  • [confirmation, close, update]
  • { confirmation, close, update }

Below is the type of ReturnValue:

  • confirmation: Promise<boolean>
  • close: () =>void
  • update: (options) => void

options#

PropertyDescriptionTypeDefault
closableShow cancel button or notbooleantrue if call model.confirm, otherwise will be false
cancelTextText of the Cancel buttonstringCancel
confirmTextText of the Confirm buttonstringConfirm
onCancelSpecify a function that will be called when the user clicks the Cancel button. The parameter of this function is a function whose execution should include closing the dialog.() => void
onConfirmSpecify a function that will be called when the user clicks the OK button. The parameter of this function is a function whose execution should include closing the dialog.() => void
titleTitleReactNode
contentcontent of the messageReactNode

The options of update function does not accept onConfirm & onCancel.