Diff
+N −N. Each line has
its old and new number, a + or − sign and a green or red tint. Pass a unified diff as text (git diff,
git format-patch, diff -u) or files you already parsed.When to use
- A person reviews or approves a code or config change: a pull request, an approval gate, a deploy.
- Showing what a run, a migration or a policy edit changed in a file.
- Code that is not a change — use
TextwithfontFamily="code". - Comparing two records field by field — use a
Tableor aDescriptionList. - You need side-by-side review, word-level highlights or syntax colours — not supported.
Usage
src/limits.ts2 additions, 1 deletion
docs/gates.md → docs/approval-gates.mdrenamed0 additions, 0 deletions
import { Diff } from '@apollion-dsi/core/data-display/diff';
<Diff patch={changes.patch} />;- Every file starts open;
defaultCollapsedstarts them closed. The header toggles the file (click, Enter or Space) andonFileToggle(file, open)reports it. A closed file renders no lines. - Binary files and files with no line changes (a rename, a mode change) show a short note instead of lines.
Long lines and long patches
- Lines keep their shape and scroll sideways inside the file.
wrapbreaks long lines instead. - A file with more rows than
virtualizeAbove(default 400) renders only the rows in view, inside a blockmaxHeighttall (default32rem). Below the threshold every line is in the page, so in-page search finds it. truncatedadds a closing note when the source cut the patch;truncatedLabelreplaces its text. A patch cut mid-hunk shows the lines up to the cut.
src/limits.ts2 additions, 1 deletion
docs/gates.md → docs/approval-gates.mdrenamed0 additions, 0 deletions
<Diff patch={changes.patch} truncated={changes.truncated} truncatedLabel={`The whole patch is at ${changes.path}`} />Parsed files
parseUnifiedDiff(patch) returns the DiffFile[] the component draws. Use it to count files and lines with the same
rules, or to parse on the server and pass files. It reads git headers, quoted paths, new and deleted files, renames,
copies, mode changes, binary files and \ No newline at end of file, and it never throws.
import { Diff, parseUnifiedDiff } from '@apollion-dsi/core/data-display/diff';
const files = parseUnifiedDiff(changes.patch);
<Diff files={files} />;Look
Colours live in the theme, never in className. The theme.component.diff tier sets added, removed and hunk
(a palette and a tint amount), surface, header, code and gutter:
createTheme({
component: {
diff: {
added: { color: 'success', tint: 0.3 },
removed: { color: 'danger', tint: 0.3 },
code: { fontSize: 'micro' },
},
},
});Tints mix per mode, so one tier works in light and dark. When a tint would drop the line text under 4.5:1, it is pulled back toward the ground until it passes. Signs, counts and line numbers reach 4.5:1 too.
Accessibility
- Never colour only: changed lines show
+/−, and screen readers hear "added" or "removed" before the text. Line numbers and signs are hidden from them. - Each file's code is a focusable region named by its path, so a keyboard user can scroll it sideways.
- The header reads its counts in words ("2 additions, 1 deletion").
- Every string has an English default;
labelsreplaces any of them.
Properties
defaultCollapsedbooleanfalsefilesDiffFile[]nonelabelsPartial<DiffLabels>noneonFileToggle((file: DiffFile, open: boolean) => void)nonepatchstringnonetruncatedbooleanfalsetruncatedLabelReactNode'The patch is cut here.'virtualizeAbovenumber400Beyond the props above, the component accepts the native
<div>attributes (id,aria-*,data-*).