# CodeDiff

Code changes, inline or side by side, with line numbers and clear size limits.

- **Use it for**: Unified or split comparison of code.
- **Not for**: Comparing artifact versions. Try [ArtifactDiff](https://unseenui.com/components/artifact-diff/).

## Installation

```bash
npm install @stackunseen/ui
```

## Usage

```tsx
import { CodeDiff } from '@stackunseen/ui';
import '@stackunseen/ui/styles.css';

<CodeDiff variant="unified" path="src/search.ts" before={original} after={updated} baseVersion="a1" nextVersion="b2" />
```

## All props

| Prop | Type | Description |
| --- | --- | --- |
| `after` (required) | `string` |  |
| `annotate` | `((line: CodeDiffLine) => ReactNode)` | Content under a line, such as review comments or a comment box. |
| `baseVersion` (required) | `string` |  |
| `before` (required) | `string` |  |
| `className` | `string` | Added to the root element, after the component's own classes. |
| `copyable` | `boolean` |  |
| `error` | `string` |  |
| `nextVersion` (required) | `string` |  |
| `path` (required) | `string` |  |
| `renderLine` | `((line: CodeDiffLine) => ReactNode)` | Trusted application rendering of an already bounded, visible source line. |
| `showVersions` | `boolean` | Shows "base → next" in the header. |
| `sourceIdentities` | `{ readonly before: DocumentIdentity; readonly after: DocumentIdentity; }` | Paired host identities allow independent sources to share a version string. |
| `status` | `"ready" \| "loading" \| "denied" \| "unavailable" \| "error" \| "conflict"` |  |
| `variant` | `"compact" \| "unified" \| "split"` |  |

## Keyboard

Tab reaches controls; Enter or Space activates buttons. Accordions use arrow keys, Home and End. Select menus support arrows and typeahead; Escape closes menus and dialogs and restores focus.

## Works with

[CodeTabs](https://unseenui.com/components/code-tabs/), [Snippet](https://unseenui.com/components/snippet/), [Commit](https://unseenui.com/components/commit/), [EnvironmentVariables](https://unseenui.com/components/environment-variables/), [PackageInfo](https://unseenui.com/components/package-info/), [SchemaDisplay](https://unseenui.com/components/schema-display/), [StackTrace](https://unseenui.com/components/stack-trace/), [WebPreview](https://unseenui.com/components/web-preview/), [Image](https://unseenui.com/components/image/), [FileExplorer](https://unseenui.com/components/file-explorer/), [TerminalOutput](https://unseenui.com/components/terminal-output/), [TestResults](https://unseenui.com/components/test-results/)

Page: https://unseenui.com/components/code-diff/
