uimaxxer

Hold to confirm

Press and hold to confirm something you cannot undo. The fill runs at the speed of time, an early release snaps back in 200ms, and it reports its progress so other parts can draw with your hold.

npx shadcn@latest add https://uimaxxer.com/r/hold-to-confirm.json
PasskeysFix the duplicate Stripe charge

agent/pricing-table is merged. Clean it up.

Captain

agent/pricing-table

14 commits, merged into main 2 days ago

Usage

import { HoldToConfirm } from "@/components/ui/hold-to-confirm"

<HoldToConfirm icon="trash" doneLabel="Deleted" onConfirm={deleteBranch}>
  Delete branch
</HoldToConfirm>

Props

PropTypeDefaultWhat it does
childrenReactNodeThe label, e.g. Delete branch.
onConfirm() => voidCalled once the hold completes.
durationnumber1600Hold length in ms. The fill is linear because time is.
iconIconNameLeading icon. Turns into a check when confirmed.
doneLabelReactNodeLabel after confirming, e.g. Deleted.
tone"danger" | "solid" | "ink""danger"Colour of the fill. solid fills with the full danger colour.
size"sm" | "md" | "lg""md"32, 40 or 48px tall. The hit area is always 44px or more.
resetAfternumber | null2200Return to idle after this many ms; null keeps the done state.
progressMotionValue<number>Your own motion value; the hold writes 0 to 1 into it every frame, so you can draw with it without re-rendering.
onProgress(p: number) => voidCalled every frame with the fill.
onHoldChange(holding: boolean) => voidA hold started or ended.

Keyboard

Space (hold)
Fill
Enter (hold)
Fill

Accessibility

  • A real button; the hold length is announced through aria-describedby.
  • Space and Enter hold works the same as a pointer hold, and releasing early cancels.
  • The result is announced in a polite live region.
  • Dragging off the button by more than 24px cancels, so a slipped finger never confirms.