Radio group
One choice from a few: a list, or cards.
Installation
Terminal
npx shadcn@latest add https://fabrickit.org/r/radio.jsonTerminal
pnpm dlx shadcn@latest add https://fabrickit.org/r/radio.jsonTerminal
yarn shadcn@latest add https://fabrickit.org/r/radio.jsonTerminal
bunx --bun shadcn@latest add https://fabrickit.org/r/radio.jsonThis copies the component into components/fabricui and its engine into lib/fabricui. It's your code from then on. First time? Add the theme once: see Installation.
Step 1: Add the theme (once)
Every colour, radius and curve the components use, as --fabric-* variables. Save it as fabric.css next to your global CSS and import it there. If you've added another Fabric Kit component before, skip this.globals.css@import "./fabric.css";fabric.css/* * fabric.css — Fabric Kit's theme: every colour, radius, ring and curve the * components use, as --fabric-* variables (prefixed, so they never clash * with your own shadcn theme). Installed by `shadcn add @fabrickit/theme` * (it lands in your global CSS) — or import this file once, globally. * Dark by default. For light, put data-theme="light" on <html> (or on any * element: the tokens follow it down the tree; data-theme="dark" turns back). */ :root, [data-theme="dark"] { --fabric-page: #111111; --fabric-surface: #191919; /* triggers, recessed tiles */ --fabric-panel: #202020; /* open panels */ --fabric-raised: #2a2a2a; /* hover, range band */ --fabric-raised-hi: #343434; /* hover inside a band */ --fabric-preview: #252525; /* soft preview fills */ --fabric-text: #e0e0e0;Step 2: Copy the shared engines
Plain JavaScript that does the motion, shared between components. Create each file at the same path in your project; if a file is already there from another component, keep it.lib/fabricui/goo-slide.js/* * goo-slide.js — the library's sliding highlight (Tabs, Radio cards). * * The highlight moves like a drop of liquid: its two edges are separate * springs. The edge on the side it's heading to is quick and the other is * lazier, so on the way the pill stretches toward its target, then the back * catches up and it settles to exactly the new option's size. While it's * stretched it squashes a touch the other way, like jelly. No blur, no * filters: just two springs, worked out every frame. * * const slide = new GooSlide(el, { axis: "x" }); // "x": side to side, "y": up and down * slide.to(optionEl); // animate there * slide.to(optionEl, true); // jump there (load, resize) * * The element is positioned with left/top 0 inside the options' container * (the option's offsetLeft/Top are used); the script sets its transform andStep 3: Copy the Radio group files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/radio.tsx"use client"; import * as React from "react"; import { GooSlide } from "@/lib/fabricui/goo-slide"; import "./radio.css"; const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect; export type RadioOption = { value: string; label: React.ReactNode; /** a dim line under the label (cards) */ hint?: React.ReactNode; /** on the right: a price, say */ meta?: React.ReactNode; disabled?: boolean;components/fabricui/radio.css/* * Radio group — native radio inputs (so arrow keys, labels and forms just * work), drawn three ways. Shared by the Radio group page. * * The dot (.radio): the round checkbox's sibling. Choosing it, white spreads * from the centre of the circle (never from outside), then a dark dot pops in * the middle. The old choice draws back to its centre. * * <label class="radio-row"> * <span class="radio"><input class="radio__input" type="radio" name="ship" /><span class="radio__ring"><span class="radio__ink"></span></span><span class="radio__dot"></span></span> * … * </label> * * Cards (.radio-cards) have one highlight that slides to the chosen card, * the library's gooey way (goo-slide.js). For a segmented look, use Tabs. */Step 4: Check the import paths
The files import each other through the @/ alias (the shadcn default, there in a new Next.js app). If your project doesn't have it, add it to tsconfig.json, or change the imports to relative paths.tsconfig.json{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } }Step 5: Use it
Import it from @/components/fabricui/radio. The Usage example below shows it in a page.
Code
components/fabricui/radio.tsx
"use client";
import * as React from "react";
import { GooSlide } from "@/lib/fabricui/goo-slide";
import "./radio.css";
const useIsoLayoutEffect = typeof window !== "undefined" ? React.useLayoutEffect : React.useEffect;
export type RadioOption = {
value: string;
label: React.ReactNode;
/** a dim line under the label (cards) */
hint?: React.ReactNode;
/** on the right: a price, say */
meta?: React.ReactNode;
disabled?: boolean;components/fabricui/radio.css
/*
* Radio group — native radio inputs (so arrow keys, labels and forms just
* work), drawn three ways. Shared by the Radio group page.
*
* The dot (.radio): the round checkbox's sibling. Choosing it, white spreads
* from the centre of the circle (never from outside), then a dark dot pops in
* the middle. The old choice draws back to its centre.
*
* <label class="radio-row">
* <span class="radio"><input class="radio__input" type="radio" name="ship" /><span class="radio__ring"><span class="radio__ink"></span></span><span class="radio__dot"></span></span>
* …
* </label>
*
* Cards (.radio-cards) have one highlight that slides to the chosen card,
* the library's gooey way (goo-slide.js). For a segmented look, use Tabs.
*/Usage
Usage
"use client";
import * as React from "react";
import { RadioGroup } from "@/components/fabricui/radio";
export function Plan() {
const [plan, setPlan] = React.useState("pro");
return (
<RadioGroup
variant="cards"
aria-label="Plan"
value={plan}
onValueChange={setPlan}
options={[
{ value: "starter", label: "Starter", hint: "For trying things out", meta: "$0" },
{ value: "pro", label: "Pro", hint: "For one person shipping often", meta: "$12" },
{ value: "team", label: "Team", hint: "Shared workspace, up to 10", meta: "$29", disabled: true },
]}
/>
);
}Props
| Prop | Type | Default |
|---|---|---|
| options The choices. hint is a dim line under the label; meta sits on the right (a price, say). | { value, label, hint?, meta?, disabled? }[] | — |
| value The chosen value, if you control it. | string | — |
| defaultValue The starting choice when you don't. | string | — |
| onValueChange Called when the choice changes. | (value: string) => void | — |
| variant Rows with a line between them, or cards with a highlight that slides to the chosen one. | "list" | "cards" | "list" |
| name The radios' form name. One is made up if you leave it out. | string | — |
| Radio The dot on its own (a native radio input), for your own layouts. Takes every <input> prop. | component | — |