A button that runs the task and lands its result
Press it, or Tab to it and press Enter
pnpm dlx shadcn@latest add https://notchset.dev/r/action-button.jsonOne press that runs a job and says how it went.
Every shadcn style · one file
Import it and pass your content. The props that matter most are listed next.
"use client";
import * as React from "react";
import { ActionButton } from "@/components/ui/notchset/action-button";
import type { FeedbackProps } from "@/lib/notchset/feedback";
import { useLessMotion } from "@/lib/notchset/motion";
import { pressIn, useSelfPlay } from "./self-play";
/*
* One action button, alone and centred, a whole press-to-done moment in place; the look picks which. Send invoice: the
* plane launches, "Sending…" rolls in, and it alternates a send that lands (a hop, the tick, a green ring) with one
* that fails (a head shake, rose Not sent · Retry, the plane flies home); a press retries. Delete deal: the words tip
* into the bin and the lid slams, an Undo waits 3s. Upload contract: the arrow rockets out of its well, the ring fills
* as the digits roll, and it lands green. It plays its press once on arrival and rests on the end; then it is yours.
* The button sits in a row the Large button's height and the Undo outside the row's flow, so nothing on the stage moves.
*
* `state` puts it in one moment of its life, drawn by pressing it for real against a task that answers that way:
* working (the task never settles), done, failed (held until a press retries), retrying (failed, then pressed again
* and working) or unavailable. Once there, a press is a real press again.
*/
const READINGS = [0, 12, 27, 41, 58, 73, 86, 97, 100];
type Look = "send" | "delete" | "upload";
type State = "rest" | "busy" | "done" | "failed" | "retry" | "disabled";
const never = () => new Promise<void>(() => undefined);
export default function ActionButtonDemo() {
return <ActionButtonScene />;
}
/* onFeedback is yours to give: your sound or haptics for each move */
function ActionButtonScene({ onFeedback }: FeedbackProps) {
const less = useLessMotion();
const look = "send" as Look;
const state = "rest" as State;
const tries = React.useRef(0);
/* the presses that put the button in `state`; afterwards every press is a real one */
const staged = React.useRef(state !== "rest" && state !== "disabled");
const failing = React.useRef(state === "failed" || state === "retry");
const [said, say] = React.useState("");
const root = React.useRef<HTMLDivElement>(null);
const button = React.useRef<HTMLButtonElement>(null);
/* the arrival: the button pressed once, as a hand would, then it rests on its result */
const play = useSelfPlay(root, { beats: [400], off: less, hold: state !== "rest" });
React.useEffect(() => {
if (!play.mine && play.step === 0) pressIn(root.current, "[data-kind=action-button]");
}, [play.step, play.mine]);
/* with less motion the task answers at once, so the result shows without the wait */
const wait = less ? 0 : 1300;
const tick = less ? 0 : 230;
/* the task the button runs, answering as the state asks while it is being drawn */
const staging = (report?: (pct: number) => void, at = 58): Promise<void> | undefined => {
if (!staged.current) return undefined;
if (failing.current) return Promise.reject(new Error("not done"));
if (state === "done") {
report?.(100);
return Promise.resolve();
}
report?.(at);
return never();
};
const send = () =>
staging() ??
new Promise<void>((done, fail) => {
const ok = tries.current++ % 2 === 0;
setTimeout(() => (ok ? done() : fail(new Error("not sent"))), wait);
});
const remove = () => {
const held = staging();
if (held) return held;
say("Deal deleted");
return undefined;
};
const upload = (report: (pct: number) => void) =>
staging(report, state === "retry" ? 41 : 58) ??
new Promise<void>((done) => {
if (less) {
report(100);
return done();
}
READINGS.forEach((n, i) =>
setTimeout(() => {
report(n);
if (n === 100) setTimeout(done, tick);
}, i * tick),
);
});
React.useEffect(() => {
if (!staged.current) return;
const timers: ReturnType<typeof setTimeout>[] = [];
const press = () => button.current?.click();
press();
if (state === "retry") {
/* the failure lands, then a press retries and the task works again */
timers.push(
setTimeout(() => {
failing.current = false;
press();
}, 700),
);
timers.push(setTimeout(() => (staged.current = false), 800));
} else timers.push(setTimeout(() => ((staged.current = false), (failing.current = false)), 100));
return () => timers.forEach(clearTimeout);
}, [state]);
const working = state === "retry" ? "Retrying…" : undefined;
const failedWords = state === "failed" || state === "retry";
const off = state === "disabled";
/* the stage's own presses make no sound; a person's do */
const feedback: typeof onFeedback = onFeedback && ((event) => void (staged.current || !play.mine || onFeedback(event)));
return (
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="flex w-full flex-col items-center py-12">
<div className="flex h-[var(--ns-button-lg)] items-center">
{look === "send" ? (
<ActionButton ref={button} variant="send" busyLabel={working ?? "Sending…"} doneLabel="Sent" failLabel="Not sent · Retry" disabled={off} reason={off ? "Add a billing contact first" : undefined} run={send} onFeedback={feedback}>
Send invoice
</ActionButton>
) : look === "delete" ? (
<ActionButton ref={button} variant="delete" deleteStyle="letters" busyLabel={working ?? "Deleting…"} doneLabel="Deleted" failLabel={failedWords ? "Not deleted · Retry" : undefined} disabled={off} reason={off ? "Only owners can delete deals" : undefined} run={remove} onUndo={() => say("Deal restored")} onFeedback={feedback}>
Delete deal
</ActionButton>
) : (
<ActionButton ref={button} variant="upload" busyLabel={working ?? "Uploading"} doneLabel="Uploaded" failLabel={failedWords ? "Not uploaded · Retry" : undefined} disabled={off} reason={off ? "The contract is still a draft" : undefined} run={upload} onFeedback={feedback}>
Upload contract
</ActionButton>
)}
</div>
<span role="status" className="sr-only">
{said}
</span>
</div>
);
}"use client";
import * as React from "react";
import { ActionButton } from "@/components/ui/notchset/action-button";
import type { FeedbackProps } from "@/lib/notchset/feedback";
import { useLessMotion } from "@/lib/notchset/motion";
import { pressIn, useSelfPlay } from "./self-play";
/*
* One action button, alone and centred, a whole press-to-done moment in place; the look picks which. Send invoice: the
* plane launches, "Sending…" rolls in, and it alternates a send that lands (a hop, the tick, a green ring) with one
* that fails (a head shake, rose Not sent · Retry, the plane flies home); a press retries. Delete deal: the words tip
* into the bin and the lid slams, an Undo waits 3s. Upload contract: the arrow rockets out of its well, the ring fills
* as the digits roll, and it lands green. It plays its press once on arrival and rests on the end; then it is yours.
* The button sits in a row the Large button's height and the Undo outside the row's flow, so nothing on the stage moves.
*
* `state` puts it in one moment of its life, drawn by pressing it for real against a task that answers that way:
* working (the task never settles), done, failed (held until a press retries), retrying (failed, then pressed again
* and working) or unavailable. Once there, a press is a real press again.
*/
const READINGS = [0, 12, 27, 41, 58, 73, 86, 97, 100];
type Look = "send" | "delete" | "upload";
type State = "rest" | "busy" | "done" | "failed" | "retry" | "disabled";
const never = () => new Promise<void>(() => undefined);
export default function ActionButtonDemo() {
return <ActionButtonScene />;
}
/* onFeedback is yours to give: your sound or haptics for each move */
function ActionButtonScene({ onFeedback }: FeedbackProps) {
const less = useLessMotion();
const look = "send" as Look;
const state = "rest" as State;
const tries = React.useRef(0);
/* the presses that put the button in `state`; afterwards every press is a real one */
const staged = React.useRef(state !== "rest" && state !== "disabled");
const failing = React.useRef(state === "failed" || state === "retry");
const [said, say] = React.useState("");
const root = React.useRef<HTMLDivElement>(null);
const button = React.useRef<HTMLButtonElement>(null);
/* the arrival: the button pressed once, as a hand would, then it rests on its result */
const play = useSelfPlay(root, { beats: [400], off: less, hold: state !== "rest" });
React.useEffect(() => {
if (!play.mine && play.step === 0) pressIn(root.current, "[data-kind=action-button]");
}, [play.step, play.mine]);
/* with less motion the task answers at once, so the result shows without the wait */
const wait = less ? 0 : 1300;
const tick = less ? 0 : 230;
/* the task the button runs, answering as the state asks while it is being drawn */
const staging = (report?: (pct: number) => void, at = 58): Promise<void> | undefined => {
if (!staged.current) return undefined;
if (failing.current) return Promise.reject(new Error("not done"));
if (state === "done") {
report?.(100);
return Promise.resolve();
}
report?.(at);
return never();
};
const send = () =>
staging() ??
new Promise<void>((done, fail) => {
const ok = tries.current++ % 2 === 0;
setTimeout(() => (ok ? done() : fail(new Error("not sent"))), wait);
});
const remove = () => {
const held = staging();
if (held) return held;
say("Deal deleted");
return undefined;
};
const upload = (report: (pct: number) => void) =>
staging(report, state === "retry" ? 41 : 58) ??
new Promise<void>((done) => {
if (less) {
report(100);
return done();
}
READINGS.forEach((n, i) =>
setTimeout(() => {
report(n);
if (n === 100) setTimeout(done, tick);
}, i * tick),
);
});
React.useEffect(() => {
if (!staged.current) return;
const timers: ReturnType<typeof setTimeout>[] = [];
const press = () => button.current?.click();
press();
if (state === "retry") {
/* the failure lands, then a press retries and the task works again */
timers.push(
setTimeout(() => {
failing.current = false;
press();
}, 700),
);
timers.push(setTimeout(() => (staged.current = false), 800));
} else timers.push(setTimeout(() => ((staged.current = false), (failing.current = false)), 100));
return () => timers.forEach(clearTimeout);
}, [state]);
const working = state === "retry" ? "Retrying…" : undefined;
const failedWords = state === "failed" || state === "retry";
const off = state === "disabled";
/* the stage's own presses make no sound; a person's do */
const feedback: typeof onFeedback = onFeedback && ((event) => void (staged.current || !play.mine || onFeedback(event)));
return (
<div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} className="flex w-full flex-col items-center py-12">
<div className="flex h-[var(--ns-button-lg)] items-center">
{look === "send" ? (
<ActionButton ref={button} variant="send" busyLabel={working ?? "Sending…"} doneLabel="Sent" failLabel="Not sent · Retry" disabled={off} reason={off ? "Add a billing contact first" : undefined} run={send} onFeedback={feedback}>
Send invoice
</ActionButton>
) : look === "delete" ? (
<ActionButton ref={button} variant="delete" deleteStyle="letters" busyLabel={working ?? "Deleting…"} doneLabel="Deleted" failLabel={failedWords ? "Not deleted · Retry" : undefined} disabled={off} reason={off ? "Only owners can delete deals" : undefined} run={remove} onUndo={() => say("Deal restored")} onFeedback={feedback}>
Delete deal
</ActionButton>
) : (
<ActionButton ref={button} variant="upload" busyLabel={working ?? "Uploading"} doneLabel="Uploaded" failLabel={failedWords ? "Not uploaded · Retry" : undefined} disabled={off} reason={off ? "The contract is still a draft" : undefined} run={upload} onFeedback={feedback}>
Upload contract
</ActionButton>
)}
</div>
<span role="status" className="sr-only">
{said}
</span>
</div>
);
}"use client";
import * as React from "react";
/*
* A demo that plays itself until the first touch: the script lives in the demo, never in the piece, which only gets
* the props a person would give it. It moves 0.4 s after the piece is first seen, then takes each step on its beat;
* off screen or paused it waits. The first press, key or focus on the piece (bind `handOver` to it; a scroll over it never counts) makes it the
* visitor's for good and drops every queued step; with less motion (`off`) it never plays and rests in its first frame.
* A host can hand it over from outside the piece too (a settings panel beside it the visitor has used): under
* <HandedOver value>, it never plays, a remount included.
*
* const play = useSelfPlay(root, { beats: [2800, 2800], loop: true, off: less });
* <div ref={root} onPointerDownCapture={play.handOver} onKeyDownCapture={play.handOver} onFocusCapture={play.handOver}>
* play.step // the step it is at, -1 before its first
* play.control // "pause" while it plays, "play" once paused (a new take), "replay" once it is over or yours
*
* Each step presses the piece's own controls (pressIn), so the script shows exactly what a hand can do.
*
* A host that shows the piece once (<PlayOnce value={{ settle }}>) changes three things: the script starts when the
* piece is first half in view and never again on coming back, it never loops, and with less motion (or `settle`) it
* takes every step at once, so the piece rests on the END of its moment. `hold` is a reason not to play at all that is
* not motion (a mode with nothing to show): it holds in every host. Under <PlayOnce value={{ active: false }}> (a look
* that is mounted but not shown) it waits until it is shown.
*/
type SelfPlayOptions = {
/** how long each step waits after the one before it, in ms; the first step waits 0.4 s after the piece is seen */
beats: readonly number[];
/** starts over after the last step; without it the script plays once and rests */
loop?: boolean | undefined;
/** no self-play at all (less motion): the piece is the visitor's from the start */
off: boolean;
/** no self-play for a reason other than motion (a mode with nothing to show), in every host */
hold?: boolean | undefined;
};
/** How a host shows the piece: once on arrival (see useSelfPlay). */
type PlayOnceHost = {
/** rest on the end at once, without playing (less motion, or a reset) */
settle?: boolean | undefined;
/** false while the piece is mounted but not shown: it waits */
active?: boolean | undefined;
};
const START = 400;
/**
* Whether a demo plays itself at all. Off: every piece rests in its first frame and is
* the visitor's from the start; nothing presses its controls for them.
*/
const SELF_PLAY: boolean = false;
/** True where the visitor has already taken the piece from outside it: nothing under it plays itself. */
const HandedOver = React.createContext(false);
/** A host that shows the piece once: play once on arrival, rest on the end (null: play as the demo asks). */
const PlayOnce = React.createContext<PlayOnceHost | null>(null);
function useSelfPlay(root: React.RefObject<Element | null>, { beats, loop: looped = false, off: still, hold = false }: SelfPlayOptions) {
const once = React.useContext(PlayOnce);
const active = once?.active !== false;
/* shown once: less motion (or a settled host) takes every step at once and rests on the end */
const quick = once != null && (still || Boolean(once.settle));
const loop = once == null && looped;
/* the first touch hands it over for good */
const [mine, setMine] = React.useState(false);
const handOver = React.useCallback(() => setMine(true), []);
const handedOver = React.useContext(HandedOver);
const off = !SELF_PLAY || hold || (quick ? false : still) || mine || (handedOver && !quick);
const [seen, setSeen] = React.useState(false);
const [paused, setPaused] = React.useState(false);
const [taken, setTaken] = React.useState(0);
const n = Math.max(1, beats.length);
const done = !loop && taken >= n;
React.useEffect(() => {
const el = root.current;
if (!active) return;
/* without an observer (an old browser, a test) it counts as seen */
if (!el || typeof IntersectionObserver === "undefined" || quick) {
const t = window.setTimeout(() => setSeen(true));
return () => window.clearTimeout(t);
}
/* shown once: first half in view starts it, and leaving never stops or restarts it */
const io = once
? new IntersectionObserver((es) => {
if (es.some((e) => e.isIntersecting && e.intersectionRatio >= 0.5)) {
setSeen(true);
io.disconnect();
}
}, { threshold: 0.5 })
: new IntersectionObserver((es) => setSeen(es.some((e) => e.isIntersecting)));
io.observe(el);
return () => io.disconnect();
}, [root, active, once, quick]);
const playing = !off && seen && active && !paused && !done;
const delay = quick ? 0 : taken === 0 ? START : (beats[taken % n] ?? START);
React.useEffect(() => {
if (!playing) return;
const t = window.setTimeout(() => setTaken((k) => k + 1), delay);
return () => window.clearTimeout(t);
}, [playing, taken, delay]);
/* one control in one place: Pause while it plays, Play (a new take) once paused, Replay once it is over or yours */
/* self-play off: never "over", so a demo rests in its FIRST frame, not its end frame */
const control: "pause" | "play" | "replay" = paused || !SELF_PLAY ? "play" : off || done ? "replay" : "pause";
return { step: taken === 0 ? -1 : (taken - 1) % n, taken, playing, control, mine, handOver, pause: () => setPaused(true) };
}
/**
* Presses a real control inside `root`, as the visitor would: the first match of `selector`, or the one whose text is
* `text`. A click only, so it never counts as the visitor's touch.
*/
function pressIn(root: Element | null, selector: string, text?: string) {
const all = [...(root?.querySelectorAll<HTMLElement>(selector) ?? [])];
(text == null ? all[0] : all.find((el) => el.textContent?.trim() === text))?.click();
}
export { HandedOver, PlayOnce, pressIn, useSelfPlay, type PlayOnceHost, type SelfPlayOptions };components/ui/notchset/action-button.tsx
LevelMolecule: made of atoms only.
Made ofButton
Free, no account or key. One command for every shadcn style. With the @notchset registry added, @notchset/<name> works too.
Works with React 18.3 or 19 on Tailwind CSS v4, in any shadcn project. What's tested
The CLI adds the styles to the CSS file named in components.json (tailwind.css). Check that it points at your global stylesheet, that the project uses Tailwind CSS v4, and that the file is imported in your root layout. Installed by hand: paste styles.css into that file.
variant–
ActionKindsend (the default), delete or upload: the mark in front and its moment
kind–
ActionKindDeprecated: use `variant` (kept for one release)
run–
(report: (pct: number) => void) => unknownThe task. Return a promise: busy until it settles, the result when it resolves, failLabel when it throws. An upload calls `report` with how far it is (0-100). Returning nothing lands the result at once (a delete with Undo).
Three usessending an invoice from a deal · deleting a deal with an Undo · uploading a signed contract
Give your coding assistant the Markdown guide instead of screenshots.
https://notchset.dev/api/mcp (setup)v1.2.0 · 2026-11-17
Ships button-class.ts (QUIET_PILL, buttonBase, buttonIntents, buttonResults, buttonSizes, buttonSquare), which it now uses. Ships button-move.ts (ButtonRoll, buttonRollLayer, play, ButtonRollState, useButtonRoll), which it now uses. Internal files split; installs smaller; no change to the piece's own API.
v1.1.0 · 2026-11-17
New props: variant.
v1.0.0 · 2026-11-09
Released free with the Notchset system.