# Toggle

A two-state pressed control with semantic surfaces, sizes, and icon layouts.

A two-state pressed control for toolbar actions, filters, and optional settings. Zenos styling follows the design-system Toggle spec: neutral idle/hover surfaces and a red pressed treatment shared with selection tokens.

<p className="zenos-base-ui-source">
  Backed by <a href="https://base-ui.com/react/components/toggle">Base UI Toggle</a> for upstream
  behavior and configuration. Zenos owns the public API, styling, and composition shown on this
  page.
</p>

```tsx
import { PlusIcon, TextBIcon } from "@phosphor-icons/react";
import { Stack, Toggle } from "@zentara-co/zenos-ui";

function TogglePatternsExample() {
  return (
    <Stack direction="row" gap="3" align="center" justify="center" wrap="wrap" className="w-full">
      <Toggle variant="subtle">Default</Toggle>
      <Toggle variant="subtle">
        <PlusIcon aria-hidden />
        Add More
      </Toggle>
      <Toggle variant="subtle" defaultPressed>
        Add to List
        <PlusIcon aria-hidden />
      </Toggle>
      <Toggle variant="subtle" disabled aria-label="Bold">
        <TextBIcon aria-hidden />
      </Toggle>
      <Toggle variant="subtle" defaultPressed disabled>
        Activated
      </Toggle>
    </Stack>
  );
}
```

```tsx
import { Toggle } from "@zentara-co/zenos-ui";
```

## Composition

Place label text and icons as children. Padding adjusts automatically for text-only, leading icon, trailing icon, and icon-only layouts (square control at each size). Icons should use `aria-hidden` when adjacent text supplies the accessible name.

```tsx
import { PlusIcon } from "@phosphor-icons/react";
import { Toggle } from "@zentara-co/zenos-ui";

<Toggle variant="subtle">
  <PlusIcon aria-hidden />
  Add More
</Toggle>;
```

## Variants

| Variant          | Use                                                                                      |
| ---------------- | ---------------------------------------------------------------------------------------- |
| `subtle`         | Default filled neutral surface (recommended for most toggles).                           |
| `subtle-outline` | Filled neutral surface with a border; the previous `outline` appearance.                 |
| `outline`        | Transparent surface; selected border, translucent fill, and semibold label when pressed. |
| `default`        | Transparent until hover; lightweight toolbar actions.                                    |

```tsx
import { Stack, Toggle } from "@zentara-co/zenos-ui";

type CatalogVariantProps = { limit?: number };

const limited = <T,>(items: readonly T[], limit?: number) =>
  limit === undefined ? items : items.slice(0, limit);

function ToggleVariantsExample({ limit }: CatalogVariantProps = {}) {
  if (limit !== undefined) {
    return (
      <Stack direction="row" gap="3" align="center" wrap="wrap" className="justify-center">
        {limited(["default", "outline", "subtle", "subtle-outline"] as const, limit).map(
          (variant) => (
            <Toggle key={variant} variant={variant} aria-label={variant}>
              {variant}
            </Toggle>
          ),
        )}
      </Stack>
    );
  }

  return (
    <Stack gap="4">
      {(["default", "outline", "subtle", "subtle-outline"] as const).map((variant) => (
        <Stack key={variant} direction="row" align="center" gap="3" wrap="wrap">
          {(["sm", "md", "lg"] as const).map((size) => (
            <Toggle key={size} variant={variant} size={size} aria-label={`${variant} ${size}`}>
              {variant} {size}
            </Toggle>
          ))}
        </Stack>
      ))}
    </Stack>
  );
}
```

## Sizes

`sm`, `md`, and `lg` map to 28px, 32px, and 40px control heights. Use the same size as neighboring controls to keep a consistent rhythm.

```tsx
import { Stack, Toggle } from "@zentara-co/zenos-ui";

function ToggleSizesExample() {
  return (
    <Stack direction="row" gap="3" align="center" wrap="wrap">
      {(["sm", "md", "lg"] as const).map((size) => (
        <Toggle key={size} size={size} defaultPressed={size === "md"}>
          {size}
        </Toggle>
      ))}
    </Stack>
  );
}
```

## Visual states

Hover darkens the neutral surface (`subtle` / `subtle-outline`) or shows a light neutral fill (`default` / `outline`). Pressed `outline` toggles use `border-selected`, `cover-selected`, selected text, and a semibold label in both themes. Other variants retain the accent red subtlest pressed fill. Disabled toggles use muted text and no hover fill; a disabled pressed toggle keeps a faint red surface and muted red label so the prior selection remains visible but not editable.

