Toast
Toast is a short, non-blocking notification that appears in a corner of the screen and dismisses itself.
<Toaster /> once at the app root, then call dispatchToast from useToast() (or the toast() helper). Each toast has an intent (info / success / warning / error) with the same icons as MessageBar, a title, a body, one action and a close button. Swipe to dismiss it; hovering pauses the timer; F8 moves focus to the notification region.Import
Install from npm, copy the source into your project with @yugen-ui/cli or the shadcn CLI, or import directly when working in this repo.
// npm install yugen-uiimport { Toaster, useToast, toast } from "yugen-ui";Variants
Each tile is a standalone example: hover to copy, or press Code to see the source.
Intent
info, success, warning, error, with the same icons and colors as MessageBar.
Position
Toaster position: top-start, top, top-end, bottom-start, bottom, bottom-end (default).
No auto-dismiss & dismiss from code
timeout: -1 keeps the toast open until people or your code dismiss it.
Usage
- Use it for short feedback after an action: saved, sent, deleted (with Undo).
- Keep the title short and the body to 1–2 lines.
- For errors that need attention right away, set timeout to -1 or use MessageBar / Dialog.
- Don't put important information only in a toast. It disappears.
- Don't fire a burst of toasts for the same event.
- Don't put a form or several actions in a toast.
Props
| Prop · Type | Default | Description |
|---|---|---|
| Toaster | Default: "bottom-end" | Position of the notification region. |
| Toaster | Default: — | Identifier when there are several Toasters; use it with useToast(toasterId). |
| Toaster | Default: 5 | Number of toasts shown at once. |
| useToast | Default: — | Imperative API; dispatchToast returns the id. The dispatchToast function imported straight from the package is deprecated (removed in 1.0): use toast() or useToast().dispatchToast. |
| intent"info" | "success" | "warning" | "error" | Default: "info" | Icon and icon color. |
| title / bodyReactNode | Default: — | Title (body1 semibold) and body. |
| action{ label: string; altText?: string; onClick?: () => void } | Default: — | Link-style action to the right of the title. |
| timeoutnumber | Default: 3000 | Time before the toast closes on its own (ms); -1 = never. |
| toastId / onDismiss / dismissiblestring / () => void / boolean | Default: — / — / true | Fixed id, callback on dismiss, shows the X button. The old name hideDismiss is deprecated (removed in 1.0). |
Messages
Text built into the component: labels, aria-labels, screen reader announcements.
English by default. Change it with the messages prop of YugenProvider, by the namespace below; messagesVi has the Vietnamese set. See Interface language.
messages.toast
| Key · Type | Default (English) | messagesVi |
|---|---|---|
| regionstring Tên vùng thông báo cho trình đọc màn hình. | Default (English)"Notifications" | messagesVi"Thông báo" |
| regionHotkeystring Tên vùng kèm phím tắt nhảy tới; | Default (English)"Notifications ({hotkey})" | messagesVi"Thông báo ({hotkey})" |
| dismissstring Nhãn nút đóng từng toast. | Default (English)"Dismiss notification" | messagesVi"Đóng thông báo" |