Toast
Status: stableAccessibility reviewedtenet-ui@0.4.0
import { Toast, useToast } from 'tenet-ui';Source: src/components/Toast/Toast.tsx
Usage guidelines
Section titled “Usage guidelines”When to use: brief, transient, non-blocking feedback about something that just happened (“Saved”, “Copied”, “Upload failed”). For a message anchored to content use Banner; for something that must be acknowledged use Dialog.
- Wrap your app once in
<ToastProvider>(optionally setdurationandplacement). Callconst { toast } = useToast()anywhere beneath it.
- Keep it short — a
titleplus one line ofmessage. Toasts are glanceable, not a place for forms or long text. - Pick
variantby meaning;dangeris announced assertively (role="alert"), the rest politely (role="status"). The viewport is a labelled live region. - Let them auto-dismiss (default 5s); only set
duration: 0for a message the user must dismiss, and always keep the manual dismiss button. - Never put critical, must-act information only in a toast — it disappears. Mirror it in a
Banneror inline error. - Don’t stack many at once; collapse repeats rather than flooding the corner.
Do / Don’t
Section titled “Do / Don’t”- ✅
toast({ variant: 'success', title: 'Saved', message: 'Your changes are live.' }) - ✅
<ToastProvider placement="bottom-right"><App /></ToastProvider> - ❌ A toast as the only record of a validation error the user must fix.
- ❌ Long, interactive content inside a toast — use a Dialog.
See also: Banner for persistent or anchored messages, Dialog for decisions, FormControl.Validation for field errors; system guideline feedback has the decision table.
Examples
Section titled “Examples”1 story for Toast — open in Storybook
- Default
components-toast--default
The full matrix (all args, controls, accessibility panel) is in Storybook.
Toast
| Prop | Type | Default | Description |
|---|---|---|---|
duration | number | 5000 | Default auto-dismiss duration (ms) when an individual toast doesn't set one. |
placement | 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | bottom-right | Viewport corner. |
children | ReactNode | — |
ToastProvider
| Prop | Type | Default | Description |
|---|---|---|---|
duration | number | 5000 | Default auto-dismiss duration (ms) when an individual toast doesn't set one. |
placement | 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left' | bottom-right | Viewport corner. |
children | ReactNode | — |
useToast hook
| Prop | Type | Default | Description |
|---|---|---|---|
toast * | (options: ToastOptions) => string | — | Show a toast; returns its id. |
dismiss * | (id: string) => void | — | Dismiss a toast by id. |
* required
Related types
ToastOptions
| Member | Type | Default | Description |
|---|---|---|---|
variant | 'info' | 'success' | 'warning' | 'danger' | — | Semantic tone. |
title | ReactNode | — | Optional bold lead-in line. |
message * | ReactNode | — | Main message. |
duration | number | — | Auto-dismiss after N ms. 0 keeps it until dismissed. |
ToastEntry
| Member | Type | Default | Description |
|---|---|---|---|
variant | 'info' | 'success' | 'warning' | 'danger' | — | Semantic tone. |
title | ReactNode | — | Optional bold lead-in line. |
message * | ReactNode | — | Main message. |
duration | number | — | Auto-dismiss after N ms. 0 keeps it until dismissed. |
id * | string | — |