{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"radio-cards","type":"registry:component","title":"Radio cards","description":"The selection ring glides to the plan you pick.","author":"Yash Bavadiya <https://xevrion.dev>","dependencies":["motion"],"registryDependencies":["utils"],"files":[{"path":"components/radio-cards.tsx","type":"registry:component","content":"\"use client\";\n\nimport { useId, useState } from \"react\";\nimport { LayoutGroup, motion } from \"motion/react\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\ntype Option = {\n  value: string;\n  title: string;\n  description: string;\n  price: string;\n  period?: string;\n  badge?: string;\n};\n\nconst RING = { type: \"spring\", duration: 0.3, bounce: 0 } as const;\nconst ICON_SWAP = { type: \"spring\", duration: 0.3, bounce: 0 } as const;\n// The one bounce in the component: the dot filling is the confirmation, and\n// a small overshoot makes it land rather than just appear.\nconst DOT_IN = { type: \"spring\", duration: 0.35, bounce: 0.35 } as const;\nconst DOT_OUT = { duration: 0.15, ease: [0.23, 1, 0.32, 1] } as const;\nconst INSTANT = { duration: 0 } as const;\n\nexport function RadioCards({\n  options,\n  value,\n  onChange,\n  label,\n  name,\n  className,\n}: {\n  options: Option[];\n  value: string;\n  onChange: (value: string) => void;\n  label: string;\n  name?: string;\n  className?: string;\n}) {\n  const reduceMotion = useReducedMotion();\n  // Scopes the ring's layoutId and the radio name, so two groups on one\n  // page never trade rings or selections.\n  const id = useId();\n\n  return (\n    <LayoutGroup id={id}>\n      <fieldset className={cn(\"w-[min(480px,100%)] min-w-0\", className)}>\n        <legend className=\"mb-3 text-[15px] font-medium text-foreground\">\n          {label}\n        </legend>\n        {/* Equal rows keep every card the same size, so the ring only ever\n            translates between them and its 2px border never stretches. */}\n        <div className=\"grid auto-rows-fr gap-3\">\n          {options.map((option) => {\n            const selected = option.value === value;\n            return (\n              <label\n                key={option.value}\n                className={cn(\n                  \"group relative flex cursor-pointer touch-manipulation items-center gap-4 rounded-2xl bg-background p-4 shadow-raised select-none\",\n                  // 0.98 rather than the usual 0.96: on a card this wide, 4%\n                  // moves its edges nearly 10px and reads as a lurch.\n                  \"transition-[scale,background-color] duration-150 ease-out hover:bg-muted active:scale-[0.98] motion-reduce:transition-[background-color]\",\n                  \"has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-solid has-[:focus-visible]:outline-offset-2 has-[:focus-visible]:outline-foreground\",\n                  // The ring lives in the selected card, so lifting that card\n                  // keeps the ring above its neighbours as it slides across\n                  // them, even while the press scale traps it in this card.\n                  selected && \"z-10\",\n                )}\n              >\n                <input\n                  type=\"radio\"\n                  name={name ?? id}\n                  value={option.value}\n                  checked={selected}\n                  onChange={() => onChange(option.value)}\n                  className=\"sr-only\"\n                />\n                {selected && (\n                  <motion.span\n                    layoutId=\"ring\"\n                    aria-hidden\n                    transition={reduceMotion ? INSTANT : RING}\n                    className=\"pointer-events-none absolute inset-0 rounded-2xl border-2 border-foreground\"\n                  />\n                )}\n                <Dot selected={selected} reduceMotion={Boolean(reduceMotion)} />\n                <span className=\"flex min-w-0 flex-1 flex-col gap-0.5\">\n                  <span className=\"flex items-center gap-2\">\n                    <span className=\"text-[15px] font-semibold text-foreground\">\n                      {option.title}\n                    </span>\n                    {option.badge && (\n                      <span className=\"rounded-full bg-muted px-2 py-0.5 text-xs font-medium text-muted-foreground transition-[background-color] duration-150 ease-out group-hover:bg-background\">\n                        {option.badge}\n                      </span>\n                    )}\n                  </span>\n                  <span className=\"text-sm text-pretty text-muted-foreground\">\n                    {option.description}\n                  </span>\n                </span>\n                <span className=\"flex shrink-0 items-baseline gap-0.5\">\n                  <span className=\"text-lg font-semibold text-foreground tabular-nums\">\n                    {option.price}\n                  </span>\n                  {option.period && (\n                    <span className=\"text-[13px] text-muted-foreground\">\n                      {option.period}\n                    </span>\n                  )}\n                </span>\n              </label>\n            );\n          })}\n        </div>\n      </fieldset>\n    </LayoutGroup>\n  );\n}\n\nfunction Dot({\n  selected,\n  reduceMotion,\n}: {\n  selected: boolean;\n  reduceMotion: boolean;\n}) {\n  return (\n    <span\n      aria-hidden\n      className={cn(\n        \"relative grid size-5 shrink-0 place-items-center rounded-full border-[1.5px] transition-[border-color] duration-150 ease-out\",\n        selected\n          ? \"border-foreground\"\n          : \"border-foreground/25 group-hover:border-foreground/45\",\n      )}\n    >\n      {/* Covers the border too, so the filled dot is exactly 20px. Starts at\n          half size, never zero: it grows out of the ring's own center. */}\n      <motion.span\n        className=\"absolute -inset-[1.5px] rounded-full bg-foreground\"\n        initial={false}\n        animate={\n          selected\n            ? { scale: 1, opacity: 1 }\n            : { scale: reduceMotion ? 1 : 0.5, opacity: 0 }\n        }\n        transition={reduceMotion ? DOT_OUT : selected ? DOT_IN : DOT_OUT}\n      />\n      <motion.svg\n        viewBox=\"0 0 16 16\"\n        className=\"relative size-3 text-background\"\n        fill=\"none\"\n        stroke=\"currentColor\"\n        // Heavier than the lab's usual 1.5: at 12px a thinner check turns\n        // to a hairline against the filled dot.\n        strokeWidth={2.25}\n        strokeLinecap=\"round\"\n        strokeLinejoin=\"round\"\n        initial={false}\n        animate={\n          selected\n            ? { scale: 1, opacity: 1, filter: \"blur(0px)\" }\n            : reduceMotion\n              ? { scale: 1, opacity: 0, filter: \"blur(0px)\" }\n              : { scale: 0.25, opacity: 0, filter: \"blur(4px)\" }\n        }\n        transition={ICON_SWAP}\n      >\n        <path d=\"m3.5 8.5 3 3 6-7\" />\n      </motion.svg>\n    </span>\n  );\n}\n\nconst PLANS: Option[] = [\n  {\n    value: \"hobby\",\n    title: \"Hobby\",\n    description: \"For side projects and trying things out.\",\n    price: \"$0\",\n    period: \"/mo\",\n  },\n  {\n    value: \"pro\",\n    title: \"Pro\",\n    description: \"Unlimited projects and custom domains.\",\n    price: \"$12\",\n    period: \"/mo\",\n    badge: \"Popular\",\n  },\n  {\n    value: \"team\",\n    title: \"Team\",\n    description: \"Shared workspaces, roles and priority support.\",\n    price: \"$32\",\n    period: \"/mo\",\n  },\n];\n\nexport default function RadioCardsDemo() {\n  const [plan, setPlan] = useState(\"pro\");\n  return (\n    <RadioCards\n      label=\"Choose a plan\"\n      options={PLANS}\n      value={plan}\n      onChange={setPlan}\n    />\n  );\n}\n"},{"path":"hooks/use-reduced-motion.ts","type":"registry:hook","target":"hooks/use-reduced-motion.ts","content":"\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\n// Motion's useReducedMotion reads the media query on the very first client\n// render, but the server can't know it, so every component that renders\n// differently under reduced motion broke hydration for those users. This\n// reports false during hydration, matching the server HTML, then the real\n// preference straight after, and follows it if it changes.\nconst query = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribe(onChange: () => void) {\n  const media = window.matchMedia(query);\n  media.addEventListener(\"change\", onChange);\n  return () => media.removeEventListener(\"change\", onChange);\n}\n\nexport function useReducedMotion() {\n  return useSyncExternalStore(\n    subscribe,\n    () => window.matchMedia(query).matches,\n    () => false,\n  );\n}\n"}],"cssVars":{"light":{"shadow-raised":"0 0 0 1px oklch(0 0 0 / 0.06), 0 1px 2px oklch(0 0 0 / 0.06), 0 6px 16px -6px oklch(0 0 0 / 0.12)"},"dark":{"shadow-raised":"0 0 0 1px oklch(1 0 0 / 0.08), 0 1px 2px oklch(0 0 0 / 0.4), 0 6px 16px -6px oklch(0 0 0 / 0.6)"},"theme":{"shadow-raised":"var(--shadow-raised)"}},"categories":["inputs"],"docs":"From ui lab: https://lab.xevrion.dev/lab/radio-cards"}