Components
Undo action
Let a destructive action wait out a short undo window, or ask for a hold when nothing can undo it.
import { … } from "@fungi.computer/caps/components/undo-action";Hero
import { UndoAction } from "@fungi.computer/caps/components/undo-action";
export default function Hero() { return ( <UndoAction armedAnnouncement="Listing removed in 5 seconds" onCommit={() => { /* This specimen has no host action. */ }} undoneAnnouncement="Listing kept" variant="ghost-destructive" > Remove listing </UndoAction> );}Interactive
import { useState } from "react";import { UndoAction } from "@fungi.computer/caps/components/undo-action";
export default function Interactive() { const [status, setStatus] = useState("Port 5173 is open"); return ( <div className="flex flex-col items-start gap-2"> <UndoAction armedAnnouncement="Port 5173 stops in 5 seconds" onCommit={() => { setStatus("Port 5173 stopped"); }} undoMs={3000} undoneAnnouncement="Port 5173 kept open" variant="outline" > Stop port 5173 </UndoAction> <p className="text-sm text-base-content">{status}</p> </div> );}Props
UndoActionProps
| Prop | Type | Description |
|---|---|---|
children | ReactNode | The action's label, such as "Stop". |
onCommit() | () => void | Runs when the undo window closes without an undo: the action happens then. |
armedAnnouncement | string | Spoken when the action is armed, such as "Port 5173 stops in 5 seconds". |
undoneAnnouncement | string | Spoken after an undo, such as "Port 5173 kept open". |
undoLabel? | ReactNode | |
undoMs? | number | The undo window in milliseconds. |
childrenReactNodeThe action's label, such as "Stop".
onCommit()() => voidRuns when the undo window closes without an undo: the action happens then.
armedAnnouncementstringSpoken when the action is armed, such as "Port 5173 stops in 5 seconds".
undoneAnnouncementstringSpoken after an undo, such as "Port 5173 kept open".
undoLabel?ReactNodeundoMs?numberThe undo window in milliseconds.
Full types: API reference.