Installation
npx logic2b@next add sonnerUsage
Add the Toaster component once, then call toast() from anywhere.
import { Toaster } from "@/components/ui/sonner"
<Toaster />
import { toast } from "sonner"
toast("Event has been created")
Usage notes
The Toaster component wraps sonner’s Toaster and forwards every
ToasterProps. Toasts themselves are
created imperatively with toast().
Examples
With an action
Promise
Live playground
Edit the component props and inspect the exact JSX before copying it. The preview loads only when this section enters the viewport.
Generated JSX
<div
className="flex min-h-28 items-center justify-center"
>
<Toaster
position="top-center"
richColors
/>
<button
type="button"
className="rounded-md bg-primary px-4 py-2 text-sm font-medium text-primary-foreground shadow-sm"
onClick={() => toast("Release published successfully")}
>Publish release</button>
</div>API reference
Generated from the public TypeScript exports in src/ui/sonner.tsx.
Toaster
ComponentProps: ToasterProps| Prop | Type | Required | Default | Description |
|---|---|---|---|---|
theme | "light" | "dark" | "system" | No | "system" | — |
Accessibility contract
Machine-readable behavior and consumer responsibilities for sonner.
- Support
- Authored behavior
- Pattern
- toast status messages
- Sonner
| Keys | Behavior |
|---|---|
| Escape | Close the open surface and restore focus. |
Built-in semantics
- Toast messages use status/alert semantics appropriate to their urgency and expose dismiss actions when configured.
Consumer responsibilities
- Keep messages concise, avoid moving focus automatically and provide a persistent recovery path for consequential actions.