ComponentsForm
Option Cards
A radiogroup of 2–4 lettered option cards, each with a label, a one-line detail and its pros and cons, a Recommended mark on at most one, and a selection ring that slides to the picked card.
Default
With a Footnote
Each card can end on a quiet footnote, for example what picking it sends.
Installation
npx visor add option-cardsThis copies two files into your project:
components/ui/option-cards/option-cards.tsx— the componentcomponents/ui/option-cards/option-cards.module.css— the styles
Usage
import { OptionCards } from '@/components/ui/option-cards/option-cards';
const [pick, setPick] = React.useState<number | null>(null);
<OptionCards
aria-label="Hosting"
value={pick}
onValueChange={setPick}
options={[
{ label: 'Keep Vercel', detail: 'As today.', pros: ['No setup'], cons: ['Per-seat cost'], recommended: true },
{ label: 'Self-Host', detail: 'Our own box.', pros: ['No bill'], cons: ['We run upgrades'] },
]}
/>Pass value and onValueChange to control it, or defaultValue to leave it uncontrolled. The selection is the picked option's index, or null before anything is picked.
Behavior
- Recommended. Only the first option with
recommendedgets the mark, so a row never recommends two. - Selection ring. One ring slides to the picked card on a CSS transition. Under
prefers-reduced-motion: reduceit moves without sliding. - Keyboard. The group is one tab stop. Arrow keys move and select, wrapping at the ends. While focus is in the group, the A, B, C and D keys pick that card directly.
- Layout. Cards sit side by side, and stack once the component is narrower than 900px (a container query, so a narrow column stacks too).
- Colour. Every colour is a theme token: the card is a tile a half-step off
--surface-pagetoward the ink, ink and the ring are--text-primary, pros and the Recommended mark are--text-success, cons are--text-warning.
API Reference
OptionCardsProps
| Prop | Type | Default | Description |
|---|---|---|---|
options* | { label: ReactNode; detail?: ReactNode; pros?: ReactNode[]; cons?: ReactNode[]; recommended?: boolean; footnote?: ReactNode }[] | — | Two to four options, lettered A to D in order. Only the first option with recommended is marked. |
value | number | null | — | Controlled selection, the picked option's index. |
defaultValue | number | null | null | Uncontrolled initial selection. |
onValueChange | (index: number) => void | — | Fires with the picked option's index. |