RadioCards
A few options drawn as cards, each with a title and a sentence, of which one is chosen. For choices that deserve a moment of reading, like a plan.
import { RadioCards, RadioCardsSkeleton } from '@sypnia/ui/react'
Choose a plan
The whole card is the target. The hint says what the choice costs.
No cost, and no card needed.
Code
import { useState } from 'react';
import { Field, RadioCards, type Option } from '@sypnia/ui/react';
const plans: Option[] = [
{ value: 'free', label: 'Free', description: 'One project, 500 MB, backups every week. Sleeps after 7 days without use.' },
{ value: 'pro', label: 'Pro', description: 'Unlimited projects, 20 GB each, backups every day, no sleeping.' },
{ value: 'team', label: 'Team', description: 'Everything in Pro, plus roles, audit log and support by chat.' },
];
const price: Record<string, string> = { free: 'No cost, and no card needed.', pro: 'USD 25 a month for each project.', team: 'USD 99 a month for each project.' };
export default function Basic() {
const [plan, setPlan] = useState('free');
return (
<Field label="Plan" hint={price[plan]}>
<RadioCards options={plans} value={plan} onChange={setPlan} />
</Field>
);
} With icons
An icon at the end of each card helps to tell them apart at a glance.
Code
import { Field, RadioCards, type Option } from '@sypnia/ui/react';
const kinds: Option[] = [
{ value: 'cloud', label: 'Sypnia Cloud', description: 'We run it. Ready in a minute.', icon: 'cloud' },
{ value: 'self', label: 'Your own server', description: 'You run it, with the open source engine.', icon: 'self-host' },
];
export default function WithIcons() {
return (
<Field label="Where will it run?">
<RadioCards options={kinds} defaultValue="cloud" />
</Field>
);
} States
Nothing chosen with an error, one option that cannot be chosen, and all disabled.
Choose where the data will live: it cannot be moved later.
The region was chosen when the project was created.
Code
import { Field, RadioCards, type Option } from '@sypnia/ui/react';
const regions: Option[] = [
{ value: 'us-east-1', label: 'Virginia', description: 'Closest to North America.' },
{ value: 'sa-east-1', label: 'São Paulo', description: 'Closest to South America.' },
{ value: 'ap-southeast-1', label: 'Singapore', description: 'Opens in January.', disabled: true },
];
export default function States() {
return (
<div className="sy-stack">
<Field label="Region" error="Choose where the data will live: it cannot be moved later.">
<RadioCards options={regions} />
</Field>
<Field label="Region" hint="The region was chosen when the project was created.">
<RadioCards disabled options={regions.slice(0, 2)} defaultValue="sa-east-1" />
</Field>
</div>
);
} Skeleton
The real piece and its skeleton: the same box, so nothing moves when the data arrives.
Code
import { RadioCards, RadioCardsSkeleton } from '@sypnia/ui/react';
// Plans whose prices are still loading. The skeleton has the same box as the real one, so nothing moves when the data arrives.
export default function Skeleton() {
return (
<div className="sy-stack">
<RadioCards aria-label="Plan" defaultValue="team" options={[{ value: 'starter', label: 'Starter', description: '3 people, 1 project.' }, { value: 'team', label: 'Team', description: '10 people, every project.' }]} />
<RadioCardsSkeleton items={2} />
</div>
);
} When to use it
Use it when
- Two to four options that need a sentence each to be understood: plans, regions, kinds of project.
- The choice is the main thing the screen asks for.
Do not use it when
- Options are short words: RadioGroup takes less room.
- There are more than four or five: Select.
- Several can be chosen: a group of CheckboxCards.
For everyone
- They are native radios inside labels: the group is one tab stop, the arrows move the choice, and the whole card can be pressed.
- It is announced as a
radiogroupwith the question as its name; each card reads its title and then its sentence. - The chosen card is told by its border and tint and by the filled radio: never by colour alone.
- On phones the cards stack one under another; nothing scrolls sideways.
Props
| RadioCards | Type | Default |
|---|---|---|
optionsrequired | Option[] | |
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | string | |
disabled | boolean | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
nameThe name of the value when it travels in a form. | string | |
onChange | ((value: string) => void) | |
value | string | null |
| RadioCardsSkeleton | Type | Default |
|---|---|---|
items | number | 3 |