

<InteractiveDemo
  name="switch"
  controls="[
  {
    name: 'label',
    type: 'string',
    defaultValue: 'Airplane mode',
  },
  'size',
  'isDisabled',
  'isReadOnly',
]"
/>

## Installation [#installation]

<CodeBlockTabs defaultValue="npm">
  <CodeBlockTabsList>
    <CodeBlockTabsTrigger value="npm">
      npm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="pnpm">
      pnpm
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="yarn">
      yarn
    </CodeBlockTabsTrigger>

    <CodeBlockTabsTrigger value="bun">
      bun
    </CodeBlockTabsTrigger>
  </CodeBlockTabsList>

  <CodeBlockTab value="npm">
    ```bash
    npx shadcn@latest add @dotui/switch
    ```
  </CodeBlockTab>

  <CodeBlockTab value="pnpm">
    ```bash
    pnpm dlx shadcn@latest add @dotui/switch
    ```
  </CodeBlockTab>

  <CodeBlockTab value="yarn">
    ```bash
    yarn dlx shadcn@latest add @dotui/switch
    ```
  </CodeBlockTab>

  <CodeBlockTab value="bun">
    ```bash
    bun x shadcn@latest add @dotui/switch
    ```
  </CodeBlockTab>
</CodeBlockTabs>

## Usage [#usage]

Use switch for communicating activation (e.g. on/off states), while checkboxes are best used for communicating selection (e.g. multiple table rows).

```tsx
import { Label } from '@/components/ui/field'
import { Switch, SwitchControl } from '@/components/ui/switch'
```

```tsx
<Switch>
  <SwitchControl />
  <Label>Focus mode</Label>
</Switch>
```

## Examples [#examples]

<Examples className="lg:grid-cols-2">
  <Example name="switch/demos/standalone" title="Standalone" />

  <Example name="switch/demos/basic" title="Basic" />

  <Example name="switch/demos/description" title="With Description" />

  <Example name="switch/demos/disabled" title="Disabled" />

  <Example name="switch/demos/read-only" title="Read Only" />

  <Example name="switch/demos/sizes" title="Sizes" />

  <Example name="switch/demos/controlled" title="Controlled" />

  <Example name="switch/demos/card" title="Card" />
</Examples>

## API Reference [#api-reference]

### Switch [#switch]

<Reference name="switch" />

### SwitchControl [#switchcontrol]

<Reference name="switch-control" />

### SwitchIndicator [#switchindicator]

<Reference name="switch-indicator" />

### SwitchThumb [#switchthumb]

<Reference name="switch-thumb" />
