# Switch

A setting that is on or off. It is off until the person turns it on or the app says so with `checked` or `defaultChecked`. Space or Enter flips it. Pair it with a `Label`. To lock it, wrap it in `Locked` with a reason: it stays focusable, says why, and doesn't flip. Use a switch for a setting that takes effect at once; a choice the person confirms belongs in a `Checkbox` or `RadioGroup` with a button.

- Registry name: `switch` (`@candor/switch`)
- Tier: Free (MIT). No licence key needed.
- Docs: https://candor.themethodic.com/docs/switch

## Install

```bash
npx candor-ui add switch
```

Run `npx candor-ui@latest init` once first (https://candor.themethodic.com/get-started.md). Without the CLI: `npx shadcn@latest add @candor/switch`.
It brings in: motion, render-prop, utils.
npm packages: radix-ui@^1.8.1.

## Example

```tsx
"use client"

import * as React from "react"
import { Switch } from "@/components/ui/switch"
import { Label } from "@/components/ui/label"

export default function Example() {
  // The setting is off until the person turns it on.
  const [on, setOn] = React.useState(false)
  return (
    <div className="flex items-center gap-2.5">
      <Switch id="notify" checked={on} onCheckedChange={setOn} />
      <Label htmlFor="notify">{on ? "Notifications are on" : "Notifications are off"}</Label>
    </div>
  )
}
```

## <Switch>

No props.

Also takes the props of `React.ComponentProps<typeof SwitchPrimitive.Root>`, `RenderProp`.

## Rules for using Candor UI

- Components take plain typed data. Never pass model output as HTML or render it as a link; messages are typed blocks.
- A control that can't be used says why: wrap it in `<Locked reason="…">`, don't just disable it.
- Don't show a value you don't have: leave it out (it renders as —) rather than guess. An estimate is labelled as one.
- Nothing is pre-selected in a decision a person makes, and the agent is named from your app's data, never from model output.
- Your app's words go in `LocaleProvider` (fixed strings) and `TermsProvider` (nouns); entity kinds and agent roles in `EntityKindsProvider` and `AgentRolesProvider`.
