Components
Toast
A short, dismissible message that confirms an action, with an optional undo.
pnpm dlx shadcn@latest add @caliper/toastWhen to use
Use it for
- Confirming something the person just did, such as archiving a project.
- Offering Undo for a reversible action.
Skip it when
- The message must be read before continuing; use an alert or dialog.
- The content is long; keep toasts to a title and one line.
Decisions
Why it is built this way, so you know what to keep when you change your copy.
Behaviour
- Loading resolves in place
- A toast that starts as “Saving…” becomes “Saved” or the error where it is, instead of stacking a second toast.
- Errors and loading never time out
- A message that needs action or is still working stays until it is dealt with; only plain confirmations leave on their own.
Styling
- Frosted, because it floats
- Toasts use the shared frosted surface with a 14px radius; the reading canvas underneath stays solid.
Installation
pnpm dlx shadcn@latest add @caliper/toast
Adds its 4 files to components/ui/, each with its own stylesheet, and installs their packages. No account needed. The first part also adds Caliper UI’s tokens; import them once as in Installation.
Usage
This is the code behind the preview above. It is built from Toast, ToastProvider and ToastStack.
import { useState, type ReactNode } from "react" import { Avatar } from "@/components/ui/avatar" import { Button } from "@/components/ui/button" import { cn } from "@/components/ui/lib/cn" import { Toast, ToastProvider, ToastStack } from "@/components/ui/toast" function Panel({ title, context, action, className, children }: { title: string; context: string; action?: ReactNode; className?: string; children: ReactNode }) { return ( <section className={cn("grid w-full max-w-md gap-5 rounded-overlay border border-border bg-background p-6 shadow-resting", className)}> <div className="flex items-start justify-between gap-3"> <div className="grid min-w-0 gap-1"> <p className="font-medium">{title}</p> <p className="text-sm text-muted-foreground">{context}</p> </div> {action} </div> {children} </section> ); } const invoices = [ { company: "Ostra Freight", amount: "$4,200.00", due: "Due 14 Oct" }, { company: "Halden Analytics", amount: "$1,860.00", due: "Due 16 Oct" }, { company: "Lumen Labs", amount: "$920.00", due: "Card failing" }, ]; export function ArchiveToast() { const [sending, setSending] = useState<"idle" | "pending" | "done">("idle"); const [failed, setFailed] = useState(false); return ( <ToastProvider duration={5000}> <Panel title="Invoices ready" context="October · 3 customers · $6,980.00 in total"> <ul className="grid gap-3"> {invoices.map((invoice) => ( <li key={invoice.company} className="flex items-center gap-3 text-sm"> <Avatar name={invoice.company} shape="square" className="size-8" /> <span className="grid min-w-0 flex-1"> <span className="truncate font-medium">{invoice.company}</span> <span className={invoice.due === "Card failing" ? "text-destructive" : "text-muted-foreground"}>{invoice.due}</span> </span> <span className="tabular-nums">{invoice.amount}</span> </li> ))} </ul> <div className="flex flex-wrap gap-2 border-t border-border pt-5"> <Button onClick={() => { setSending("pending"); window.setTimeout(() => setSending("done"), 1600); }} > Send 3 invoices </Button> <Button variant="secondary" className="text-danger" onClick={() => setFailed(true)}>Charge failing card</Button> </div> </Panel> <Toast title={sending === "pending" ? "Sending 3 invoices…" : "Sent 3 invoices"} loading={sending === "pending"} variant="success" open={sending !== "idle"} onOpenChange={(open) => !open && setSending("idle")} > {sending === "pending" ? "Ostra Freight, Halden Analytics, Lumen Labs" : "Each customer got a PDF and a pay link."} </Toast> <Toast title="Lumen Labs card declined" variant="error" open={failed} onOpenChange={setFailed} action={{ label: "Email Lumen Labs", altText: "Ask Lumen Labs to update their card", onClick: () => setFailed(false) }} > Insufficient funds. We will retry on 12 Oct. Errors stay until you dismiss them. </Toast> <ToastStack /> </ToastProvider> ); }
API reference
Toast
component
Also accepts the native props of its root element and a ref.
ToastProvider
component
No props of its own; it accepts the native props of its root element.
ToastStack
component
No props of its own; it accepts the native props of its root element.
Accessibility
It is built on native elements and keeps aria-busy, aria-labelledby, aria-describedby, aria-label, aria-hidden and aria-live in step with state. Changes that matter are announced through a live region.
Keyboard and focus handling comes from Radix toast: arrow keys move through items, Enter and Space select, and Escape closes and returns focus.
Motion
Transitions use the shared duration and easing tokens. Under prefers-reduced-motion those tokens collapse to instant and travel distances go to zero, so state changes still happen without movement.