← All proposals

Content Diff

A component, ContentDiff: the old value on a red line with a minus, the new value on a green line with a plus, in one bordered block, like a text diff.

Net-new componentOpen in Storybook

proposals/ContentDiff/HANDOFF.md138 lines · View on GitHub

Handoff: Content Diff

Rewritten 2026-11-20 against v2.0.0-beta.21 to the lessons template. Nothing in this file was checked by eye in a session; where a result is quoted from an earlier note it says so.

What and why

A before and after of a piece of content, stacked like a text diff: the old value on a critical-status line with a minus, the new value on a success-status line with a plus, in one bordered block. For text an agent proposes to change (page copy); code diffs use the Code diff recipe. PDS has nothing like it. It started as the body of the Suggestion Card's SuggestionChange and was taken out as its own component on 2026-10-21; SuggestionChange now composes it.

  • Figma / Jira: Figma page under Preview; Jira none. Source: the designer's screenshot of the stacked diff in the Suggestion Card.
  • Context: context.md

Exploration and decisions

  • Stacked, not columns. It reads top to bottom, gives long text the full width and matches the diff look used elsewhere.
  • A definition list. dl with a visually hidden dt ("Before", "After") and a dd per value; beforeLabel and afterLabel are required strings so they can be translated. The minus and plus icons are aria-hidden.
  • Color is not the only cue: the minus and plus carry the meaning too.
  • Colors are the status tokens: critical for before, success for after (the after text is medium weight).
  • size s or xs was added 2026-10-22 (after the first handoff): text only, the icons stay the same size.

Full list: decisions.md.

API

From ContentDiff.tsx. ContentDiffProps extends ComponentPropsWithoutRef<'dl'>.

Prop Type Default Purpose
after ReactNode required The new value.
afterLabel string required Name of the new value for screen readers (visually hidden), for example "After". Provide it translated.
before ReactNode required The current value.
beforeLabel string required Name of the current value for screen readers (visually hidden), for example "Before". Provide it translated.
className string none Additional class names.
size ContentDiffSize ('xs' | 's') 's' Text size, applied as pds-copy-s or pds-copy-xs on the block. The minus and plus icons stay the same size (s).

Variants and states: size s (default) and xs. There is one story, Default; xs is reached with the size control. No hover, focus, disabled or loading state (the block is not interactive).

Tokens used

From content-diff.css as it is now:

  • --pds-border-radius-default, --pds-border-width-default
  • --pds-color-border-default
  • --pds-color-status-critical-background, --pds-color-status-critical-foreground
  • --pds-color-status-success-background, --pds-color-status-success-foreground
  • --pds-spacing-2xs, --pds-spacing-5xs, --pds-spacing-xs
  • --pds-typography-fw-medium

Text size and line height come from the pds-copy-s / pds-copy-xs classes, not from this CSS. No custom CSS variables, no raw values.

Impact

From impact.md: no existing PDS component is reached and no --pds-* token is redefined. SuggestionCard builds on it (SuggestionChange); it uses the default size s, which is what it rendered before the size prop, so it should be unchanged (not checked by eye).

Reused vs net-new

  • Reused: the PDS Icon (minus, plus, size s; the proposal imports it through the local Icon wrapper, which passes both through to the package), the pds-copy-s and pds-copy-xs classes, the visually-hidden class.
  • Net-new: .pds-content-diff with __line, --before, --after, __marker and __text; all props. See custom.md.

Accessibility

  • A dl with hidden dt names, so a screen reader should hear "Before: ..." and "After: ...". Give the block a name from the screen around it (for example the field), as SuggestionChange does. The dl itself has no role or label. Not tested with a screen reader.
  • The minus and plus icons are aria-hidden; the meaning is carried by the hidden dts and by the icons, so color is not the only cue.
  • Keyboard: nothing is focusable and nothing needs to be. Not checked in a browser.
  • Contrast: status foreground on status background, both tokens from the package. The old handoff said the Storybook a11y panel was run on Default at both sizes, light and dark, on 2026-10-22 with no violations; docs/STATUS.md says the a11y panel was not run for this proposal. Treat both as "not verified", and run the panel on Default at both sizes in both themes before porting.
  • Markup validity: <svg> icons sit between <dt> and <dd> inside the <div> wrapper of the dl (ContentDiff.tsx:65-74); HTML allows only dt and dd there. See "Expect to change".

Decisions and open questions

Each has a recommended answer (the designer decides).

  • Highlight the changed words inside each line? Recommendation: not now. It needs a word-level diff and a new prop or slot shape, and no screen needs it yet; add it when one does.
  • Should it take a visible title (the field name) itself? Recommendation: no. Keep the block title-less and let the screen name it, as SuggestionChange does; a title would be one more translated prop.

Extension or new component

