Guides
Toasts, alerts and dialogs
Tell the user what happened with toasts, alerts, confirmation dialogs and empty states.
Pick the pattern by how important the message is and how long it should stay.
Pattern | Use it when | API |
|---|---|---|
| Toast | An action finished: saved, sent, moved to the trash. | useToast() |
| Alert | Something on the page needs attention: late orders, overdue invoices. | BaseAlert |
| Form feedback | A form failed, succeeded or has invalid fields. | BaseFormFeedback |
| Confirmation | An action is destructive or hard to undo. | useConfirm() + BaseConfirmDialog |
| Empty state | A list has no items or a search found nothing. | BaseEmptyState |
| Result | A flow ended: payment done, account created. | BaseResultState |
Toasts
AppToast renders once in the layout. Call useToast() from anywhere:
const toast = useToast()
toast.success(t('orders.saved'))
toast.error(t('orders.saveFailed'), { description: t('orders.tryAgain') })
toast.info(t('files.moved'), {
action: { label: t('actions.undo'), onClick: restore },
})
Method | Notes |
|---|---|
success, info, warning, error, neutral | (title, options?). Errors stay until dismissed. |
promise(task, { loading, success, error }) | Shows a loading toast and turns it into success or error when the promise settles. |
show(message, { color }) | Shorthand used across the demo; color maps to a type. |
update(id, type, title), dismiss(id), clear() | Manage existing toasts. |
Options: description, action ({ label, onClick }), duration and progress. Identical toasts are merged into one with a counter. Durations and the maximum number on screen live in config/toast.config.ts.
Never add a local v-snackbar.
Alerts
<BaseAlert
type="warning"
:title="$t('orders.lateTitle', { count: late.length })"
:text="$t('orders.lateText')"
:action-text="$t('orders.showLate')"
@action="view = 'late'"
/>
type is info, success, warning or error. Use the #actions slot for more than one button. The alert sets role="alert" for errors and role="status" otherwise. Never use a raw v-alert.
Confirmation dialogs
useConfirm() turns a dialog into a promise:
<template>
<BaseButton button-type="danger" prepend-icon="trash-2" @click="removeSelected">
{{ $t('actions.delete') }}
</BaseButton>
<BaseConfirmDialog
v-model="isOpen"
icon="trash-2"
tone="error"
:title="$t('files.confirm.title')"
:message="$t('files.confirm.message')"
:confirm-label="$t('actions.delete')"
@confirm="accept"
@cancel="reject"
/>
</template>
<script setup lang="ts">
const { isOpen, ask, accept, reject } = useConfirm()
async function removeSelected() {
if (!(await ask())) return
remove(selected.value)
}
</script>
For irreversible actions such as deleting an account, pass confirm-text: the user must type it before the confirm button enables.
Empty and result states
<BaseEmptyState icon="search-x" :title="$t('orders.empty.title')" :text="$t('orders.empty.text')">
<template #actions>
<BaseButton @click="clearFilters">{{ $t('filters.clear') }}</BaseButton>
</template>
</BaseEmptyState>
BaseResultState has the same shape for the end of a flow, with a type of success, info, warning or error, optional details (label and value rows such as the order number) and align="center" for full-screen outcomes.
Actions without a backend
In the demo, buttons that need a server call useToast().show(t('apps.common.demoAction')). Replace those calls when you connect your API.