{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tally-poll-demo",
  "type": "registry:block",
  "title": "Tally: Live Poll",
  "description": "Animated Dot Chart example, Live Poll: A naming poll where every vote is a dot that flies in from the edge as it's cast, yours included. A take on the chart (graph). Fits stats, app UI and about sections.",
  "author": "KeyframeUI <https://keyframeui.com>",
  "categories": [
    "stats",
    "app-ui",
    "about",
    "chart",
    "particle-effect",
    "data",
    "canvas"
  ],
  "docs": "Live preview, examples and props: https://keyframeui.com/components/tally#tally-poll-demo",
  "registryDependencies": [
    "https://keyframeui.com/r/tally.json"
  ],
  "files": [
    {
      "path": "components/tally-poll-demo.tsx",
      "type": "registry:component",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nimport { Tally } from \"@/components/ui/tally\";\n\nconst QUESTION = \"What should we call the new model?\";\nconst OPTIONS = [\n  { id: \"juniper\", label: \"Juniper\", votes: 46, color: \"text-[#00b25d] dark:text-[#34d399]\" },\n  { id: \"halcyon\", label: \"Halcyon\", votes: 38, color: \"text-[#2f45e8] dark:text-[#8b98ff]\" },\n  { id: \"ember\", label: \"Ember\", votes: 27, color: \"text-[#ff5a1f] dark:text-[#ff7a45]\" },\n  { id: \"quill\", label: \"Quill\", votes: 19, color: \"text-[#ff2d87] dark:text-[#ff5ca8]\" },\n];\n\n// A vote from someone else every ~0.8s, until the poll has this many.\nconst EVERY = 0.8;\nconst CLOSE_AT = 260;\n\nexport function TallyPollDemo() {\n  const [votes, setVotes] = React.useState(() => Object.fromEntries(OPTIONS.map((o) => [o.id, o.votes])));\n  const [mine, setMine] = React.useState<string | null>(null);\n  const total = Object.values(votes).reduce((a, b) => a + b, 0);\n  const open = total < CLOSE_AT;\n\n  // Other people voting, leaning toward what's already ahead.\n  React.useEffect(() => {\n    if (!open) return;\n    const id = window.setTimeout(\n      () => {\n        setVotes((v) => {\n          const sum = Object.values(v).reduce((a, b) => a + b, 0);\n          let pick = Math.random() * (sum + OPTIONS.length * 20);\n          for (const o of OPTIONS) {\n            pick -= v[o.id] + 20;\n            if (pick <= 0) return { ...v, [o.id]: v[o.id] + 1 };\n          }\n          return v;\n        });\n      },\n      EVERY * (0.5 + Math.random()) * 1000,\n    );\n    return () => window.clearTimeout(id);\n  }, [votes, open]);\n\n  const items = React.useMemo(\n    () => OPTIONS.map((o) => ({ id: o.id, label: o.label, value: votes[o.id], dotClassName: o.color })),\n    [votes],\n  );\n\n  const vote = (id: string) => {\n    if (mine) return;\n    setMine(id);\n    setVotes((v) => ({ ...v, [id]: v[id] + 1 }));\n  };\n\n  return (\n    <div className=\"w-full max-w-3xl overflow-hidden rounded-2xl border border-zinc-950/10 bg-white text-zinc-950 dark:border-white/10 dark:bg-zinc-950 dark:text-white\">\n      <div className=\"flex flex-wrap items-start justify-between gap-3 px-5 pt-5\">\n        <div>\n          <p className=\"font-mono text-[11px] tracking-wide text-zinc-500 uppercase dark:text-zinc-400\">Orrery team poll</p>\n          <h3 className=\"mt-1 text-[17px] font-medium tracking-tight text-balance\">{QUESTION}</h3>\n        </div>\n        <p className=\"flex items-center gap-2 font-mono text-[11px] text-zinc-500 tabular-nums dark:text-zinc-400\">\n          <span aria-hidden className={open ? \"size-1.5 rounded-full bg-emerald-500\" : \"size-1.5 rounded-full bg-zinc-400\"} />\n          {total} votes · {open ? \"live\" : \"closed\"}\n        </p>\n      </div>\n\n      <Tally items={items} per={1} unit=\"vote\" dotSize={11} gap={2.5} label={QUESTION} className=\"mx-5 mt-4 h-[24rem] sm:h-72\" />\n\n      <div className=\"mt-2 border-t border-zinc-950/10 px-5 py-4 dark:border-white/10\">\n        <p aria-live=\"polite\" className=\"font-mono text-xs text-zinc-600 dark:text-zinc-400\">\n          {mine ? `Thanks. Your vote went to ${OPTIONS.find((o) => o.id === mine)?.label}.` : \"Cast yours:\"}\n        </p>\n        <div className=\"mt-3 flex flex-wrap gap-2\">\n          {OPTIONS.map((o) => (\n            <button\n              key={o.id}\n              type=\"button\"\n              disabled={!!mine && mine !== o.id}\n              aria-pressed={mine === o.id}\n              onClick={() => vote(o.id)}\n              className=\"flex items-center gap-2 rounded-full border border-zinc-950/15 px-3.5 py-1.5 text-sm transition-colors enabled:hover:border-zinc-950/40 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-zinc-950 disabled:opacity-40 aria-pressed:border-transparent aria-pressed:bg-zinc-950 aria-pressed:text-white dark:border-white/15 dark:enabled:hover:border-white/40 dark:focus-visible:outline-white dark:aria-pressed:bg-white dark:aria-pressed:text-zinc-950\"\n            >\n              <span aria-hidden className={`size-2 bg-current ${o.color}`} />\n              {o.label}\n            </button>\n          ))}\n        </div>\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}