Blocks / Diff view

Diff view

What changed between two texts or two records: unified or side by side, words marked.

import { DiffView, FieldDiff, structureDiffRows, structureDiffSeq, structureDiffFields } from "@forgeron/ui";
/01 → Text
+6−3
Changes from v3 to v4
11 # Leave policy
22
3−Every employee has 25 days of paid leave per year.
4−Requests are sent to the manager at least two weeks ahead.
3+Every employee has 27 days of paid leave per year.
4+Requests are sent to the manager at least one week ahead.
55
66 ## Carry over
7−Unused days are lost on 31 December.
7+Up to five unused days carry over until 31 March.
88
99 ## Sick leave
1212 Long absences are reviewed monthly.
1313 HR keeps the certificate for five years.
14+
15+## Parental leave
16+See the dedicated page.
import { DiffView } from "@forgeron/ui";

const before = `# Leave policy

Every employee has 25 days of paid leave per year.
Requests are sent to the manager at least two weeks ahead.

## Carry over
Unused days are lost on 31 December.

## Sick leave
Send the certificate within 48 hours.
Managers are told the same day.
Long absences are reviewed monthly.
HR keeps the certificate for five years.`;

const after = `# Leave policy

Every employee has 27 days of paid leave per year.
Requests are sent to the manager at least one week ahead.

## Carry over
Up to five unused days carry over until 31 March.

## Sick leave
Send the certificate within 48 hours.
Managers are told the same day.
Long absences are reviewed monthly.
HR keeps the certificate for five years.

## Parental leave
See the dedicated page.`;

export default function Text() {
  return (
    <div style={{ width: "100%", maxWidth: 760 }}>
      <DiffView before={before} after={after} beforeLabel="v3" afterLabel="v4" context={2} />
    </div>
  );
}
/02 → Fields
Fields from Nov 12 to Nov 18
FieldNov 12Nov 18
name (Changed)Acme LogisticsAcme Logistics SAS
status (Changed)ProspectCustomer
City (Changed)LyonVilleurbanne
tags (Changed)transport, eutransport, eu, priority
notes (Changed)Asked for a quote on pallets.Asked for a quote on pallets and containers.
website (Added)—acme.example
import { FieldDiff } from "@forgeron/ui";

const before = {
  name: "Acme Logistics",
  status: "Prospect",
  owner: "Hugo Bernard",
  address: { street: "12 rue Vauban", city: "Lyon" },
  tags: ["transport", "eu"],
  notes: "Asked for a quote on pallets.",
  phone: "+33 4 72 00 00 00",
};
const after = {
  name: "Acme Logistics SAS",
  status: "Customer",
  owner: "Hugo Bernard",
  address: { street: "12 rue Vauban", city: "Villeurbanne" },
  tags: ["transport", "eu", "priority"],
  notes: "Asked for a quote on pallets and containers.",
  website: "acme.example",
  phone: "+33 4 72 00 00 00",
};

export default function Fields() {
  return (
    <div style={{ width: "100%", maxWidth: 760 }}>
      <FieldDiff
        before={before}
        after={after}
        beforeLabel="Nov 12"
        afterLabel="Nov 18"
        labels={{ "address.city": "City", "address.street": "Street" }}
      />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
before / afterstring—DiffView: the older and the newer text. Compared by lines (Myers), words marked inside a changed line.
mode / defaultMode / onModeChange"unified" | "split""unified"The layout.
contextnumber3Unchanged lines kept around a change.
collapsebooleantrueFold the longer runs: a button shows them.
beforeLabel / afterLabelstring—Names the sides: v2, v4.
bareboolean—No counts and no layout switch.
FieldDiff: before / afterRecord<string, unknown>—The fields of two records. Nested ones by path (address.city), lists joined, added, removed and changed told in words as well as colour.
FieldDiff: labelsRecord<string, string>—The name shown for a key.
FieldDiff: showUnchangedbooleanfalseA button shows the fields that did not change.
classNamestring—Extra classes.