RadioCard
A single-select whose options are cards. Use it when each option carries a description or a visual.
Import
Copy code
import { RadioCard } from '@k8ordo/ui';Usage
Choose a plan
Copy code
import { RadioCard } from '@k8ordo/ui';
import { useState } from 'react';
const options = [
{ value: 'starter', label: 'Starter', description: '...' },
{ value: 'pro', label: 'Pro', description: '...' },
{ value: 'team', label: 'Team', description: '...' },
];
const [value, setValue] = useState('pro');
<p id="plan-label">Choose a plan</p>
<RadioCard
disabled={false}
invalid={false}
aria-labelledby="plan-label"
onChange={(value) => setValue(value)}
options={options}
value={value}
/>Default value
Choose a plan
Copy code
const options = [
{ value: 'starter', label: 'Starter', description: '...' },
{ value: 'pro', label: 'Pro', description: '...' },
{ value: 'team', label: 'Team', description: '...' },
];
<p id="plan-default-label">Choose a plan</p>
<RadioCard
defaultValue="starter"
disabled={false}
invalid={false}
aria-labelledby="plan-default-label"
options={options}
/>In a form
The cards are real input[type=radio] elements. With name, the browser groups the radios that share it, and the chosen value comes straight out of FormData.
Copy code
const [submitted, setSubmitted] = useState<string | null>(null);
<Form
action={(formData) => {
const plan = formData.get('plan');
setSubmitted(typeof plan === 'string' ? plan : null);
}}
>
<p id="plan-form-label">Choose a plan</p>
<RadioCard
defaultValue="pro"
disabled={false}
invalid={false}
aria-labelledby="plan-form-label"
name="plan"
options={options}
/>
<Button type="submit">Submit</Button>
</Form>Props
aria-labelledby- Type:
string - Default: -
options- Type:
readonly RadioCardOption[] - Default: -
defaultValue?- Type:
string - Default: -
invalid?- Type:
boolean - Default:
false onChange?- Type:
(value: string) => void - Default: -
ref?- Type:
Ref<HTMLFieldSetElement> - Default: -
required?- Type:
boolean - Default:
false value?- Type:
string - Default: -
| Prop | Type | Default |
|---|---|---|
aria-labelledby | string | - |
options | readonly RadioCardOption[] | - |
defaultValue? | string | - |
invalid? | boolean | false |
onChange? | (value: string) => void | - |
ref? | Ref<HTMLFieldSetElement> | - |
required? | boolean | false |
value? | string | - |
Inherited attributes (except the ones set internally): FieldsetHTMLAttributes<HTMLFieldSetElement>