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.
On this page
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.
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
Usage
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
Search, image and code toggles at rest and pressed, each opening into its own color.
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-pressedand 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-columns0fr 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.