Modal
Modal dialogs.
Examples
Basic
Asynchronously Close
Asynchronously close a modal dialog when a the OK button is pressed. For example, you can use this pattern when you submit a form.
Confirmation Modal Dialog
Use Modal.confirm() to show a confirmation modal dialog. The onOk and onCancel buttons can return a promise and will delay the modal from closing until completed.
Information Modal Dialog
The information modal dialog is used to communicate system status. Only one button is used to close the dialog.
Manually Updating and Destroying
Use Svelte's built in $set function to update the modal. The Modal.destroy() function will destroy a modal.
Positioning
You can use the centered prop, or set the verticalPosition's top or bottom to position the modal.
Destroying all Modals Open
Modal.destroyAll() will destroy all confirmation modal dialogs.
API
Attributes
| Property | Description | Type | Default |
|---|---|---|---|
| bodyStyle | Body style for modal body element. Such as height, padding etc. | String|Object | |
| cancelText | Text of the Cancel button. | String | Cancel |
| centered | Centered Modal | Boolean | false |
| closable | Whether a close (x) button is visible on top right of the modal dialog or not. | Boolean | true |
| closeIcon | Custom close icon. | SvelteComponent | CloseOutlined |
| confirmLoading | Whether to apply loading visual effect for OK button or not. | Boolean | false |
| mask | Whether show mask or not. | Boolean | true |
| maskClosable | Whether to close the modal dialog when the mask (area outside the modal) is clicked. | Boolean | true |
| maskStyle | Style for modal's mask element. | String|Object | |
| okText | Text of the OK button. | String | OK |
| okType | Button `type` of the OK button. | String | primary |
| okButtonProps | The OK button props. | Object | {} |
| cancelButtonProps | The Cancel button props. | Object | {} |
| verticalPosition | The vertical position of the modal (top or bottom) | Object | {} |
| title | The modal dialog's title | String | - |
| visible | Whether the modal dialog is visible or not. | Boolean | false |
| width | Width of the modal dialog. | String | 520px |
| wrapClassName | The class name of the container of the modal dialog. | String | - |
| zIndex | The `z-index` of the Modal. | Number | 1000 |
| autoFocusButton | Specify which button to autofocus when the modal opens. | null|'ok'|'cancel' | ok |
| keyboard | Whether the escape key will close the modal. | Boolean | true |
Events
| Name | Description |
|---|---|
| cancel | Specify a function that will be called when a user clicks mask, close button on top right or Cancel button. |
| ok | Specify a function that will be called when a user clicks the OK button. |
| undefined | Specify a function that will be called when modal is closed completely. |
Modal.method()
There are five ways to display the information based on the content's nature:
Modal.infoModal.successModal.errorModal.warningModal.confirm
The items listed above are all functions, expecting a settings object as parameter. The settings object takes any of the props above as attributes.
Note: The
closeableandmaskClosableprops default to false for these types of modals.
Additionally these options are available:
Modal.method() Attributes
| Property | Description | Type | Default |
|---|---|---|---|
| content | Content for the modal body. | String|SvelteComponent | - |
| icon | Custom icon to display next to the content. | SvelteComponent | Depends on the modal method |
| onCancel | Specify a function that will be called when a user clicks mask, close button on top right or Cancel button. | Function | - |
| onOk | Specify a function that will be called when a user clicks the OK button. | Function | - |