CLI previewInstall commands shown on this site are not released yet.

DocsComponentsAdvanced

DiffViewer

React example follows below.
ts
import { DiffViewer } from "@grassroot/ui-react/advanced";
const lines = [
{ type: "ctx", oldNo: 41, newNo: 41, code: [{ text: "function charge(req) {" }] },
{ type: "del", oldNo: 42, newNo: null, code: [{ text: " if (!acct) throw …" }] },
{ type: "add", oldNo: null, newNo: 42, code: [{ text: " if (!acct) throw new NotFoundError();" }] },
];
<DiffViewer fileName="services/ledger/charge.ts" lines={lines} />
ts
<script setup lang="ts">
import { DiffViewer } from "@grassroot/ui-vue";
const lines = [
{ type: "ctx", oldNo: 41, newNo: 41, code: [{ text: "function charge(req) {" }] },
{ type: "del", oldNo: 42, newNo: null, code: [{ text: " if (!acct) throw …" }] },
{ type: "add", oldNo: null, newNo: 42, code: [{ text: " if (!acct) throw new NotFoundError();" }] },
];
</script>
<template>
<DiffViewer file-name="services/ledger/charge.ts" :lines="lines" />
</template>

No translated snippet for this adapter yet.

ts
<script lang="ts">
import { DiffViewer } from "@grassroot/ui-svelte";
const lines = [
{ type: "ctx", oldNo: 41, newNo: 41, code: [{ text: "function charge(req) {" }] },
{ type: "del", oldNo: 42, newNo: null, code: [{ text: " if (!acct) throw …" }] },
{ type: "add", oldNo: null, newNo: 42, code: [{ text: " if (!acct) throw new NotFoundError();" }] },
];
</script>
<DiffViewer fileName="services/ledger/charge.ts" lines={lines} />
ts
import { DiffViewer } from "@grassroot/ui-solid";
const lines = [
{ type: "ctx", oldNo: 41, newNo: 41, code: [{ text: "function charge(req) {" }] },
{ type: "del", oldNo: 42, newNo: null, code: [{ text: " if (!acct) throw …" }] },
{ type: "add", oldNo: null, newNo: 42, code: [{ text: " if (!acct) throw new NotFoundError();" }] },
];
export function Example() {
return (
<>
<DiffViewer fileName="services/ledger/charge.ts" lines={lines} />
</>
);
}

Installation

bash
pnpm dlx grassroot add ui/diff-viewer
bash
npx grassroot@latest add ui/diff-viewer
bash
yarn dlx grassroot add ui/diff-viewer
bash
bunx grassroot add ui/diff-viewer

API Reference

DiffViewerProps
PropTypeDefault
fileNamerequiredFile path shown in the header.string
linesrequiredThe diff lines, in order.DiffLine[]
modeControlled view mode. Falls back to internal state when omitted."split" | "unified" | undefined
onModeChangeCalled when the user toggles the view.((mode: "unified" | "split") => void) | undefined
defaultModeInitial view when uncontrolled."split" | "unified" | undefined"unified"