{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"social-posts-poll","type":"registry:component","title":"Social posts · Poll","description":"Poll post where voting grows the result bars and counts percentages up, with your choice marked and undo.","author":"GetUrUI <hello@geturui.dev>","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/geturui/examples/social-posts/poll.tsx","type":"registry:component","target":"components/examples/social-posts/poll.tsx","content":"\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, motion, useReducedMotion, useSpring, useTransform } from \"motion/react\";\nimport { CheckCircle2, Clock } from \"lucide-react\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface PollOption {\n  id: string;\n  label: string;\n  votes: number;\n}\n\nexport interface PollPostProps {\n  author?: string;\n  handle?: string;\n  time?: string;\n  question?: string;\n  options?: PollOption[];\n  /** Label for the time left, e.g. \"2 days left\". */\n  remaining?: string;\n  /** Option id the viewer already voted for. */\n  defaultVote?: string | null;\n  onVote?: (optionId: string | null) => void;\n  className?: string;\n}\n\nconst DEFAULT_OPTIONS: PollOption[] = [\n  { id: \"o1\", label: \"Spring, stiffness 400\", votes: 412 },\n  { id: \"o2\", label: \"Ease out, 200ms\", votes: 268 },\n  { id: \"o3\", label: \"Ease in-out, 300ms\", votes: 157 },\n  { id: \"o4\", label: \"No motion by default\", votes: 89 },\n];\n\nfunction Percent({ value, reduce }: { value: number; reduce: boolean }) {\n  const mv = useSpring(reduce ? value : 0, { stiffness: 120, damping: 22 });\n  const text = useTransform(mv, (v) => `${Math.round(v)}%`);\n  React.useEffect(() => {\n    if (reduce) mv.jump(value);\n    else mv.set(value);\n  }, [mv, value, reduce]);\n  return <motion.span className=\"tabular-nums\">{text}</motion.span>;\n}\n\n/** Poll post: pick an option and the results bars grow in with percentages counting up, your choice marked, with undo while the poll is open. */\nexport function PollPost({\n  author = \"Jonah Reyes\",\n  handle = \"@jonahbuilds\",\n  time = \"1h\",\n  question = \"Which motion default should ship in our design system v2?\",\n  options = DEFAULT_OPTIONS,\n  remaining = \"2 days left\",\n  defaultVote = null,\n  onVote,\n  className,\n}: PollPostProps) {\n  const reduce = useReducedMotion() ?? false;\n  const [vote, setVote] = React.useState<string | null>(defaultVote);\n  const id = React.useId();\n\n  const counts = options.map((o) => o.votes + (vote === o.id && defaultVote !== o.id ? 1 : 0) - (defaultVote === o.id && vote !== o.id ? 1 : 0));\n  const total = counts.reduce((a, b) => a + b, 0);\n  const pct = counts.map((c) => (total ? (c / total) * 100 : 0));\n  const lead = Math.max(...counts);\n\n  function choose(next: string | null) {\n    setVote(next);\n    onVote?.(next);\n  }\n\n  return (\n    <article aria-labelledby={`${id}-q`} className={cn(\"w-full max-w-[480px] rounded-xl border border-border bg-surface-raised p-4 shadow-sm\", className)}>\n      <header className=\"flex items-center gap-3\">\n        <span aria-hidden className=\"grid size-10 place-items-center rounded-full bg-ink font-display text-[13px] font-semibold text-bg\">\n          {author.split(\" \").map((p) => p[0]).join(\"\")}\n        </span>\n        <p className=\"min-w-0 text-[14px] font-semibold text-ink\">\n          {author}\n          <span className=\"block text-[12.5px] font-normal text-ink-subtle\">\n            {handle} · {time}\n          </span>\n        </p>\n      </header>\n      <h3 id={`${id}-q`} className=\"mt-3 text-[15px] font-medium leading-[1.45] text-ink\">\n        {question}\n      </h3>\n\n      <AnimatePresence mode=\"wait\" initial={false}>\n        {vote === null ? (\n          <motion.ul key=\"vote\" exit={{ opacity: 0, filter: \"blur(6px)\" }} transition={{ duration: 0.15 }} className=\"mt-3 flex flex-col gap-2\">\n            {options.map((o) => (\n              <li key={o.id}>\n                <motion.button\n                  type=\"button\"\n                  onClick={() => choose(o.id)}\n                  whileTap={reduce ? undefined : { scale: 0.98 }}\n                  className=\"h-10 w-full rounded-full border border-border-strong px-4 text-left text-[13.5px] font-medium text-ink outline-none transition-colors hover:bg-surface-hover focus-visible:shadow-[var(--focus-ring)]\"\n                >\n                  {o.label}\n                </motion.button>\n              </li>\n            ))}\n          </motion.ul>\n        ) : (\n          <motion.ul key=\"results\" aria-label=\"Poll results\" initial={{ opacity: 0 }} animate={{ opacity: 1 }} className=\"mt-3 flex flex-col gap-2\">\n            {options.map((o, i) => {\n              const mine = vote === o.id;\n              const top = counts[i] === lead;\n              return (\n                <li key={o.id} className=\"relative flex h-10 items-center overflow-hidden rounded-sm px-3.5\">\n                  <span aria-hidden className=\"absolute inset-0 bg-surface\" />\n                  <motion.span\n                    aria-hidden\n                    initial={{ scaleX: reduce ? pct[i] / 100 : 0 }}\n                    animate={{ scaleX: pct[i] / 100 }}\n                    transition={{ type: \"spring\", stiffness: 120, damping: 22, delay: reduce ? 0 : i * 0.05 }}\n                    className={cn(\"absolute inset-y-0 left-0 w-full origin-left\", mine ? \"bg-volt/30\" : top ? \"bg-ink/15\" : \"bg-ink/[0.07]\")}\n                  />\n                  <span className={cn(\"relative flex min-w-0 flex-1 items-center gap-1.5 text-[13.5px]\", top ? \"font-semibold text-ink\" : \"text-ink-muted\")}>\n                    <span className=\"truncate\">{o.label}</span>\n                    {mine && (\n                      <>\n                        <CheckCircle2 aria-hidden className=\"size-4 shrink-0 text-volt-ink\" />\n                        <span className=\"sr-only\">Your vote</span>\n                      </>\n                    )}\n                  </span>\n                  <span className={cn(\"relative text-[13px]\", top ? \"font-semibold text-ink\" : \"text-ink-muted\")}>\n                    <Percent value={pct[i]} reduce={reduce} />\n                  </span>\n                </li>\n              );\n            })}\n          </motion.ul>\n        )}\n      </AnimatePresence>\n\n      <div className=\"mt-3 flex items-center gap-2 text-[12.5px] text-ink-subtle\">\n        <span className=\"tabular-nums\">{total.toLocaleString(\"en-US\")} votes</span>\n        <span aria-hidden>·</span>\n        <span className=\"inline-flex items-center gap-1\">\n          <Clock aria-hidden className=\"size-3.5\" />\n          {remaining}\n        </span>\n        {vote !== null && (\n          <button type=\"button\" onClick={() => choose(null)} className=\"ml-auto rounded-xs px-1 font-medium text-ink outline-none underline-offset-2 hover:underline focus-visible:shadow-[var(--focus-ring)]\">\n            Undo vote\n          </button>\n        )}\n      </div>\n      <p aria-live=\"polite\" className=\"sr-only\">\n        {vote ? `Voted for ${options.find((o) => o.id === vote)?.label}. ${options.map((o, i) => `${o.label} ${Math.round(pct[i])}%`).join(\", \")}` : \"\"}\n      </p>\n    </article>\n  );\n}\n"},{"path":"LICENSE-geturui.md","type":"registry:file","target":"LICENSE-geturui.md","content":"MIT License\n\nCopyright (c) 2026 geturui.com\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n"}],"categories":["examples","social","post","feed","like","repost","poll","image grid","link preview","timeline"],"meta":{"tier":"free","license":"MIT","docs":"https://geturui.com/docs/social-posts#poll"}}