Skip to content
Thrum

Diff viewer

Shows what changed between two texts: a config before and after, two versions of a document, a generated file. Lines are compared, then the changed words inside them are marked, side by side or in one column. To show one version, use a code block instead.

Install

npx shadcn@latest add @thrum-pro/diff-viewer

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Automatically installs icon chevrons-up-down from the icon set.

Props

PropTypeDefaultDescription
beforestringRequiredThe old text.
afterstringRequiredThe new text.
titlestringRequiredA name for the change, such as a file name. It heads the frame and names the diff for screen readers.
view"split" | "unified"–The view, when the parent holds it. Use it with onViewChange.
defaultView"split" | "unified"Default "split"The view at first, when the viewer holds it itself. Below 560 pixels wide split shows as unified, and the switch is hidden.
onViewChange(view: "split" | "unified") => void–Called with the view picked in the header.
contextnumberDefault 3Unchanged lines kept on each side of a change. Longer runs fold behind a Show N unchanged lines button.
lineNumbersbooleanDefault trueShow the old and the new line numbers.
wordDiffbooleanDefault trueMark the changed words inside a changed line, pairing removed and added lines of one change in order.
emptyLabelstringDefault "No changes"Shown when the two texts are the same.
soundbooleanDefault truePlay a click when the view changes, if the visitor has sound on.
classNamestring–Extra classes for the frame, merged last. Give it a height, such as h-80, to scroll a long diff inside it.
diffSequences(), diffLines(), diffWords(), foldUnchanged()functions–More exports: the shortest edit script of two lists (Myers' algorithm), the lines of a text diff, the word marks of a changed pair, and the folding of unchanged runs.

Motion and sound

Motion

  • Nothing moves but the view switch's thumb, which slides over 150 ms.
  • Reduced motion: the thumb moves at once.

Sound

  • A click when the view changes. Opening a fold is silent.

Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works

Accessibility

  • Each view is a table named by the title and the counts, such as sync.config.ts, 4 added, 3 removed.
  • Removed lines carry a minus and added lines a plus as well as their tint, and screen readers hear Removed or Added before the line.
  • Changed words are ins and del elements, which some screen readers announce as inserted or deleted.
  • The counts in the header read 4 lines added, 3 lines removed to screen readers.
  • The frame is a panel surface (data-surface="panel"): under a glass material it becomes translucent while keeping diff tints and code readable.
  • Long lines wrap anywhere, so nothing is cut at 160 pixels wide.
KeysAction
TabMove to the view switch, the frame, which then scrolls with the arrow keys, and each Show unchanged lines button.
← / →On the view switch: pick split or unified.
Enter / SpaceOn a fold: show the lines behind it.

Source

SourcePro

The source comes with Pro

TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies

Files and dependencies

Adds
components/ui/diff-viewer.tsx
Packages
None
Brings along
Segmented controlChart foundations
Icons
chevrons-up-down

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor