Skip to main content
Clever Ops

Undo Window Button

An undo-window button for React, the click commits only after a countdown, with a depleting hairline timer, mono seconds, and an Undo recall that never drops focus.

Preview & code

Loading Undo Window Button preview

Installation

pnpm dlx shadcn@latest add @cleverui/button-undo-window

Requires the @cleverui registry in your components.json, a one-off, two-line setup.

Usage

tsx
import { ButtonUndoWindow } from '@/components/ui/button-undo-window'
Exampletsx
'use client'

import { useState } from 'react'
import { ButtonUndoWindow } from '@/components/ui/button-undo-window'

export default function ButtonUndoWindowDemo() {
  const [archiveNote, setArchiveNote] = useState(
    'Northwind Q2 board pack stays in Active projects until you archive it.'
  )
  const [revokeNote, setRevokeNote] = useState(
    'Staging deploy token last used 14 minutes ago from build runner #7.'
  )

  return (
    <div className="mx-auto flex min-h-[380px] max-w-lg flex-col items-center justify-center gap-12 px-6 py-16">
      <div className="flex w-full flex-col items-center gap-3 text-center">
        <p className="font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
          Projects · archive
        </p>
        <p className="max-w-sm text-sm leading-relaxed text-muted-foreground">{archiveNote}</p>
        <ButtonUndoWindow
          onCommit={() =>
            setArchiveNote('Archived, restored to the archive drawer, not deleted.')
          }
          onUndo={() =>
            setArchiveNote('Archive cancelled, Northwind Q2 stays in Active projects.')
          }
          committedLabel="Archived"
        >
          Archive project
        </ButtonUndoWindow>
      </div>

      <div className="flex w-full flex-col items-center gap-3 border-t border-border/60 pt-10 text-center">
        <p className="font-mono text-[11px] uppercase tracking-[0.2em] text-muted-foreground">
          Security · revoke token
        </p>
        <p className="max-w-sm text-sm leading-relaxed text-muted-foreground">{revokeNote}</p>
        <ButtonUndoWindow
          windowMs={4000}
          undoLabel="Undo"
          committedLabel="Revoked"
          onCommit={() =>
            setRevokeNote('Token revoked, runners will fail authentication on next job.')
          }
          onUndo={() =>
            setRevokeNote('Revoke cancelled, staging deploy token remains valid.')
          }
        >
          Revoke deploy token
        </ButtonUndoWindow>
      </div>
    </div>
  )
}

API reference

ButtonUndoWindow accepts the following props.

PropTypeDefaultDescription
children*React.ReactNodeidle action label, e.g. 'Archive project'
onCommit*() => voidfires exactly once when the undo window elapses without a recall, the real work happens here, never at click time
onUndo() => voidfires when the user recalls the action during the window
windowMsnumber5000undo window duration in ms; the visible countdown rounds up to whole seconds
undoLabelstring'Undo'pending-state label, rendered with the mono seconds counter
committedLabelstring'Archived'brief settled confirmation after the window closes, then the button returns to idle

…plus everything from Omit< React.ButtonHTMLAttributes<HTMLButtonElement>, 'children' | 'onClick' | 'onDrag' | 'onDragStart' | 'onDragEnd' | 'onAnimationStart' >: className, event handlers, aria attributes and the rest pass straight through.

Frequently asked questions

How do I install the Undo Window Button component?

Register the @cleverui registry in your components.json ("@cleverui": "https://cleverops.com.au/r/{name}.json"), then run `npx shadcn@latest add @cleverui/button-undo-window`. The shadcn CLI copies the source into your project, you own the code from that point. You can also copy the source directly from this page.

What dependencies does Undo Window Button require?

Undo Window Button uses motion on top of React and Tailwind CSS. You don't need to install it manually, the shadcn CLI resolves and installs npm dependencies automatically when you add the component.

Can I theme Undo Window Button to match my brand?

Yes. The component is styled entirely with Tailwind utilities over standard design tokens (primary, background, muted, border), so it inherits your existing shadcn/ui theme automatically. Change your CSS variables and the component follows, no source edits needed for palette, radius, or fonts.

Want this built for you?

CleverUI is built by the Clever Ops web team. If you'd rather ship a hand-coded, fast, custom website than assemble one, we build them for Australian businesses every week.

Explore web development services