{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hold-to-confirm","type":"registry:ui","title":"Hold To Confirm","description":"Destructive action guard: press and hold until the bar fills. Works with Space and Enter.","dependencies":[],"registryDependencies":[],"files":[{"path":"registry/ui/hold-to-confirm.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useEffect, useRef, useState, type KeyboardEvent } from \"react\";\n\nexport interface HoldToConfirmProps {\n  /** Ms the button must be held. */\n  duration?: number;\n  label?: string;\n  confirmedLabel?: string;\n  color?: string;\n  onConfirm?: () => void;\n  className?: string;\n}\n\nexport function HoldToConfirm({\n  duration = 1500,\n  label = \"Hold to delete\",\n  confirmedLabel = \"Deleted\",\n  color = \"#ef4444\",\n  onConfirm,\n  className,\n}: HoldToConfirmProps) {\n  const [holding, setHolding] = useState(false);\n  const [done, setDone] = useState(false);\n  const timer = useRef<number | undefined>(undefined);\n\n  const start = () => {\n    if (done) return;\n    setHolding(true);\n    timer.current = window.setTimeout(() => {\n      setHolding(false);\n      setDone(true);\n      onConfirm?.();\n      timer.current = window.setTimeout(() => setDone(false), 2000);\n    }, duration);\n  };\n\n  const cancel = () => {\n    if (done) return;\n    window.clearTimeout(timer.current);\n    setHolding(false);\n  };\n\n  useEffect(() => () => window.clearTimeout(timer.current), []);\n\n  const onKey = (e: KeyboardEvent<HTMLButtonElement>, down: boolean) => {\n    if (e.key !== \" \" && e.key !== \"Enter\") return;\n    e.preventDefault();\n    if (down && !e.repeat) start();\n    if (!down) cancel();\n  };\n\n  return (\n    <button\n      type=\"button\"\n      onPointerDown={start}\n      onPointerUp={cancel}\n      onPointerLeave={cancel}\n      onKeyDown={(e) => onKey(e, true)}\n      onKeyUp={(e) => onKey(e, false)}\n      onContextMenu={(e) => e.preventDefault()}\n      className={`relative h-11 select-none overflow-hidden rounded-full border border-border bg-card px-6 text-sm font-medium text-foreground ${className ?? \"\"}`}\n      style={{ touchAction: \"none\" }}\n    >\n      <span\n        aria-hidden\n        className=\"absolute inset-y-0 left-0\"\n        style={{\n          width: holding || done ? \"100%\" : \"0%\",\n          background: color,\n          opacity: 0.9,\n          transition: holding ? `width ${duration}ms linear` : \"width 250ms ease-out\",\n        }}\n      />\n      <span className=\"relative\" aria-live=\"polite\">\n        {done ? confirmedLabel : label}\n      </span>\n    </button>\n  );\n}\n"}]}