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 nameDescriptionParametersReturn value
showDialogDisplay message prompt pop-up window, including confirmation button by defaultoptions: DialogOptionsPromise<void>
showConfirmDialogDisplay message confirmation pop-up window, including confirm and cancel buttons by defaultoptions: DialogOptionsPromise<void>
closeDialogClose the currently displayed pop-up window-void
setDialogDefaultOptionsModify the default configuration, affecting all showDialog callsoptions: DialogOptionsvoid
resetDialogDefaultOptionsResets the default configuration, affecting all showDialog calls-void

DialogOptions

When calling methods such as showDialog, the following options are supported:

ParametersDescriptionTypeDefault value
titletitlestring-
widthPop-up window width, default unit is pxnumber | string320px
messagetext contentstring-
messageAlignContent alignment, optional values are left rightstringcenter
themeStyle, optional value is round-buttonstringdefault
classNameCustom class namestring | Array | object-
showConfirmButtonWhether to display the confirmation buttonbooleantrue
showCancelButtonWhether to display the cancel buttonbooleanfalse
confirmButtonTextConfirm button copystringConfirm
confirmButtonColorConfirm button colorstring#ee0a24
confirmButtonDisabledWhether to disable the confirm buttonbooleanfalse
cancelButtonTextCancel button copystringCancel
cancelButtonColorCancel button colorstringblack
cancelButtonDisabledWhether to disable the cancel buttonbooleanfalse
overlaywhether to display the mask layerbooleantrue
overlayClassCustom mask layer class namestring | Array | object-
overlayStyleCustom mask layer styleobject-
closeOnClickOverlayWhether to close the pop-up window after clicking the mask layerbooleanfalse
lockScrollWhether to lock background scrollingbooleantrue
beforeCloseCallback function before closing, return false to prevent closing, support returning Promise(action: string) => boolean | Promise<boolean>-
transitionanimation class name, equivalent to the name attribute of transitionstring-

Props

When calling Dialog through a component, the following Props are supported:

ParametersDescriptionTypeDefault value
v-model:showWhether to display the pop-up windowboolean-
titletitlestring-
widthPop-up window width, default unit is pxnumber | string640rpx
messagetext contentstring-
message-alignContent horizontal alignment, optional values are left right justifystringcenter
themeStyle, optional value is round-buttonstringdefault
show-confirm-buttonWhether to show the confirmation buttonbooleantrue
show-cancel-buttonWhether to show the cancel buttonbooleanfalse
confirm-button-textConfirm button copystringConfirm
confirm-button-colorConfirm button colorstring#ee0a24
confirm-button-disabledWhether to disable the confirm buttonbooleanfalse
cancel-button-textCancel button textstringCancel
cancel-button-colorCancel button colorstringblack
cancel-button-disabledWhether to disable the cancel buttonbooleanfalse
z-indexSet the z-index level of the pop-up window to a fixed valuenumber | string2000+
overlaywhether to display the mask layerbooleantrue
overlay-classCustom mask layer class namestring-
overlay-styleCustom mask layer styleobject-
close-on-click-overlayWhether to close the pop-up window after clicking the mask layerbooleanfalse
lock-scrollWhether to lock background scrollingbooleantrue
before-closeCallback function before closing, return false to prevent closing, support returning Promise(action: string) => boolean | Promise<boolean>-
transitionanimation class name, equivalent to the name attribute of transitionstring-

Events

When calling Dialog through a component, the following events are supported:

Event nameDescriptionCallback parameters
confirmTriggered when the confirm button is clicked-
cancelTriggered when the cancel button is clicked-
openTriggered when the pop-up window is opened-
closeTriggered when closing the pop-up window-
openedTriggered after the pop-up window is opened and the animation ends-
closedTriggered after the pop-up window is closed and the animation ends-

Slots

When calling Dialog through a component, the following slots are supported:

NameDescription
defaultcustom content
titlecustom title
footerCustomize 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.

NameDefaultDescription
--z-dialog-width640rpx-
--z-dialog-small-screen-width90%-
--z-dialog-font-sizevar(--z-font-size-lg)-
--z-dialog-transitionvar(--z-duration-base)-
--z-dialog-radius32rpx-
--z-dialog-backgroundvar(--z-background-2)-
--z-dialog-header-font-weightvar(--z-font-bold)-
--z-dialog-header-line-height48rpx-
--z-dialog-header-padding-top52rpx-
--z-dialog-header-isolated-paddingvar(--z-padding-lg) 0-
--z-dialog-message-paddingvar(--z-padding-lg)-
--z-dialog-message-font-sizevar(--z-font-size-md)-
--z-dialog-message-line-heightvar(--z-line-height-md)-
--z-dialog-message-max-height60vh-
--z-dialog-has-title-message-text-colorvar(--z-gray-7)-
--z-dialog-has-title-message-padding-topvar(--z-padding-xs)-
--z-dialog-button-height96rpx-
--z-dialog-round-button-height72rpx-
--z-dialog-confirm-button-text-colorvar(--z-primary-color)-