# Radio

Radio is a control component that allows users to select one option from a set of mutually exclusive options.

## Import

```tsx
import { Radio } from '@coinbase/cds-web/controls/Radio'
```

## Examples

### Basic Usage

Radio components are typically used individually as part of a radio group. Each radio represents a single option in a mutually exclusive set.

```jsx live
function BasicRadio() {
  const [selectedValue, setSelectedValue] = useState('option1');

  return (
    <VStack gap={2}>
      <Radio
        name="basic-radio"
        value="option1"
        checked={selectedValue === 'option1'}
        onChange={(e) => setSelectedValue(e.target.value)}
      >
        Option 1
      </Radio>
      <Radio
        name="basic-radio"
        value="option2"
        checked={selectedValue === 'option2'}
        onChange={(e) => setSelectedValue(e.target.value)}
      >
        Option 2
      </Radio>
      <Radio
        name="basic-radio"
        value="option3"
        checked={selectedValue === 'option3'}
        onChange={(e) => setSelectedValue(e.target.value)}
      >
        Option 3
      </Radio>
    </VStack>
  );
}
```

### Radio Groups

The recommended way to use Radio components is with a ControlGroup for better accessibility and easier state management.

```jsx live
function RadioGroupExample() {
  const options = [
    { value: 'btc', children: 'Bitcoin' },
    { value: 'eth', children: 'Ethereum' },
    { value: 'ltc', children: 'Litecoin' },
  ];

  const [selectedCurrency, setSelectedCurrency] = useState('btc');

  return (
    <ControlGroup
      role="radiogroup"
      ControlComponent={Radio}
      label="Choose a cryptocurrency"
      options={options}
      value={selectedCurrency}
      onChange={(e) => setSelectedCurrency(e.target.value)}
      name="currency-radio-group"
    />
  );
}
```

### Custom Colors

You can customize the radio's color using the `controlColor` prop.

```jsx live
function CustomColorRadio() {
  const [selectedColor, setSelectedColor] = useState('default');

  return (
    <VStack gap={2}>
      <Radio
        name="color-radio"
        value="default"
        checked={selectedColor === 'default'}
        onChange={(e) => setSelectedColor(e.target.value)}
      >
        Default Color
      </Radio>
      <Radio
        name="color-radio"
        value="green"
        checked={selectedColor === 'green'}
        onChange={(e) => setSelectedColor(e.target.value)}
        controlColor="accentBoldGreen"
      >
        Custom Green
      </Radio>
      <Radio
        name="color-radio"
        value="purple"
        checked={selectedColor === 'purple'}
        onChange={(e) => setSelectedColor(e.target.value)}
        controlColor="accentBoldPurple"
      >
        Custom Purple
      </Radio>
    </VStack>
  );
}
```

### Disabled State

Radio components can be disabled to prevent user interaction.

```jsx live
function DisabledRadio() {
  const [selectedValue, setSelectedValue] = useState('enabled');

  return (
    <VStack gap={2}>
      <Radio
        name="disabled-radio"
        value="enabled"
        checked={selectedValue === 'enabled'}
        onChange={(e) => setSelectedValue(e.target.value)}
      >
        Enabled Radio
      </Radio>
      <Radio
        name="disabled-radio"
        value="disabled-unchecked"
        checked={false}
        disabled
        onChange={(e) => setSelectedValue(e.target.value)}
      >
        Disabled & Unchecked
      </Radio>
      <Radio
        name="disabled-radio"
        value="disabled-checked"
        checked={true}
        disabled
        onChange={(e) => setSelectedValue(e.target.value)}
      >
        Disabled & Checked
      </Radio>
    </VStack>
  );
}
```

### Custom Styling

You can further customize the radio's appearance using style props.

```jsx live
function CustomStyledRadio() {
  const [selectedStyle, setSelectedStyle] = useState('styled1');

  return (
    <VStack gap={2}>
      <Radio
        name="styled-radio"
        value="styled1"
        checked={selectedStyle === 'styled1'}
        onChange={(e) => setSelectedStyle(e.target.value)}
        background="bgSecondary"
        borderColor="accentBoldBlue"
        controlColor="accentBoldBlue"
      >
        Custom Background & Border
      </Radio>
      <Radio
        name="styled-radio"
        value="styled2"
        checked={selectedStyle === 'styled2'}
        onChange={(e) => setSelectedStyle(e.target.value)}
        controlColor="accentBoldOrange"
        borderColor="accentBoldOrange"
      >
        Orange Theme
      </Radio>
    </VStack>
  );
}
```

## Props

| Prop | Type | Required | Default | Description |
| --- | --- | --- | --- | --- |
| `accessibilityLabel` | `string` | No | `-` | Accessibility label describing the element. |
| `background` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `-` | Background color of the overlay (element being interacted with). |
| `borderColor` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `-` | Border color of the element. |
| `borderRadius` | `0 \| 100 \| 200 \| 300 \| 400 \| 500 \| 600 \| 700 \| 800 \| 900 \| 1000` | No | `-` | - |
| `borderWidth` | `0 \| 100 \| 200 \| 300 \| 400 \| 500` | No | `-` | - |
| `children` | `null \| string \| number \| false \| true \| ReactElement<any, string \| JSXElementConstructor<any>> \| Iterable<ReactNode> \| ReactPortal` | No | `-` | Label for the control option. |
| `color` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `black` | - |
| `controlColor` | `currentColor \| fg \| fgMuted \| fgInverse \| fgPrimary \| fgWarning \| fgPositive \| fgNegative \| bg \| bgAlternate \| bgInverse \| bgOverlay \| bgElevation1 \| bgElevation2 \| bgPrimary \| bgPrimaryWash \| bgSecondary \| bgTertiary \| bgSecondaryWash \| bgNegative \| bgNegativeWash \| bgPositive \| bgPositiveWash \| bgWarning \| bgWarningWash \| bgLine \| bgLineHeavy \| bgLineInverse \| bgLinePrimary \| bgLinePrimarySubtle \| accentSubtleRed \| accentBoldRed \| accentSubtleGreen \| accentBoldGreen \| accentSubtleBlue \| accentBoldBlue \| accentSubtlePurple \| accentBoldPurple \| accentSubtleYellow \| accentBoldYellow \| accentSubtleGray \| accentBoldGray \| transparent` | No | `bgPrimary` | Sets the checked/active color of the control. |
| `iconStyle` | `CSSProperties` | No | `-` | Style for the icon element |
| `indeterminate` | `boolean` | No | `-` | Enable indeterminate state. Useful when you want to indicate that sub-items of a control are partially filled. |
| `labelStyle` | `CSSProperties` | No | `-` | Style for the label element |
| `onChange` | `FormEventHandler<HTMLDivElement>` | No | `-` | - |
| `ref` | `null \| (instance: HTMLInputElement \| null) => void \| RefObject<HTMLInputElement>` | No | `-` | - |
| `testID` | `string` | No | `-` | Used to locate this element in unit and end-to-end tests. Under the hood, testID translates to data-testid on Web. On Mobile, testID stays the same - testID |
| `type` | `button \| submit \| reset` | No | `-` | - |
| `value` | `string` | No | `-` | Value of the option. Useful for multiple choice. |


