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";| 1 | 1 | # Leave policy | |
| 2 | 2 | ||
| 3 | − | Every employee has | |
| 4 | − | Requests are sent to the manager at least | |
| 3 | + | Every employee has 27 days of paid leave per year. | |
| 4 | + | Requests are sent to the manager at least one week ahead. | |
| 5 | 5 | ||
| 6 | 6 | ## Carry over | |
| 7 | − | Unused days are lost on 31 December. | |
| 7 | + | Up to five unused days carry over until 31 March. | |
| 8 | 8 | ||
| 9 | 9 | ## Sick leave | |
| 12 | 12 | Long absences are reviewed monthly. | |
| 13 | 13 | 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>
);
}| Field | Nov 12 | Nov 18 |
|---|---|---|
| name (Changed) | Acme Logistics | Acme Logistics SAS |
| status (Changed) | Prospect | Customer |
| City (Changed) | Lyon | Villeurbanne |
| tags (Changed) | transport, eu | transport, 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
| Prop | Type | Default | Description |
|---|---|---|---|
before / after | string | — | 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. |
context | number | 3 | Unchanged lines kept around a change. |
collapse | boolean | true | Fold the longer runs: a button shows them. |
beforeLabel / afterLabel | string | — | Names the sides: v2, v4. |
bare | boolean | — | No counts and no layout switch. |
FieldDiff: before / after | Record<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: labels | Record<string, string> | — | The name shown for a key. |
FieldDiff: showUnchanged | boolean | false | A button shows the fields that did not change. |
className | string | — | Extra classes. |