Toast
A brief, self-dismissing confirmation. Mount a single Toaster near the root and call toast() to raise one.
Purpose
A toast confirms something that already happened and then gets out of the way. Never put information in one that a person may need again — it disappears, and it is easy to miss.
Example
Each button calls toast.success, toast.error or toast.info; the Toaster mounted
alongside them renders the result.
Usage
Two halves. Mount the design system's Toaster once, near the application root — it is
the styled sonner toaster, carrying the HealthMetrics tokens:
import { Toaster } from "@healthmetrics/ui/sonner";
export default function RootLayout({ children }: { children: React.ReactNode }) {
return (
<html lang="en">
<body>
{children}
<Toaster />
</body>
</html>
);
}Then raise toasts from anywhere with toast, imported from sonner itself — the wrapper
configures appearance only, so the full sonner API applies:
import { toast } from "sonner";
toast("Claim CLM-4821 saved");
toast.success("Claim submitted successfully.");
toast.error("Something went wrong. Please try again.");
// Async work: one toast follows the promise from pending to outcome.
toast.promise(submitClaim(), {
loading: "Submitting claim…",
success: "Claim submitted",
error: "Submission failed",
});
// Optional second line and an action.
toast("Claim CLM-4824 rejected", {
description: "Rejected 5 minutes ago",
action: { label: "Undo", onClick: () => restoreClaim() },
});Duration & dismissal
The wrapper sets no timing or placement — sonner's defaults apply: each toast dismisses
itself after 4 seconds, stacks bottom-right, and pauses its timer while hovered.
Both are configurable per mount (<Toaster position="…" duration={…} />) or per call
(toast("…", { duration })).
Structure
What the wrapper styles — everything else is sonner's default behaviour.
| Property | Value |
|---|---|
| Surface | --popover with --popover-foreground text |
| Border | 1px --border |
| Radius | --radius-lg (8px) |
| Shadow | --shadow-16 |
| Icons | tone-coloured: --success-text, --destructive, --warning-text, --info-text |
| Action | --primary fill, --primary-foreground text |
| Timing | not set — sonner defaults (4s auto-dismiss, bottom-right) |
Best practices
Do
- Mount exactly one
<Toaster />, near the application root. - Keep the message to one line, in the past tense: "Claim submitted".
- Use
toast.promisefor async work — pending and outcome stay one message, not two. - Offer an inline
action(such as Undo) for reversible operations.
Don't
- Report errors that need action in a toast — use an Alert.
- Stack several at once for one user action.
- Put anything in a toast the user must read, keep or act on — four seconds later it is gone.
- Use a toast for site-wide notices — that is the System banner's job.
Accessibility & keyboard
- Sonner renders toasts into a polite live region (
aria-live="polite") — screen readers announce them after the current utterance, without interrupting. - Never make a toast the only path to an action or a piece of information — it may never be perceived. The same action must exist somewhere persistent on the page.
- The auto-dismiss timer pauses on hover, giving slower readers more time.
- Keyboard: Alt+T (sonner's default hotkey) moves focus to the toast area; action and
close buttons are real
<button>s reachable from there.
Props
Toaster passes every sonner ToasterProps through — position, duration, expand
and the rest are all available at the mount point.
The Toaster and every toast tone in Storybook