# Toggle

A two-state button in Candor's theme, for one setting that is on or off (bold, wrap lines, show hidden files).

- Registry name: `toggle` (`@candor/toggle`)
- Tier: Pro. Installing it needs a Pro, Premium or Team licence key: the person runs `npx candor-ui key <key>` themselves; never ask for the key in chat or write it to a file.
- Docs: https://candor.themethodic.com/docs/toggle

## Install

```bash
npx candor-ui add toggle
```

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

## Example

```tsx
"use client"

import * as React from "react"
import { BoldIcon, WrapTextIcon } from "lucide-react"
import { Toggle } from "@/components/ui/toggle"
import { TooltipProvider } from "@/components/ui/tooltip"

export default function Example() {
  // Nothing is pressed until the person presses it.
  const [wrap, setWrap] = React.useState(false)
  return (
    <TooltipProvider>
      <div className="flex flex-wrap items-center gap-3">
        <Toggle pressed={wrap} onPressedChange={setWrap} aria-label="Wrap long lines">
          <WrapTextIcon />
          {wrap ? "Wrapping" : "Wrap"}
        </Toggle>
        <Toggle variant="outline" size="sm" aria-label="Bold">
          <BoldIcon />
        </Toggle>
        <Toggle variant="outline" locked="Formatting is off while the draft is read-only.">
          Monospace
        </Toggle>
      </div>
    </TooltipProvider>
  )
}
```

## <Toggle>

Props:

- `variant?: "default" | "outline"` (default `"default"`): Which variant: one of `toggleVariants`'s styles.
- `size?: "default" | "sm" | "lg"` (default `"default"`): Which size: one of `toggleVariants`'s styles.
- `locked?: string | undefined`: Why the toggle can't be used right now. When set, it stays focusable and marked `aria-disabled`, pressing it changes nothing, and the reason is shown on hover and focus and read to screen readers (see `Locked`).

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

## Functions

### toggleVariants

```ts
toggleVariants(options?: { variant?: "default" | "outline"; size?: "default" | "sm" | "lg"; className?: string })
```

## Motion

- **tint** (tint): The pressed colours change when the person presses the toggle, and a ring fades in on keyboard focus. A toggle that starts pressed is drawn pressed at once.

Set with `--cd-motion-toggle-<moment>-*` in your brand file; the families are in the design reference.

## 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`.
