# Tool toggle

A composer tool switch that acts out its tool: the globe turns, the sun rises, the brackets spread, and the chip opens to say its name.

Also called: tool switch, animated toggle chip.

Example: Tools that act it out. Composer tool switches: the globe turns on its axis, the sun rises in the picture, the brackets spread for a slash. Each opens into a named chip. Preview: https://chatcn.dev/preview/tool-toggle-demo

Composer tools (search, image generation, code) are usually icons that change color. Here each glyph does its tool's gesture once as it turns on: the globe's meridians widen and narrow so it turns on its axis, the picture's sun rises from behind the hills, the code brackets spread to let a slash drop in. Off, the switch is a quiet icon button; on, it opens on a grid track into the tool's own colour with its name: search blue, image purple, code teal.

## Installation

```bash
npx shadcn@latest add https://chatcn.dev/r/tool-toggle.json
```

## Usage

```tsx
import { ToolToggle } from "@/components/ui/chatcn/tool-toggle"

<ToolToggle label="Search" glyph="search" pressed={search} onPressedChange={setSearch} />
<ToolToggle label="Canvas" icon={<CanvasIcon />} />
```

## Examples

### Off and on

Example: Every tool, off and on. Search, image and code toggles at rest and pressed, each opening into its own color. Preview: https://chatcn.dev/preview/tool-toggle-states

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `label` | `string` | Shown while on, read always |
| `glyph` | `"search" | "image" | "code"` | Built in acting glyphs. Default `search` |
| `icon` | `ReactNode` | Your own icon instead; it turns a quarter as it switches on |
| `pressed` / `defaultPressed` | `boolean` | Controlled or uncontrolled |
| `onPressedChange` | `(pressed: boolean) => void` |  |

## Accessibility

- A button with `aria-pressed` and the tool's name as its label, on or off.
- 44 px touch target on coarse pointers without changing the drawn size.

## Motion

- The globe turns on the shared heavy spring: a full turn on, half a turn back off.
- The name opens on `grid-template-columns` 0fr to 1fr, 200 ms, so the chip grows from its real width.

Under reduced motion: glyphs change state without moving and the chip opens without easing.

Source: https://chatcn.dev/docs/components/tool-toggle