Undo toast Free
Free forever. One command, source you own.
Install
npx shadcn@latest add https://cottoncandy.dev/r/undo-toast.jsonFree. Lands in components/mu/undo-toast/ with the shared foundation. Needs React 19, Tailwind v4 and motion; reads your shadcn theme, and dark mode follows .dark.
Usage
import { toast, UndoToast } from "@/components/mu/undo-toast/UndoToast";
<UndoToast className="fixed inset-x-4 bottom-6" />
<button onClick={() => { archive(id); toast({ message: "Archived 1 email", undo: () => restore(id) }); }}>Archive</button>Use with an agent Beta
npx shadcn@latest add https://cottoncandy.dev/r/uisdk/undo-toast.jsonOptional. An AI agent in your app can read and set this piece by name, and you can ask before anything it can’t undo. The piece itself doesn’t change. Built on UI SDK 0.1.0-beta.23, which is in beta too, so this add-on follows its releases.
Source
How it works
Building with an agent? Hand it a ready prompt for this piece.
Input and reduced motion
- Pointer / touch: press Undo; hovering the toast pauses its time.
- Keyboard: Tab reaches Undo (focus pauses the time); ⌘Z or Ctrl+Z undoes while it shows, unless a text field has focus; Escape inside it lets it go. When it leaves, focus returns to the button it came from. The words are read out through a polite status region ("Archived 1 email", "Restored").
- Reduced motion: no flight, bead or sink: the toast is at rest at once, the ring ticks down in steps, and it leaves at once.
Props
| Prop | Default | What it does |
|---|---|---|
open | — | boolean | shows it; leave it out to show what toast() sends |
onOpenChange | — | (open) => void | it closed itself: Undo landed, time ran out, or Escape |
message | — | string | what happened; a new message while open merges in and restarts the time |
anchor | the pressed element | ref or element | what it buds from and goes back into |
onUndo | — | () => unknown | reverses the change; a promise keeps it waiting, a rejection says "Couldn't undo. Try again." |
onExpire | — | () => void | time ran out (or Escape): the change stands |
duration | 5000 | ms | time before it expires; hover and focus pause it |
labels | Undo, Restored, Couldn't undo. Try again. | { undo, restored, failed } | its words |
accent | off | boolean | tints the success tick toward --mu-signal |
sound | off | true or 0–1 | a soft key on Undo, a low note if it fails |
className | — | — | added to the root |
Sound
None. It loads in silence.
Off unless you pass sound (true, or a volume 0–1). Undo plays a soft key; a failed undo plays failed. It never plays on hover, on mount, when it buds, when it expires, or from a prop change. setMuted(true) from components/mu/sounds.ts silences every cottoncandy item at once.
Licence
Free to use in your projects, under the terms on the licence.
The toast buds out of the button you pressed and drops to rest; Undo pulls it back in, and if time runs out it sinks away.
For deletes and actions you can undoMore in Messaging