

<Preview name="ToggleDefaultExample" />

## Overview [#overview]

The `Toggle` component is a button-like control for two-state actions such as formatting, view options, and compact toolbar settings. It owns the default and outline pressed states, so grouped toggles can reuse the same surface behavior.

## Usage [#usage]

```tsx
import { Toggle } from "@tilt-legal/cubitt-components/toggle";
```

```tsx
<Toggle aria-label="Toggle bold">
  <TextBold />
</Toggle>
```

<Accordions type="single">
  <Accordion title="URL State">
    Sync pressed state with the URL by providing a `paramName`.

    ```tsx
    <Toggle
      aria-label="Toggle bold"
      defaultPressed={false}
      paramClearOnDefault
      paramName="bold"
    >
      <TextBold />
      Bold
    </Toggle>
    ```
  </Accordion>
</Accordions>

## Examples [#examples]

### Default [#default]

Default toggles behave like ghost buttons until pressed.

<Tabs items="[&#x22;Preview&#x22;, &#x22;Code&#x22;]">
  <Tab value="Preview">
    <Preview name="ToggleDefaultExample" />
  </Tab>

  <Tab value="Code">
    ```tsx
    import { Toggle } from "@tilt-legal/cubitt-components/toggle";
    import { TextBold } from "@tilt-legal/cubitt-icons/ui/outline";

    export default function Example() {
      return (
        <Toggle aria-label="Toggle bold">
          <TextBold />
        </Toggle>
      );
    }
    ```
  </Tab>
</Tabs>

### Outline [#outline]

Use the outline variant when the toggle should carry a contextual bordered surface.

<Tabs items="[&#x22;Preview&#x22;, &#x22;Code&#x22;]">
  <Tab value="Preview">
    <Preview name="ToggleOutlineExample" />
  </Tab>

  <Tab value="Code">
    ```tsx
    import { Toggle } from "@tilt-legal/cubitt-components/toggle";
    import { TextItalic } from "@tilt-legal/cubitt-icons/ui/outline";

    export default function Example() {
      return (
        <Toggle aria-label="Toggle italic" variant="outline">
          <TextItalic />
        </Toggle>
      );
    }
    ```
  </Tab>
</Tabs>

### With Text [#with-text]

Toggles can include both an icon and a short label.

<Tabs items="[&#x22;Preview&#x22;, &#x22;Code&#x22;]">
  <Tab value="Preview">
    <Preview name="ToggleWithTextExample" />
  </Tab>

  <Tab value="Code">
    ```tsx
    import { Toggle } from "@tilt-legal/cubitt-components/toggle";
    import {
      TextBold,
      TextItalic,
    } from "@tilt-legal/cubitt-icons/ui/outline";

    export default function Example() {
      return (
        <div className="flex items-center gap-2">
          <Toggle aria-label="Toggle bold">
            <TextBold />
            Bold
          </Toggle>
          <Toggle aria-label="Toggle italic" variant="outline">
            <TextItalic />
            Italic
          </Toggle>
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

### Sizes [#sizes]

Toggles support `sm`, `md`, and `lg` sizes.

<Tabs items="[&#x22;Preview&#x22;, &#x22;Code&#x22;]">
  <Tab value="Preview">
    <Preview name="ToggleSizesExample" />
  </Tab>

  <Tab value="Code">
    ```tsx
    import { Toggle } from "@tilt-legal/cubitt-components/toggle";
    import {
      TextBold,
      TextItalic,
      TextUnderline,
    } from "@tilt-legal/cubitt-icons/ui/outline";

    export default function Example() {
      return (
        <div className="flex items-center gap-4">
          <Toggle aria-label="Toggle bold" size="sm" variant="outline">
            <TextBold />
          </Toggle>
          <Toggle aria-label="Toggle italic" size="md" variant="outline">
            <TextItalic />
          </Toggle>
          <Toggle aria-label="Toggle underline" size="lg" variant="outline">
            <TextUnderline />
          </Toggle>
        </div>
      );
    }
    ```
  </Tab>
</Tabs>

### URL State [#url-state]

Use URL state when the pressed value should be shareable or restored on refresh.

<Tabs items="[&#x22;Preview&#x22;, &#x22;Code&#x22;]">
  <Tab value="Preview">
    <Preview name="ToggleURLStateExample" />
  </Tab>

  <Tab value="Code">
    ```tsx
    import { Toggle } from "@tilt-legal/cubitt-components/toggle";
    import { TextBold } from "@tilt-legal/cubitt-icons/ui/outline";

    export default function Example() {
      return (
        <Toggle
          aria-label="Toggle bold"
          defaultPressed={false}
          paramClearOnDefault
          paramName="demo-bold"
        >
          <TextBold />
          Bold
        </Toggle>
      );
    }
    ```
  </Tab>
</Tabs>

## API Reference [#api-reference]

### Toggle [#toggle]

| Prop              | Type                         | Default     | Description                                   |
| ----------------- | ---------------------------- | ----------- | --------------------------------------------- |
| `pressed`         | `boolean`                    | -           | Controlled pressed state.                     |
| `defaultPressed`  | `boolean`                    | `false`     | Initial pressed state for uncontrolled usage. |
| `onPressedChange` | `(pressed: boolean) => void` | -           | Called when the pressed state changes.        |
| `disabled`        | `boolean`                    | `false`     | Disables the toggle.                          |
| `variant`         | `"default" \| "outline"`     | `"default"` | Visual style.                                 |
| `size`            | `"sm" \| "md" \| "lg"`       | `"md"`      | Toggle size.                                  |
| `className`       | `string`                     | -           | Additional classes.                           |
| `children`        | `React.ReactNode`            | -           | Toggle content.                               |

### URL State Props [#url-state-props]

| Prop                  | Type                                 | Default | Description                                               |
| --------------------- | ------------------------------------ | ------- | --------------------------------------------------------- |
| `paramName`           | `string`                             | -       | Search parameter name used for URL state.                 |
| `paramValue`          | `boolean`                            | -       | Controlled URL-backed value.                              |
| `onUrlValueChange`    | `(pressed: boolean \| null) => void` | -       | Called when the URL-backed value changes.                 |
| `paramClearOnDefault` | `boolean`                            | `true`  | Removes the URL parameter when value matches the default. |
| `paramThrottle`       | `number`                             | -       | Throttles URL updates in milliseconds.                    |
| `paramDebounce`       | `number`                             | -       | Debounces URL updates in milliseconds.                    |

### Notes [#notes]

* Use `aria-label` for icon-only toggles.
* Use `pressed` and `onPressedChange` for controlled state.
* Use `ToggleGroup` when related toggles need coordinated keyboard navigation or shared selection state.
