{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-toggle-count",
  "type": "registry:component",
  "title": "Button Toggle Count",
  "description": "A pill toggle for like, save, bookmark or star. The icon fills from the bottom with a spring pop and sparks, and the count rolls digit by digit like an odometer.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "toggle",
    "like",
    "bookmark",
    "counter",
    "odometer"
  ],
  "docs": "https://hyperblur.dev/effects/button-toggle-count",
  "files": [
    {
      "path": "registry/hyperblur/button-toggle-count.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-toggle-count.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type ButtonToggleCountKind = \"like\" | \"save\" | \"bookmark\" | \"star\";\n\nexport interface ButtonToggleCountProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"onChange\" | \"children\"> {\n  kind?: ButtonToggleCountKind;\n  count?: number;\n  pressed?: boolean;\n  defaultPressed?: boolean;\n  onPressedChange?: (pressed: boolean) => void;\n  label?: string;\n  accent?: string;\n  icon?: React.ReactNode;\n  compact?: boolean;\n}\n\nconst css = `\n.hb-xb6 {\n  --hb-xb6-c: #ff4d6d;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  gap: 8px;\n  box-sizing: border-box;\n  height: 38px;\n  margin: 0;\n  padding: 0 14px 0 11px;\n  border: 0;\n  border-radius: 999px;\n  font: inherit;\n  font-size: 14px;\n  font-weight: 600;\n  color: #d4d4d4;\n  background: linear-gradient(180deg, #1b1b1b, #141414);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.06), inset 0 0 0 1px #2a2a2a, 0 6px 14px -8px rgba(0, 0, 0, 0.9);\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n  transition: color 0.3s ease, box-shadow 0.35s ease, background 0.35s ease, transform 0.2s cubic-bezier(0.34, 1.56, 0.64, 1);\n}\n.hb-xb6 *, .hb-xb6 *::before, .hb-xb6 *::after { box-sizing: border-box; }\n.hb-xb6:hover:not(:disabled) { box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.08), inset 0 0 0 1px #363636, 0 6px 14px -8px rgba(0, 0, 0, 0.9); color: #ededed; }\n.hb-xb6:active:not(:disabled) { transform: scale(0.95); }\n.hb-xb6:focus-visible { outline: 2px solid var(--hb-xb6-c); outline-offset: 3px; }\n.hb-xb6:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-xb6[aria-pressed=\"true\"] {\n  color: color-mix(in srgb, var(--hb-xb6-c) 40%, #fff);\n  background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xb6-c) 16%, #161616), color-mix(in srgb, var(--hb-xb6-c) 8%, #121212));\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.07), inset 0 0 0 1px color-mix(in srgb, var(--hb-xb6-c) 45%, transparent), 0 8px 22px -12px var(--hb-xb6-c);\n}\n.hb-xb6[data-compact=\"true\"] { height: 32px; padding: 0 11px 0 9px; font-size: 13px; gap: 6px; }\n.hb-xb6-ic { position: relative; width: 20px; height: 20px; flex: none; display: grid; place-items: center; }\n.hb-xb6[data-compact=\"true\"] .hb-xb6-ic { width: 17px; height: 17px; }\n.hb-xb6-ic svg { position: absolute; inset: 0; width: 100%; height: 100%; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }\n.hb-xb6-o { fill: none; stroke: currentColor; }\n.hb-xb6-f { fill: var(--hb-xb6-c); stroke: var(--hb-xb6-c); clip-path: inset(100% 0 0 0); transition: clip-path 0.45s cubic-bezier(0.65, 0, 0.35, 1); }\n.hb-xb6[aria-pressed=\"true\"] .hb-xb6-f { clip-path: inset(0 0 0 0); }\n.hb-xb6[data-pop=\"true\"] .hb-xb6-ic { animation: hb-xb6-pop 0.6s cubic-bezier(0.34, 1.56, 0.64, 1); }\n.hb-xb6[data-pop=\"false\"] .hb-xb6-ic { animation: hb-xb6-dip 0.35s ease; }\n.hb-xb6-spark { position: absolute; left: 50%; top: 50%; width: 3px; height: 3px; margin: -1.5px; border-radius: 50%; background: var(--hb-xb6-c); opacity: 0; pointer-events: none; }\n.hb-xb6[data-pop=\"true\"] .hb-xb6-spark { animation: hb-xb6-spark 0.5s cubic-bezier(0.22, 1, 0.36, 1) 0.06s; }\n.hb-xb6-ring { position: absolute; inset: -4px; border-radius: 50%; border: 1.5px solid var(--hb-xb6-c); opacity: 0; pointer-events: none; }\n.hb-xb6[data-pop=\"true\"] .hb-xb6-ring { animation: hb-xb6-ring 0.5s cubic-bezier(0.22, 1, 0.36, 1); }\n.hb-xb6-num { display: inline-flex; font-variant-numeric: tabular-nums; height: 1.2em; line-height: 1.2em; overflow: hidden; }\n.hb-xb6-col { display: inline-block; height: 1.2em; overflow: hidden; }\n.hb-xb6-reel { display: flex; flex-direction: column; transform: translateY(calc(var(--hb-xb6-d) * -1.2em)); transition: transform 0.55s cubic-bezier(0.34, 1.3, 0.64, 1) var(--hb-xb6-dl, 0s); }\n.hb-xb6-reel > span { height: 1.2em; display: block; text-align: center; }\n.hb-xb6-sep { display: inline-block; }\n@keyframes hb-xb6-pop { 0% { transform: scale(1); } 30% { transform: scale(0.7) rotate(-8deg); } 60% { transform: scale(1.28) rotate(4deg); } 100% { transform: scale(1) rotate(0); } }\n@keyframes hb-xb6-dip { 0% { transform: scale(1); } 40% { transform: scale(0.82); } 100% { transform: scale(1); } }\n@keyframes hb-xb6-spark { 0% { opacity: 1; transform: rotate(var(--hb-xb6-a)) translateY(0) scale(1); } 100% { opacity: 0; transform: rotate(var(--hb-xb6-a)) translateY(-17px) scale(0.3); } }\n@keyframes hb-xb6-ring { 0% { opacity: 0.8; transform: scale(0.5); } 100% { opacity: 0; transform: scale(1.4); } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xb6, .hb-xb6 * { transition-duration: 0.01s !important; transition-delay: 0s !important; }\n  .hb-xb6 .hb-xb6-ic, .hb-xb6 .hb-xb6-spark, .hb-xb6 .hb-xb6-ring { animation: none !important; }\n}\n`;\n\nconst paths: Record<ButtonToggleCountKind, string> = {\n  like: \"M12 20.3s-7.6-4.6-9-9.6C2 7.1 4.4 4 7.6 4c1.9 0 3.4 1 4.4 2.5C13 5 14.5 4 16.4 4 19.6 4 22 7.1 21 10.7c-1.4 5-9 9.6-9 9.6z\",\n  save: \"M3.5 7.2c0-1 .8-1.7 1.7-1.7h4.2l2 2.2h7.4c1 0 1.7.8 1.7 1.7v8.4c0 1-.8 1.7-1.7 1.7H5.2c-1 0-1.7-.8-1.7-1.7z\",\n  bookmark: \"M6.5 4.8c0-.7.6-1.3 1.3-1.3h8.4c.7 0 1.3.6 1.3 1.3v15.4l-5.5-3.9-5.5 3.9z\",\n  star: \"M12 3.4l2.6 5.4 5.9.8-4.3 4.1 1.1 5.8L12 16.7l-5.3 2.8 1.1-5.8-4.3-4.1 5.9-.8z\",\n};\n\nconst defaults: Record<ButtonToggleCountKind, { accent: string; label: string }> = {\n  like: { accent: \"#ff4d6d\", label: \"Like\" },\n  save: { accent: \"#2f7bff\", label: \"Save\" },\n  bookmark: { accent: \"#f5b301\", label: \"Bookmark\" },\n  star: { accent: \"#ffc83d\", label: \"Star\" },\n};\n\nfunction format(n: number, compact: boolean) {\n  if (compact && n >= 10000) {\n    const k = n / 1000;\n    return `${k >= 100 ? Math.round(k) : k.toFixed(1).replace(/\\.0$/, \"\")}k`;\n  }\n  return n.toLocaleString(\"en-US\");\n}\n\nfunction Odometer({ value }: { value: string }) {\n  const chars = Array.from(value);\n  return (\n    <span className=\"hb-xb6-num\" aria-hidden=\"true\">\n      {chars.map((ch, i) => {\n        const key = chars.length - i;\n        if (!/\\d/.test(ch)) {\n          return (\n            <span key={`s${key}`} className=\"hb-xb6-sep\">\n              {ch}\n            </span>\n          );\n        }\n        return (\n          <span key={`d${key}`} className=\"hb-xb6-col\">\n            <span className=\"hb-xb6-reel\" style={{ \"--hb-xb6-d\": ch, \"--hb-xb6-dl\": `${((chars.length - i - 1) * 0.04).toFixed(2)}s` } as React.CSSProperties}>\n              {\"0123456789\".split(\"\").map((d) => (\n                <span key={d}>{d}</span>\n              ))}\n            </span>\n          </span>\n        );\n      })}\n    </span>\n  );\n}\n\nexport function ButtonToggleCount({\n  kind = \"like\",\n  count = 1284,\n  pressed,\n  defaultPressed = false,\n  onPressedChange,\n  label,\n  accent,\n  icon,\n  compact = false,\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  onClick,\n  ...rest\n}: ButtonToggleCountProps) {\n  const [inner, setInner] = React.useState(defaultPressed);\n  const [pop, setPop] = React.useState<\"true\" | \"false\" | undefined>(undefined);\n  const on = pressed ?? inner;\n  const total = count + (on ? 1 : 0);\n  const name = label ?? defaults[kind].label;\n  const color = accent ?? defaults[kind].accent;\n  const sparks = [0, 60, 120, 180, 240, 300];\n\n  return (\n    <button\n      type={type}\n      disabled={disabled}\n      aria-pressed={on}\n      aria-label={`${name}, ${total.toLocaleString(\"en-US\")}`}\n      className={`hb-xb6 ${className}`.trim()}\n      data-pop={pop}\n      data-compact={compact ? \"true\" : \"false\"}\n      style={{ \"--hb-xb6-c\": color, ...style } as React.CSSProperties}\n      onClick={(e) => {\n        onClick?.(e);\n        if (e.defaultPrevented) return;\n        const next = !on;\n        if (pressed === undefined) setInner(next);\n        setPop(next ? \"true\" : \"false\");\n        onPressedChange?.(next);\n      }}\n      onAnimationEnd={(e) => {\n        if (e.target === e.currentTarget.querySelector(\".hb-xb6-ic\")) setPop(undefined);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-button-toggle-count\" precedence=\"default\">{css}</style>\n      <span className=\"hb-xb6-ic\" aria-hidden=\"true\">\n        <span className=\"hb-xb6-ring\" />\n        {sparks.map((a) => (\n          <span key={a} className=\"hb-xb6-spark\" style={{ \"--hb-xb6-a\": `${a}deg` } as React.CSSProperties} />\n        ))}\n        {icon ?? (\n          <>\n            <svg viewBox=\"0 0 24 24\" className=\"hb-xb6-o\">\n              <path d={paths[kind]} />\n            </svg>\n            <svg viewBox=\"0 0 24 24\" className=\"hb-xb6-f\">\n              <path d={paths[kind]} />\n            </svg>\n          </>\n        )}\n      </span>\n      <Odometer value={format(total, compact)} />\n    </button>\n  );\n}\n"
    }
  ]
}