# Toggle

> A two-state button, like bold in a text toolbar.

- Category: [Inputs & forms](https://tarve.dev/docs.md#inputs)
- Import: `import { Toggle } from "@tarve/core";`
- Props type: `ToggleProps`
- Source: [packages/core/src/form-controls.ts:319](https://github.com/omarcosr/tarve/blob/main/packages/core/src/form-controls.ts#L319)

## Usage

```tsx title="Toggle.tsx"
import { Row, Toggle } from "@tarve/core";

let bold = true;
let italic = false;

<Row gap={6}>
  <Toggle
    label="Bold"
    variant="outline"
    pressed={bold}
    onPressedChange={(pressed) => {
      bold = pressed;
    }}
  >
    B
  </Toggle>
  <Toggle
    label="Italic"
    variant="outline"
    pressed={italic}
    onPressedChange={(pressed) => {
      italic = pressed;
    }}
  >
    I
  </Toggle>
</Row>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `pressed` (required) | `boolean` | — |  |
| `disabled` | `boolean` | — |  |
| `glass` | `GlassProp` | — | Liquid Glass capsule; pressed, it fills with the tint (default: the theme's primary). |
| `label` | `string` | — |  |
| `onPressedChange` | `(pressed: boolean) => void` | — |  |
| `size` | `ButtonProps["size"]` | `"default"` |  |
| `variant` | `"default" \| "outline"` | `"default"` |  |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `children`, `class`, `className`, `highlight`, `id`, `key`, `motionFrom`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`, `style`.

## Types

```ts title="ButtonProps"
interface ButtonProps extends BaseProps {
  variant?: ButtonVariant;
  size?: "sm" | "default" | "lg";
  disabled?: boolean;
  control?: Control;
  onClick?: () => void;
  onHover?: (hovered: boolean) => void;
  /**
   * Liquid Glass capsule: `true`, a variant or options. `destructive` tints it red,
   * `ghost` is clear glass without a shadow, `glass={{ tint }}` makes a prominent coloured one.
   */
  glass?: GlassProp;
}
```

```ts title="GlassProp"
type GlassProp = boolean | GlassVariant | GlassOptions;
```

Previous: [Slider](https://tarve.dev/docs/components/Slider.md) · Next: [ToggleGroup](https://tarve.dev/docs/components/ToggleGroup.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/Toggle · Index for agents: https://tarve.dev/llms.txt
