Toast
A short message in the corner after an action, like "Saved". It goes away by itself. Same markup and props in every style: switch the style in the header to see it change.
Basic
Press the button. In HTML, add data-vin-toast="Title" to a button, or call VinUI.toast({ title }).
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Changes saved">Save changes</button>import { Toaster, toast } from "@/components/vin/toast";
import { Button } from "@/components/vin/button";
export function ToastBasic() {
return (
<>
<Button variant="outline" onClick={() => toast("Changes saved")}>Save changes</Button>
<Toaster />
</>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Toaster, { toast } from "@/components/vin/toast.vue";
import Button from "@/components/vin/button.vue";
</script>
<template>
<Button variant="outline" @click="toast('Changes saved')">Save changes</Button>
<Toaster />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import { toast } from "$lib/components/vin/toast.svelte";
import Toaster from "$lib/components/vin/toast-toaster.svelte";
import Button from "$lib/components/vin/button.svelte";
</script>
<Button variant="outline" onclick={() => toast("Changes saved")}>Save changes</Button>
<Toaster />Success, error and action
Icons for success and errors, and an action such as Undo.
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Payment received" data-vin-toast-description="We've emailed your receipt." data-vin-toast-variant="success">Success</button>
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Upload failed" data-vin-toast-description="The file is larger than 10 MB." data-vin-toast-variant="danger">Error</button>
<button type="button" class="vin-btn vin-btn--outline" data-vin-toast="Message archived" data-vin-toast-action="Undo">With action</button>import { Toaster, toast } from "@/components/vin/toast";
import { Button } from "@/components/vin/button";
export function ToastVariants() {
return (
<>
<Button variant="outline" onClick={() => toast({ title: "Payment received", description: "We've emailed your receipt.", variant: "success" })}>Success</Button>
<Button variant="outline" onClick={() => toast({ title: "Upload failed", description: "The file is larger than 10 MB.", variant: "danger" })}>Error</Button>
<Button variant="outline" onClick={() => toast({ title: "Message archived", action: { label: "Undo", onClick: () => {} } })}>With action</Button>
<Toaster />
</>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import Toaster, { toast } from "@/components/vin/toast.vue";
import Button from "@/components/vin/button.vue";
</script>
<template>
<Button variant="outline" @click="toast({ title: 'Payment received', description: 'We\'ve emailed your receipt.', variant: 'success' })">Success</Button>
<Button variant="outline" @click="toast({ title: 'Upload failed', description: 'The file is larger than 10 MB.', variant: 'danger' })">Error</Button>
<Button variant="outline" @click="toast({ title: 'Message archived', action: { label: 'Undo', onClick: () => {} } })">With action</Button>
<Toaster />
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import { toast } from "$lib/components/vin/toast.svelte";
import Toaster from "$lib/components/vin/toast-toaster.svelte";
import Button from "$lib/components/vin/button.svelte";
</script>
<Button
variant="outline"
onclick={() => toast({ title: "Payment received", description: "We've emailed your receipt.", variant: "success" })}>Success</Button
>
<Button variant="outline" onclick={() => toast({ title: "Upload failed", description: "The file is larger than 10 MB.", variant: "danger" })}>Error</Button>
<Button variant="outline" onclick={() => toast({ title: "Message archived", action: { label: "Undo", onClick: () => {} } })}>With action</Button>
<Toaster />How it looks
The same toast shown inline, for reference.
Payment received
We've emailed your receipt.
Message archived
<div style="display: grid; gap: 10px; width: 100%; max-width: 360px">
<div class="vin-toast vin-toast--success">
<svg class="vin-toast__icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="12" cy="12" r="9"/><path d="m8.5 12 2.5 2.5 4.5-5"/></svg>
<div class="vin-toast__content">
<p class="vin-toast__title">Payment received</p>
<p class="vin-toast__description">We've emailed your receipt.</p>
</div>
<button type="button" class="vin-btn vin-btn--ghost vin-btn--icon vin-toast__close" aria-label="Close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
</div>
<div class="vin-toast">
<div class="vin-toast__content">
<p class="vin-toast__title">Message archived</p>
<div class="vin-toast__actions">
<button type="button" class="vin-btn vin-btn--outline vin-btn--sm">Undo</button>
</div>
</div>
<button type="button" class="vin-btn vin-btn--ghost vin-btn--icon vin-toast__close" aria-label="Close"><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 6 6 18"/><path d="m6 6 12 12"/></svg></button>
</div>
</div>Payment received
We've emailed your receipt.
Message archived
import { Toast } from "@/components/vin/toast";
export function ToastAppearance() {
return (
<div style={{ display: "grid", gap: 10, width: "100%", maxWidth: 360 }}>
<Toast variant="success" title="Payment received" description="We've emailed your receipt." />
<Toast title="Message archived" action={{ label: "Undo", onClick: () => {} }} />
</div>
);
}The Vue version renders the same markup as the HTML tab, so it looks and works the same.
<script setup lang="ts">
import { Toast } from "@/components/vin/toast.vue";
</script>
<template>
<div style="display: grid; gap: 10px; width: 100%; max-width: 360px">
<Toast variant="success" title="Payment received" description="We've emailed your receipt." />
<Toast title="Message archived" :action="{ label: 'Undo', onClick: () => {} }" />
</div>
</template>The Svelte version renders the same markup as the HTML tab, so it looks and works the same.
<script lang="ts">
import Toast from "$lib/components/vin/toast.svelte";
</script>
<div style="display: grid; gap: 10px; width: 100%; max-width: 360px">
<Toast variant="success" title="Payment received" description="We've emailed your receipt." />
<Toast title="Message archived" action={{ label: "Undo", onClick: () => {} }} />
</div>Installation
React, Vue and Svelte: add the component to your project with the CLI. It reads your framework from vin.json and also copies any component this one needs. Then import it:
npx @vinish/ui add toastimport { Toaster, Toast, toast, dismissToast } from "@/components/vin/toast";import Toaster, { Toast, toast, dismissToast } from "@/components/vin/toast.vue";import Toast, { toast, dismissToast, toasts } from "$lib/components/vin/toast.svelte";
import Toaster from "$lib/components/vin/toast-toaster.svelte";The import paths assume the default folders: @/components/vin (React and Vue, with the usual @ → src alias) and $lib/components/vin (SvelteKit). Use your own if you chose another folder in init. How the Vue and Svelte versions pass values and content is in Frameworks.
Plain HTML: the classes come with the style's stylesheet. This component also needs vinui.js for its keyboard and pointer behaviour.
API
From spec/toast.json, which every framework version is tested against.
| Prop | Values | Default | In HTML |
|---|---|---|---|
toast(options)Shows a toast: { title, description?, variant?, action?: { label, onClick }, duration? }. Returns an id for dismiss(id). | function | — | VinUI.toast({ … }) or data-vin-toast="Title" on a button (with data-vin-toast-description, -variant) |
variant | defaultsuccessdanger | default | vin-toast--{value} |
durationMilliseconds before it closes. Hovering or focusing it pauses the timer. | number | 5000 | — |
ToasterPut it once in your app; toasts appear in it. | component | — | section.vin-toaster (vinui.js makes it) |
ToastThe toast itself, if you want to show one inline. | component | — | .vin-toast |
Parts
| React, Vue, Svelte | HTML classes |
|---|---|
<Toaster><Toast> | .vin-toaster.vin-toast.vin-toast--success.vin-toast--danger.vin-toast__icon.vin-toast__content.vin-toast__title.vin-toast__description.vin-toast__actions.vin-toast__close |
Accessibility
- Each toast is a status message (role="status"), so screen readers read it without moving focus. Errors use role="alert".
- Toasts sit in a landmark named "Notifications", so keyboard users can find them.
- The timer pauses while the pointer or focus is on a toast, and every toast has a close button (WCAG 2.2.1).
- Don't put the only way to do something in a toast: it goes away.
Customize
Saved in this browser. Style and accent are in the header.