honestui

Undoable Action

Dashboards

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>
  )
}

Dependencies

More by honestui

View all
  • Chromatic Text Reveal

    Chromatic Text Reveal

    31
  • Warp

    Warp

    1
  • Morphing Dialog

    Morphing Dialog

    1
  • Scroll Velocity Text

    Scroll Velocity Text

    1
  • Spotlight

    Spotlight

    1
  • Success Check

    Success Check

    1
  • Typewriter

    Typewriter

    1
  • Schedule Builder

    Schedule Builder

More in Dashboards

View all
  • Fernly — Project Management Dashboard with Kanban

    Fernly — Project Management Dashboard with Kanban

    774
  • Analytics Dashboard

    Analytics Dashboard

    89
  • Creator Dashboard

    Creator Dashboard

    222
  • Insights Dashboard

    Insights Dashboard

    47
  • Corbel — Sales Analytics Dashboard

    Corbel — Sales Analytics Dashboard

    500
  • serf dashboard

    serf dashboard

    146
  • Dashboard with Collapsible Sidebar

    Dashboard with Collapsible Sidebar

    2.7K
  • Halden — CRM Dashboard with Sales Pipeline

    Halden — CRM Dashboard with Sales Pipeline

    74