- Prop
fileName- Type
string- Default
- —
- Requirement
- required
- Description
- File path shown in the header.
Docs Components Advanced
DiffViewer
React example follows below.
Vue example follows below.
Angular example follows below.
Svelte example follows below.
Solid example follows below.
- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
const diffViewerFixture = { id: "diff-viewer", fileName: "services/ledger/charge.ts", lines: [ { type: "ctx" as const, oldNo: 41, newNo: 41, code: "function charge(req) {" }, { type: "del" as const, oldNo: 42, newNo: null, code: " if (!acct) throw new Error();" }, { type: "add" as const, oldNo: null, newNo: 42, code: " if (!acct) throw new NotFoundError();", }, ], defaultMode: "unified" as const,}; import { DiffViewer } from "@grassroot/ui-react/advanced"; export default function DiffViewerDemo() { const { id: _id, ...props } = diffViewerFixture; return ( <div> <DiffViewer {...props} /> </div> );}- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
<script setup lang="ts">const diffViewerFixture = { id: "diff-viewer", fileName: "services/ledger/charge.ts", lines: [ { type: "ctx" as const, oldNo: 41, newNo: 41, code: "function charge(req) {" }, { type: "del" as const, oldNo: 42, newNo: null, code: " if (!acct) throw new Error();" }, { type: "add" as const, oldNo: null, newNo: 42, code: " if (!acct) throw new NotFoundError();", }, ], defaultMode: "unified" as const,}; import { DiffViewer } from "@grassroot/ui-vue";</script> <template> <div> <DiffViewer :file-name="diffViewerFixture.fileName" :lines="diffViewerFixture.lines" :default-mode="diffViewerFixture.defaultMode" /> </div></template>- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
import { Component } from "@angular/core";const diffViewerFixture = { id: "diff-viewer", fileName: "services/ledger/charge.ts", lines: [ { type: "ctx" as const, oldNo: 41, newNo: 41, code: "function charge(req) {" }, { type: "del" as const, oldNo: 42, newNo: null, code: " if (!acct) throw new Error();" }, { type: "add" as const, oldNo: null, newNo: 42, code: " if (!acct) throw new NotFoundError();", }, ], defaultMode: "unified" as const,}; import { GrassrootDiffViewer } from "@grassroot/ui-angular"; @Component({ selector: "app-diff-viewer-demo", standalone: true, imports: [GrassrootDiffViewer], template: ` <div> <grassroot-diff-viewer [fileName]="fixture.fileName" [lines]="fixture.lines" [defaultMode]="fixture.defaultMode" /> </div> `,})export class DiffViewerDemoComponent { protected readonly fixture = diffViewerFixture;} export default DiffViewerDemoComponent;- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
<script lang="ts"> const diffViewerFixture = { id: "diff-viewer", fileName: "services/ledger/charge.ts", lines: [ { type: "ctx" as const, oldNo: 41, newNo: 41, code: "function charge(req) {" }, { type: "del" as const, oldNo: 42, newNo: null, code: " if (!acct) throw new Error();" }, { type: "add" as const, oldNo: null, newNo: 42, code: " if (!acct) throw new NotFoundError();", }, ], defaultMode: "unified" as const, }; import { DiffViewer } from "@grassroot/ui-svelte";</script> <div> <DiffViewer fileName={diffViewerFixture.fileName} lines={diffViewerFixture.lines} defaultMode={diffViewerFixture.defaultMode} /></div>- parts
- —
- nodes
- —
- size
- —
- part
- —
ts
/** @jsxImportSource solid-js */const diffViewerFixture = { id: "diff-viewer", fileName: "services/ledger/charge.ts", lines: [ { type: "ctx" as const, oldNo: 41, newNo: 41, code: "function charge(req) {" }, { type: "del" as const, oldNo: 42, newNo: null, code: " if (!acct) throw new Error();" }, { type: "add" as const, oldNo: null, newNo: 42, code: " if (!acct) throw new NotFoundError();", }, ], defaultMode: "unified" as const,}; import { DiffViewer } from "@grassroot/ui-solid"; export default function DiffViewerDemo() { return ( <div> <DiffViewer fileName={diffViewerFixture.fileName} lines={diffViewerFixture.lines} defaultMode={diffViewerFixture.defaultMode} /> </div> );}Installation
API Reference
Import
import { DiffViewer } from "@grassroot/ui-react/advanced";
Props
Prop
Type
Default
Requirement
Description
fileNamestring—
required
File path shown in the header.
linesDiffLine[]—
required
The diff lines, in order.
mode"split" | "unified" | undefined—
optional
Controlled view mode.
onModeChange((mode: "unified" | "split") => void) | undefined—
optional
Called when the user toggles the view.
defaultMode"split" | "unified" | undefined"unified"optional
Initial view when uncontrolled.
- Prop
lines- Type
DiffLine[]- Default
- —
- Requirement
- required
- Description
- The diff lines, in order.
- Prop
mode- Type
"split" | "unified" | undefined- Default
- —
- Requirement
- optional
- Description
- Controlled view mode.
- Prop
onModeChange- Type
((mode: "unified" | "split") => void) | undefined- Default
- —
- Requirement
- optional
- Description
- Called when the user toggles the view.
- Prop
defaultMode- Type
"split" | "unified" | undefined- Default
"unified"- Requirement
- optional
- Description
- Initial view when uncontrolled.
Events
| Event | Payload |
|---|---|
onModeChange | ((mode: "unified" | "split") => void) | undefined |
Native attributes
Standard DOM and ARIA attributes not listed above spread onto the root element.
Import
import { DiffViewer } from "@grassroot/ui-vue";
Props
Prop
Type
Default
Requirement
fileNamestring—
required
linesreadonly DiffLine[]—
required
modeDiffViewMode | undefined—
optional
defaultModeDiffViewMode | undefined—
optional
classNamestring | undefined—
optional
- Prop
fileName- Type
string- Default
- —
- Requirement
- required
- Prop
lines- Type
readonly DiffLine[]- Default
- —
- Requirement
- required
- Prop
mode- Type
DiffViewMode | undefined- Default
- —
- Requirement
- optional
- Prop
defaultMode- Type
DiffViewMode | undefined- Default
- —
- Requirement
- optional
- Prop
className- Type
string | undefined- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
modeChange | [mode: DiffViewMode] |
Import
import { Component } from "@angular/core";
import { GrassrootDiffViewer } from "@grassroot/ui-angular";
Props
Prop
Type
Default
Requirement
classNamestring—
optional
fileNamestring—
required
linesreadonly DiffLine[]—
required
modeDiffViewMode—
optional
defaultModeDiffViewMode"unified"optional
- Prop
className- Type
string- Default
- —
- Requirement
- optional
- Prop
fileName- Type
string- Default
- —
- Requirement
- required
- Prop
lines- Type
readonly DiffLine[]- Default
- —
- Requirement
- required
- Prop
mode- Type
DiffViewMode- Default
- —
- Requirement
- optional
- Prop
defaultMode- Type
DiffViewMode- Default
"unified"- Requirement
- optional
Events
| Event | Payload |
|---|---|
modeChange | DiffViewMode |
Import
import { DiffViewer } from "@grassroot/ui-svelte";
Props
Prop
Type
Default
Requirement
fileNamestring—
required
linesreadonly DiffLine[]—
required
modeDiffViewMode—
optional
defaultModeDiffViewMode"unified"optional
onModeChange(mode: DiffViewMode) => void—
optional
classNamestring—
optional
- Prop
fileName- Type
string- Default
- —
- Requirement
- required
- Prop
lines- Type
readonly DiffLine[]- Default
- —
- Requirement
- required
- Prop
mode- Type
DiffViewMode- Default
- —
- Requirement
- optional
- Prop
defaultMode- Type
DiffViewMode- Default
"unified"- Requirement
- optional
- Prop
onModeChange- Type
(mode: DiffViewMode) => void- Default
- —
- Requirement
- optional
- Prop
className- Type
string- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
onModeChange | (mode: DiffViewMode) => void |
Import
import { DiffViewer } from "@grassroot/ui-solid";
Props
Prop
Type
Default
Requirement
fileNamestring—
required
linesreadonly DiffLine[]—
required
modeDiffViewMode—
optional
onModeChange(mode: DiffViewMode) => void—
optional
defaultModeDiffViewMode—
optional
classNamestring—
optional
- Prop
fileName- Type
string- Default
- —
- Requirement
- required
- Prop
lines- Type
readonly DiffLine[]- Default
- —
- Requirement
- required
- Prop
mode- Type
DiffViewMode- Default
- —
- Requirement
- optional
- Prop
onModeChange- Type
(mode: DiffViewMode) => void- Default
- —
- Requirement
- optional
- Prop
defaultMode- Type
DiffViewMode- Default
- —
- Requirement
- optional
- Prop
className- Type
string- Default
- —
- Requirement
- optional
Events
| Event | Payload |
|---|---|
onModeChange | (mode: DiffViewMode) => void |