To preserve the previous filled, bordered appearance, change `variant="outline"` to `variant="subtle-outline"`.

```tsx
import { TextBIcon } from "@phosphor-icons/react";
import { Stack, Toggle } from "@zentara-co/zenos-ui";

function ToggleStatesExample() {
  return (
    <Stack gap="3">
      {(["subtle", "subtle-outline", "outline"] as const).map((variant) => (
        <Stack key={variant} direction="row" gap="3" align="center" wrap="wrap">
          <Toggle variant={variant}>Default</Toggle>
          <Toggle variant={variant} defaultPressed>
            Pressed
          </Toggle>
          <Toggle variant={variant} disabled>
            Disabled
          </Toggle>
          <Toggle variant={variant} defaultPressed disabled>
            Pressed disabled
          </Toggle>
          <Toggle variant={variant} aria-label="Bold text">
            <TextBIcon aria-hidden />
          </Toggle>
        </Stack>
      ))}
    </Stack>
  );
}
```

## Custom styling

Pass `className` to replace the surface, border, foreground, shape, or state treatments while retaining Toggle's sizing, focus ring, disabled behavior, and `aria-pressed` semantics. Custom classes apply after the selected `variant`.

Use `hover:` for pointer feedback and `data-[pressed]:` for the active state. Prefer semantic color tokens so the result remains legible in light and dark themes. Layout-only classes do not remove the built-in appearance unless they conflict with it.

```tsx
import { Stack, Toggle } from "@zentara-co/zenos-ui";

function ToggleCustomExample() {
  return (
    <Stack direction="row" justify="center" className="w-full">
      <Toggle
        defaultPressed
        className="rounded-full border-border-accent-teal-default bg-background-accent-teal-subtlest-default text-text-accent-teal-bolder hover:bg-background-accent-teal-subtlest-hover data-[pressed]:bg-background-accent-teal-subtlest-pressed data-[pressed]:text-text-accent-teal-bolder"
      >
        Live updates
      </Toggle>
    </Stack>
  );
}
```

## Controlled state

Pair `pressed` with `onPressedChange` when application state owns the toggle. Use `defaultPressed` for an initial uncontrolled state.

```tsx
import { PlusIcon } from "@phosphor-icons/react";
import { Stack, Text, Toggle } from "@zentara-co/zenos-ui";
import { useState } from "react";

function ToggleControlledExample() {
  const [pressed, setPressed] = useState(false);

  return (
    <Stack gap="3" align="start">
      <Toggle
        pressed={pressed}
        onPressedChange={setPressed}
        variant="subtle"
        aria-label="Pin workspace"
      >
        <PlusIcon aria-hidden />
        Pin workspace
      </Toggle>
      <Text size="s" color="subtle" aria-live="polite">
        Workspace is {pressed ? "pinned" : "not pinned"}.
      </Text>
    </Stack>
  );
}
```

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| variant | 'default' \| 'outline' \| 'subtle' \| 'subtle-outline' | subtle | Surface treatment. |
| size | 'sm' \| 'md' \| 'lg' | md | Control height. |
| pressed | boolean | — | Controlled pressed state. |
| defaultPressed | boolean | false | Initial uncontrolled pressed state. |
| onPressedChange | (pressed: boolean, eventDetails) => void | — | Runs when pressed state changes. |

## Sizes

sm, md, lg

## API

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| pressed | boolean | — | Controlled pressed state. |
| defaultPressed | boolean | false | Initial uncontrolled state. |
| onPressedChange | (pressed: boolean, eventDetails) => void | — | Runs when pressed state changes. |
| variant | default \| outline \| subtle \| subtle-outline | subtle | Surface treatment: filled neutral (`subtle`), filled and bordered (`subtle-outline`), transparent with a selected border (`outline`), or transparent until hover (`default`). |
| size | sm \| md \| lg | md | Control size. |
| native props | React.Base UI Toggle props | — | Forwards native attributes, events, aria-*, data-*, className, style, and ref. |

Unless narrowed above, each DOM-rendering part also accepts its underlying native or Base UI props, including className, style, aria-*, and data-*.

## Accessibility

Toggle uses a native button with `aria-pressed`. Space or Enter changes its state, and disabled toggles remain unavailable to keyboard and pointer interaction. The label should describe the feature being switched, not its current state; assistive technology announces pressed state separately. Icon-only toggles require `aria-label` (or visible text elsewhere).

## Related

Use [`ToggleGroup`](/components/toggle-group/) when several toggles share selection logic and inherited `variant` / `size`.

Source: https://zenos-ui.pages.dev/components/toggle/