{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-dots-morph",
  "type": "registry:component",
  "title": "Button Dots Morph",
  "description": "The letters of the label fold inward and become three hopping dots while the action runs. The dots then pinch together and the done label rises in letter by letter behind a drawn check.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "loading",
    "dots",
    "letters",
    "morph",
    "publish"
  ],
  "docs": "https://hyperblur.dev/effects/button-dots-morph",
  "files": [
    {
      "path": "registry/hyperblur/button-dots-morph.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-dots-morph.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ButtonDotsMorphStatus = \"idle\" | \"loading\" | \"done\";\n\nexport interface ButtonDotsMorphProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onClick\" | \"children\"> {\n  children?: string;\n  loadingLabel?: string;\n  doneLabel?: string;\n  status?: ButtonDotsMorphStatus;\n  onClick?: (event: React.MouseEvent<HTMLButtonElement>) => unknown;\n  duration?: number;\n  resetAfter?: number;\n  variant?: \"light\" | \"accent\" | \"dark\";\n  accent?: string;\n}\n\nconst css = `\n.hb-xb5 {\n  --hb-xb5-c: #2f7bff;\n  --hb-xb5-bg: #f4f4f5;\n  --hb-xb5-fg: #0b0b0c;\n  --hb-xb5-ok: #16a34a;\n  position: relative;\n  display: inline-grid;\n  place-items: center;\n  box-sizing: border-box;\n  margin: 0;\n  padding: 0 22px;\n  height: 44px;\n  border: 0;\n  border-radius: 999px;\n  font: inherit;\n  font-size: 15px;\n  font-weight: 600;\n  letter-spacing: -0.01em;\n  color: var(--hb-xb5-fg);\n  background: var(--hb-xb5-bg);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.65), inset 0 -2px 0 rgba(0, 0, 0, 0.08), 0 10px 24px -12px rgba(0, 0, 0, 0.9), 0 0 0 1px rgba(255, 255, 255, 0.04);\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1), background 0.4s ease, color 0.4s ease, box-shadow 0.3s ease;\n}\n.hb-xb5 *, .hb-xb5 *::before, .hb-xb5 *::after { box-sizing: border-box; }\n.hb-xb5[data-variant=\"accent\"] { --hb-xb5-bg: var(--hb-xb5-c); --hb-xb5-fg: #fff; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.28), 0 10px 24px -12px var(--hb-xb5-c); }\n.hb-xb5[data-variant=\"dark\"] { --hb-xb5-bg: #1a1a1a; --hb-xb5-fg: #ededed; box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px #2c2c2c, 0 10px 24px -12px rgba(0, 0, 0, 0.9); }\n.hb-xb5:hover[data-state=\"idle\"]:not(:disabled) { transform: translateY(-1px); }\n.hb-xb5:active[data-state=\"idle\"]:not(:disabled) { transform: scale(0.96); }\n.hb-xb5[data-state=\"loading\"] { cursor: progress; }\n.hb-xb5[data-state=\"done\"] { cursor: default; }\n.hb-xb5:focus-visible { outline: 2px solid var(--hb-xb5-c); outline-offset: 3px; }\n.hb-xb5:disabled[data-state=\"idle\"] { opacity: 0.45; cursor: not-allowed; }\n.hb-xb5-row { grid-area: 1 / 1; display: inline-flex; align-items: center; white-space: pre; pointer-events: none; }\n.hb-xb5-ch {\n  display: inline-block;\n  transition: transform 0.42s cubic-bezier(0.55, 0, 0.3, 1) var(--hb-xb5-dl, 0s), opacity 0.3s ease var(--hb-xb5-dl, 0s), filter 0.3s ease var(--hb-xb5-dl, 0s);\n}\n.hb-xb5-row[data-on=\"false\"] .hb-xb5-ch { transform: translateX(calc(var(--hb-xb5-o) * -0.62em)) translateY(0.1em) scale(0.15); opacity: 0; filter: blur(2px); }\n.hb-xb5-row[data-kind=\"done\"] .hb-xb5-ch { transition: transform 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) var(--hb-xb5-dl, 0s), opacity 0.3s ease var(--hb-xb5-dl, 0s); }\n.hb-xb5-row[data-kind=\"done\"][data-on=\"false\"] .hb-xb5-ch { transform: translateY(0.7em) rotate(8deg); filter: none; }\n.hb-xb5-ok {\n  display: inline-grid;\n  place-items: center;\n  width: 18px;\n  height: 18px;\n  margin-right: 8px;\n  border-radius: 50%;\n  background: var(--hb-xb5-ok);\n  color: #fff;\n  transform: scale(0);\n  transition: transform 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.05s;\n}\n.hb-xb5-row[data-kind=\"done\"][data-on=\"true\"] .hb-xb5-ok { transform: scale(1); }\n.hb-xb5-ok svg { width: 11px; height: 11px; fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-xb5-ok path { stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset 0.4s cubic-bezier(0.65, 0, 0.35, 1) 0.3s; }\n.hb-xb5-row[data-kind=\"done\"][data-on=\"true\"] .hb-xb5-ok path { stroke-dashoffset: 0; }\n.hb-xb5-dots { grid-area: 1 / 1; display: inline-flex; gap: 6px; pointer-events: none; }\n.hb-xb5-dot { width: 7px; height: 7px; transform: scale(0); opacity: 0; transition: transform 0.35s cubic-bezier(0.34, 1.56, 0.64, 1), opacity 0.2s ease, translate 0.35s cubic-bezier(0.55, 0, 0.3, 1); }\n.hb-xb5[data-state=\"loading\"] .hb-xb5-dot { transform: scale(1); opacity: 1; transition-delay: 0.28s; }\n.hb-xb5-dot > i { display: block; width: 100%; height: 100%; border-radius: 50%; background: currentColor; font-style: normal; }\n.hb-xb5[data-state=\"loading\"] .hb-xb5-dot > i { animation: hb-xb5-hop 0.9s cubic-bezier(0.45, 0, 0.55, 1) 0.5s infinite; }\n.hb-xb5[data-state=\"loading\"] .hb-xb5-dot:nth-child(2) > i { animation-delay: 0.62s; }\n.hb-xb5[data-state=\"loading\"] .hb-xb5-dot:nth-child(3) > i { animation-delay: 0.74s; }\n.hb-xb5-dot:first-child { translate: 0 0; }\n.hb-xb5[data-state=\"done\"] .hb-xb5-dot { transform: scale(0.4); opacity: 0; }\n.hb-xb5[data-state=\"done\"] .hb-xb5-dot:first-child { translate: 13px 0; }\n.hb-xb5[data-state=\"done\"] .hb-xb5-dot:last-child { translate: -13px 0; }\n@keyframes hb-xb5-hop { 0%, 60%, 100% { transform: translateY(0) scale(1, 1); } 20% { transform: translateY(-7px) scale(0.9, 1.1); } 40% { transform: translateY(0) scale(1.15, 0.85); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xb5, .hb-xb5 * { transition-duration: 0.01s !important; transition-delay: 0s !important; }\n  .hb-xb5-dot > i { animation: none !important; }\n}\n`;\n\nfunction isThenable(v: unknown): v is PromiseLike<unknown> {\n  return typeof v === \"object\" && v !== null && typeof (v as { then?: unknown }).then === \"function\";\n}\n\nfunction Letters({ text, on, kind }: { text: string; on: boolean; kind: \"idle\" | \"done\" }) {\n  const chars = Array.from(text);\n  const mid = (chars.length - 1) / 2;\n  return (\n    <span className=\"hb-xb5-row\" data-on={on ? \"true\" : \"false\"} data-kind={kind} aria-hidden={!on}>\n      {kind === \"done\" && (\n        <span className=\"hb-xb5-ok\">\n          <svg viewBox=\"0 0 24 24\">\n            <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n          </svg>\n        </span>\n      )}\n      {chars.map((ch, i) => {\n        const o = i - mid;\n        const delay = kind === \"done\" ? (on ? 0.12 + i * 0.025 : 0) : on ? Math.abs(o) * 0.022 + 0.05 : (mid - Math.abs(o)) * 0.018;\n        return (\n          <span key={i} className=\"hb-xb5-ch\" style={{ \"--hb-xb5-o\": o.toFixed(2), \"--hb-xb5-dl\": `${delay.toFixed(3)}s` } as React.CSSProperties}>\n            {ch}\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function ButtonDotsMorph({\n  children = \"Publish story\",\n  loadingLabel = \"Publishing\",\n  doneLabel = \"Published\",\n  status,\n  onClick,\n  duration = 1700,\n  resetAfter = 2000,\n  variant = \"light\",\n  accent = \"#2f7bff\",\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  ...rest\n}: ButtonDotsMorphProps) {\n  const [inner, setInner] = React.useState<ButtonDotsMorphStatus>(\"idle\");\n  const timers = React.useRef<number[]>([]);\n  const current = status ?? inner;\n\n  React.useEffect(() => {\n    const list = timers.current;\n    return () => list.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  const done = () => {\n    setInner(\"done\");\n    timers.current.push(window.setTimeout(() => setInner(\"idle\"), resetAfter));\n  };\n\n  const handle = (e: React.MouseEvent<HTMLButtonElement>) => {\n    if (disabled || current !== \"idle\") return;\n    setInner(\"loading\");\n    const started = performance.now();\n    const result = onClick?.(e);\n    if (isThenable(result)) {\n      const finish = () => timers.current.push(window.setTimeout(done, Math.max(0, 900 - (performance.now() - started))));\n      result.then(finish, () => {\n        timers.current.push(window.setTimeout(() => setInner(\"idle\"), 300));\n      });\n    } else {\n      timers.current.push(window.setTimeout(done, duration));\n    }\n  };\n\n  return (\n    <button\n      type={type}\n      disabled={disabled}\n      aria-busy={current === \"loading\" || undefined}\n      aria-label={current === \"loading\" ? loadingLabel : current === \"done\" ? doneLabel : children}\n      className={`hb-xb5 ${className}`.trim()}\n      data-state={current}\n      data-variant={variant}\n      style={{ \"--hb-xb5-c\": accent, ...style } as React.CSSProperties}\n      onClick={handle}\n      {...rest}\n    >\n      <style href=\"hb-button-dots-morph\" precedence=\"default\">{css}</style>\n      <Letters text={children} on={current === \"idle\"} kind=\"idle\" />\n      <Letters text={doneLabel} on={current === \"done\"} kind=\"done\" />\n      <span className=\"hb-xb5-dots\" aria-hidden=\"true\">\n        <span className=\"hb-xb5-dot\">\n          <i />\n        </span>\n        <span className=\"hb-xb5-dot\">\n          <i />\n        </span>\n        <span className=\"hb-xb5-dot\">\n          <i />\n        </span>\n      </span>\n      <span role=\"status\" aria-live=\"polite\" style={{ position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", clip: \"rect(0 0 0 0)\" }}>\n        {current === \"loading\" ? loadingLabel : current === \"done\" ? doneLabel : \"\"}\n      </span>\n    </button>\n  );\n}\n"
    }
  ]
}