Dialog popup box
introduce
Pop-up modal boxes are often used for message prompts, message confirmation, or to complete specific interactive operations within the current page. Supports both component calling and function calling.
Function call
In order to facilitate the use of Dialog
, zebra provides a series of auxiliary functions through which global pop-up components can be quickly evoked.
For example, using the showDialog
function, the corresponding pop-up box will be rendered directly on the page after being called.
import { useDialog } from '../../uni_modules/zebra-ui'
const dialog = useDialog()
dialog.showDialog({ title: 'Title', message: 'This is a sample prompt' })
Code Demo
notification
Used to prompt some messages, which only contains a confirmation button by default.
import { useDialog } from '../../uni_modules/zebra-ui'
const dialog = useDialog()
dialog.showDialog({ title: 'Title', message: 'This is a sample prompt' })
Message confirmation
Used to confirm messages, including confirm and cancel buttons by default.
dialog.showConfirmDialog({
title: 'title',
message: 'This is a sample prompt'
})
Rounded button style
Set the theme option to round-button
to display a rounded button style popup.
dialog.showDialog({
title: 'title',
theme: 'round-button',
message: 'This is a sample prompt'
})
Asynchronous shutdown
A callback function can be passed in through the beforeClose
attribute to perform specific operations before the pop-up window is closed.
const showDialogMethod = () => {
dialog.showConfirmDialog({
title: 'title',
message: 'Asynchronous shutdown example',
beforeClose
})
}
const beforeClose = (action: any) =>
new Promise((resolve) => {
setTimeout(() => {
// action !== 'confirm' intercepts the cancellation operation
resolve(action === 'confirm')
}, 1000)
})
Using Dialog component
If you need to embed components or other custom content within Dialog, you can use the Dialog component directly and use the default slots for customization.
<z-dialog
v-model:show="show"
use-component
title="title"
show-cancel-button
>
<z-picker :columns="columns" :show-toolbar="false" />
</z-dialog>
import { ref } from 'vue';
const show = ref(false);
API
method
Zebra exports the following Dialog-related auxiliary functions:
Method name | Description | Parameters | Return value |
---|---|---|---|
showDialog | Display message prompt pop-up window, including confirmation button by default | options: DialogOptions | Promise<void> |
showConfirmDialog | Display message confirmation pop-up window, including confirm and cancel buttons by default | options: DialogOptions | Promise<void> |
closeDialog | Close the currently displayed pop-up window | - | void |
setDialogDefaultOptions | Modify the default configuration, affecting all showDialog calls | options: DialogOptions | void |
resetDialogDefaultOptions | Resets the default configuration, affecting all showDialog calls | - | void |
DialogOptions
When calling methods such as showDialog
, the following options are supported:
Parameters | Description | Type | Default value |
---|---|---|---|
title | title | string | - |
width | Pop-up window width, default unit is px | number | string | 320px |
message | text content | string | - |
messageAlign | Content alignment, optional values are left right | string | center |
theme | Style, optional value is round-button | string | default |
className | Custom class name | string | Array | object | - |
showConfirmButton | Whether to display the confirmation button | boolean | true |
showCancelButton | Whether to display the cancel button | boolean | false |
confirmButtonText | Confirm button copy | string | Confirm |
confirmButtonColor | Confirm button color | string | #ee0a24 |
confirmButtonDisabled | Whether to disable the confirm button | boolean | false |
cancelButtonText | Cancel button copy | string | Cancel |
cancelButtonColor | Cancel button color | string | black |
cancelButtonDisabled | Whether to disable the cancel button | boolean | false |
overlay | whether to display the mask layer | boolean | true |
overlayClass | Custom mask layer class name | string | Array | object | - |
overlayStyle | Custom mask layer style | object | - |
closeOnClickOverlay | Whether to close the pop-up window after clicking the mask layer | boolean | false |
lockScroll | Whether to lock background scrolling | boolean | true |
beforeClose | Callback function before closing, return false to prevent closing, support returning Promise | (action: string) => boolean | Promise<boolean> | - |
transition | animation class name, equivalent to the name attribute of transition | string | - |
Props
When calling Dialog
through a component, the following Props are supported:
Parameters | Description | Type | Default value |
---|---|---|---|
v-model:show | Whether to display the pop-up window | boolean | - |
title | title | string | - |
width | Pop-up window width, default unit is px | number | string | 640rpx |
message | text content | string | - |
message-align | Content horizontal alignment, optional values are left right justify | string | center |
theme | Style, optional value is round-button | string | default |
show-confirm-button | Whether to show the confirmation button | boolean | true |
show-cancel-button | Whether to show the cancel button | boolean | false |
confirm-button-text | Confirm button copy | string | Confirm |
confirm-button-color | Confirm button color | string | #ee0a24 |
confirm-button-disabled | Whether to disable the confirm button | boolean | false |
cancel-button-text | Cancel button text | string | Cancel |
cancel-button-color | Cancel button color | string | black |
cancel-button-disabled | Whether to disable the cancel button | boolean | false |
z-index | Set the z-index level of the pop-up window to a fixed value | number | string | 2000+ |
overlay | whether to display the mask layer | boolean | true |
overlay-class | Custom mask layer class name | string | - |
overlay-style | Custom mask layer style | object | - |
close-on-click-overlay | Whether to close the pop-up window after clicking the mask layer | boolean | false |
lock-scroll | Whether to lock background scrolling | boolean | true |
before-close | Callback function before closing, return false to prevent closing, support returning Promise | (action: string) => boolean | Promise<boolean> | - |
transition | animation class name, equivalent to the name attribute of transition | string | - |
Events
When calling Dialog
through a component, the following events are supported:
Event name | Description | Callback parameters |
---|---|---|
confirm | Triggered when the confirm button is clicked | - |
cancel | Triggered when the cancel button is clicked | - |
open | Triggered when the pop-up window is opened | - |
close | Triggered when closing the pop-up window | - |
opened | Triggered after the pop-up window is opened and the animation ends | - |
closed | Triggered after the pop-up window is closed and the animation ends | - |
Slots
When calling Dialog
through a component, the following slots are supported:
Name | Description |
---|---|
default | custom content |
title | custom title |
footer | Customize bottom button area |
Theme customization
Style variables
The component provides the following CSS variables, which can be used to customize styles. For usage, please refer to ConfigProvider component.
Name | Default | Description |
---|---|---|
--z-dialog-width | 640rpx | - |
--z-dialog-small-screen-width | 90% | - |
--z-dialog-font-size | var(--z-font-size-lg) | - |
--z-dialog-transition | var(--z-duration-base) | - |
--z-dialog-radius | 32rpx | - |
--z-dialog-background | var(--z-background-2) | - |
--z-dialog-header-font-weight | var(--z-font-bold) | - |
--z-dialog-header-line-height | 48rpx | - |
--z-dialog-header-padding-top | 52rpx | - |
--z-dialog-header-isolated-padding | var(--z-padding-lg) 0 | - |
--z-dialog-message-padding | var(--z-padding-lg) | - |
--z-dialog-message-font-size | var(--z-font-size-md) | - |
--z-dialog-message-line-height | var(--z-line-height-md) | - |
--z-dialog-message-max-height | 60vh | - |
--z-dialog-has-title-message-text-color | var(--z-gray-7) | - |
--z-dialog-has-title-message-padding-top | var(--z-padding-xs) | - |
--z-dialog-button-height | 96rpx | - |
--z-dialog-round-button-height | 72rpx | - |
--z-dialog-confirm-button-text-color | var(--z-primary-color) | - |