Components
Undo Toast
A toast with an Undo button.
<UndoToast open={open} message="Message deleted" onUndo={restore} onClose={close} />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/undo-toast.jsonimport { UndoToast } from "@/components/undo-toast"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
"Message deleted · Undo". It times out on its own, and hovering or focusing it pauses the timer, so there's time to reach the button. It sits fixed in the bottom-right corner of the window and announces itself politely to screen readers.
import { UndoToast } from "@/components/undo-toast";
export function Inbox() {
const [deleted, setDeleted] = useState<Message | null>(null);
return (
<UndoToast
open={!!deleted}
message="Message deleted"
onUndo={() => restore(deleted!)}
onClose={() => setDeleted(null)}
/>
);
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
open | boolean | Shows the toast. | |
message | string | What happened. | |
onUndo | () => void | Called when Undo is pressed. | |
onClose | () => void | Called when it times out, is dismissed, or after Undo. | |
duration | number | 5000 | Milliseconds before it times out. |
With reduced motion, it appears without sliding in.