Skip to content
Sign in
SafetyUndo windowMenu

Undo windowPro

Undo an agent action within a short window, with a visible countdown that pauses on hover.

ProArchived newsletters with 10 s to undo; point at it to pause.

Installation

$ pnpm dlx shadcn@latest add @chatcn-pro/undo-window

Usage

tsx
import { UndoWindow } from "@/components/ui/chatcn/pro/undo-window"

<UndoWindow
  message="Archived 214 newsletters"
  undoneMessage="214 newsletters are back in your inbox"
  duration={10}
  onUndo={restore}
  onExpire={commit}
/>

One Web Animation drives the hairline along the bottom edge, the seconds and the deadline, so they never drift apart. Pointing at the row or focusing inside it pauses all three and swaps the seconds for a pause glyph; leaving resumes exactly where it stopped. After the window the row settles into a quiet past tense line instead of vanishing, so the person can still read what happened.

Examples

States

ProPaused, toast, small, undone, closed, failed and long content.

Props

PropTypeNotes
message, detailReactNodeWhat happened, past tense, and a second line
durationnumberSeconds. Default 10
onUndo() => void | Promise<void>Reject with an Error to show why it failed
onExpire() => voidThe window closed; commit the action
undoneMessage, expiredMessageReactNodeSettled lines
variant"inline" | "toast"Default inline
size"sm" | "md"Default md
pausedbooleanPause from outside, for example under a dialog
shortcutReactNodeHint on the Undo button; your app binds it
defaultState"counting" | "undone" | "expired" | "failed"For docs and tests

Keyboard

KeyAction
TabFocus Undo; focus pauses the countdown
Enter or SpaceUndo

Accessibility

  • The row is a status region, so the undone and failed lines are announced.
  • Seconds left are in hidden text with the paused state; the visible number is hidden to avoid a chatty live region.
  • Hover and focus both pause, so keyboard and screen reader users get the same time.

Motion

The hairline drains linearly, the one place linear is right: it is a clock. Settled lines slide 4 px and fade in 180 ms. Reduced motion keeps the hairline, which is information, and drops the slide.