# Switch

> The everyday switch: a thumb that stretches toward where it's going while you press, travels on a soft spring and casts a real shadow. Optional on/off glyphs so state doesn't rest on color alone, a loading state that spins in the thumb while a change saves, labels on either side for settings rows, and three sizes. Built on Base UI.

- Slug: `switch`
- Category: [Toggles](https://www.assembli.design/category/toggles.md)
- Type: component
- Tags: switch, toggle, settings, form, loading, shadcn, base-ui
- npm dependencies: @base-ui/react
- shadcn/ui dependencies: none
- Live preview: https://www.assembli.design/preview/switch
- Page: https://www.assembli.design/components/switch

![Switch preview](https://www.assembli.design/thumbnails/switch-light.png)

## Props

Other props pass through to the root element.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` | `React.ReactNode` |  |  |
| `description` | `React.ReactNode` |  | A second, quieter line under the label. Linked with `aria-describedby`. |
| `labelPosition` | `"start" \| "end"` | `"end"` | `end` puts the label after the switch; `start` makes a full-width settings row with the switch on the right. |
| `size` | `keyof typeof SIZES` | `"md"` |  |
| `loading` | `boolean` |  | Spins in the thumb and holds the value (read-only, `aria-busy`) while a change saves. |
| `indicators` | `boolean` |  | Prints a bar for on and a ring for off inside the track, so state doesn't rest on color alone. |
| `className` | `string` |  |  |

## Install

One-time setup (needs a subscription):

1. Add the registry to the project's `components.json`: `{"@assembli":{"url":"https://www.assembli.design/r/{name}.json","headers":{"Authorization":"Bearer ${ASSEMBLI_API_KEY}"}}}` (merge into `"registries"`).
2. Put an API key from https://www.assembli.design/account in `.env.local` as `ASSEMBLI_API_KEY=asm_…`.

Then install with the shadcn CLI (writes `components/switch/switch.tsx` and installs dependencies):

```bash
npx shadcn@latest add @assembli/switch
```

Registry item JSON: https://www.assembli.design/r/switch.json (send `Authorization: Bearer <api key>`)

## Code

> Component source needs an Assembli subscription ($12/month or $96/year) and an API key sent as `Authorization: Bearer <key>`. To get one without copying anything, POST https://www.assembli.design/api/agent/login (or call the MCP tool connect_account), show the user the link it returns, and poll https://www.assembli.design/api/agent/token for the key. Or subscribe at https://www.assembli.design/pricing and create a key at https://www.assembli.design/account.
