Radio group
Pick one, as cards or a list.
Variants
3 more takes on the radio group, each a single file you install on its own by its id.
aui-055Plan picker
Plan rows with a gliding ring.
$ pnpm dlx asta-ui@latest add radio-group-aui-055aui-056Segmented range
A range picked from segments.
$ pnpm dlx asta-ui@latest add radio-group-aui-056aui-057Swatches
Colour swatches.
$ pnpm dlx asta-ui@latest add radio-group-aui-057Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/, installsradix-ui@base-ui/reactand the colour tokens go into your CSS. This is the Radix build. Drop --radix for Base UI.This is the Base UI build, the default. Want Radix? Add --radix.$ pnpm dlx asta-ui@latest add radio-group --radixOr install the package
Don’t want the file? Import from
asta-uiasta-ui/baseand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-ui radix-ui @base-ui/reactimport { RadioGroup } from "asta-ui";import { RadioGroup } from "asta-ui/base";Or copy it by hand
Install
radix-ui@base-ui/react, then copy this file. Keep the paths, or fix the@/imports. Then add the tokens fromglobals.css."use client"; import { RadioGroup as R } from "radix-ui"; import { useLayoutEffect, useRef, useState, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export interface RadioOption { value: string; label: ReactNode; description?: ReactNode; /** Shown on the right of a card, e.g. a price. */ aside?: ReactNode; disabled?: boolean; } export interface RadioGroupProps { options: RadioOption[]; value?: string; defaultValue?: string; onChange?: (value: string) => void; /** `cards` (default): option cards with a ring that glides to the selection. `list`: compact rows. */ variant?: "cards" | "list"; /** Cards per row on wider screens. */ columns?: 1 | 2 | 3; label?: string; name?: string; className?: string; } const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)]"; /** Choose one, on Radix Radio Group: arrow keys move and select (roving focus) like native radios, and `name` submits with a form. */ export function RadioGroup({ options, value, defaultValue, onChange, variant = "cards", columns = 3, label, name, className }: RadioGroupProps) { const [inner, setInner] = useState(defaultValue ?? options.find((o) => !o.disabled)?.value ?? ""); const current = value ?? inner; const refs = useRef<(HTMLButtonElement | null)[]>([]); const box = useRef<HTMLDivElement>(null); const [glide, setGlide] = useState<{ x: number; y: number; w: number; h: number } | null>(null); const pick = (v: string) => { if (value === undefined) setInner(v); onChange?.(v); }; const index = Math.max(0, options.findIndex((o) => o.value === current)); useLayoutEffect(() => { if (variant !== "cards") return; const measure = () => { const el = refs.current[index]; if (el) setGlide({ x: el.offsetLeft, y: el.offsetTop, w: el.offsetWidth, h: el.offsetHeight }); }; // ResizeObserver reports once right after layout, so there is no layout read while the page mounts. const ro = new ResizeObserver(measure); if (box.current) ro.observe(box.current); return () => ro.disconnect(); }, [index, variant]); const grid = columns === 1 ? "" : columns === 2 ? "sm:grid-cols-2" : "sm:grid-cols-3"; return ( <R.Root ref={box} value={current} onValueChange={pick} name={name} aria-label={label} className={cx("relative", variant === "cards" ? `grid gap-2.5 ${grid}` : `flex flex-col rounded-xl bg-paper p-1.5 ${RING}`, className)} > {variant === "cards" && glide && ( <span aria-hidden // perf-ok: a small indicator whose size follows the item under it, once per change. className="pointer-events-none absolute left-0 top-0 z-10 rounded-xl shadow-[inset_0_0_0_2px_var(--color-brand),0_0_0_4px_color-mix(in_srgb,var(--color-brand)_14%,transparent)] transition-[transform,width,height] duration-500 ease-[cubic-bezier(.16,1,.3,1)] motion-reduce:transition-none" style={{ transform: `translate(${glide.x}px, ${glide.y}px)`, width: glide.w, height: glide.h }} /> )} {options.map((o, i) => { const on = o.value === current; return ( <R.Item key={o.value} value={o.value} ref={(el) => { refs.current[i] = el; }} disabled={o.disabled} className={cx( "group/radio relative flex text-left outline-none transition-[background-color,box-shadow,opacity] duration-300 focus-visible:ring-2 focus-visible:ring-brand/50 disabled:cursor-not-allowed disabled:opacity-45", variant === "cards" ? cx("flex-col gap-1 rounded-xl bg-paper p-4", RING, !on && "hover:bg-paper-2") : cx("flex-col gap-0.5 rounded-lg px-3 py-2.5", on ? "bg-paper-2" : "hover:bg-paper-2/60"), )} > <span className="flex w-full items-center gap-3"> <Dot on={on} /> <span className="min-w-0 flex-1 text-[14px] font-medium tracking-[-0.01em] text-ink">{o.label}</span> {o.aside && <span className="text-[13px] tabular-nums text-ink-2">{o.aside}</span>} </span> {o.description && <span className={cx("text-[13px] leading-snug text-mute", "pl-7")}>{o.description}</span>} </R.Item> ); })} </R.Root> ); } /** The radio circle: the inner dot pops in with a small overshoot. */ export function Dot({ on }: { on: boolean }) { return ( <span aria-hidden className={cx( "relative flex h-4 w-4 shrink-0 items-center justify-center rounded-full transition-[background-color,box-shadow] duration-300", on ? "bg-brand shadow-none" : "bg-paper shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_24%,transparent)] group-hover/radio:shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_40%,transparent)]", )} > <span className={cx( "h-1.5 w-1.5 rounded-full bg-on-brand transition-transform duration-300 ease-[cubic-bezier(.34,1.8,.64,1)] motion-reduce:transition-none", on ? "scale-100" : "scale-0", // perf-ok: 6px radio dot, not a surface )} /> </span> ); } export default RadioGroup;"use client"; import { Radio } from "@base-ui/react/radio"; import { RadioGroup as Group } from "@base-ui/react/radio-group"; import { useLayoutEffect, useRef, useState, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export interface RadioOption { value: string; label: ReactNode; description?: ReactNode; /** Shown on the right of a card, e.g. a price. */ aside?: ReactNode; disabled?: boolean; } export interface RadioGroupProps { options: RadioOption[]; value?: string; defaultValue?: string; onChange?: (value: string) => void; /** `cards` (default): option cards with a ring that glides to the selection. `list`: compact rows. */ variant?: "cards" | "list"; /** Cards per row on wider screens. */ columns?: 1 | 2 | 3; label?: string; name?: string; className?: string; } const RING = "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)]"; /** Choose one, on Base UI Radio Group: arrow keys move and select (roving focus) like native radios, and `name` submits with a form. */ export function RadioGroup({ options, value, defaultValue, onChange, variant = "cards", columns = 3, label, name, className }: RadioGroupProps) { const [inner, setInner] = useState(defaultValue ?? options.find((o) => !o.disabled)?.value ?? ""); const current = value ?? inner; const refs = useRef<(HTMLSpanElement | null)[]>([]); const box = useRef<HTMLDivElement>(null); const [glide, setGlide] = useState<{ x: number; y: number; w: number; h: number } | null>(null); const pick = (v: string) => { if (value === undefined) setInner(v); onChange?.(v); }; const index = Math.max(0, options.findIndex((o) => o.value === current)); useLayoutEffect(() => { if (variant !== "cards") return; const measure = () => { const el = refs.current[index]; if (el) setGlide({ x: el.offsetLeft, y: el.offsetTop, w: el.offsetWidth, h: el.offsetHeight }); }; // ResizeObserver reports once right after layout, so there is no layout read while the page mounts. const ro = new ResizeObserver(measure); if (box.current) ro.observe(box.current); return () => ro.disconnect(); }, [index, variant]); const grid = columns === 1 ? "" : columns === 2 ? "sm:grid-cols-2" : "sm:grid-cols-3"; return ( <Group ref={box} value={current} onValueChange={(v) => pick(String(v))} name={name} aria-label={label} className={cx("relative", variant === "cards" ? `grid gap-2.5 ${grid}` : `flex flex-col rounded-xl bg-paper p-1.5 ${RING}`, className)} > {variant === "cards" && glide && ( <span aria-hidden // perf-ok: a small indicator whose size follows the item under it, once per change. className="pointer-events-none absolute left-0 top-0 z-10 rounded-xl shadow-[inset_0_0_0_2px_var(--color-brand),0_0_0_4px_color-mix(in_srgb,var(--color-brand)_14%,transparent)] transition-[transform,width,height] duration-500 ease-[cubic-bezier(.16,1,.3,1)] motion-reduce:transition-none" style={{ transform: `translate(${glide.x}px, ${glide.y}px)`, width: glide.w, height: glide.h }} /> )} {options.map((o, i) => { const on = o.value === current; return ( <Radio.Root key={o.value} value={o.value} ref={(el) => { refs.current[i] = el; }} disabled={o.disabled} className={cx( "group/radio relative flex cursor-pointer select-none text-left outline-none transition-[background-color,box-shadow,opacity] duration-300 focus-visible:ring-2 focus-visible:ring-brand/50 data-[disabled]:cursor-not-allowed data-[disabled]:opacity-45", variant === "cards" ? cx("flex-col gap-1 rounded-xl bg-paper p-4", RING, !on && "hover:bg-paper-2") : cx("flex-col gap-0.5 rounded-lg px-3 py-2.5", on ? "bg-paper-2" : "hover:bg-paper-2/60"), )} > <span className="flex w-full items-center gap-3"> <Dot on={on} /> <span className="min-w-0 flex-1 text-[14px] font-medium tracking-[-0.01em] text-ink">{o.label}</span> {o.aside && <span className="text-[13px] tabular-nums text-ink-2">{o.aside}</span>} </span> {o.description && <span className={cx("text-[13px] leading-snug text-mute", "pl-7")}>{o.description}</span>} </Radio.Root> ); })} </Group> ); } /** The radio circle: the inner dot pops in with a small overshoot. */ export function Dot({ on }: { on: boolean }) { return ( <span aria-hidden className={cx( "relative flex h-4 w-4 shrink-0 items-center justify-center rounded-full transition-[background-color,box-shadow] duration-300", on ? "bg-brand shadow-none" : "bg-paper shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_24%,transparent)] group-hover/radio:shadow-[inset_0_0_0_1.5px_color-mix(in_srgb,var(--color-ink)_40%,transparent)]", )} > <span className={cx( "h-1.5 w-1.5 rounded-full bg-on-brand transition-transform duration-300 ease-[cubic-bezier(.34,1.8,.64,1)] motion-reduce:transition-none", on ? "scale-100" : "scale-0", // perf-ok: 6px radio dot, not a surface )} /> </span> ); } export default RadioGroup;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Radio group component to my project. Pick one, as cards or a list. It includes: cards, list, keys. Install it (Radix build): ```sh pnpm dlx asta-ui@latest add radio-group --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/radio-group.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { RadioGroup } from "@/components/astabyte/radio-group"; ``` Usage example and props: https://ui.astabyte.com/radio-group Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Radix primitives from the radix-ui package). - Stay on Radix: install other Astabyte UI components with `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Add the Astabyte UI Radio group component to my project. Pick one, as cards or a list. It includes: cards, list, keys. Install it (Base UI build): ```sh pnpm dlx asta-ui@latest add radio-group ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/base/radio-group.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { RadioGroup } from "@/components/astabyte/radio-group"; ``` Usage example and props: https://ui.astabyte.com/radio-group Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour (interactive pieces are built on Base UI primitives from the @base-ui/react package). - Stay on Base UI: install other Astabyte UI components without `--radix` so the project uses one primitive library. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div role="radiogroup" aria-label="Plan" class="asta-radio-group"> <label class="asta-radio"><span class="asta-radio-row"><span class="asta-radio-dot"><input type="radio" class="asta-radio-input" name="plan" value="starter" checked><span class="asta-radio-mark" aria-hidden="true"></span></span><span class="asta-radio-label">Starter</span><span class="asta-radio-aside">$0</span></span><span class="asta-radio-desc">For side projects.</span></label> <label class="asta-radio"><span class="asta-radio-row"><span class="asta-radio-dot"><input type="radio" class="asta-radio-input" name="plan" value="pro" ><span class="asta-radio-mark" aria-hidden="true"></span></span><span class="asta-radio-label">Pro</span><span class="asta-radio-aside">$12</span></span><span class="asta-radio-desc">For small teams.</span></label> <label class="asta-radio"><span class="asta-radio-row"><span class="asta-radio-dot"><input type="radio" class="asta-radio-input" name="plan" value="scale" ><span class="asta-radio-mark" aria-hidden="true"></span></span><span class="asta-radio-label">Scale</span><span class="asta-radio-aside">$48</span></span><span class="asta-radio-desc">For the whole of Astabyte.</span></label> </div>
Usage
The demo above, as code.
"use client";
import { useState } from "react";
import { RadioGroup } from "@/components/astabyte/radio-group";
const PLANS = [
{ value: "starter", label: "Starter", aside: "$0", description: "For side projects and trying things out." },
{ value: "pro", label: "Pro", aside: "$24", description: "Unlimited projects and a custom domain." },
{ value: "team", label: "Team", aside: "$79", description: "Shared workspaces, roles and audit logs." },
];
const SHIPPING = [
{ value: "standard", label: "Standard", aside: "Free", description: "3–5 business days" },
{ value: "express", label: "Express", aside: "$12", description: "Next business day" },
{ value: "pickup", label: "Pick up in store", aside: "Free", disabled: true, description: "Not available near you" },
];
export default function RadioGroupDemo() {
const [plan, setPlan] = useState("pro");
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex w-full max-w-[640px] flex-col gap-8">
<div>
<p className="mb-3 text-[13px] text-mute">
Plan · <span className="text-ink">{PLANS.find((p) => p.value === plan)?.label}</span>
</p>
<RadioGroup label="Plan" options={PLANS} value={plan} onChange={setPlan} />
</div>
<div className="max-w-sm">
<p className="mb-3 text-[13px] text-mute">Shipping</p>
<RadioGroup label="Shipping" variant="list" options={SHIPPING} defaultValue="standard" />
</div>
</div>
</div>
);
}