# Inline rewrite

> Drag a dial and the paragraph rewrites itself in place: shared words glide, the rest blur out and rise in.

Writing tools hand you a rewrite as a new block of text, and you read both to find what changed. Here a paragraph sits under a dial of versions: Shorter, Original, Longer, or Blunt, Neutral, Warm. Drag the thumb and the paragraph changes in place as you cross each stop, word by word. Words both versions share glide to their new places, the ones that go blur out where they stood, and the new ones rise in one after another and glow for a moment, so you see exactly what moved. The box eases to its new height, the word count rolls and +added −cut against the original roll beside it. Versions you haven’t written yet are written the first time the dial settles on them: a spinner opens in the thumb and a sheen runs over the paragraph until the new words arrive.

## Install

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

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

- npm: none
- Hairline UI components it needs (the CLI installs them too): `number-roll`, `text-morph`
- Docs and live preview: https://hairlineui.com/ui/inline-rewrite
- Registry item (source): https://hairlineui.com/r/inline-rewrite.json

## Usage

```tsx
import { InlineRewrite } from "@/components/inline-rewrite";

<InlineRewrite
  label="Length"
  defaultValue={1}
  versions={[
    { label: "Shorter", text: short },
    { label: "Original", text: original },
    { label: "Longer", text: long },
  ]}
/>
```

## With a model writing the versions

Give only the original; each other stop is written the first time someone lands on it, then kept.

```tsx
"use client";
import { InlineRewrite } from "@/components/inline-rewrite";

export function ToneDial({ draft }: { draft: string }) {
  return (
    <InlineRewrite
      label="Tone"
      defaultValue={1}
      versions={[{ label: "Blunt" }, { label: "Neutral", text: draft }, { label: "Warm" }, { label: "Playful" }]}
      onRewrite={async ({ label, original, signal }) => {
        const res = await fetch("/api/rewrite", {
          method: "POST",
          body: JSON.stringify({ text: original, tone: label }),
          signal,
        });
        if (!res.ok) throw new Error("rewrite failed");
        return (await res.json()).text;
      }}
    />
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `versions` | `{ label: string; text?: string }[]` | – | The dial’s stops in order. Leave text out to have onRewrite write it. |
| `value / defaultValue / onValueChange` | `number` | `0` | The chosen version’s index; controlled or not. Changes as the thumb crosses each stop. |
| `onRewrite` | `({ index, label, current, original, signal }) => Promise<string>` | – | Writes a version that has no text, once the dial settles on it. The result is kept; throw to show it failed. |
| `originalIndex` | `number` | – | The version the +added and −cut counts compare against. Defaults to the one chosen first. |
| `label` | `string` | `"Rewrite"` | The dial’s accessible name, e.g. "Length" or "Tone". |
| `highlight` | `boolean` | `true` | Let new words glow for a moment after each rewrite. |

## States

- **drag**: The thumb follows the pointer (no easing); crossing a stop swaps the version straight away and morphs the thumb’s label. Release and it settles on the nearest stop (420ms, a slight overshoot).
- **rewrite**: Shared words glide from their old place (FLIP, 480ms); new words rise 0.35em out of a 4px blur, 14ms apart, and glow for 1.8s; words that go blur out and lift (240ms); the paragraph’s height eases (480ms).
- **writing**: A version without text, once the dial settles on it: a spinner opens in the thumb, "Rewriting" morphs in and a sheen sweeps the paragraph until onRewrite resolves.
- **counts**: The word count and +added −cut against the original roll; on the original itself the counts crossfade to "Original".
- **failed**: onRewrite threw: the thumb goes back to the version on screen and "Couldn’t rewrite it" shows for 4 seconds.

## What it handles

Writing tools hand you a rewrite as a new block of text, and you read both to find what changed. This rewrites the paragraph in place and shows exactly what moved.

- **A dial of versions**: Stops such as Shorter, Original and Longer, or Blunt, Neutral and Warm. You name the stops.
- **The paragraph changes in place**: Words both versions share glide to their new places, removed words blur out and new ones rise in and glow briefly.
- **Versions are written on demand**: A stop without text calls onRewrite the first time the dial settles on it, and the result is kept.
- **No request per stop**: Sweeping across the dial doesn’t send a request at every stop. Only the one you land on is written.
- **It counts what changed**: The word count rolls, with “+added −cut” against the original beside it.
- **Real text, real slider**: The paragraph can be selected and copied, the dial works with arrow keys, and a status says which version is showing.

## Replaces

a rewrite menu, a text diff, word-by-word animation, a versions slider, a loading state for generated text, word counts

## Where it fits

- **AI writing assistants**: Make a paragraph shorter or longer without leaving it.
- **Tone controls**: Switch a message between Blunt, Neutral and Warm.
- **Marketing copy tools**: Try variations of a headline or a product description.
- **Editors and docs**: Let writers rewrite a paragraph in place and see what changed.

## Notes

- The dial is a slider: arrow keys step through the versions, Home and End go to the ends, and it reads its version’s name as its value.
- Words match exactly, punctuation and case included, so "fresh" and "Fresh" swap rather than glide.
- The paragraph is real text you can select and copy; the words on their way out are hidden from assistive tech, and a polite status says which version is showing and how many words it has.
- Dragging only writes versions once you let go, so sweeping across the dial doesn’t fire a request at every stop.
- Installs Number roll and Text morph. With reduced motion the words change in place and the thumb jumps to its stop.

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