@k8ordo/ui

RadioCard

A single-select whose options are cards. Use it when each option carries a description or a visual.

Import

ts
import { RadioCard } from '@k8ordo/ui';

Usage

Choose a plan

tsx
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

tsx
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.

Choose a plan

tsx
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: -
PropTypeDefault
aria-labelledbystring-
optionsreadonly RadioCardOption[]-
defaultValue?string-
invalid?booleanfalse
onChange?(value: string) => void-
ref?Ref<HTMLFieldSetElement>-
required?booleanfalse
value?string-

Inherited attributes (except the ones set internally): FieldsetHTMLAttributes<HTMLFieldSetElement>

k8ordo

React libraries that use Baseline features without holding back.