{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-download-progress",
  "type": "registry:component",
  "title": "Button Download Progress",
  "description": "Click starts a simulated download. A fill bar and percentage run inside the button and it ends on Done with a drawn check.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "download",
    "progress",
    "percent",
    "loading",
    "file"
  ],
  "docs": "https://hyperblur.dev/effects/button-download-progress",
  "files": [
    {
      "path": "registry/hyperblur/button-download-progress.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-download-progress.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonDownloadProgressProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"color\"> {\n  duration?: number;\n  progressLabel?: React.ReactNode;\n  doneLabel?: React.ReactNode;\n  resetAfter?: number;\n  onComplete?: () => void;\n  variant?: \"outline\" | \"solid\";\n  accent?: string;\n  size?: \"sm\" | \"md\" | \"lg\";\n}\n\ntype Phase = \"idle\" | \"running\" | \"done\";\n\nconst curve: [number, number][] = [\n  [0, 0],\n  [0.12, 0.16],\n  [0.3, 0.34],\n  [0.42, 0.4],\n  [0.6, 0.71],\n  [0.74, 0.78],\n  [0.9, 0.97],\n  [1, 1],\n];\n\nfunction shape(t: number) {\n  if (t <= 0) return 0;\n  if (t >= 1) return 1;\n  for (let i = 1; i < curve.length; i += 1) {\n    const [t1, p1] = curve[i];\n    if (t <= t1) {\n      const [t0, p0] = curve[i - 1];\n      const k = (t - t0) / (t1 - t0);\n      const s = k * k * (3 - 2 * k);\n      return p0 + (p1 - p0) * (0.5 * k + 0.5 * s);\n    }\n  }\n  return 1;\n}\n\nconst css = `\n.hb-qa9 {\n  --hb-qa9-c: #2f7bff;\n  --hb-qa9-bg: #141414;\n  --hb-qa9-fg: #ededed;\n  --hb-qa9-ring: #2a2a2a;\n  --hb-qa9-fill: color-mix(in srgb, var(--hb-qa9-c) 55%, transparent);\n  --hb-qa9-p: 0;\n  position: relative;\n  display: inline-grid;\n  place-items: center;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 0.8em 1.5em;\n  font: inherit;\n  font-size: 15px;\n  font-weight: 600;\n  line-height: 1.2;\n  color: var(--hb-qa9-fg);\n  background: var(--hb-qa9-bg);\n  border: 0;\n  border-radius: 12px;\n  box-shadow: inset 0 0 0 1px var(--hb-qa9-ring);\n  cursor: pointer;\n  overflow: hidden;\n  isolation: isolate;\n  user-select: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: manipulation;\n  transition: transform 0.18s cubic-bezier(0.2, 0.8, 0.2, 1), background-color 0.3s ease, box-shadow 0.3s ease, color 0.3s ease;\n}\n.hb-qa9[data-size=\"sm\"] { font-size: 13px; }\n.hb-qa9[data-size=\"lg\"] { font-size: 17px; }\n.hb-qa9[data-variant=\"solid\"] {\n  --hb-qa9-bg: color-mix(in srgb, var(--hb-qa9-c) 78%, #000000);\n  --hb-qa9-fg: #ffffff;\n  --hb-qa9-ring: transparent;\n  --hb-qa9-fill: var(--hb-qa9-c);\n}\n.hb-qa9[data-phase=\"done\"] {\n  --hb-qa9-bg: #15803d;\n  --hb-qa9-fg: #ffffff;\n  --hb-qa9-ring: transparent;\n  --hb-qa9-fill: #22c55e;\n}\n.hb-qa9[data-phase=\"done\"][data-variant=\"outline\"] {\n  --hb-qa9-bg: #0f2a18;\n  --hb-qa9-fg: #86efac;\n  --hb-qa9-ring: color-mix(in srgb, #22c55e 50%, transparent);\n  --hb-qa9-fill: color-mix(in srgb, #22c55e 18%, transparent);\n}\n.hb-qa9-f {\n  position: absolute;\n  inset: 0;\n  z-index: -1;\n  background: var(--hb-qa9-fill);\n  transform: scaleX(var(--hb-qa9-p));\n  transform-origin: left center;\n  transition: transform 0.14s linear;\n}\n.hb-qa9[data-phase=\"idle\"] .hb-qa9-f { transition: none; }\n.hb-qa9-l {\n  grid-area: 1 / 1;\n  display: inline-flex;\n  align-items: center;\n  gap: 0.55em;\n  white-space: nowrap;\n  opacity: 0;\n  transform: translateY(0.6em);\n  transition: opacity 0.25s ease, transform 0.38s cubic-bezier(0.22, 1, 0.36, 1);\n}\n.hb-qa9-l[data-on=\"true\"] { opacity: 1; transform: none; }\n.hb-qa9-l[data-on=\"false\"][data-past=\"true\"] { transform: translateY(-0.6em); }\n.hb-qa9-n { font-variant-numeric: tabular-nums; min-width: 3ch; text-align: right; }\n.hb-qa9-s { font-size: 0.8em; font-weight: 500; opacity: 0.75; }\n.hb-qa9-i {\n  width: 1.1em;\n  height: 1.1em;\n  flex: none;\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 2;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n}\n.hb-qa9-ck { stroke-width: 2.6; stroke-dasharray: 24; stroke-dashoffset: 24; }\n.hb-qa9-l[data-on=\"true\"] .hb-qa9-ck { animation: hb-qa9-draw 0.4s cubic-bezier(0.65, 0, 0.35, 1) 0.1s forwards; }\n.hb-qa9[data-phase=\"idle\"]:not(:hover):not(:disabled) .hb-qa9-ar { animation: hb-qa9-bob 3.6s ease-in-out 1s infinite; }\n.hb-qa9:hover:not(:disabled):not([data-phase=\"running\"]) { --hb-qa9-ring: color-mix(in srgb, var(--hb-qa9-c) 60%, #2a2a2a); }\n.hb-qa9[data-phase=\"running\"] { cursor: progress; }\n.hb-qa9[data-phase=\"done\"] { cursor: default; }\n.hb-qa9:active:not(:disabled):not([data-phase=\"running\"]) { transform: scale(0.97); }\n.hb-qa9:focus-visible { outline: 2px solid var(--hb-qa9-c); outline-offset: 3px; }\n.hb-qa9:disabled:not([data-phase=\"running\"]):not([data-phase=\"done\"]) { opacity: 0.45; cursor: not-allowed; }\n@keyframes hb-qa9-draw { to { stroke-dashoffset: 0; } }\n@keyframes hb-qa9-bob {\n  0%, 70%, 100% { transform: none; }\n  80% { transform: translateY(2px); }\n  90% { transform: translateY(-1px); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qa9, .hb-qa9-f, .hb-qa9-l { transition-duration: 0.01s; }\n  .hb-qa9 .hb-qa9-ar { animation: none !important; }\n  .hb-qa9-l { transform: none; }\n  .hb-qa9-l[data-on=\"true\"] .hb-qa9-ck { animation: none; stroke-dashoffset: 0; }\n  .hb-qa9:active:not(:disabled) { transform: none; }\n}\n`;\n\nexport function ButtonDownloadProgress({\n  children = \"Download\",\n  progressLabel = \"Downloading\",\n  doneLabel = \"Done\",\n  duration = 3200,\n  resetAfter = 2200,\n  onComplete,\n  onClick,\n  variant = \"outline\",\n  accent = \"#2f7bff\",\n  size = \"md\",\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  ...rest\n}: ButtonDownloadProgressProps) {\n  const [phase, setPhase] = React.useState<Phase>(\"idle\");\n  const [pct, setPct] = React.useState(0);\n  const raf = React.useRef(0);\n  const timer = React.useRef(0);\n  const finished = React.useRef(onComplete);\n\n  React.useEffect(() => {\n    finished.current = onComplete;\n  }, [onComplete]);\n\n  React.useEffect(() => {\n    return () => {\n      cancelAnimationFrame(raf.current);\n      window.clearTimeout(timer.current);\n    };\n  }, []);\n\n  function handleClick(e: React.MouseEvent<HTMLButtonElement>) {\n    if (phase !== \"idle\" || disabled) return;\n    onClick?.(e);\n    const total = Math.max(300, duration);\n    const t0 = performance.now();\n    setPct(0);\n    setPhase(\"running\");\n    function tick(now: number) {\n      const t = Math.min(1, (now - t0) / total);\n      const value = Math.round(shape(t) * 100);\n      setPct(value);\n      if (t < 1) {\n        raf.current = requestAnimationFrame(tick);\n        return;\n      }\n      setPhase(\"done\");\n      finished.current?.();\n      timer.current = window.setTimeout(() => {\n        setPhase(\"idle\");\n        setPct(0);\n      }, Math.max(0, resetAfter));\n    }\n    raf.current = requestAnimationFrame(tick);\n  }\n\n  const vars = {\n    \"--hb-qa9-c\": accent,\n    \"--hb-qa9-p\": phase === \"done\" ? \"1\" : (pct / 100).toFixed(2),\n    ...style,\n  } as React.CSSProperties;\n\n  const order: Phase[] = [\"idle\", \"running\", \"done\"];\n\n  return (\n    <>\n      <style href=\"hb-button-download-progress\" precedence=\"default\">{css}</style>\n      <button\n        type={type}\n        className={`hb-qa9 ${className}`}\n        style={vars}\n        data-variant={variant}\n        data-size={size}\n        data-phase={phase}\n        disabled={disabled || phase !== \"idle\"}\n        aria-busy={phase === \"running\" || undefined}\n        aria-live=\"polite\"\n        onClick={handleClick}\n        {...rest}\n      >\n        <span className=\"hb-qa9-f\" aria-hidden=\"true\" />\n        {order.map((key) => (\n          <span\n            key={key}\n            className=\"hb-qa9-l\"\n            data-on={phase === key ? \"true\" : \"false\"}\n            data-past={order.indexOf(key) < order.indexOf(phase) ? \"true\" : undefined}\n            aria-hidden={phase === key ? undefined : true}\n          >\n            {key === \"idle\" ? (\n              <>\n                <svg className=\"hb-qa9-i hb-qa9-ar\" viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\">\n                  <path d=\"M12 4v11M7 11l5 5 5-5M5 20h14\" />\n                </svg>\n                {children}\n              </>\n            ) : null}\n            {key === \"running\" ? (\n              <>\n                <span className=\"hb-qa9-s\">{progressLabel}</span>\n                <span className=\"hb-qa9-n\">{pct}%</span>\n              </>\n            ) : null}\n            {key === \"done\" ? (\n              <>\n                <svg className=\"hb-qa9-i hb-qa9-ck\" viewBox=\"0 0 24 24\" aria-hidden=\"true\" focusable=\"false\">\n                  <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n                </svg>\n                {doneLabel}\n              </>\n            ) : null}\n          </span>\n        ))}\n      </button>\n    </>\n  );\n}\n"
    }
  ]
}