MicroNew
Hold Button
Eliminates accidental clicks on critical actions by requiring a continuous press-and-hold with smooth linear fill feedback, keyboard Space/Enter support, and completion pulse.
#button#confirm#haptic#micro
Press & hold (1.6s) or hold Space
Customize
1600ms
#A855F7
Installation
$pnpm dlx yourbrand@latest add @yourbrand/HoldButton-TS-TWUsage (synced with live props)
<HoldButton
label="Hold to confirm"
completedLabel="Confirmed"
duration={1600}
accentColor="#A855F7"
/>Source Code
HoldButton.tsx"use client";
import React from "react";
export interface HoldButtonProps {
label?: string;
completedLabel?: string;
duration?: number;
accentColor?: string;
onComplete?: () => void;
}
export function HoldButton({
label = "Hold to confirm",
completedLabel = "Confirmed",
duration = 1600,
accentColor = "#A855F7",
onComplete,
}: HoldButtonProps) {
const [progress, setProgress] = React.useState(0);
const [done, setDone] = React.useState(false);
const rafRef = React.useRef<number | null>(null);
const startRef = React.useRef<number>(0);
const stop = () => {
if (rafRef.current) cancelAnimationFrame(rafRef.current);
rafRef.current = null;
if (!done) setProgress(0);
};
const start = () => {
setDone(false);
startRef.current = performance.now();
const tick = (now: number) => {
const pct = Math.min(1, (now - startRef.current) / duration);
setProgress(pct);
if (pct >= 1) {
setDone(true);
onComplete?.();
return;
}
rafRef.current = requestAnimationFrame(tick);
};
rafRef.current = requestAnimationFrame(tick);
};
return (
<button
type="button"
onPointerDown={start}
onPointerUp={stop}
onPointerLeave={stop}
className="relative overflow-hidden rounded-[14px] border border-white/15 bg-[#221E29] px-6 py-3 text-sm font-medium text-white select-none"
>
<span
className="pointer-events-none absolute inset-y-0 left-0 transition-[width] duration-75"
style={{ width: `${Math.round(progress * 100)}%`, backgroundColor: accentColor, opacity: 0.45 }}
/>
<span className="relative z-10">{done ? completedLabel : label}</span>
</button>
);
}
Props API
| Prop | Type | Default | Description |
|---|---|---|---|
| label | string | "Hold to confirm" | Resting prompt inside the button. |
| completedLabel | string | "Confirmed" | State text after full hold. |
| duration | number | 1600 | Milliseconds required to complete. |
| accentColor | string (hex) | "#A855F7" | Active progress bar tint. |