A high-trust mobile & FinTech safety interaction requiring a 1.2-second press-and-hold (mouse, touch, or Spacebar) with synchronized SVG progress ring and smooth fill rollback if released early.
'use client'
import { useRef, useState } from 'react'
export function HoldToConfirmButton({ durationMs = 1200, onConfirm }: { durationMs?: number; onConfirm?: () => void }) {
const [progress, setProgress] = useState(0)
const [confirmed, setConfirmed] = useState(false)
const rafRef = useRef<number>(0)
const startRef = useRef<number>(0)
const begin = () => {
if (confirmed) { setConfirmed(false); setProgress(0); return }
startRef.current = performance.now()
const tick = (now: number) => {
const p = Math.min(1, (now - startRef.current) / durationMs)
setProgress(p)
if (p >= 1) { setConfirmed(true); onConfirm?.(); return }
rafRef.current = requestAnimationFrame(tick)
}
rafRef.current = requestAnimationFrame(tick)
}
const cancel = () => {
cancelAnimationFrame(rafRef.current)
if (!confirmed) setProgress(0)
}
return (
<button
type="button"
onPointerDown={begin}
onPointerUp={cancel}
onPointerLeave={cancel}
className="relative flex h-14 w-full items-center justify-center overflow-hidden rounded-full border border-white/15 bg-slate-900 font-semibold text-white touch-none select-none"
>
<span
className="absolute inset-y-0 left-0 transition-[width] duration-75"
style={{ width: `${progress * 100}%`, background: `linear-gradient(90deg, #635bff, #10b981)` }}
/>
<span className="relative z-10 text-sm">
{confirmed ? 'Transfer Sent ✓' : progress > 0 ? `Confirming… ${Math.round(progress * 100)}%` : 'Hold 1.2s to Confirm'}
</span>
</button>
)
}Loading single-file HTML…
Create a single-file Hold-to-Confirm Safety Button using pure HTML, inline SVG, and vanilla JS (zero dependencies) for FinTech transfers and destructive mobile actions on a dark slate card (#090d16). - Hold Physics: Track pointerdown/pointerup and Spacebar/Enter key hold using requestAnimationFrame over 1,200ms, smoothly advancing both a gradient fill bar (#635bff → #10b981) and a circular SVG stroke-dashoffset ring. Releasing early smoothly rewinds progress back to 0%; reaching 100% locks into a crisp "Transfer Sent ✓" confirmation state. - Mobile Ready: Uses touch-action: none and user-select: none so mobile users can press-and-hold cleanly without triggering text selection.
WHY THIS WORKS IN PRODUCTION
- Prevents accidental wire transfers, trades, and destructive deletes
- Synchronized SVG ring + gradient bar fill with smooth early-release rollback
- Supports Mouse, Mobile Touch (touch-action: none) and Spacebar hold
- Includes drop-in <HoldToConfirmButton /> React + Tailwind TSX code
DROP-IN SPECS // WEB & MOBILE FIT









