Skip to content

MazDialogConfirm ​

MazDialogConfirm is a standalone component that dialogs with the user to show important information and propose confirmation. You should wait for this response with await.

Before use it, you should install the MazUi plugin in your project, follow instructions in Getting Started

INFO

This component uses MazDialog, so it inherits all its props

TIP

This component uses <Teleport to="body"> with MazBackdrop, so you can implement this component anywhere and it inherits all its props

Basic usage ​

vue
<script setup>
import MazDialogConfirm, { useMazDialogConfirm } from 'maz-ui/components/MazDialogConfirm'
import MazDialog from 'maz-ui/components/MazDialog'

import { ref } from 'vue'

const confirmDialog = ref(false)

const { showDialogAndWaitChoice, data } = useMazDialogConfirm()

data.value = {
  title: 'Delete user',
  message: 'Are you sure you want to delete this user?',
}

const buttons: DialogCustomButton[] = [
  {
    text: 'Cancel',
    type: 'reject',
    color: 'destructive',
    outlined: true,
    response: 'cancel',
    size: 'sm',
  },
  {
    text: 'Delete!',
    type: 'resolve',
    color: 'success',
    response: 'delete',
    size: 'lg',
  },
]

async function askToUser() {
  try {
    const acceptResponse = await showDialogAndWaitChoice('one')
    toast.success(acceptResponse, {
      position: 'top-right'
    })
    const rejectResponse = await showDialogAndWaitChoice('two')
    toast.success(rejectResponse, {
      position: 'top-right'
    })
    confirmDialog.value = true
  }
  catch (rejectResponse) {
    toast.error(rejectResponse, {
      position: 'top-right'
    })
  }
}
</script>

<template>
  <MazBtn @click="askToUser">
    Ask user
  </MazBtn>

  <MazDialogConfirm
    :data="dataPromiseOne"
    identifier="one"
  />

  <MazDialogConfirm identifier="two" :buttons="buttons">
    <template #title>
      Do you really want to delete this user?
    </template>
    <template #default>
      Are you really sure you want to delete this user?
    </template>
  </MazDialogConfirm>

  <MazDialog v-model="confirmDialog">
    <template #title>
      User deleted
    </template>
    <template #default>
      User has been deleted!
    </template>
    <template #footer="{ close }">
      <MazBtn @click="close">
        Ok
      </MazBtn>
    </template>
  </MazDialog>
</template>

Types ​

ts
interface MazDialogConfirmData {
  /**
   * Dialog title
   */
  title?: string
  /**
   * Dialog message
   */
  message?: string
  /**
   * Dialog custom buttons
   * @default [{ text: 'Confirm', color: 'success', type: 'accept' }, { text: 'Cancel', color: 'destructive', type: 'reject' }]
   * @type {MazDialogConfirmButton[]}
   */
  buttons?: MazDialogConfirmButton[]
}

// All props of MazBtn
interface MazDialogConfirmButton {
  text?: string
  block?: boolean
  color?: Color
  disabled?: boolean
  loading?: boolean
  outlined?: boolean
  rounded?: boolean
  size?: Size
  text: string
  type: 'accept' | 'reject'
  response?: unknown
}

type Color = 'primary'
    | 'secondary'
    | 'info'
    | 'success'
    | 'warning'
    | 'destructive'
    | 'accent'
    | 'contrast'
    | 'transparent'

type Size = 'mini' | 'xs' | 'sm' | 'md' | 'lg' | 'xl'

Props ​

NameDescriptionTypeRequiredDefaultPossible values
identifierUniq identifier of the dialog - This is used to identify the dialog in the statestringYes--
titleDialog title displayed in the header Title of the modal in headerstringNo--
messageDialog message displayed in the bodystringNo--
reject-textText for the reject button - will be applied only if buttons props is not providedstringNo--
reject-propsProps for the reject button - will be applied only if buttons props is not provided(Omit<MazBtnProps, "type"> & MazDialogConfirmButton)No{ color: 'destructive', type: 'reject', text: 'Cancel', response: 'reject' }-
hide-reject-buttonHide the reject button (unset: the value of useMazDialogConfirm().data, else shown)booleanNofalse-
accept-textText for the accept buttonstringNo--
accept-propsProps for the accept button - will be applied only if buttons props is not provided(Omit<MazBtnProps, "type"> & MazDialogConfirmButton)No{ color: 'success', type: 'accept', text: 'Confirm', response: 'accept' }-
hide-accept-buttonHide the accept button (unset: the value of useMazDialogConfirm().data, else shown)booleanNofalse-
buttonsButtons to display in the footerMazDialogConfirmButton[]No--
model-valueModal's model valuebooleanNo--
hide-close-buttonRemove the close button in headerbooleanNo--
max-widthModal's max-width.stringNoTheme preset components.dialog.max-widthviavar(--maz-dialog-max-width, 38rem)``-
min-widthModal's min-width.stringNoTheme preset components.dialog.min-widthviavar(--maz-dialog-min-width, 32rem)``-
scrollableModal's content becomes scrollable - warning: a overflow is appliedbooleanNo--
persistentPersistent dialog (not closable by clicking outside and remove close button)booleanNo--
teleport-selectorTeleport selectorstringNo--
before-closeFunction called before modal is close(() => void | Promise<void>)No--
close-on-escapePrevent close on escape keybooleanNotrue-
transition-nameTransition namestringNo--
backdrop-classBackdrop classClassValueNo--
backdrop-content-classBackdrop content classClassValueNo--
content-paddingAdd padding to the contentbooleanNo--
justifyJustify content"none" | "center" | "end" | "start" | "space-between" | "space-around"No-'none' | 'center' | 'end' | 'start' | 'space-between' | 'space-around'
alignAlign content"none" | "center" | "end" | "start"No-'none' | 'center' | 'end' | 'start'
variantVariant"bottom-sheet" | "dialog" | "drawer"No-'bottom-sheet' | 'dialog' | 'drawer'
aria-labelledbyID for aria-labelledbystringNo--
aria-describedbyID for aria-describedbystringNo--

Events ​

Event namePayloadDescription
openvalue?: void | undefinedEmitted when modal is open
closevalue?: void | undefinedEmitted when modal is close

Slots ​

NameDescriptionBindings
titletitle slot - Place your title-
defaultDefault slot - Place your contentaccept (reason?: unknown) => Promise<unknown> - accept function
reject (reason?: unknown) => Promise<unknown> - reject function
footer-buttonFooter slotaccept (reason?: unknown) => Promise<unknown> - accept function
reject (reason?: unknown) => Promise<unknown> - reject function

Expose ​

close ​

Close the dialog

isActive ​

Check if the dialog is active