# Stretch switch

A switch whose knob stretches and wobbles as it flips.

Also called: animated switch, toggle animation, rubber switch.

Example: A knob that stretches. Flip a tool on or off and the knob stretches as it travels and wobbles at the wall, while the colour floods in behind it. Preview: https://chatcn.dev/preview/stretch-switch-demo

Flip it and the knob's leading edge runs ahead while the trailing edge catches up, so it stretches as it travels, hits the far wall hard and wobbles back to round. The colour floods in behind it through an ordered dither with a wavering front, rather than fading. Press it and the knob squashes toward where it is going; drag it and it follows your finger.

## Installation

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

## Usage

```tsx
import { StretchSwitch } from "@/components/ui/chatcn/stretch-switch"

<StretchSwitch checked={webSearch} onCheckedChange={setWebSearch} aria-label="Web search" />
```

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `checked` / `defaultChecked` / `onCheckedChange` | `boolean` |  |
| `color` | `string` | The flood; default the theme blue |

## Keyboard

| Key | Action |
| --- | --- |
| `Space` / `Enter` | Flip it |

## Accessibility

- A real `switch` button with `aria-checked`; give it a label.

## Motion

- The leading edge springs stiff (430) and the trailing edge soft (125); the wall kick sets off the wobble. Reduced motion: it moves without the stretch and the flood steps.

Source: https://chatcn.dev/docs/components/stretch-switch