{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "radio-group-cards",
  "title": "Radio Group Cards",
  "description": "A create-resource screen built from radio card groups: plan cards with prices and features, region cards with latency bars and one at capacity, and compute size cards that lock on the free plan. A sliding selection outline moves between cards, a monthly or yearly switch reprices everything, and a summary with an animated total creates the database.",
  "dependencies": [
    "motion",
    "clsx",
    "tailwind-merge"
  ],
  "files": [
    {
      "path": "registry/new-york/radio-group-cards/radio-group-cards.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { AnimatePresence, animate, motion, useMotionValue, useReducedMotion, useTransform } from \"motion/react\";\nimport { clsx, type ClassValue } from \"clsx\";\nimport { twMerge } from \"tailwind-merge\";\n\nfunction cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs));\n}\n\ntype PlanId = \"starter\" | \"pro\" | \"team\";\ntype RegionId = \"fra\" | \"iad\" | \"sin\" | \"gru\";\ntype ComputeId = \"micro\" | \"small\" | \"medium\" | \"large\";\n\nexport interface RadioGroupCardsSelection {\n  plan: PlanId;\n  region: RegionId;\n  compute: ComputeId;\n  billing: \"monthly\" | \"yearly\";\n}\n\nexport interface RadioGroupCardsProps {\n  defaultValue?: Partial<RadioGroupCardsSelection>;\n  onSubmit?: (selection: RadioGroupCardsSelection & { monthlyTotal: number }) => Promise<void> | void;\n  theme?: \"dark\" | \"light\";\n  className?: string;\n}\n\nconst PALETTES = {\n  dark: { bg: \"#0A0A0A\", text: \"#F5F4F1\", muted: \"rgba(245,244,241,0.62)\", faint: \"rgba(245,244,241,0.38)\", card: \"#121212\", hover: \"#171717\", border: \"rgba(255,255,255,0.09)\", sel: \"#F5F4F1\", chip: \"rgba(255,255,255,0.06)\", on: \"#F5F4F1\", onText: \"#0A0A0A\", accent: \"#60A5FA\", green: \"#4ADE80\", amber: \"#FBBF24\", ring: \"rgba(245,244,241,0.6)\" },\n  light: { bg: \"#FAFAF8\", text: \"#0A0A0A\", muted: \"rgba(10,10,10,0.62)\", faint: \"rgba(10,10,10,0.42)\", card: \"#FFFFFF\", hover: \"#F6F6F3\", border: \"rgba(10,10,10,0.1)\", sel: \"#0A0A0A\", chip: \"rgba(10,10,10,0.05)\", on: \"#0A0A0A\", onText: \"#FAFAF8\", accent: \"#2563EB\", green: \"#15803D\", amber: \"#B45309\", ring: \"rgba(10,10,10,0.5)\" },\n};\n\nconst PLANS: { id: PlanId; name: string; price: number; blurb: string; features: string[]; badge?: string }[] = [\n  { id: \"starter\", name: \"Starter\", price: 0, blurb: \"For side projects and trying things out.\", features: [\"1 database\", \"500 MB storage\", \"Daily backups\"] },\n  { id: \"pro\", name: \"Pro\", price: 25, blurb: \"For production apps with real traffic.\", features: [\"Unlimited databases\", \"50 GB storage\", \"Point-in-time restore\"], badge: \"Popular\" },\n  { id: \"team\", name: \"Team\", price: 99, blurb: \"For teams that need control and audit.\", features: [\"Everything in Pro\", \"SSO and audit log\", \"99.95% uptime SLA\"] },\n];\nconst REGIONS: { id: RegionId; city: string; code: string; ms: number; full?: boolean }[] = [\n  { id: \"fra\", city: \"Frankfurt\", code: \"eu-central-1\", ms: 12 },\n  { id: \"iad\", city: \"Virginia\", code: \"us-east-1\", ms: 84 },\n  { id: \"sin\", city: \"Singapore\", code: \"ap-southeast-1\", ms: 162 },\n  { id: \"gru\", city: \"São Paulo\", code: \"sa-east-1\", ms: 198, full: true },\n];\nconst COMPUTE: { id: ComputeId; name: string; cpu: string; ram: string; price: number }[] = [\n  { id: \"micro\", name: \"Micro\", cpu: \"1 vCPU\", ram: \"1 GB\", price: 0 },\n  { id: \"small\", name: \"Small\", cpu: \"2 vCPU\", ram: \"4 GB\", price: 15 },\n  { id: \"medium\", name: \"Medium\", cpu: \"4 vCPU\", ram: \"8 GB\", price: 60 },\n  { id: \"large\", name: \"Large\", cpu: \"8 vCPU\", ram: \"16 GB\", price: 120 },\n];\n\nconst money = (n: number) => `$${Number.isInteger(n) ? n : n.toFixed(2)}`;\nconst perMonth = (n: number, billing: \"monthly\" | \"yearly\") => (billing === \"yearly\" ? Math.round((n * 10) / 12 * 100) / 100 : n);\n\nexport function RadioGroupCards({ defaultValue, onSubmit, theme = \"dark\", className }: RadioGroupCardsProps) {\n  const p = PALETTES[theme];\n  const reduce = !!useReducedMotion();\n  const uid = React.useId();\n  const [sel, setSel] = React.useState<RadioGroupCardsSelection>(() => ({ plan: \"pro\", region: \"fra\", compute: \"small\", billing: \"monthly\", ...defaultValue }));\n  const [note, setNote] = React.useState<string | null>(null);\n  const [status, setStatus] = React.useState<\"idle\" | \"creating\" | \"done\">(\"idle\");\n  const timer = React.useRef<ReturnType<typeof setTimeout> | null>(null);\n\n  const plan = PLANS.find((x) => x.id === sel.plan)!;\n  const region = REGIONS.find((x) => x.id === sel.region)!;\n  const compute = COMPUTE.find((x) => x.id === sel.compute)!;\n  const total = perMonth(plan.price + compute.price, sel.billing);\n\n  const mv = useMotionValue(total);\n  const shown = useTransform(mv, (v) => money(Math.round(v * 100) / 100));\n  React.useEffect(() => {\n    const c = animate(mv, total, { duration: reduce ? 0 : 0.45, ease: [0.22, 1, 0.36, 1] });\n    return () => c.stop();\n  }, [total, mv, reduce]);\n  React.useEffect(() => {\n    if (!note) return;\n    const t = setTimeout(() => setNote(null), 3200);\n    return () => clearTimeout(t);\n  }, [note]);\n  React.useEffect(\n    () => () => {\n      if (timer.current) clearTimeout(timer.current);\n    },\n    [],\n  );\n\n  const choosePlan = (id: PlanId) => {\n    if (id === \"starter\" && sel.compute !== \"micro\") {\n      setNote(\"Starter runs on Micro, so compute was switched to Micro.\");\n      setSel((s) => ({ ...s, plan: id, compute: \"micro\" }));\n    } else setSel((s) => ({ ...s, plan: id }));\n  };\n\n  const submit = () => {\n    if (status !== \"idle\") return;\n    setStatus(\"creating\");\n    const payload = { ...sel, monthlyTotal: total };\n    const done = () => setStatus(\"done\");\n    const r = onSubmit?.(payload);\n    if (r instanceof Promise) r.then(done, () => setStatus(\"idle\"));\n    else timer.current = setTimeout(done, reduce ? 0 : 1100);\n  };\n\n  const ring = { [\"--tw-ring-color\" as string]: p.ring, [\"--tw-ring-offset-color\" as string]: p.bg } as React.CSSProperties;\n  const focus = \"outline-none focus-visible:ring-2 focus-visible:ring-offset-2\";\n  const cardCls = \"relative flex cursor-pointer rounded-xl border transition-colors has-[:focus-visible]:ring-2 has-[:focus-visible]:ring-offset-2 has-[:disabled]:cursor-not-allowed\";\n  const selRing = (group: string) => (\n    <motion.span layoutId={`${uid}-${group}`} className=\"pointer-events-none absolute -inset-px rounded-xl border-2\" style={{ borderColor: p.sel }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 38 }} aria-hidden=\"true\" />\n  );\n  const dot = (on: boolean) => (\n    <span className=\"relative flex h-4 w-4 shrink-0 items-center justify-center rounded-full border\" style={{ borderColor: on ? p.sel : p.faint }} aria-hidden=\"true\">\n      <motion.span className=\"h-2 w-2 rounded-full\" style={{ background: p.sel }} initial={false} animate={{ scale: on ? 1 : 0 }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 700, damping: 30 }} />\n    </span>\n  );\n  const legend = (id: string, title: string, hint: string) => (\n    <div className=\"mb-3 flex flex-wrap items-baseline justify-between gap-x-3 gap-y-1\">\n      <legend id={`${uid}-${id}`} className=\"float-left p-0 text-[15px] font-semibold\">\n        {title}\n      </legend>\n      <span className=\"text-[12.5px]\" style={{ color: p.faint }}>\n        {hint}\n      </span>\n    </div>\n  );\n\n  if (status === \"done\")\n    return (\n      <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n        <motion.div initial={reduce ? false : { opacity: 0, y: 8 }} animate={{ opacity: 1, y: 0 }} className=\"mx-auto flex max-w-md flex-col items-center px-4 py-20 text-center\" role=\"status\">\n          <motion.span initial={reduce ? false : { scale: 0.6 }} animate={{ scale: 1 }} transition={{ type: \"spring\", stiffness: 400, damping: 18 }} className=\"grid h-12 w-12 place-items-center rounded-full\" style={{ background: `${p.green}22`, color: p.green }}>\n            <svg width=\"22\" height=\"22\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n            </svg>\n          </motion.span>\n          <h2 className=\"m-0 mt-5 text-[20px] font-semibold\">Database created</h2>\n          <p className=\"m-0 mt-2 text-[14px] leading-[1.55]\" style={{ color: p.muted }}>\n            {plan.name} · {compute.name} ({compute.cpu}, {compute.ram}) in {region.city}. You will be billed {money(total)} a month{sel.billing === \"yearly\" ? \", paid yearly\" : \"\"}.\n          </p>\n          <button type=\"button\" onClick={() => setStatus(\"idle\")} className={cn(\"mt-6 h-9 cursor-pointer rounded-lg border bg-transparent px-4 text-[13px] font-medium\", focus)} style={{ borderColor: p.border, color: p.text, ...ring }}>\n            Create another\n          </button>\n        </motion.div>\n      </section>\n    );\n\n  return (\n    <section className={cn(\"@container w-full\", className)} style={{ background: p.bg, color: p.text }}>\n      <form\n        onSubmit={(e) => {\n          e.preventDefault();\n          submit();\n        }}\n        className=\"mx-auto max-w-6xl px-4 py-10 @[640px]:px-6 @[640px]:py-14\"\n      >\n        <header className=\"mb-8 flex flex-col gap-4 @[640px]:flex-row @[640px]:items-end @[640px]:justify-between\">\n          <div>\n            <h2 className=\"m-0 text-[22px] font-semibold tracking-[-0.01em] @[640px]:text-[26px]\">New database</h2>\n            <p className=\"m-0 mt-1.5 text-[14px]\" style={{ color: p.muted }}>\n              Pick a plan, where it runs and how much power it gets. You can change all of this later.\n            </p>\n          </div>\n          <div role=\"radiogroup\" aria-label=\"Billing period\" className=\"relative flex shrink-0 self-start rounded-full border p-0.5 @[640px]:self-auto\" style={{ borderColor: p.border, background: p.card }}>\n            {([\"monthly\", \"yearly\"] as const).map((b) => (\n              <label key={b} className=\"relative cursor-pointer rounded-full px-3.5 py-1.5 text-[13px] font-medium has-[:focus-visible]:ring-2\" style={{ color: sel.billing === b ? p.onText : p.muted, ...ring }}>\n                {sel.billing === b && <motion.span layoutId={`${uid}-bill`} className=\"absolute inset-0 rounded-full\" style={{ background: p.on }} transition={reduce ? { duration: 0 } : { type: \"spring\", stiffness: 520, damping: 38 }} />}\n                <input type=\"radio\" name={`${uid}-billing`} value={b} checked={sel.billing === b} onChange={() => setSel((s) => ({ ...s, billing: b }))} className=\"sr-only\" />\n                <span className=\"relative\">\n                  {b === \"monthly\" ? \"Monthly\" : \"Yearly\"}\n                  {b === \"yearly\" && (\n                    <span className=\"ml-1.5 text-[11px]\" style={{ color: sel.billing === b ? p.onText : p.green }}>\n                      −17%\n                    </span>\n                  )}\n                </span>\n              </label>\n            ))}\n          </div>\n        </header>\n\n        <div className=\"grid grid-cols-[minmax(0,1fr)] gap-8 @[920px]:grid-cols-[minmax(0,1fr)_300px] @[920px]:gap-10\">\n          <div className=\"flex min-w-0 flex-col gap-9\">\n            {/* Plan */}\n            <fieldset className=\"m-0 min-w-0 border-0 p-0\" aria-labelledby={`${uid}-plan`}>\n              {legend(\"plan\", \"Plan\", \"Prices per month, before compute\")}\n              <div className=\"clear-both grid grid-cols-1 gap-3 @[560px]:grid-cols-3\">\n                {PLANS.map((x) => {\n                  const on = sel.plan === x.id;\n                  return (\n                    <label key={x.id} className={cn(cardCls, \"flex-col p-4\")} style={{ borderColor: p.border, background: p.card, ...ring }}>\n                      {on && selRing(\"plan\")}\n                      <input type=\"radio\" name={`${uid}-plan`} value={x.id} checked={on} onChange={() => choosePlan(x.id)} className=\"sr-only\" aria-describedby={`${uid}-plan-${x.id}`} />\n                      <span className=\"flex items-center justify-between gap-2\">\n                        <span className=\"flex items-center gap-2 text-[14px] font-semibold\">\n                          {x.name}\n                          {x.badge && (\n                            <span className=\"rounded-full px-1.5 py-0.5 text-[10.5px] font-medium\" style={{ background: `${p.accent}22`, color: p.accent }}>\n                              {x.badge}\n                            </span>\n                          )}\n                        </span>\n                        {dot(on)}\n                      </span>\n                      <span className=\"mt-3 flex items-baseline gap-1\">\n                        <span className=\"text-[24px] font-semibold tabular-nums tracking-[-0.02em]\">{money(perMonth(x.price, sel.billing))}</span>\n                        <span className=\"text-[12.5px]\" style={{ color: p.faint }}>\n                          /mo\n                        </span>\n                      </span>\n                      <span id={`${uid}-plan-${x.id}`} className=\"mt-1 text-[13px] leading-[1.5]\" style={{ color: p.muted }}>\n                        {x.blurb}\n                      </span>\n                      <span className=\"mt-3 flex flex-col gap-1.5 border-t pt-3\" style={{ borderColor: p.border }}>\n                        {x.features.map((f) => (\n                          <span key={f} className=\"flex items-center gap-2 text-[12.5px]\" style={{ color: p.muted }}>\n                            <svg width=\"12\" height=\"12\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.green} strokeWidth=\"3\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                              <path d=\"m5 12.5 4.5 4.5L19 7.5\" />\n                            </svg>\n                            {f}\n                          </span>\n                        ))}\n                      </span>\n                    </label>\n                  );\n                })}\n              </div>\n            </fieldset>\n\n            {/* Region */}\n            <fieldset className=\"m-0 min-w-0 border-0 p-0\" aria-labelledby={`${uid}-region`}>\n              {legend(\"region\", \"Region\", \"Latency measured from your browser\")}\n              <div className=\"clear-both grid grid-cols-1 gap-3 @[480px]:grid-cols-2 @[760px]:grid-cols-4\">\n                {REGIONS.map((x) => {\n                  const on = sel.region === x.id;\n                  const bars = x.ms < 40 ? 3 : x.ms < 120 ? 2 : 1;\n                  return (\n                    <label key={x.id} className={cn(cardCls, \"items-start gap-3 p-3.5\")} style={{ borderColor: p.border, background: p.card, opacity: x.full ? 0.55 : 1, ...ring }} title={x.full ? \"At capacity. Try again later.\" : undefined}>\n                      {on && selRing(\"region\")}\n                      <input type=\"radio\" name={`${uid}-region`} value={x.id} checked={on} disabled={x.full} onChange={() => setSel((s) => ({ ...s, region: x.id }))} className=\"sr-only\" />\n                      <span className=\"mt-0.5\">{dot(on)}</span>\n                      <span className=\"min-w-0 flex-1\">\n                        <span className=\"block text-[13.5px] font-medium\">{x.city}</span>\n                        <span className=\"block truncate font-mono text-[11.5px]\" style={{ color: p.faint }}>\n                          {x.code}\n                        </span>\n                        <span className=\"mt-2 flex items-center gap-2 text-[12px]\" style={{ color: x.full ? p.amber : p.muted }}>\n                          {x.full ? (\n                            \"At capacity\"\n                          ) : (\n                            <>\n                              <span className=\"flex items-end gap-[2px]\" aria-hidden=\"true\">\n                                {[0, 1, 2].map((i) => (\n                                  <span key={i} className=\"w-[3px] rounded-sm\" style={{ height: 5 + i * 3, background: i < bars ? (bars === 3 ? p.green : bars === 2 ? p.amber : p.faint) : p.chip }} />\n                                ))}\n                              </span>\n                              {x.ms} ms\n                            </>\n                          )}\n                        </span>\n                      </span>\n                    </label>\n                  );\n                })}\n              </div>\n            </fieldset>\n\n            {/* Compute */}\n            <fieldset className=\"m-0 min-w-0 border-0 p-0\" aria-labelledby={`${uid}-compute`}>\n              {legend(\"compute\", \"Compute\", sel.plan === \"starter\" ? \"Bigger sizes need Pro or Team\" : \"Added to the plan price\")}\n              <AnimatePresence initial={false}>\n                {note && (\n                  <motion.p key=\"note\" role=\"status\" initial={reduce ? false : { height: 0, opacity: 0 }} animate={{ height: \"auto\", opacity: 1 }} exit={reduce ? undefined : { height: 0, opacity: 0 }} className=\"clear-both m-0 overflow-hidden text-[12.5px]\" style={{ color: p.amber }}>\n                    <span className=\"mb-3 block\">{note}</span>\n                  </motion.p>\n                )}\n              </AnimatePresence>\n              <div className=\"clear-both grid grid-cols-2 gap-3 @[760px]:grid-cols-4\">\n                {COMPUTE.map((x) => {\n                  const on = sel.compute === x.id;\n                  const locked = sel.plan === \"starter\" && x.id !== \"micro\";\n                  return (\n                    <label key={x.id} className={cn(cardCls, \"flex-col p-3.5\")} style={{ borderColor: p.border, background: p.card, opacity: locked ? 0.5 : 1, ...ring }}>\n                      {on && selRing(\"compute\")}\n                      <input type=\"radio\" name={`${uid}-compute`} value={x.id} checked={on} disabled={locked} onChange={() => setSel((s) => ({ ...s, compute: x.id }))} className=\"sr-only\" />\n                      <span className=\"flex items-center justify-between gap-2\">\n                        <span className=\"text-[13.5px] font-medium\">{x.name}</span>\n                        {locked ? (\n                          <svg width=\"13\" height=\"13\" viewBox=\"0 0 24 24\" fill=\"none\" stroke={p.faint} strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-label=\"Needs Pro\">\n                            <rect x=\"5\" y=\"11\" width=\"14\" height=\"10\" rx=\"2\" />\n                            <path d=\"M8 11V8a4 4 0 0 1 8 0v3\" />\n                          </svg>\n                        ) : (\n                          dot(on)\n                        )}\n                      </span>\n                      <span className=\"mt-2 text-[12.5px] tabular-nums\" style={{ color: p.muted }}>\n                        {x.cpu} · {x.ram}\n                      </span>\n                      <span className=\"mt-2 text-[13px] font-medium tabular-nums\">{x.price ? `+${money(perMonth(x.price, sel.billing))}/mo` : \"Included\"}</span>\n                    </label>\n                  );\n                })}\n              </div>\n            </fieldset>\n          </div>\n\n          {/* Summary */}\n          <aside className=\"@[920px]:sticky @[920px]:top-6 @[920px]:self-start\" aria-labelledby={`${uid}-sum`}>\n            <div className=\"rounded-2xl border p-5\" style={{ borderColor: p.border, background: p.card }}>\n              <h3 id={`${uid}-sum`} className=\"m-0 text-[14px] font-semibold\">\n                Summary\n              </h3>\n              <dl className=\"m-0 mt-4 flex flex-col gap-2.5 text-[13px]\">\n                {[\n                  [\"Plan\", plan.name, money(perMonth(plan.price, sel.billing))],\n                  [\"Compute\", `${compute.name} · ${compute.cpu}`, money(perMonth(compute.price, sel.billing))],\n                  [\"Region\", region.city, \"—\"],\n                ].map(([k, v, price]) => (\n                  <div key={k} className=\"flex items-baseline justify-between gap-3\">\n                    <dt className=\"shrink-0\" style={{ color: p.faint }}>\n                      {k}\n                    </dt>\n                    <dd className=\"m-0 flex min-w-0 items-baseline gap-2\">\n                      <AnimatePresence mode=\"popLayout\" initial={false}>\n                        <motion.span key={v} initial={reduce ? false : { opacity: 0, y: 6 }} animate={{ opacity: 1, y: 0 }} exit={reduce ? undefined : { opacity: 0, y: -6 }} className=\"truncate\">\n                          {v}\n                        </motion.span>\n                      </AnimatePresence>\n                      <span className=\"w-12 shrink-0 text-right tabular-nums\" style={{ color: p.muted }}>\n                        {price}\n                      </span>\n                    </dd>\n                  </div>\n                ))}\n              </dl>\n              <div className=\"mt-4 flex items-baseline justify-between border-t pt-4\" style={{ borderColor: p.border }}>\n                <span className=\"text-[13px]\" style={{ color: p.muted }}>\n                  Total\n                </span>\n                <span className=\"flex items-baseline gap-1\">\n                  <motion.span className=\"text-[26px] font-semibold tabular-nums tracking-[-0.02em]\" aria-live=\"polite\">\n                    {shown}\n                  </motion.span>\n                  <span className=\"text-[12.5px]\" style={{ color: p.faint }}>\n                    /mo\n                  </span>\n                </span>\n              </div>\n              <p className=\"m-0 mt-1 text-right text-[12px]\" style={{ color: p.faint }}>\n                {sel.billing === \"yearly\" ? `Billed ${money(Math.round(total * 12))} yearly` : \"Billed monthly, cancel anytime\"}\n              </p>\n              <button type=\"submit\" disabled={status === \"creating\"} className={cn(\"mt-5 flex h-10 w-full cursor-pointer items-center justify-center gap-2 rounded-lg border-0 text-[14px] font-medium disabled:cursor-wait\", focus)} style={{ background: p.on, color: p.onText, ...ring }}>\n                {status === \"creating\" && <motion.span className=\"h-3.5 w-3.5 rounded-full border-2 border-current border-t-transparent\" animate={reduce ? undefined : { rotate: 360 }} transition={{ repeat: Infinity, duration: 0.7, ease: \"linear\" }} aria-hidden=\"true\" />}\n                {status === \"creating\" ? \"Creating…\" : \"Create database\"}\n              </button>\n            </div>\n          </aside>\n        </div>\n      </form>\n    </section>\n  );\n}\n\nexport default RadioGroupCards;\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}