Toast

Transient messages. Toasts pile up with the newest in front, and fan out on hover.

Playground

Every kind of toast. Each setting answers with a toast.

Dark previewReplay previewOpen in new tab

Customize

Position
Style
Status
Progress
Content
Actions

Usage

Import the parts you need from the component's folder.

ts
import { Toaster, toast } from "@/components/ui/toast";

Default

Call toast from a click.

Dark previewReplay previewOpen in new tab

Types

Errors close after 8 seconds, the rest after 5. Loading toasts and toasts with a button stay.

Dark previewReplay previewOpen in new tab

With description

A second line under the title.

Dark previewReplay previewOpen in new tab

Promise

A loading toast that morphs into the result.

Dark previewReplay previewOpen in new tab

Update in place

Every call returns an id. Pass it to toast.update.

Dark previewReplay previewOpen in new tab

Actions

Return a patch from onClick to morph the toast, or nothing to close it.

Dark previewReplay previewOpen in new tab

Light and dark

Inverted against the page: dark on light, light on dark. Pass theme to pin one.

Switching the engine

The engine is our own copy of Ding. index.ts holds the two lines that put vue-sonner back.

API Reference

Toaster

PropTypeDefaultDescription
position"top-left" | "top-center" | "top-right" | "bottom-left" | "bottom-center" | "bottom-right""top-center"Where the toast sits.
theme"light" | "dark" | "system"inverse of the pagePin a theme instead of inverting against the app's color mode.
labels{ region?: string, dismiss?: string }EnglishAccessible names of the notifications region and the close button.
noncestring—CSP nonce for the injected stylesheet, for pages that block inline styles.

toast

PropTypeDefaultDescription
titlestring—First argument. The text of the toast.
descriptionstring—Second line under the title.
action{ label: string, onClick: () => void | ToastPatch }—Button on the toast. A toast with one stays until dismissed.
secondary{ label: string, onClick: () => void | ToastPatch }—Second button beside the action.
imagestring—Avatar or thumbnail URL, shown in place of the status icon.
metastring—Small trailing text beside the title, such as a timestamp.
progressnumber—0 to 1. Draws a thin bar inside the toast.
durationnumber5000Milliseconds before it closes. 0 keeps it until dismissed.
idstring | number—Your own id, to update or dismiss the toast later.
classNamestring—Extra class on this one toast. Style it as .tst.your-class.
MethodDescription
toast.success / error / warning / info / loading(title, options?)Show a toast of that type. Returns its id.
toast.promise(promise, { loading, success, error })Loading toast that morphs into the result.
toast.update(id, patch)Change a live toast in place.
toast.dismiss(id?)Close one toast, or all of them.
toast.configure({ position, theme, labels, sound, volume, stack })Change the global toaster at runtime.