# Diff

> Unified diffs with word-level highlights and collapsible files.

- Category: [Rich content](https://tarve.dev/docs.md#rich-content)
- Import: `import { Diff } from "@tarve/core";`
- Props type: `DiffProps`
- Source: [packages/core/src/components/rich-content.ts:88](https://github.com/omarcosr/tarve/blob/main/packages/core/src/components/rich-content.ts#L88)

## Usage

```tsx title="Diff.tsx"
import { Diff } from "@tarve/core";

<Diff
  oldText={"const greeting = 'hello';\nconsole.log(greeting);\n"}
  newText={"const greeting = 'hello, tarve';\nconsole.log(greeting);\n"}
  wordDiff
/>
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `collapsedPaths` | `string[]` | — | File paths rendered as headers only. |
| `maxLines` | `number` | — | Maximum changed/context lines to render per file before a Show more row. |
| `newText` | `string` | — |  |
| `oldText` | `string` | — | Supply both oldText and newText to calculate a diff natively. |
| `onLineClick` | `(event: { text: string; path?: string; oldLine?: number; newLine?: number }) => void` | — |  |
| `onShowMore` | `(hidden: number, path?: string) => void` | — |  |
| `onToggleFile` | `(path: string) => void` | — |  |
| `source` | `string` | — | A unified or git diff. |
| `wordDiff` | `boolean` | — | Enables/disables word-level emphasis inside paired changed lines. Default: true. |

### Inherited from `RichProps`

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `syntaxTheme` | `Partial<SyntaxTheme>` | — | Overrides syntax colours without changing parsing or layout. |

## Common props

Shared by every component (descriptions: https://tarve.dev/docs.md#common-props): `class`, `className`, `highlight`, `id`, `key`, `motionFrom`, `onHighlight`, `onPaste`, `onPointerLeave`, `onPointerMove`, `onSize`, `onTransitionEnd`, `rovingGroup`, `style`.

Previous: [Code](https://tarve.dev/docs/components/Code.md) · Next: [Message](https://tarve.dev/docs/components/Message.md)

---

Tarve v0.13.8 · HTML version: https://tarve.dev/docs/components/Diff · Index for agents: https://tarve.dev/llms.txt
