Vitral 0.2
Messages

Toast

Notifications sent from anywhere with useToast, stacked at a chosen position, that pause their timer while hovered or focused.

Import

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

Severities

Four seconds each; hover one to keep it.

<script setup lang="ts">import { Button, Toast, useToast } from '@vitral/vue'; const toast = useToast();const severities = [    { severity: 'success', summary: 'Saved', detail: 'Your changes are live.' },    { severity: 'info', summary: 'Update available', detail: 'Restart to install version 2.4.' },    { severity: 'warn', summary: 'Storage almost full', detail: '92% of 15 GB used.' },    { severity: 'danger', summary: 'Upload failed', detail: 'The connection was reset.' },    { severity: 'secondary', summary: 'Synced', detail: 'Everything is up to date.' },    { severity: 'contrast', summary: 'Copied', detail: 'The link is on your clipboard.' }] as const; // A group of its own, so only this example's <Toast> shows these messages// when another <Toast> is on the page.function show(index: number) {    toast.add({ ...severities[index]!, group: 'severities', life: 4000 });}</script> <template>    <Toast group="severities" />    <Button v-for="(s, i) in severities" :key="s.severity" :label="s.severity" severity="secondary" @click="show(i)" /></template>

Sticky and grouped

Without a `life` a toast waits to be closed. A `group` sends it to another `<Toast>`, here one at the bottom.

<script setup lang="ts">import { Button, Toast, useToast } from '@vitral/vue'; const toast = useToast(); // Each <Toast> has a group, so it shows only the messages sent to it// when another <Toast> is on the page.function sticky() {    toast.add({ group: 'sticky', severity: 'info', summary: 'Stays until closed', detail: 'No life, so it waits for you.' });} function bottom() {    toast.add({ group: 'bc', severity: 'success', summary: 'Message sent', life: 3000 });}</script> <template>    <Toast group="sticky" />    <Toast position="bottom-center" group="bc" />    <Button label="Sticky" severity="secondary" @click="sticky" />    <Button label="Bottom centre" severity="secondary" @click="bottom" />    <Button label="Clear all" severity="secondary" variant="outlined" @click="toast.removeAll()" /></template>

API

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

Props

NameTypeDescription
positionToastPositionDefaults to `'top-right'`.
groupstringShows only the messages sent with the same `group`.

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

Emits

EventPayloadDescription
closeevent: ToastEventClosed by its close button.
life-endevent: ToastEventClosed because its `life` ran out.

Slots

NameSlot propsDescription
message(props: { message: ToastMessage })Replaces the icon and text of each message; the close button stays.
container(props: { message: ToastMessage; closeCallback: () => void })Replaces the whole card's inside, close button included.
closeicon——