Code Diff Viewer
ProNewLine-numbered code listing and unified diff viewer with a gliding Diff/Final switcher, +/- counters, and copy button.
Installation
pnpm dlx shadcn@latest add @viewport/code-diff-viewer
First time? Add the @viewport registry to components.json. Setup takes one minute.
Usage
The code behind the preview above comes with Truffle Pro.
Props
| Prop | Type | Default |
|---|---|---|
| filename* | stringFile path shown in the header, e.g. "src/lib/batch.ts". | — |
| lines* | DiffLine[]Unified diff lines; the "Final" view derives automatically from context + add lines. | — |
| defaultMode | "diff" | "code"Initial view mode. | "diff" |
| className | string | — |
Accessibility
- Mode switcher uses tablist/tab semantics; copy button updates its accessible label.
- Horizontal scrolling keeps long lines readable on narrow mobile screens.
- View transitions disable under reduced motion.