Plan picker
Slant / Data
Radio cards for choosing a plan.
Demo
Usage
import { Field, PlanPicker } from '@tuttn/slant'
const plans = [
{ id: 'solo', name: 'Solo', price: 'Free', note: 'One workspace' },
{ id: 'studio', name: 'Studio', price: '$12', period: '/mo', note: 'Unlimited workspaces' },
]
// Controlled.
<PlanPicker plans={plans} value={plan} onValueChange={setPlan} label="Choose a plan" />
// Uncontrolled: the picker keeps its own choice, and the form submits it as "plan".
<PlanPicker plans={plans} defaultValue="studio" name="plan" label="Choose a plan" />
// In a Field, required: the field's label names the group and its error describes it.
<Field invalid={!plan} required>
<Field.Label>Plan</Field.Label>
<PlanPicker plans={plans} value={plan} onValueChange={setPlan} label="Plan" />
<Field.Error>Choose a plan to continue.</Field.Error>
</Field>Props
| Prop | Type | Default | Description |
|---|---|---|---|
plans | readonly Plan[] | — | The plans, one radio card each: the name is the radio's label, the note and the price describe it. |
value | string | — | The chosen plan's id, controlled. Omit it and the picker keeps its own, starting from `defaultValue`. |
defaultValue | string | none chosen | The plan an uncontrolled picker starts on. |
onValueChange | (id: string) => void | — | Called with the plan's id when the reader picks one. |
label | string | — | The group's accessible name. |
name | string | generated | The radios' name, which a form submits the chosen id under. |
form | string | — | The id of the form the radios belong to, when the group sits outside it. |
orientation | 'vertical' | 'horizontal' | — | A column of options, or a row that wraps (cards share it in equal columns). |
size | 'sm' | 'md' | — | `md` is a 14px mark with 13px text; `sm` a 12px mark with 12px text. |
disabled | boolean | — | Disables every radio. A disabled group is not submitted with its form. |
required | boolean | — | Requires a choice: aria-required on the group, and `required` on the radios for the form's own validation. |
invalid | boolean | — | Sets aria-invalid on the group and a danger border on its unchosen marks. Inside a Field, the field's `invalid` does this. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style, other attributes and the ref go on the radiogroup element. RadioGroup's form, disabled, required, invalid, size and orientation pass through. |
A plan picker is a radio group of cards: each plan's name labels its radio, and its note and price describe it. The radios are native, so the arrow keys move between plans, Tab enters at the chosen one, and a form submits the chosen id without extra code. The chosen card fills with the accent and shows a check.
Since 0.5.0 the ref reaches the radiogroup <div>, not a fieldset, and the cards are .sl-radio labels with data-checked.