{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "follow-button",
  "type": "registry:component",
  "title": "Follow Button",
  "description": "A pill that morphs its width between Follow, Following and Unfollow on hover, with a check that draws itself.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "social",
    "follow",
    "button",
    "morph",
    "profile",
    "subscribe",
    "toggle"
  ],
  "docs": "https://hyperblur.dev/effects/follow-button",
  "files": [
    {
      "path": "registry/hyperblur/follow-button.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/follow-button.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface FollowButtonLabels {\n  follow?: string;\n  following?: string;\n  unfollow?: string;\n}\n\nexport interface FollowButtonProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"onChange\" | \"defaultValue\"> {\n  following?: boolean;\n  defaultFollowing?: boolean;\n  onFollowChange?: (following: boolean) => void;\n  labels?: FollowButtonLabels;\n  accent?: string;\n}\n\ntype Face = \"follow\" | \"following\" | \"unfollow\";\n\nconst css = `\n.hb-qb6 {\n  --hb-qb6-a: #2f7bff;\n  position: relative;\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  height: 36px;\n  margin: 0;\n  padding: 0 16px;\n  overflow: hidden;\n  border: 1px solid transparent;\n  border-radius: 999px;\n  font: inherit;\n  font-size: 13px;\n  font-weight: 600;\n  line-height: 1;\n  white-space: nowrap;\n  box-sizing: border-box;\n  cursor: pointer;\n  user-select: none;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  transition: width 0.38s cubic-bezier(0.3, 1.1, 0.4, 1), background-color 0.25s ease, border-color 0.25s ease, color 0.25s ease, transform 0.12s ease;\n}\n.hb-qb6 *, .hb-qb6 *::before, .hb-qb6 *::after { box-sizing: border-box; }\n.hb-qb6:active:not(:disabled) { transform: scale(0.96); }\n.hb-qb6:focus-visible { outline: 2px solid var(--hb-qb6-a); outline-offset: 2px; }\n.hb-qb6:disabled { opacity: 0.5; cursor: not-allowed; }\n.hb-qb6[data-face=\"follow\"] { background: #ededed; color: #0a0a0a; }\n.hb-qb6[data-face=\"follow\"]:hover:not(:disabled) { background: #ffffff; }\n.hb-qb6[data-face=\"following\"] { background: #171717; border-color: #2e2e2e; color: #ededed; }\n.hb-qb6[data-face=\"unfollow\"] {\n  background: color-mix(in srgb, #ff5a5f 11%, #171717);\n  border-color: color-mix(in srgb, #ff5a5f 48%, #262626);\n  color: #ff8a8e;\n}\n.hb-qb6-face {\n  display: inline-flex;\n  align-items: center;\n  gap: 7px;\n  animation: hb-qb6-in 0.3s cubic-bezier(0.3, 1.2, 0.5, 1) both;\n}\n@keyframes hb-qb6-in {\n  from { opacity: 0; transform: translateY(7px); }\n  to { opacity: 1; transform: translateY(0); }\n}\n.hb-qb6-icon {\n  display: block;\n  width: 14px;\n  height: 14px;\n  flex: none;\n  fill: none;\n  stroke: currentColor;\n  stroke-width: 2.2;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n}\n.hb-qb6[data-face=\"following\"] .hb-qb6-icon { stroke: var(--hb-qb6-a); }\n.hb-qb6-check {\n  stroke-dasharray: 20;\n  stroke-dashoffset: 20;\n  animation: hb-qb6-draw 0.4s ease-out 0.12s forwards;\n}\n@keyframes hb-qb6-draw {\n  to { stroke-dashoffset: 0; }\n}\n.hb-qb6-measure {\n  position: absolute;\n  left: 0;\n  top: 0;\n  visibility: hidden;\n  pointer-events: none;\n}\n.hb-qb6-measure > span {\n  position: absolute;\n  left: 0;\n  top: 0;\n  display: inline-flex;\n  align-items: center;\n  gap: 7px;\n  white-space: nowrap;\n}\n.hb-qb6-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  margin: -1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-qb6 { transition: none; }\n  .hb-qb6-face { animation: none; }\n  .hb-qb6-check { animation: none; stroke-dashoffset: 0; }\n}\n`;\n\nconst faces: Face[] = [\"follow\", \"following\", \"unfollow\"];\n\nfunction Icon({ face }: { face: Face }) {\n  return (\n    <svg className=\"hb-qb6-icon\" viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n      {face === \"follow\" && <path d=\"M12 5v14M5 12h14\" />}\n      {face === \"following\" && <path className=\"hb-qb6-check\" d=\"M5 12.5l4.6 4.6L19 7.4\" />}\n      {face === \"unfollow\" && <path d=\"M6.5 6.5l11 11M17.5 6.5l-11 11\" />}\n    </svg>\n  );\n}\n\nexport function FollowButton({\n  following,\n  defaultFollowing = false,\n  onFollowChange,\n  labels,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onClick,\n  onPointerEnter,\n  onPointerLeave,\n  ...rest\n}: FollowButtonProps) {\n  const controlled = following !== undefined;\n  const [inner, setInner] = React.useState(defaultFollowing);\n  const current = controlled ? following : inner;\n  const [peek, setPeek] = React.useState(false);\n\n  const btnRef = React.useRef<HTMLButtonElement>(null);\n  const measure = React.useRef<(HTMLSpanElement | null)[]>([]);\n\n  const text: Record<Face, string> = {\n    follow: labels?.follow ?? \"Follow\",\n    following: labels?.following ?? \"Following\",\n    unfollow: labels?.unfollow ?? \"Unfollow\",\n  };\n\n  const face: Face = current ? (peek ? \"unfollow\" : \"following\") : \"follow\";\n\n  React.useLayoutEffect(() => {\n    let live = true;\n    function apply() {\n      const node = btnRef.current;\n      const probe = measure.current[faces.indexOf(face)];\n      if (!live || !node || !probe) return;\n      node.style.width = `${probe.offsetWidth + 34}px`;\n    }\n    apply();\n    if (typeof document !== \"undefined\" && document.fonts) {\n      document.fonts.ready.then(apply);\n    }\n    return () => {\n      live = false;\n    };\n  }, [face, text.follow, text.following, text.unfollow]);\n\n  function handleClick(e: React.MouseEvent<HTMLButtonElement>) {\n    onClick?.(e);\n    if (e.defaultPrevented) return;\n    const next = !current;\n    if (!controlled) setInner(next);\n    setPeek(false);\n    onFollowChange?.(next);\n  }\n\n  const vars = { \"--hb-qb6-a\": accent, ...style } as React.CSSProperties;\n\n  return (\n    <button\n      ref={btnRef}\n      type=\"button\"\n      className={`hb-qb6 ${className}`}\n      style={vars}\n      data-face={face}\n      aria-pressed={current}\n      aria-label={current ? `${text.following}. Activate to ${text.unfollow.toLowerCase()}` : text.follow}\n      onClick={handleClick}\n      onPointerEnter={(e) => {\n        onPointerEnter?.(e);\n        if (e.pointerType === \"mouse\") setPeek(true);\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        setPeek(false);\n      }}\n      {...rest}\n    >\n      <style href=\"hb-follow-button\" precedence=\"default\">{css}</style>\n      <span key={face} className=\"hb-qb6-face\" aria-hidden=\"true\">\n        <Icon face={face} />\n        <span>{text[face]}</span>\n      </span>\n      <span className=\"hb-qb6-measure\" aria-hidden=\"true\">\n        {faces.map((f, i) => (\n          <span\n            key={f}\n            ref={(el) => {\n              measure.current[i] = el;\n            }}\n          >\n            <span className=\"hb-qb6-icon\" style={{ display: \"block\" }} />\n            <span>{text[f]}</span>\n          </span>\n        ))}\n      </span>\n    </button>\n  );\n}\n"
    }
  ]
}