{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "micro-slide-commit",
  "type": "registry:component",
  "title": "Slide Commit",
  "description": "A press-and-slide control for destructive actions. The track turns from neutral to danger as the handle moves and locks with a pop when it reaches the end. Hold Enter does the same from the keyboard.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "micro",
    "slider",
    "confirm",
    "destructive",
    "delete",
    "gesture",
    "danger"
  ],
  "docs": "https://hyperblur.dev/effects/micro-slide-commit",
  "files": [
    {
      "path": "registry/hyperblur/micro-slide-commit.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/micro-slide-commit.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface SlideCommitProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\" | \"onChange\" | \"color\"> {\n  label?: string;\n  committedLabel?: string;\n  onCommit?: () => void;\n  accent?: string;\n  threshold?: number;\n  holdDuration?: number;\n  resetAfter?: number;\n  disabled?: boolean;\n}\n\nconst css = `\n.hb-qs4 {\n  --hb-qs4-c: #ff4d5e;\n  --hb-qs4-p: 0;\n  position: relative;\n  box-sizing: border-box;\n  width: 100%;\n  height: 54px;\n  padding: 5px;\n  font: inherit;\n  font-size: 14px;\n  color: #ededed;\n  background: #141414;\n  border: 1px solid #262626;\n  border-radius: 999px;\n  overflow: hidden;\n  isolation: isolate;\n  user-select: none;\n  -webkit-user-select: none;\n  transition: border-color 0.3s ease;\n}\n.hb-qs4 *, .hb-qs4 *::before, .hb-qs4 *::after { box-sizing: border-box; font-family: inherit; }\n.hb-qs4[data-p=\"on\"] { border-color: color-mix(in srgb, var(--hb-qs4-c) 60%, #262626); }\n.hb-qs4[data-disabled=\"true\"] { opacity: 0.45; }\n.hb-qs4-f {\n  position: absolute;\n  top: 0;\n  bottom: 0;\n  left: 0;\n  z-index: -1;\n  width: calc(52px + var(--hb-qs4-p) * (100% - 52px));\n  border-radius: 999px;\n  background: linear-gradient(90deg, color-mix(in srgb, var(--hb-qs4-c) 55%, #141414) 0%, var(--hb-qs4-c) 100%);\n  opacity: calc(0.15 + var(--hb-qs4-p) * 0.85);\n  transition: width 0.45s cubic-bezier(0.34, 1.4, 0.5, 1), opacity 0.3s ease;\n}\n.hb-qs4[data-drag=\"true\"] .hb-qs4-f, .hb-qs4[data-hold=\"true\"] .hb-qs4-f { transition: none; }\n.hb-qs4-l {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  padding-left: 40px;\n  font-weight: 500;\n  letter-spacing: 0.01em;\n  pointer-events: none;\n  opacity: max(0, calc(1 - var(--hb-qs4-p) * 1.7));\n}\n.hb-qs4-lt {\n  color: transparent;\n  background: linear-gradient(100deg, #6f6f6f 35%, #f2f2f2 50%, #6f6f6f 65%) 0 0 / 250% 100%;\n  -webkit-background-clip: text;\n  background-clip: text;\n  animation: hb-qs4-shine 2.8s linear infinite;\n}\n.hb-qs4-d {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  gap: 8px;\n  font-weight: 600;\n  color: #fff;\n  pointer-events: none;\n  opacity: 0;\n  transform: scale(0.9);\n  transition: opacity 0.25s ease 0.15s, transform 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) 0.15s;\n}\n.hb-qs4[data-done=\"true\"] .hb-qs4-d { opacity: 1; transform: scale(1); }\n.hb-qs4[data-done=\"true\"] .hb-qs4-l { opacity: 0; }\n.hb-qs4-h {\n  position: absolute;\n  top: 4px;\n  left: calc(4px + var(--hb-qs4-p) * (100% - 52px));\n  display: grid;\n  place-items: center;\n  width: 44px;\n  height: 44px;\n  margin: 0;\n  padding: 0;\n  color: #0a0a0a;\n  background: #f2f2f2;\n  border: 0;\n  border-radius: 999px;\n  cursor: grab;\n  touch-action: none;\n  -webkit-tap-highlight-color: transparent;\n  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45);\n  transition: left 0.45s cubic-bezier(0.34, 1.4, 0.5, 1), transform 0.2s ease, background-color 0.25s ease, color 0.25s ease;\n  animation: hb-qs4-nudge 3.6s ease-in-out infinite;\n}\n.hb-qs4-h:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }\n.hb-qs4-h:disabled { cursor: not-allowed; animation: none; }\n.hb-qs4[data-drag=\"true\"] .hb-qs4-h, .hb-qs4[data-hold=\"true\"] .hb-qs4-h { transition: transform 0.2s ease, background-color 0.25s ease; animation: none; cursor: grabbing; transform: scale(1.04); }\n.hb-qs4[data-done=\"true\"] .hb-qs4-h {\n  animation: hb-qs4-lock 0.55s cubic-bezier(0.34, 1.56, 0.64, 1);\n  background: #fff;\n  color: var(--hb-qs4-c);\n}\n.hb-qs4-i { grid-area: 1 / 1; width: 20px; height: 20px; transition: opacity 0.2s ease, transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-qs4-ic { opacity: 1; }\n.hb-qs4-ik { opacity: 0; transform: scale(0.4) rotate(-30deg); }\n.hb-qs4[data-done=\"true\"] .hb-qs4-ic { opacity: 0; transform: scale(0.4); }\n.hb-qs4[data-done=\"true\"] .hb-qs4-ik { opacity: 1; transform: scale(1) rotate(0deg); }\n.hb-qs4-ic path { animation: hb-qs4-chev 1.4s ease-in-out infinite; }\n.hb-qs4-ic path:nth-child(2) { animation-delay: 0.18s; }\n.hb-qs4[data-drag=\"true\"] .hb-qs4-ic path, .hb-qs4[data-hold=\"true\"] .hb-qs4-ic path { animation: none; opacity: 1; }\n.hb-qs4-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  padding: 0;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n  border: 0;\n}\n@keyframes hb-qs4-shine {\n  from { background-position: 150% 0; }\n  to { background-position: -50% 0; }\n}\n@keyframes hb-qs4-nudge {\n  0%, 62%, 100% { translate: 0 0; }\n  72% { translate: 9px 0; }\n  82% { translate: 0 0; }\n  90% { translate: 5px 0; }\n}\n@keyframes hb-qs4-lock {\n  0% { transform: scale(1); }\n  35% { transform: scale(0.84); }\n  70% { transform: scale(1.12); }\n  100% { transform: scale(1); }\n}\n@keyframes hb-qs4-chev {\n  0%, 100% { opacity: 0.35; }\n  50% { opacity: 1; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qs4, .hb-qs4-f, .hb-qs4-h, .hb-qs4-d, .hb-qs4-i { transition: none; }\n  .hb-qs4-lt, .hb-qs4-h, .hb-qs4-ic path { animation: none; }\n  .hb-qs4-lt { color: #8f8f8f; background: none; }\n  .hb-qs4[data-done=\"true\"] .hb-qs4-h { animation: none; }\n}\n`;\n\nexport function SlideCommit({\n  label = \"Slide to delete\",\n  committedLabel = \"Deleted\",\n  onCommit,\n  accent = \"#ff4d5e\",\n  threshold = 0.92,\n  holdDuration = 1200,\n  resetAfter = 2200,\n  disabled = false,\n  className = \"\",\n  style,\n  ...rest\n}: SlideCommitProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const handleRef = React.useRef<HTMLButtonElement>(null);\n  const progress = React.useRef(0);\n  const dragging = React.useRef(false);\n  const holding = React.useRef(false);\n  const raf = React.useRef(0);\n  const timer = React.useRef(0);\n  const latest = React.useRef(onCommit);\n  const hintId = React.useId();\n  const [done, setDone] = React.useState(false);\n  const [mode, setMode] = React.useState<\"idle\" | \"drag\" | \"hold\">(\"idle\");\n\n  React.useEffect(() => {\n    latest.current = onCommit;\n  }, [onCommit]);\n\n  React.useEffect(() => {\n    return () => {\n      cancelAnimationFrame(raf.current);\n      window.clearTimeout(timer.current);\n    };\n  }, []);\n\n  function paint(p: number) {\n    progress.current = p;\n    const root = rootRef.current;\n    if (!root) return;\n    root.style.setProperty(\"--hb-qs4-p\", p.toFixed(4));\n    root.dataset.p = p > 0.02 ? \"on\" : \"off\";\n  }\n\n  function settle() {\n    dragging.current = false;\n    holding.current = false;\n    cancelAnimationFrame(raf.current);\n    setMode(\"idle\");\n  }\n\n  function commit() {\n    settle();\n    paint(1);\n    setDone(true);\n    latest.current?.();\n    if (resetAfter > 0) {\n      timer.current = window.setTimeout(() => {\n        setDone(false);\n        paint(0);\n      }, resetAfter);\n    }\n  }\n\n  function release() {\n    if (!dragging.current) return;\n    const p = progress.current;\n    if (p >= threshold) commit();\n    else {\n      settle();\n      paint(0);\n    }\n  }\n\n  function readX(clientX: number) {\n    const root = rootRef.current;\n    const handle = handleRef.current;\n    if (!root || !handle) return 0;\n    const box = root.getBoundingClientRect();\n    const span = Math.max(1, box.width - 2 - 8 - handle.offsetWidth);\n    return Math.min(1, Math.max(0, (clientX - box.left - 1 - 4 - handle.offsetWidth / 2) / span));\n  }\n\n  function onPointerDown(e: React.PointerEvent<HTMLButtonElement>) {\n    if (disabled || done || e.button !== 0) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    dragging.current = true;\n    setMode(\"drag\");\n  }\n\n  function onPointerMove(e: React.PointerEvent<HTMLButtonElement>) {\n    if (!dragging.current) return;\n    paint(readX(e.clientX));\n  }\n\n  function startHold() {\n    if (disabled || done || holding.current || dragging.current) return;\n    holding.current = true;\n    setMode(\"hold\");\n    const from = progress.current;\n    const t0 = performance.now();\n    const total = Math.max(1, holdDuration);\n    function tick(now: number) {\n      if (!holding.current) return;\n      const p = Math.min(1, from + (now - t0) / total);\n      paint(p);\n      if (p >= 1) {\n        commit();\n        return;\n      }\n      raf.current = requestAnimationFrame(tick);\n    }\n    raf.current = requestAnimationFrame(tick);\n  }\n\n  function endHold() {\n    if (!holding.current) return;\n    settle();\n    paint(0);\n  }\n\n  const vars = { \"--hb-qs4-c\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <>\n      <style href=\"hb-micro-slide-commit\" precedence=\"default\">{css}</style>\n      <div\n        ref={rootRef}\n        className={`hb-qs4 ${className}`}\n        style={vars}\n        data-p=\"off\"\n        data-done={done}\n        data-drag={mode === \"drag\"}\n        data-hold={mode === \"hold\"}\n        data-disabled={disabled}\n        {...rest}\n      >\n        <span className=\"hb-qs4-f\" aria-hidden=\"true\" />\n        <span className=\"hb-qs4-l\" aria-hidden=\"true\">\n          <span className=\"hb-qs4-lt\">{label}</span>\n        </span>\n        <span className=\"hb-qs4-d\" aria-hidden=\"true\">\n          {committedLabel}\n        </span>\n        <button\n          ref={handleRef}\n          type=\"button\"\n          className=\"hb-qs4-h\"\n          disabled={disabled}\n          aria-label={done ? committedLabel : label}\n          aria-describedby={hintId}\n          onPointerDown={onPointerDown}\n          onPointerMove={onPointerMove}\n          onPointerUp={release}\n          onPointerCancel={release}\n          onLostPointerCapture={release}\n          onKeyDown={(e) => {\n            if (e.key !== \"Enter\") return;\n            e.preventDefault();\n            if (!e.repeat) startHold();\n          }}\n          onKeyUp={(e) => {\n            if (e.key !== \"Enter\") return;\n            e.preventDefault();\n            endHold();\n          }}\n          onBlur={endHold}\n          onContextMenu={(e) => e.preventDefault()}\n        >\n          <svg className=\"hb-qs4-i hb-qs4-ic\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"m4.5 5 5 5-5 5\" />\n            <path d=\"m10.5 5 5 5-5 5\" />\n          </svg>\n          <svg className=\"hb-qs4-i hb-qs4-ik\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"m4.5 10.5 3.6 3.6 7.4-8.2\" />\n          </svg>\n        </button>\n        <span id={hintId} className=\"hb-qs4-sr\">\n          Drag the handle to the end, or hold Enter, to confirm\n        </span>\n        <span className=\"hb-qs4-sr\" role=\"status\" aria-live=\"polite\">\n          {done ? committedLabel : \"\"}\n        </span>\n      </div>\n    </>\n  );\n}\n"
    }
  ]
}