Vitral 0.2.18
Overlay

ConfirmDialog

A modal question before an action, opened from anywhere with useConfirm, that can default to the safe answer.

Import

main.ts
import { ConfirmDialog } from '@vitral/vue';

Severity

The icon and the accept button take the severity’s colour.

<script setup lang="ts">import { Button, ConfirmDialog, Toast, useConfirm, useToast } from '@vitral/vue'; const confirm = useConfirm();const toast = useToast(); function remove() {    confirm.require({        header: 'Delete “Quarterly report.xlsx”?',        message: 'The file moves to the recycle bin for 30 days, then it is gone for good.',        severity: 'danger',        acceptLabel: 'Delete',        rejectLabel: 'Cancel',        defaultFocus: 'reject',        accept: () => toast.add({ severity: 'success', summary: 'Deleted', detail: 'Quarterly report.xlsx', life: 3000 }),        reject: () => toast.add({ severity: 'secondary', summary: 'Kept', detail: 'Nothing was deleted.', life: 3000 })    });} function publish() {    confirm.require({        header: 'Publish changes?',        message: 'Everyone with access will see the new version.',        severity: 'info',        acceptLabel: 'Publish',        rejectLabel: 'Not now',        accept: () => toast.add({ severity: 'info', summary: 'Published', life: 3000 })    });}</script> <template>    <ConfirmDialog />    <Toast />    <Button label="Delete file" icon="trash" severity="danger" @click="remove" />    <Button label="Publish" icon="upload" @click="publish" /></template>

Without a header

The labels come from the locale and the dialog is named “Confirmation”.

<script setup lang="ts">import { Button, ConfirmDialog, Toast, useConfirm, useToast } from '@vitral/vue'; const confirm = useConfirm();const toast = useToast(); // A group of its own, so this dialog and its toasts answer only these calls// when another <ConfirmDialog> or <Toast> is on the page.function plain() {    confirm.require({ group: 'leave', message: 'Leave without saving?', accept: () => toast.add({ group: 'leave', summary: 'Left the page', life: 2000 }) });}</script> <template>    <ConfirmDialog group="leave" />    <Toast group="leave" />    <Button label="Leave page" severity="secondary" @click="plain" /></template>

API

Read from packages/vue/src/components/ConfirmDialog/types.ts, so it says what the component actually accepts.

Props

NameTypeDescription
group stringAnswers only the `useConfirm().require()` calls sent with the same `group`.
draggable booleanMove the dialog by dragging its header. Defaults to true.
keepInViewport booleanWhile it is dragged, keep the whole dialog on the screen. Defaults to true.

Plus pt, dt and unstyled from BaseProps, see pass-through and unstyled mode.

Slots

NameSlot propsDescription
message (props: { message: ConfirmOptions })Replaces the message text; it still describes the dialog.
icon (props: { message: ConfirmOptions })—