Hold button Free
Free forever. One command, source you own.
Install
npx shadcn@latest add https://cottoncandy.dev/r/hold-button.jsonFree. Lands in components/mu/hold-button/ with the shared foundation. Needs React 19, Tailwind v4 and motion; reads your shadcn theme, and dark mode follows .dark.
Usage
import { HoldButton } from "@/components/mu/hold-button/HoldButton";
<HoldButton onConfirm={remove} labels={{ busy: "Deleting…", done: "Deleted" }}>Hold to delete</HoldButton>
<HoldButton size="md" progress={upload} onClick={start} labels={{ progress: "Uploading {n}%", done: "Uploaded" }}>Upload</HoldButton>
<HoldButton round onConfirm={clearCache}>Hold to clear the cache</HoldButton>Use with an agent Beta
npx shadcn@latest add https://cottoncandy.dev/r/uisdk/hold-button.jsonOptional. An AI agent in your app can read and set this piece by name, and you can ask before anything it can’t undo. The piece itself doesn’t change. Built on UI SDK 0.1.0-beta.23, which is in beta too, so this add-on follows its releases.
Source
How it works
Building with an agent? Hand it a ready prompt for this piece.
Input and reduced motion
- Pointer / touch: press and hold anywhere on the button; the body presses in for the whole hold. Letting go early drains it with a slosh; a long press on a phone holds rather than opening a menu.
- Keyboard: hold Space or Enter; letting go early cancels, as does leaving the button.
- Busy: while
onConfirmruns the button stays focusable (aria-disabled,aria-busy) and says so in words;doneandfailedare announced (role="status"). - Reduced motion: the level is drawn flat with no slosh or chop; a hold still fills (it is the measure) and a cancel empties at once.
Props
| Prop | Default | What it does |
|---|---|---|
children | — | text | the words at rest; also the accessible name |
holdMs | 1500 | 300–5000 | how long the hold takes |
onConfirm | — | () => unknown | runs when the hold reaches the top. Return a promise: the button says busy until it resolves (done) or rejects (failed, and the liquid drains so it can be held again) |
progress | — | 0–1 | a progress button instead: the level follows this, the hold is off, and onClick is yours |
size | "lg" | lg 50px, md 16px, sm 8px | the body's height (the meter family's geometry); md and sm show no words, which stay the accessible name |
round | false | boolean | a round key at 36px (--mu-control-sm) |
tone | "danger" (hold), "info" (progress) | danger, info, success | the liquid's light |
labels | Keep holding, Working…, Done, Didn't work · hold to retry, {n}%, Press and hold | strings | holding, busy, done, failed, progress (a template: {n} is the percent), tap (shown for 1.6s after a press let go under a fifth full, so a click is answered) |
className | — | — | added to the root |
Sound
None. It loads in silence.
None.
Licence
Free to use in your projects, under the terms on the licence.
Hold to confirm: liquid light fills the button, and lets go with a slosh if you stop early.
For deletes, payments and careful confirmsMore in Controls & forms