Blocks / Version compare

Version compare

The versions of a document or record in a list: pick two and see what changed.

import { VersionCompare } from "@forgeron/ui";
/01 → Text
  1. v4
    Current versionCamille Roy · Nov 18, 15:40
  2. v3
    Nov 14, 09:12Léa MartinBudget raised
  3. v2
    Nov 9, 17:30Hugo BernardBigger goal
  4. v1
    Nov 2, 11:05Léa Martin

v3v4

+1−0
Changes from v3 to v4
88 1. Announce on the blog
99 2. Email the waiting list
1010 3. Open the community
11+4. Press briefing
import { VersionCompare, type CompareVersion } from "@forgeron/ui";
import { useState } from "react";

const page = (n: number) =>
  [
    "# Launch plan",
    "",
    n >= 2 ? "Goal: 500 sign-ups in the first month." : "Goal: 300 sign-ups.",
    "Owner: Léa Martin",
    n >= 3 ? "Budget: 12 000 EUR, reviewed weekly." : "Budget: 10 000 EUR.",
    "",
    "## Steps",
    "1. Announce on the blog",
    "2. Email the waiting list",
    n >= 3 ? "3. Open the community" : null,
    n >= 4 ? "4. Press briefing" : null,
  ]
    .filter((l): l is string => l !== null)
    .join("\n");

const versions: CompareVersion[] = [
  { id: "v4", label: "v4", at: "Nov 18, 15:40", by: "Camille Roy", content: page(4) },
  {
    id: "v3",
    label: "v3",
    at: "Nov 14, 09:12",
    by: "Léa Martin",
    note: "Budget raised",
    content: page(3),
  },
  {
    id: "v2",
    label: "v2",
    at: "Nov 9, 17:30",
    by: "Hugo Bernard",
    note: "Bigger goal",
    content: page(2),
  },
  { id: "v1", label: "v1", at: "Nov 2, 11:05", by: "Léa Martin", content: page(1) },
];

export default function Text() {
  const [log, setLog] = useState("");
  return (
    <div style={{ display: "grid", gap: 8, width: "100%" }}>
      <VersionCompare versions={versions} onRestore={(id) => setLog(`Restore ${id}`)} />
      {log ? (
        <span style={{ color: "var(--ink-dim)", font: "400 11px/16px var(--font-mono)" }}>
          {log}
        </span>
      ) : null}
    </div>
  );
}
/02 → Record
  1. v3
    Current versionMaya Lopez · Nov 18, 10:02
  2. v2
    Nov 16, 14:20Hugo BernardDiscount applied
  3. v1
    Nov 15, 09:41Hugo Bernard

v2v3

Fields from v2 to v3
Fieldv2v3
Total (Changed)1920018400
status (Changed)DraftSent
// The versions of a record: each one's content is its fields, and the diff is a before and after.
import { VersionCompare, type CompareVersion } from "@forgeron/ui";

const versions: CompareVersion[] = [
  {
    id: "r3",
    label: "v3",
    at: "Nov 18, 10:02",
    by: "Maya Lopez",
    content: {
      title: "Quote 2026-114",
      amount: 18400,
      currency: "EUR",
      status: "Sent",
      terms: "Net 30",
    },
  },
  {
    id: "r2",
    label: "v2",
    at: "Nov 16, 14:20",
    by: "Hugo Bernard",
    note: "Discount applied",
    content: {
      title: "Quote 2026-114",
      amount: 19200,
      currency: "EUR",
      status: "Draft",
      terms: "Net 30",
    },
  },
  {
    id: "r1",
    label: "v1",
    at: "Nov 15, 09:41",
    by: "Hugo Bernard",
    content: { title: "Quote 2026-114", amount: 21000, currency: "EUR", status: "Draft" },
  },
];

export default function Record() {
  return (
    <div style={{ width: "100%" }}>
      <VersionCompare versions={versions} labels={{ amount: "Total", terms: "Payment terms" }} />
    </div>
  );
}
API → Props
PropTypeDefaultDescription
versionsCompareVersion[]—Newest first: { id, label, at, by, note?, content }. content is a string (text diff) or a record (field diff).
from / defaultFrom / onFromChangestring—The older side. Default: the version before the right one.
to / defaultTo / onToChangestring—The newer side. Default: the current version.
onRestore(id) => void—Makes an older version the current one; leave out on a read-only record.
labelsRecord<string, string>—Names of the fields, for records.
mode / defaultMode / onModeChange"unified" | "split"—The text diff layout.
classNamestring—Extra classes.