# Switch

> An on/off toggle whose knob swells into a clear lens while it crosses the track.

```tsx
import { useState } from 'react'

import { Switch } from '@/components/liquid-glass/controls/Switch'

export default function Demo() {
  const [on, setOn] = useState(true)
  return <Switch label="Notifications" description="Banners and sounds" checked={on} onChange={setOn} />
}
```

**Use it for**

- A setting that takes effect at once: Wi-Fi, notifications, dark mode.

**Not for**

- A choice that is saved later with a form: use Checkbox.
- More than two states: use Tabs.

```bash
npx shadcn@latest add https://onemorethink.dev/r/switch.json
```

## Usage

```tsx
import { Switch } from '@/components/liquid-glass/controls/Switch'

const [on, setOn] = useState(false)

<Switch label="Notifications" description="Banners and sounds" checked={on} onChange={setOn} />
```

Tap to flip, or hold the knob and drag it across. Needs `three` and UI SDK, like Slider.

## Examples

### Colours

```tsx
import { Switch } from '@/components/liquid-glass/controls/Switch'

// `color` is the track while on. Without it the switch is the kit's blue.
export default function Demo() {
  return (
    <div className="flex flex-col gap-5">
      <Switch label="Blue" checked />
      <Switch label="Green" color="#34c759" checked />
      <Switch label="Orange" color="#ff9500" checked />
      <Switch label="Pink" color="#ff2d55" checked />
    </div>
  )
}
```

`color` is the track while on; without it the switch is the kit's blue. The knob stays white. Without `onChange` a switch keeps its own state, starting from `checked`.

## API reference

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `checked` | `boolean` | `false` | On or off. |
| `onChange` | `(checked: boolean) => void` | — | Called with the new state. |
| `label` | `string` | `'Notifications'` | Text beside the switch; an empty string leaves the switch alone. |
| `description` | `string` | — | A second, quieter line under the label. |
| `name` | `string` | — | Submits with the form around it under this name. |
| `labelSide` | `'left' \| 'right'` | `'right'` | Which side the label sits on. |
| `size` | `'sm' \| 'md' \| 'lg'` | `'md'` | Track height 22, 28 or 36 px. |
| `color` | `string` | `'#3291FF'` | The track while on: a hex, `rgb()` or named colour, not a CSS variable. |
| `theme` | `'light' \| 'dark'` | — | Overrides the page theme for this switch. |
| `disabled` | `boolean` | `false` | Dimmed and not interactive. |
| `lensScale` | `number` | `1.55` | Size of the travelling lens relative to the resting knob. |
| `refraction / knobBounce` | `number` | `26 / 0.3` | How far the lens bends the track; how much the knob overshoots. |

## Accessibility

- A `<button role="switch">` with `aria-checked`: Space and Enter flip it.
- The `label` is a real `<label>` tied to the button.
- With reduced motion the knob simply jumps.

Source: https://onemorethink.dev/docs/switch
