CodeDiff
code-diffShows line-oriented additions and removals in unified or split views with line numbers and a summary.
Usage
Basic usage (unified single column)
Input oldText / newText, automatically line by line diff, add green / delete red.
<CodeDiff filename="greet.ts" oldText={oldText} newText={newText} />Double column comparison (split)
mode="split" The old on the left and the new on the right are displayed side by side, making it easy to compare large changes.
<CodeDiff mode="split" filename="greet.ts" oldText={oldText} newText={newText} />Purely new (new file)
When oldText is an empty string, each line is judged as new.
<CodeDiff filename="hello.txt" oldText="" newText={"line 1\nline 2\nline 3"} />Hide line number
showLineNumbers={false} Remove the line number slots on both sides to save horizontal space.
<CodeDiff filename="greet.ts" oldText={oldText} newText={newText} showLineNumbers={false} />When to use
Use CodeDiff to compare two text versions during a pull-request review, agent-change inspection, or configuration audit. It shows additions and deletions with paired line numbers and supports line annotations. Use CodeBlock for static code or Snippet for a single-line command. diffLines and diffStat are pure functions that can also power custom rendering or statistics.
Import
import { CodeDiff, diffLines, diffStat } from "@hulianui/ui"Props
| Name | Type | Default | Description |
|---|---|---|---|
| oldText* | string | — | old text |
| newText* | string | — | new text |
| mode | "unified" | "split" | "unified" | Unified single-column or split side-by-side comparison. |
| filename | string | — | Header file name bar; if omitted, the header will not be rendered. |
| showLineNumbers | boolean | true | Show line number slot |
| annotations | CodeDiffAnnotation[] | — | Row-anchored annotations: Insert full-width content slot below matching row rendering gutter tag + row (unified mode inserts content only) |
| className | string | — | Container class name |
CodeDiffAnnotation has the shape { side?: "old"\|"new"(default "new"); line: number(1-based); gutter?: ReactNode; content?: ReactNode }.
Usage guidelines
- The
contentslot inannotationsis inserted only in unified mode. Split mode renders gutter markers only. Usemode="unified"to place a CodeReviewThread or other content below a changed line. annotations[].lineis one-based, andsideidentifies the old or new file. Do not treat it as a zero-based array index.
Related
Playground
<CodeDiff filename="greet.ts" oldText={old} newText={next} />