Installation
npx sdaia-ui@latest add toast
Usage
import { Toast, ToastProvider, useToast } from '@/components/ui/Toast';1<Toast2type="success"3title="Changes saved"4message="Your changes were saved successfully."5actionLabel="Undo"6onAction={undo}7onClose={() => setOpen(false)}8/>
1const toast = useToast();2toast.show({ type: "success", title: "Record saved", actionLabel: "Undo", onAction: undo });
Examples
Default
Title, message, one action and the close button. The toast closes itself after five seconds; hover or focus pauses the timer.
Loading demo: toast-default
Types
Five types pair a colour with an icon so the outcome is clear at a glance.
Loading demo: toast-types
Neutral
General information that is not good or bad news.
Loading demo: toast-neutral
Info
Helpful context about what the system is doing.
Loading demo: toast-info
Success
The action completed as expected.
Loading demo: toast-success
Warning
The action worked but needs attention.
Loading demo: toast-warning
Error
The action failed. Pair it with a retry action. Error toasts stay until the user closes them.
Loading demo: toast-error
Title only
The message and the action are optional.
Loading demo: toast-title-only
ToastProvider and useToast
Show toasts from anywhere below the provider, one at a time; the next one waits until the current one closes. In an app they sit at the window’s bottom-end corner; this preview passes `contained` to keep them inside the frame.
Loading demo: toast-provider
Arabic (RTL)
The layout mirrors and reads right to left.
Loading demo: toast-rtl
When to use
Use toasts for:
- Confirming a save, delete or submit
- Offering a short Undo after an action
- Reporting that a background task finished
- Low-risk status updates
Don't use toasts for:
- Errors that block the task: use an inline Alert
- Messages that need a decision: use a Modal
- Long or detailed content
- Stacking several toasts at once
Best practices
- Keep the message short: say what happened in one sentence. A toast closes after about five seconds.
- Match the type to the message: Success for completed actions, Warning for something to check, Error for a failure.
- Give users control: offer one action such as Undo and keep the close button available.
Props
Toast
Prop | Type | Default | Required |
|---|---|---|---|
type | "neutral" | "info" | "success" | "warning" | "error" | "neutral" | optional |
title | ReactNode | — | required |
message | ReactNode | — | optional |
actionLabel | ReactNode | — | optional |
onAction | (event) => void | — | optional |
actionHref | string | — | optional |
closeButton | boolean | true | optional |
onClose | (reason: "timeout" | "close-button" | "escape" | "action") => void | — | optional |
duration | number | null | 5000 | optional |
dir | "ltr" | "rtl" | — | optional |
labels | { close?: string } | { close: "Close" } | optional |
ToastProvider
Prop | Type | Default | Required |
|---|---|---|---|
placement | "top-start" | "top-center" | "top-end" | "bottom-start" | "bottom-center" | "bottom-end" | "bottom-end" | optional |
contained | boolean | false | optional |
limit | number | 1 | optional |
hotkey | string | null | "F8" | optional |
dir | "ltr" | "rtl" | — | optional |
labels | { region?: string; close?: string } | { region: "Notifications", close: "Close" } | optional |
useToast()
Prop | Type | Default | Required |
|---|---|---|---|
show | (options: ToastProps & { id?: string }) => string | — | optional |
dismiss | (id?: string) => void | — | optional |
Accessibility
- Neutral, Info, Success and Warning toasts are announced politely (role="status"); Error toasts are announced at once (role="alert"). Only the title and message are read.
- A toast never takes focus. Tab reaches its action and close button; with ToastProvider, F8 moves focus to the toasts.
- Escape closes the toast that has focus, and focus goes back to where the user was.
- The timer is at least five seconds and pauses while the toast is hovered or focused, or the page is hidden. Error toasts never close themselves.
- The close button is named "Close" (translatable) and is 32 × 32 px. The type is shown by an icon and the title, not by colour alone.
Responsive behavior
- The toast is 420 px wide at most and shrinks to the screen on phones; long messages wrap and the toast grows taller.
- ToastProvider keeps a 16 px gap from the screen edges at every width.
- Spacing uses the brand spacing scale Figma binds, the same at every width; text sizes follow the responsive type tokens.