New component, not an extension. Searched .pds-reference/src/components at beta.21: the closest are code-display/FileDiff (a bar of added and removed line counts) and code-display/BranchDiff (a branch comparison with loading state); neither shows a before and after value. No existing component can carry it. The proposal does not change any existing PDS component, so no human behavior or stories are touched. Recommendation: place it under src/components/ in a category folder of the engineer's choice (lists or code-display are candidates; not a decision made here).

Footprint

  • Nothing is drawn outside the box: no shadow, ring, pseudo-element or absolutely positioned part. The block is a 1px bordered, rounded box with overflow: hidden, so the line backgrounds are clipped to the rounded corners.
  • A parent cannot clip anything of ours. The reverse: overflow: hidden here would cut off any focus ring or tooltip a consumer puts inside before or after. Recommendation: say this in the docs; the values are meant to be plain text.
  • Width: the block is a normal block dl (margin 0) and fills its parent. Long text wraps (overflow-wrap: anywhere, min-width: 0 on the text); the block itself sets no min-width, so inside a flex or grid parent it follows that parent's rules. Not checked in a narrow layout.
  • Height: grows with the text. Two lines minimum (one per value).

Dark mode and per-size values

There is no per-theme CSS override; the colors switch because every color is a --pds-* token. Per-size values come from the pds-copy-* class plus one fixed marker size.

Value s (default) xs Dark mode
Text size / line height 14px / 150% (21px) 12px / 150% (18px) same
Icon size s = 14px s = 14px (does not change) same
Marker offset margin-block-start 2px (5xs) 2px (same) same
Line padding / gap 8px block, 10px inline / gap 8px same same
Border / radius 1px border-default / 4px (radius-default) same border-default is a token that changes by theme
Before line colors critical background and foreground same tokens change by theme, no CSS override
After line colors / weight success background and foreground, medium same tokens change by theme, no CSS override

Computed from the CSS and the token files in the package, not seen: with the one 2px offset the 14px icon centre sits at 9px from the top of the line, and the first text line centre is at 10.5px (s) or 9px (xs), so the icon is about 1.5px higher than the text centre at s and level at xs. Recommendation: the designer checks the s alignment by eye and, if it needs correcting, the port uses a per-size offset instead of one value.

Expect to change

Each is a choice that may not match toolkit conventions, with a recommended answer.

  1. beforeLabel and afterLabel are required (L2). They are top-level and translatable (good, L3). The toolkit prefers optional plus a dev warning. Recommendation: keep them required, because an English default would be hardcoded content in the component; if the engineer makes them optional, add a [ContentDiff] dev warning with process.env.NODE_ENV !== 'production', as Button does.
  2. Screen-reader text is the dt content. It is not nested in another prop's object (L3 satisfied). What is announced: "Before" then the old value, "After" then the new value. Nothing else repeats it.
  3. Invalid dl content (<svg> between dt and dd). Recommendation: move each icon inside its dd (before the text span) or inside its dt; both keep the hidden-name behavior. The __marker offset in the CSS would then need re-checking.
  4. size ('xs' | 's'). It has two real values and is not a knob with one right value (L11). The decision note said it matches Timeline's size; Timeline at beta.21 has no size prop, so there is no shared convention to match. Recommendation: keep size with s as default, and reuse a shared PDS size type if the engineer knows one that fits (none found for 'xs' | 's' in libs/types).
  5. Position props. None. before and after are values, not positions of different content (L11).
  6. Defaults. No boolean props, nothing defaults on (L2).
  7. Only Default story. There is no xs story and no story that shows both lines with long text (L9 is not an issue: no story-only helpers). Recommendation: the engineer adds an all-sizes story; this handoff does not add stories.

Target-version check

Checked 2026-11-20 against .pds-reference/src at v2.0.0-beta.21 and its CHANGELOG.mdx.

Item Already in beta.21?
ContentDiff or content-diff component, class No (grep of src and CHANGELOG.mdx finds nothing).
.pds-content-diff* classes No.
Icons minus and plus Yes, in icons/Icon/icon-registry.ts.
pds-copy-s, pds-copy-xs, visually-hidden Yes (typography-styles.css, foundations/a11y.css).
Tokens listed above Yes, in variables.light.css, variables.dark.css and global.
Icon size s (14px) Yes (.pds-icon--s is 0.875rem).
mergeClasses Yes, @libs/components/utils (the proposal uses a local stand-in).

Not verified: whether Suggestion Card (not shipped) changes in a way that affects the port order.

Port notes

  • New component (npm run generate:component). Swap the local Icon wrapper for @components/icons/Icon/Icon and the local mergeClasses for @libs/components/utils.
  • Port it before SuggestionCard.
  • The story title today is Component Proposals/Content Diff; the new-pattern tag becomes v2-new in the toolkit.

Preview

npm run storybook, then Component Proposals/Content Diff. Figma: https://www.figma.com/design/AMGWJbraJoi2PKWnxo29Ah/PDS-Proposals?node-id=489-43