Components / Feedback
Undo Toast
A toast with an Undo button and a countdown ring, for safe destructive actions.
📄 design-final-v3.fig
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/undo-toast.tsx. - 3
Use it
example.tsx"use client"; import { useState } from "react"; import { UndoToast } from "@/components/ui/undo-toast"; export default function UndoToastDemo() { const [open, setOpen] = useState(false); const [status, setStatus] = useState("design-final-v3.fig"); return ( <div className="flex flex-col items-center gap-6"> <div className="flex items-center gap-3 rounded-xl border border-zinc-200 dark:border-white/10 bg-zinc-50/80 dark:bg-zinc-900/60 px-4 py-3 text-sm text-zinc-700 dark:text-zinc-300"> 📄 {status} <button type="button" disabled={open || status === "Deleted"} onClick={() => { setOpen(true); setStatus("design-final-v3.fig"); }} className="rounded-md bg-rose-500/15 px-2.5 py-1 text-xs font-semibold text-rose-300 transition hover:bg-rose-500/25 disabled:opacity-40" > Delete </button> </div> <div className="h-12"> <UndoToast open={open} message="File moved to trash" onUndo={() => setOpen(false)} onExpire={() => { setOpen(false); setStatus("Deleted"); setTimeout(() => setStatus("design-final-v3.fig"), 1500); }} /> </div> </div> ); }
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| open | boolean | — | Show the toast. The countdown restarts each time it opens. |
| message | ReactNode | — | Text, e.g. "File moved to trash". |
| onUndo | () => void | — | Called when Undo is clicked. |
| onExpire | () => void | — | Called when time runs out. Do the real action here. |
| duration | number | 5000 | Milliseconds before expiring. |