{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "vote-arrows",
  "type": "registry:component",
  "title": "Vote Arrows",
  "description": "An up and down vote pair with a rolling score, one active vote at a time and optimistic updates that roll back when onVote rejects.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "social",
    "vote",
    "upvote",
    "score",
    "optimistic",
    "forum",
    "arrows"
  ],
  "docs": "https://hyperblur.dev/effects/vote-arrows",
  "files": [
    {
      "path": "registry/hyperblur/vote-arrows.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/vote-arrows.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type Vote = -1 | 0 | 1;\n\nexport interface VoteArrowsProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"defaultValue\"> {\n  score?: number;\n  value?: Vote;\n  defaultValue?: Vote;\n  onVote?: (value: Vote, score: number) => void | PromiseLike<unknown>;\n  orientation?: \"vertical\" | \"horizontal\";\n  upColor?: string;\n  downColor?: string;\n  label?: string;\n}\n\nconst css = `\n.hb-qb7 {\n  position: relative;\n  display: inline-flex;\n  flex-direction: column;\n  align-items: center;\n  gap: 2px;\n  padding: 4px;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  background: #171717;\n  box-sizing: border-box;\n  font-family: inherit;\n  color: #ededed;\n  vertical-align: middle;\n}\n.hb-qb7 *, .hb-qb7 *::before, .hb-qb7 *::after { box-sizing: border-box; }\n.hb-qb7[data-o=\"horizontal\"] { flex-direction: row; border-radius: 999px; gap: 4px; padding: 3px; }\n.hb-qb7-btn {\n  display: inline-flex;\n  align-items: center;\n  justify-content: center;\n  width: 34px;\n  height: 30px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 10px;\n  background: transparent;\n  color: #7a7a7a;\n  cursor: pointer;\n  touch-action: manipulation;\n  -webkit-tap-highlight-color: transparent;\n  transition: background-color 0.2s ease, color 0.2s ease, transform 0.12s ease;\n}\n.hb-qb7[data-o=\"horizontal\"] .hb-qb7-btn { height: 32px; border-radius: 50%; }\n.hb-qb7-btn:hover { background: color-mix(in srgb, var(--hb-qb7-k) 14%, transparent); color: var(--hb-qb7-k); }\n.hb-qb7-btn:active { transform: scale(0.9); }\n.hb-qb7-btn:focus-visible { outline: 2px solid var(--hb-qb7-k); outline-offset: 1px; }\n.hb-qb7-btn[aria-pressed=\"true\"] {\n  background: color-mix(in srgb, var(--hb-qb7-k) 18%, transparent);\n  color: var(--hb-qb7-k);\n}\n.hb-qb7-up { --hb-qb7-k: var(--hb-qb7-u); }\n.hb-qb7-down { --hb-qb7-k: var(--hb-qb7-d); }\n.hb-qb7-arrow {\n  display: block;\n  width: 20px;\n  height: 20px;\n}\n.hb-qb7-arrow svg {\n  display: block;\n  width: 100%;\n  height: 100%;\n  fill: transparent;\n  stroke: currentColor;\n  stroke-width: 1.8;\n  stroke-linejoin: round;\n  transition: fill 0.2s ease;\n}\n.hb-qb7-btn[aria-pressed=\"true\"] .hb-qb7-arrow svg { fill: currentColor; }\n.hb-qb7-arrow[data-pop=\"up\"] { animation: hb-qb7-pop-up 0.5s cubic-bezier(0.3, 1.5, 0.5, 1); }\n.hb-qb7-arrow[data-pop=\"down\"] { animation: hb-qb7-pop-down 0.5s cubic-bezier(0.3, 1.5, 0.5, 1); }\n@keyframes hb-qb7-pop-up {\n  0% { transform: translateY(5px) scale(0.8); }\n  45% { transform: translateY(-4px) scale(1.25); }\n  100% { transform: translateY(0) scale(1); }\n}\n@keyframes hb-qb7-pop-down {\n  0% { transform: translateY(-5px) scale(0.8); }\n  45% { transform: translateY(4px) scale(1.25); }\n  100% { transform: translateY(0) scale(1); }\n}\n.hb-qb7-score {\n  display: inline-flex;\n  min-width: 2.2em;\n  justify-content: center;\n  color: var(--hb-qb7-t, #ededed);\n  font-size: 13px;\n  font-weight: 700;\n  line-height: 1;\n  transition: color 0.25s ease;\n}\n.hb-qb7-score[data-shake=\"true\"] { animation: hb-qb7-shake 0.4s ease-in-out; }\n@keyframes hb-qb7-shake {\n  0%, 100% { transform: translateX(0); }\n  20% { transform: translateX(-4px); }\n  45% { transform: translateX(4px); }\n  70% { transform: translateX(-2px); }\n}\n.hb-qb7-count {\n  display: inline-flex;\n  font-variant-numeric: tabular-nums;\n  white-space: pre;\n}\n.hb-qb7-roll {\n  display: inline-grid;\n  overflow: hidden;\n  line-height: 1.25;\n  margin: -0.125em 0;\n}\n.hb-qb7-roll > span { grid-area: 1 / 1; display: block; }\n.hb-qb7-in { animation: hb-qb7-up-in 0.38s cubic-bezier(0.3, 1.3, 0.5, 1) both; }\n.hb-qb7-out { animation: hb-qb7-up-out 0.3s ease-in both; }\n.hb-qb7-roll[data-up=\"false\"] .hb-qb7-in { animation-name: hb-qb7-down-in; }\n.hb-qb7-roll[data-up=\"false\"] .hb-qb7-out { animation-name: hb-qb7-down-out; }\n@keyframes hb-qb7-up-in {\n  from { transform: translateY(100%); opacity: 0; }\n  to { transform: translateY(0); opacity: 1; }\n}\n@keyframes hb-qb7-up-out {\n  from { transform: translateY(0); opacity: 1; }\n  to { transform: translateY(-100%); opacity: 0; }\n}\n@keyframes hb-qb7-down-in {\n  from { transform: translateY(-100%); opacity: 0; }\n  to { transform: translateY(0); opacity: 1; }\n}\n@keyframes hb-qb7-down-out {\n  from { transform: translateY(0); opacity: 1; }\n  to { transform: translateY(100%); opacity: 0; }\n}\n.hb-qb7-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-qb7-btn, .hb-qb7-arrow svg, .hb-qb7-score { transition: none; }\n  .hb-qb7-arrow[data-pop], .hb-qb7-score[data-shake] { animation: none; }\n  .hb-qb7-out { display: none; }\n  .hb-qb7-in { animation: none; }\n}\n`;\n\nconst arrow = \"M12 4.4l7.6 8.6h-4.8v6.6H9.2V13H4.4z\";\n\ninterface RollState {\n  value: number;\n  prev: number;\n  id: number;\n  live: boolean;\n}\n\nfunction Roll({ value }: { value: number }) {\n  const [view, setView] = React.useState<RollState>({ value, prev: value, id: 0, live: false });\n  if (view.value !== value) {\n    setView({ value, prev: view.value, id: view.id + 1, live: true });\n  }\n  const to = value.toLocaleString(\"en-US\");\n  if (!view.live) {\n    return (\n      <span className=\"hb-qb7-count\" aria-hidden=\"true\">\n        {to}\n      </span>\n    );\n  }\n  const from = view.prev.toLocaleString(\"en-US\");\n  let p = 0;\n  while (p < from.length && p < to.length && from[p] === to[p]) p++;\n  return (\n    <span className=\"hb-qb7-count\" aria-hidden=\"true\">\n      {to.slice(0, p)}\n      <span key={view.id} className=\"hb-qb7-roll\" data-up={value > view.prev ? \"true\" : \"false\"}>\n        <span className=\"hb-qb7-out\">{from.slice(p)}</span>\n        <span\n          className=\"hb-qb7-in\"\n          onAnimationEnd={() => setView((v) => (v.live ? { ...v, live: false } : v))}\n        >\n          {to.slice(p)}\n        </span>\n      </span>\n    </span>\n  );\n}\n\nexport function VoteArrows({\n  score = 0,\n  value,\n  defaultValue = 0,\n  onVote,\n  orientation = \"vertical\",\n  upColor = \"#ff6a3d\",\n  downColor = \"#7b8cff\",\n  label = \"Vote\",\n  className = \"\",\n  style,\n  ...rest\n}: VoteArrowsProps) {\n  const controlled = value !== undefined;\n  const [inner, setInner] = React.useState<Vote>(defaultValue);\n  const current = controlled ? value : inner;\n  const [base] = React.useState<Vote>(current);\n  const [seen, setSeen] = React.useState({ value: current, pulse: 0 });\n  const [shake, setShake] = React.useState(0);\n\n  if (seen.value !== current) {\n    setSeen({ value: current, pulse: seen.pulse + 1 });\n  }\n\n  const total = score + current - base;\n\n  function vote(dir: 1 | -1) {\n    const prev = current;\n    const next: Vote = prev === dir ? 0 : dir;\n    if (!controlled) setInner(next);\n    const result = onVote?.(next, score + next - base);\n    if (result && typeof (result as PromiseLike<unknown>).then === \"function\") {\n      (result as PromiseLike<unknown>).then(undefined, () => {\n        if (!controlled) setInner(prev);\n        setShake((n) => n + 1);\n      });\n    }\n  }\n\n  const tone = current === 1 ? upColor : current === -1 ? downColor : undefined;\n  const vars = {\n    \"--hb-qb7-u\": upColor,\n    \"--hb-qb7-d\": downColor,\n    \"--hb-qb7-t\": tone,\n    ...style,\n  } as React.CSSProperties;\n\n  function pop(dir: 1 | -1) {\n    return current === dir && seen.pulse > 0 ? (dir === 1 ? \"up\" : \"down\") : undefined;\n  }\n\n  return (\n    <div\n      role=\"group\"\n      aria-label={label}\n      className={`hb-qb7 ${className}`}\n      data-o={orientation}\n      style={vars}\n      {...rest}\n    >\n      <style href=\"hb-vote-arrows\" precedence=\"default\">{css}</style>\n      <button\n        type=\"button\"\n        className=\"hb-qb7-btn hb-qb7-up\"\n        aria-pressed={current === 1}\n        aria-label=\"Upvote\"\n        onClick={() => vote(1)}\n      >\n        <span key={`u${current === 1 ? seen.pulse : 0}`} className=\"hb-qb7-arrow\" data-pop={pop(1)} aria-hidden=\"true\">\n          <svg viewBox=\"0 0 24 24\">\n            <path d={arrow} />\n          </svg>\n        </span>\n      </button>\n      <span key={`s${shake}`} className=\"hb-qb7-score\" data-shake={shake > 0 ? \"true\" : \"false\"}>\n        <Roll value={total} />\n      </span>\n      <button\n        type=\"button\"\n        className=\"hb-qb7-btn hb-qb7-down\"\n        aria-pressed={current === -1}\n        aria-label=\"Downvote\"\n        onClick={() => vote(-1)}\n      >\n        <span key={`d${current === -1 ? seen.pulse : 0}`} className=\"hb-qb7-arrow\" data-pop={pop(-1)} aria-hidden=\"true\">\n          <svg viewBox=\"0 0 24 24\">\n            <path d={arrow} transform=\"rotate(180 12 12)\" />\n          </svg>\n        </span>\n      </button>\n      <span className=\"hb-qb7-sr\" role=\"status\" aria-live=\"polite\">\n        {`Score ${total.toLocaleString(\"en-US\")}`}\n      </span>\n    </div>\n  );\n}\n"
    }
  ]
}