# Mode switcher

> Fast, Thinking, Research: a segmented switch with a sliding pill and locked paid modes.

Lets people choose how the model should work. A pill is thrown to the chosen mode with a little give, an optional line underneath morphs to say what that mode does, and paid modes stay visible with a lock so people can see what an upgrade unlocks. It’s a real radio group: arrow keys move between modes.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/mode-switcher.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`
- Docs and live preview: https://hairlineui.com/ui/mode-switcher
- Registry item (source): https://hairlineui.com/r/mode-switcher.json

## Usage

```tsx
import { ModeSwitcher } from "@/components/mode-switcher";
import { Zap, Brain, Telescope } from "lucide-react";

<ModeSwitcher
  modes={[
    { value: "fast", label: "Fast", icon: <Zap />, description: "Quick answers for everyday questions." },
    { value: "thinking", label: "Thinking", icon: <Brain />, description: "Takes a moment to reason first." },
    { value: "research", label: "Research", icon: <Telescope />, locked: true },
  ]}
  defaultValue="fast"
  onValueChange={setMode}
  onLockedSelect={openPricing}
  showDescription
/>
```

## With the AI SDK

```tsx
import { useChat } from "@ai-sdk/react";
import { useState } from "react";
import { ModeSwitcher } from "@/components/mode-switcher";

const { sendMessage } = useChat();
const [mode, setMode] = useState("fast");

<ModeSwitcher modes={modes} value={mode} onValueChange={setMode} />

// Send the mode with each message, and pick the model from it on the server.
sendMessage({ text }, { body: { mode } });

// app/api/chat/route.ts
const { messages, mode } = await req.json();
const result = streamText({ model: mode === "thinking" ? reasoningModel : fastModel, messages: convertToModelMessages(messages) });
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `modes` | `{ value; label; description?; icon?; locked? }[]` | – | The modes, in order. |
| `value / defaultValue / onValueChange` | `string` | – | Controlled or uncontrolled selection. |
| `onLockedSelect` | `(mode) => void` | – | Called when someone picks a locked mode. |
| `showDescription` | `boolean` | `false` | Show the chosen mode’s description underneath. |
| `label` | `string` | `"Mode"` | Accessible name of the radio group. |

## States

- **selected**: The pill is thrown to the chosen mode with a slight overshoot (460ms) while its width eases; the description below, if enabled, morphs into the new mode’s line, keeping the words they share.
- **locked**: Visible with a lock; choosing it calls onLockedSelect (e.g. open pricing) instead of switching.

## What it handles

People should be able to choose how a model works without reading a spec sheet. This is a small segmented switch that says what each mode does and shows what an upgrade would unlock.

- **A pill thrown to the choice**: The pill slides to the chosen mode with a little give, and its width eases to fit.
- **A line that says what it does**: Turn on showDescription and a line underneath morphs to describe the chosen mode.
- **Paid modes stay visible**: Locked modes show a lock. Choosing one calls onLockedSelect, for example to open pricing.
- **A real radio group**: Tab lands on the chosen mode, arrow keys move and skip locked modes.
- **Controlled or not**: Pass value and onValueChange, or let it keep its own selection.
- **Resizes cleanly**: The pill re-measures on resize, and its first placement never animates.

## Replaces

a segmented control, a sliding indicator, a mode description line, locked option handling, radio group keyboard handling

## Where it fits

- **AI chat apps**: Choose between Fast, Thinking and Research.
- **Plan-gated features**: Show paid modes with a lock so people see what an upgrade unlocks.
- **Search and assistants**: A quick or deep mode for the same question box.
- **Settings with a few options**: Any choice of two to four exclusive modes, such as view or editor modes.

## Notes

- role="radiogroup" with roving focus: Tab lands on the chosen mode, arrow keys move and skip locked modes.
- Locked modes are aria-disabled but still focusable and explained in their title.
- The pill re-measures on resize and its first placement never animates. Installs Text morph; with reduced motion the pill jumps and the description changes in place.

License: MIT (https://hairlineui.com/license#components)
