# Radio

A circle people choose when only one option from a short list can be picked.

```tsx
import { RadioGroup, Radio } from '@halo-ds/react';
```

## When to use it
Use radios when people must pick exactly one option and it helps to see every option at once. Radio is the circle on its own; Radio field adds a label and description; Radio group holds a labelled set of fields in a slot, stacked or in a row, with a hint.

## Do
- Choose a sensible default when one exists, like the most common option.
- Keep it to about 5 options; use a Select for longer lists.
- Put options in a logical order, like cheapest to fastest.
- Stack options, unless there are two or three short ones.

## Don't
- Use a single radio on its own; it can't be unchosen. Use a Checkbox.
- Use radios for a setting that changes straight away; use a Switch.
- Leave a group without a label.
- Lay out long labels in a row; they wrap and are hard to scan.

## Radio, Select or Checkbox?
All make choices. Pick by how many options there are, and how many people can choose.
- **Radio**: Pick exactly one option from a short list, about 2 to 5. Every option stays visible, so people can compare them. Good when the options need descriptions, like delivery speeds.
- **Select, Checkbox or Switch**: Select: one option from a long list, like a country. Checkbox: none, one or several options. Switch: one setting that turns on or off straight away.

## Props
### RadioGroup props
| Prop | Type | What it does |
| --- | --- | --- |
| `label` (required) | `ReactNode` | Names the group with a Field label. Figma: Label. |
| `hideLabel` | `boolean \| undefined` | Hides the label visually but keeps it for screen readers. |
| `required` | `boolean \| undefined` |  |
| `optional` | `boolean \| undefined` |  |
| `hint` | `ReactNode` | Help under the options. Figma: Hint. |
| `error` | `ReactNode` | An error message. Turns every circle red. Figma: State=Error. |
| `value` | `string \| undefined` |  |
| `defaultValue` | `string \| undefined` |  |
| `onValueChange` | `((value: string) => void) \| undefined` |  |
| `orientation` | `"vertical" \| "horizontal" \| undefined` | Stack the options, or put two or three short ones in a row. Figma: Orientation. |
| `size` | `RadioSize \| undefined` |  |
| `name` | `string \| undefined` | Form field name. Generated when left out. |
| `children` (required) | `ReactNode` |  |
| `classNames` | `Partial<Record<RadioGroupPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<RadioGroupPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

### Radio props
| Prop | Type | What it does |
| --- | --- | --- |
| `label` | `ReactNode` | What choosing this option means. Figma: Label. |
| `description` | `ReactNode` | Extra detail under the label. Figma: Description. |
| `size` | `RadioSize \| undefined` | 16px (sm) or 20px (md) circle. Set on the group instead when inside one. Figma: Size. |
| `value` (required) | `string` | The value sent when this option is chosen. |
| `invalid` | `boolean \| undefined` |  |
| `classNames` | `Partial<Record<RadioPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<RadioPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { Radio, RadioGroup } from '@halo-ds/react';

export default function Example() {
  return (
    <RadioGroup label="Plan" defaultValue="team">
      <Radio value="free" label="Free" description="For trying things out." />
      <Radio value="team" label="Team" description="$8 per member a month." />
      <Radio value="business" label="Business" description="$16 per member a month." />
    </RadioGroup>
  );
}
```

### Horizontal
Two or three short options in a row.
```tsx
import { Radio, RadioGroup } from '@halo-ds/react';

export default function Demo() {
  return (
    <RadioGroup label="Billing" orientation="horizontal" defaultValue="yearly" hint="Save 20% with yearly billing.">
      <Radio value="monthly" label="Monthly" />
      <Radio value="yearly" label="Yearly" />
    </RadioGroup>
  );
}
```

### Error
Every circle turns red and the hint shows as an error.
```tsx
import { Radio, RadioGroup } from '@halo-ds/react';

export default function Demo() {
  return (
    <RadioGroup label="Contact method" required error="Choose how we should contact you.">
      <Radio value="email" label="Email" />
      <Radio value="phone" label="Phone call" />
    </RadioGroup>
  );
}
```

More: https://halodesignsystem.dev/components/radio
