# Word swap

An edit suggestion that shows its work: old words are struck word by word and the new ones grow in.

Also called: text diff animation, word diff.

> chatcn Pro: needs a Pro license (https://chatcn.dev/pro). Install from the `@chatcn-pro` registry with your license token; setup at https://chatcn.dev/docs/chatcn-pro.

Example: An edit that shows its work. Struck words get a line drawn through them and the new words grow in beside them, word by word. Accept folds the old words shut; reject folds the new ones away. Preview: https://chatcn.dev/preview/word-swap-demo

A line is drawn through each word the rewrite drops, hunk by hunk and word by word, like a pen, and the new words grow in beside them one at a time, pushing the sentence open rather than jumping it. Accept, and the struck words fold shut while the new ones settle into plain text. Reject, and the new words fold away and the strikes lift off.

## Installation

```bash
npx shadcn@latest add @chatcn-pro/word-swap
```

## Usage

```tsx
import { WordSwap } from "@/components/ui/chatcn/pro/word-swap"

<WordSwap text={draft} suggestion={rewrite} state={state} onAccept={() => setState("accepted")} onReject={() => setState("rejected")} />
```

The diff is by word, computed inside; pass whole sentences or a short paragraph.

## Props

| Prop | Type | Notes |
| --- | --- | --- |
| `text` / `suggestion` | `string` | As written, and the rewrite |
| `state` | `"pending" | "accepted" | "rejected"` | Default pending |
| `onAccept` / `onReject` | `() => void` | Show the buttons |

## Accessibility

- Struck and new words carry hidden deleted and inserted labels; folded words leave the accessibility tree.

## Motion

- Strikes are a `scaleX` line 240 ms, 45 ms apart; new words grow from zero width. Reduced motion: both sides show, no motion.

Source: https://chatcn.dev/docs/components/word-swap