Skip to content
Eskais UI

Diff

Git Diff

A patch or a list of file diffs for review: per-file headers (rename arrow, status chip, +/- counts and bar, mode change, collapse, viewed), a tree of changed files to jump between them, unified/split and wrap controls, one virtualized document for 500-file patches, j/k and n/p, line selection for comments, and agent actions openFile, nextHunk, previousHunk, markViewed and getHunk.

Example

3 additions, 4 deletions
src
total.tsModified2 additions, 2 deletions
legacy.tsDeleted0 additions, 1 deletion
docs
install.mdRenamed1 addition, 1 deletion
Modifiedsrc/total.ts2 additions, 2 deletions
@@ -1,4 +1,4 @@
Removed, line 1
Added, line 1
Line 2
Removed, line 3
Added, line 3
Line 4
Renameddocs/install.md, renamed from docs/setup.md1 addition, 1 deletion
@@ -1,2 +1,2 @@
Line 1

Installation

npx shadcn@latest add @eskais/git-diff
npm packageslucide-react

Usage

Import
import { useOpenCurrentFile } from "@/components/ui/use-git-diff"import { GitDiffTree } from "@/components/ui/git-diff-tree"import { createDiffViewController, GitDiff } from "@/components/ui/git-diff"

Use GitDiff to review a patch or a set of changed files: pass git diff output as patch, or FileDiffs with both texts so unchanged regions expand. The tree beside it jumps to a file; marking a file viewed folds it. onLineSelect gives the line or Shift range a comment would anchor to.

API reference

GitDiffTree

PropTypeDefault
filesrequiredreadonly DiffViewFile[]–
groupsWithout it, one tree of every file.readonly GitDiffTreeGroup[]–
valueThe `path` of the file shown, highlighted in the tree.string | null–
onOpenrequired(path: string) => void–
labelsrequiredDiffLabels–
classNamestring–

GitDiff

PropTypeDefault
patchA unified diff as git prints it (`git diff`, `git show`, a `.patch`), with any number of files.string–
filesUnchanged regions expand only for a file that has `oldText` and `newText`.readonly FileDiff[]–
fileTree`--diff-tree-width` wide (13rem). `"collapsible"` adds a toolbar toggle that hides and shows it. @defaultValue trueboolean | "collapsible"true
fileTreeOpenboolean–
defaultFileTreeOpenbooleantrue
onFileTreeOpenChange(open: boolean) => void–
groupsThe tree shows one section per group; the diff lists the groups one after another, in order.readonly GitDiffGroup[]–
toolbarThe layout and wrap controls and the totals above the diff. @defaultValue truebooleantrue
height`fill` (default) fills the height GitDiff is given. `auto` grows to the whole diff, for a scrolling dialog body: the body is the one scroller and the tree stays in view up to 40rem tall. A `--diff-max-height` caps both, and the diff scrolls inside past it.DiffViewProps["height"]"fill"
currentFileSetting it scrolls the diff to that file; `onCurrentFileChange` reports the file at the top as the diff scrolls.string | null–
defaultCurrentFilestring | null–

Also takes DiffViewProps except files, headers.

Other exports

useOpenCurrentFilecreateDiffViewControllertype GitDiffTreeGrouptype GitDiffTreePropstype DiffViewControllertype GitDiffGrouptype GitDiffProps

Accessibility

  • The lines of each file are a grid with one tab stop: arrows move by line (and side, in split), Page Up and Page Down by a screen, j/k to the next or previous hunk, n/p to the next or previous file; Enter or Space selects a line, Shift extends, Escape clears.
  • Every line carries its +/- sign and a screen-reader label (Added, line 12), so a change never rests on colour; diff fills and changed words keep every syntax colour at 4.5:1 in both modes and every palette.
  • Code stays left to right in a right-to-left page; headers follow the page. Find in page reaches lines that aren't rendered and opens a folded region or file it matches.

Agent actions

The diff is one component named by its aria-label, with openFile(path), currentFile(), nextHunk(), previousHunk(), nextFile(), markViewed(path, viewed), getHunk(path, n) (read-only), expandGap, setLayout and setWrap; its items are the file paths. Viewed checkboxes, the layout control and the wrap toggle are UI SDK parts too.

Runs agent.snapshot() from @ui-sdk/react/agent on the live preview above.