Skip to content
🌏 Translated with the assistance of DeepSeek and ChatGPT

Dialog

When a dialog is triggered, the dialog will pop up.

TIP

Pixel-style components nested inside a Dialog no longer need pollSizeChange and render correctly on their own.

Basic Usage

The visible property controls the display and hiding of the dialog. When visible is passed, it enters controlled mode. If not passed or set to undefined, it is in uncontrolled mode, and the defaultVisible property can be provided as the default value.

Hide source code

Form in Dialog

This is just an example of using a form inside a dialog. As demonstrated by the example, you can directly pass attrs such as class and style through to the dialog container element.

Hide source code

Functional Usage

If you have fully registered the component library, you can use it in the following ways:

  • window.$dialog;
  • Inside a Vue component: getCurrentInstance().appContext.config.globalProperties.PixeliumVue.dialog;
  • Import from @pixelium/web-vue.

When using on-demand import, you can also import Dialog from @pixelium/web-vue/es for usage.

Hide source code

Asynchronous Confirmation

When onBeforeOk is provided, the confirmation process will wait for onBeforeOk to complete. If the result is not false, subsequent code will be executed.

Hide source code

API

Dialog Function

After calling a function on the Dialog, a Promise<boolean> is returned. If the dialog is closed via confirmation, the promise is fulfilled with true; otherwise, it is false.

ts
type DialogReturn = Promise<boolean> & {
	close: () => void
}

// ...
// Dialog
{
	[key in DialogOptions['type'] & string]: (
		options:
			| (Omit<DialogOptions, 'type'> & Omit<EmitEvent<DialogEvents>, 'update:visible'>)
			| string
	) => DialogReturn
}

Attrs

Just as demonstrated in the example above example, when used as a component, you can directly pass attributes such as class and style through to the dialog container element.

DialogOptions

AttributeTypeOptionalDefaultDescriptionVersion
contentValidContentFalseDialog content.0.1.0
titleValidContentTrueDialog title.0.1.0
iconValidVNodeContentTrueDialog title icon.0.1.0
footerValidVNodeContentTrueDialog footer area.0.1.0
type'info' | 'success' | 'warning' | 'error' | 'normal' | 'confirm' | 'notice'True'normal'Dialog type.0.1.0
closablebooleanTruetrueWhether to display the close button in the top-right corner.0.1.0
maskbooleanTruetrueWhether to display the mask layer.0.1.0
maskClosablebooleanTruetrueWhether the dialog can be closed by clicking the mask layer.0.1.0
escToClosebooleanTruetrueWhether the dialog can be closed by pressing the ESC key.0.1.0
showCancelbooleanTrueWhether to display the cancel button. If not set, it is influenced by the type field—only displayed when the type is 'confirm'.0.1.0
okTextstringTrueText content of the confirm button.0.1.0
cancelTextstringTrueText content of the cancel button.0.1.0
showFooterbooleanTruetrueWhether to display the dialog footer area.0.1.0
zIndexnumberTrueThe z-index property of the dialog.0.1.0
rootstring | HTMLElementTrue'body'The root element to which the dialog is mounted.0.1.0
okButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrsTrueProperties of the confirm button.0.1.0
cancelButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrsTrueProperties of the cancel button.0.1.0
maskPropsOmit<MaskProps, 'zIndex'>TrueProperties of the mask layer.0.1.0
containerPropsRestAttrsTrueProperties of the dialog container element.0.1.0
headerPropsRestAttrsTrueProperties of the dialog header area element.0.1.0
bodyPropsRestAttrsTrueProperties of the dialog content area element.0.1.0
footerPropsRestAttrsTrueProperties of the dialog footer area element.0.1.0

DialogProps

AttributeTypeOptionalDefaultDescriptionVersion
visibleboolean | nullTrueControls the display of the dialog (controlled mode), supports v-model.0.1.0
defaultVisibleboolean | nullTrueDefault value for controlling the display of the dialog (uncontrolled mode).0.1.0
titlestringTrue''Dialog title.0.1.0
closablebooleanTruetrueWhether to display the close button in the top-right corner.0.1.0
maskbooleanTruetrueWhether to display the mask layer.0.1.0
maskClosablebooleanTruetrueWhether the dialog can be closed by clicking the mask layer.0.1.0
escToClosebooleanTruetrueWhether the dialog can be closed by pressing the ESC key.0.1.0
showCancelbooleanTruetrueWhether to display the cancel button. If not set, it is influenced by the type field—only displayed when the type is 'confirm'.0.1.0
okTextstringTrueText content of the confirm button.0.1.0
cancelTextstringTrueText content of the cancel button.0.1.0
booleanbooleanTruefalse0.1.0
showFooterbooleanTruetrueWhether to display the dialog footer area.0.1.0
rootstring | HTMLElementTrue'body'The root element to which the dialog is mounted.0.1.0
zIndexnumberTrueThe z-index property of the dialog.0.1.0
destroyOnHidebooleanTruefalseWhether the dialog content is destroyed after hiding.0.1.0
okButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrsTrueProperties of the confirm button.0.1.0
cancelButtonPropsButtonProps & EmitEvent<ButtonEvents> & RestAttrsTrueProperties of the cancel button.0.1.0
maskPropsOmit<MaskProps, 'zIndex'>TrueProperties of the mask layer.0.1.0
containerPropsRestAttrsTrueProperties of the dialog container element.0.1.0
headerPropsRestAttrsTrueProperties of the dialog header area element.0.1.0
bodyPropsRestAttrsTrueProperties of the dialog content area element.0.1.0
footerPropsRestAttrsTrueProperties of the dialog footer area element.0.1.0

DialogSlots

SlotParameterDescriptionVersion
defaultDialog content.0.1.0
titleDialog title.0.1.0
iconDialog title icon.0.1.0
footerDialog footer area.0.1.0

DialogEvents

EventParameterDescriptionVersion
update:visibleUsed to update the visible value in controlled mode.0.1.0
beforeOkFor async confirmation. Must return a value of type Promise<boolean | void> | boolean | void to indicate success. Confirmation is successful if the result after await is not false.0.1.0
okevent: MouseEventCallback triggered when the dialog is successfully closed via confirmation.0.1.0
cancelevent: MouseEvent | KeyboardEventCallback triggered when the dialog is closed via cancellation, close button, mask layer, ESC key, etc.0.1.0
openCallback triggered when the dialog opens.0.1.0
afterOpenCallback triggered after the dialog opening animation ends.0.1.0
closeCallback triggered when the dialog closes.0.1.0
afterCloseCallback triggered after the dialog closing animation ends.0.1.0

DialogExpose

AttributeTypeOptionalDefaultDescriptionVersion
close() => voidFalseClose the dialog.0.1.0
open() => voidFalseOpen the dialog.0.1.0

ValidContent, ValidVNodeContent

ts
export type ValidContent = string | ((...args: any[]) => VNode | string | JSX.Element | null | void)
export type ValidVNodeContent = (...args: any[]) => VNode | JSX.Element

RestAttrs

ts
import type { StyleValue } from 'vue'

export type VueClassValue = string | Record<string, any> | VueClassValue[]
export type VueStyleValue = StyleValue

export type RestAttrs = {
	style?: VueStyleValue | null
	class?: VueClassValue | null
	[x: string]: any
}

EmitEvent

ts
export type EmitEvent<T extends Record<string, any>> = {
	[K in keyof T as `on${Capitalize<K & string>}`]?: (...args: T[K]) => void
}