Components / Feedback
Toast
A complete toast system: stacked notifications that fan out on hover, swipe to dismiss, with types, actions and promise support.
Installation
Requires React 18+ and Tailwind CSS.
- 1
Install dependencies
$ npm install motion - 2
Add the component
Copy the code from the Code tab above into
components/ui/toast.tsx. - 3
Use it
example.tsx"use client"; import { Toaster, toast } from "@/components/ui/toast"; const save = () => new Promise((resolve) => setTimeout(resolve, 2000)); const buttons = [ { label: "Default", run: () => toast("Event created", { description: "Friday, 10:00 AM" }) }, { label: "Success", run: () => toast.success("Changes saved") }, { label: "Error", run: () => toast.error("Couldn't upload file", { description: "The file is over 10 MB." }) }, { label: "Warning", run: () => toast.warning("Storage almost full") }, { label: "Info", run: () => toast.info("New version available") }, { label: "Action", run: () => toast("Message archived", { action: { label: "Undo", onClick: () => toast.success("Restored") } }), }, { label: "Promise", run: () => toast.promise(save(), { loading: "Saving…", success: "Saved to cloud", error: "Save failed" }), }, ]; export default function ToastDemo() { return ( <> <div className="flex max-w-md flex-wrap justify-center gap-2"> {buttons.map((b) => ( <button key={b.label} type="button" onClick={b.run} className="rounded-lg border border-zinc-200 dark:border-white/10 bg-white dark:bg-zinc-900 px-3 py-1.5 text-sm text-zinc-800 dark:text-zinc-200 transition hover:bg-zinc-100 dark:hover:bg-zinc-800 hover:text-zinc-900 dark:hover:text-white" > {b.label} </button> ))} </div> {/* Render once in your root layout. */} <Toaster position="bottom-right" /> </> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| toast(title, options?) | function | — | Show a toast. Also toast.success / error / warning / info / loading. |
| toast.promise(promise, msgs) | function | — | Loading toast that turns into success or error. |
| toast.dismiss(id?) | function | — | Dismiss one toast, or all of them. |
| options.description | ReactNode | — | Secondary text. |
| options.action | { label: string; onClick: () => void } | — | Adds an action button. |
| options.duration | number | 4000 | Milliseconds before auto-dismiss (Infinity = stay). |
| <Toaster position> | "top-left" | "top-center" | "top-right" | "bottom-…" | "bottom-right" | Where toasts appear. |
| <Toaster visibleToasts> | number | 3 | Toasts visible in the collapsed stack. |