# SegmentedControl

> Molecule — orn-ui

> ⚠️ Requires <UIProvider>: This component (like every orn-ui component) must render inside a <UIProvider> ancestor, or it throws at runtime. See https://orn-ui-docs.vercel.app/getting-started.md

> Runs on Expo SDK 54, 55, 56 and 57, and on bare React Native >=0.81 with react >=19.1. No native modules — works in Expo Go, no prebuild.

## Installation

Install just this component (copies the source into your project, no npm dependency)
```bash
npx orn-ui add segmented-control
```

Or install the whole package and import it
```tsx
pnpm add orn-ui
import { SegmentedControl } from 'orn-ui/segmented-control';
```

Depends on: core (theme + icons)

## Variants

### Switch the range of a chart — three options

```tsx
<View style={{ gap: 12 }}>
  <SegmentedControl options={RANGES} value={range} onChange={setRange} />
  <Body>Showing the last {range}.</Body>
</View>
```

### Two options — reads like an on/off switch

```tsx
<SegmentedControl
  options={[
    { value: 'left', label: 'Left' },
    { value: 'right', label: 'Right' },
  ]}
  value={side}
  onChange={setSide}
/>
```

### One option disabled — e.g. a plan not available yet

```tsx
<SegmentedControl
  options={[...RANGES.slice(0, 2), { value: 'month', label: 'Month', disabled: true }]}
  value={range}
  onChange={setRange}
/>
```

### The whole control disabled — while its data loads

```tsx
<SegmentedControl options={RANGES} value={range} onChange={setRange} disabled />
```

## Full demo source

```tsx
const variants: VariantDef[] = [
  {
    label: 'Switch the range of a chart — three options',
    content: (
      <View style={{ gap: 12 }}>
        <SegmentedControl options={RANGES} value={range} onChange={setRange} />
        <Body>Showing the last {range}.</Body>
      </View>
    ),
  },
  {
    label: 'Two options — reads like an on/off switch',
    content: (
      <SegmentedControl
        options={[
          { value: 'left', label: 'Left' },
          { value: 'right', label: 'Right' },
        ]}
        value={side}
        onChange={setSide}
      />
    ),
  },
  {
    label: 'One option disabled — e.g. a plan not available yet',
    content: (
      <SegmentedControl
        options={[...RANGES.slice(0, 2), { value: 'month', label: 'Month', disabled: true }]}
        value={range}
        onChange={setRange}
      />
    ),
  },
  {
    label: 'The whole control disabled — while its data loads',
    content: <SegmentedControl options={RANGES} value={range} onChange={setRange} disabled />,
  },
];
return <VariantList variants={variants} />;
```

## Props

| Name | Type | Default | Description |
|---|---|---|---|
| `options` | `SegmentedControlOption<T>[]` | — | — |
| `value` | `string` | — | — |
| `onChange` | `(value: T) => void` | — | — |
| `disabled?` | `boolean` | — | — |
| `style?` | `StyleProp<ViewStyle>` | — | — |
