About
Make a change on screen at once, offer Undo during a countdown, and send the request only when it ends.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Undoable Action to your project and fits it to your theme.
Code
How Undoable Action is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client"
import "honestui/theme.css";
import * as React from "react"
import {
UndoBar,
useUndoableAction,
} from "@/components/ui/honest-undoable-action"
import { Button } from "@/components/ui/honest-undoable-action"
const people = ["Ana Ruiz", "Li Wei", "Sam Cole", "Dee Park"]
function wait(milliseconds: number) {
return new Promise((resolve) => window.setTimeout(resolve, milliseconds))
}
/** There is no server behind this preview; each invite is a timer. */
export default function UndoableActionFlush() {
const [invited, setInvited] = React.useState<string[]>([])
const [sent, setSent] = React.useState(0)
const undoable = useUndoableAction({ duration: 10000, max: 2 })
const waiting = undoable.entries.filter((entry) => entry.phase === "waiting").length
const next = people.find((person) => !invited.includes(person))
const invite = (person: string) =>
undoable.run({
message: `Invited ${person}`,
apply: () => {
setInvited((current) => [...current, person])
return () => setInvited((current) => current.filter((item) => item !== person))
},
commit: () => wait(500),
onCommit: () => setSent((count) => count + 1),
})
return (
<div data-theme="light" className="flex w-full max-w-lg min-w-0 flex-col gap-[var(--hui-space-4)]">
<div className="flex flex-wrap items-center gap-[var(--hui-space-3)]">
<Button size="sm" disabled={!next} onClick={() => next && invite(next)}>
{next ? `Invite ${next}` : "Everyone is invited"}
</Button>
<Button
size="sm"
variant="outline"
disabled={waiting === 0}
onClick={() => undoable.flush()}
>
Send now
</Button>
</div>
<p className="m-0 text-[var(--hui-color-foreground-base-secondary)] tabular-nums [font-size:var(--hui-font-size-small)] [line-height:var(--hui-line-height-small)]">
Waiting: {waiting}. Sent: {sent}.
</p>
<UndoBar action={undoable} labels={{ region: "Recent invites" }} />
</div>
)
}
















