← All proposals

Code diff

A recipe, not a component (decided 2026-10-21): a Panel List of changed files, with each row's file icon and name, an optional File Diff (counts and bar), and an expand button that reveals the diff in a Code Block.

Extends a PDS componentOpen in Storybook

proposals/CodeDiff/HANDOFF.md145 lines · View on GitHub

Handoff: Code diff (recipe)

Rewritten 2026-11-20 against v2.0.0-beta.21 to the lessons template. Facts checked against _story-helpers/CodeDiffSample.tsx, _story-helpers/code-diff-sample.css, CodeDiff.stories.tsx and the package source at beta.21; nothing was checked by eye.

What and why

An agent proposes or applies changes to files, and the person needs to review them in place, in a chat message or an approval report. PDS has the parts (Panel List, Code Block with language='diff', File Diff) but no pattern that puts them together. This is a Panel List of changed files: each row has the file icon and name, an optional File Diff (counts and bar), and an expand button that reveals the diff in a Code Block.

It is a recipe, not a component (2026-10-21): a story and a Usage page that compose existing PDS components. There is nothing to port beyond those components. The engineer copies the composition (see _story-helpers/CodeDiffSample.tsx) and keeps the story as documentation.

  • Figma / Jira: none. Source was Erika's reference image (Diff viewer.png): the list collapsed, the list expanded, and a single expanded file.
  • Context: context.md

Exploration and decisions

  • Composed from the package: PanelList, PanelRow, CodeBlock and FileDiff are all exported, so the recipe composes them. The only new CSS is the file name (code font), the stats width and the compact-row overrides.
  • The "diff variant" of Code Block is the existing language='diff'. No new Code Block variant. diff is in the Code Block's language union at beta.21.
  • File Diff is optional, shown when both additions and deletions are given. The reference has none; the approval report row had it.
  • Compact rows. The Panel List's paddingSize only sets block padding, and each row is also held open by a 3rem minimum height on .pds-panel-row__main and --pds-spacing-l (20px) side padding on .pds-panel-row that no prop changes (panel-list.css at beta.21). The recipe overrides those (--pds-spacing-2xl minimum height, --pds-spacing-s side padding) and defaults paddingSize to 2xs. The old handoff said rows go from about 73px to 48px; that figure was not re-measured in this pass (not verified).
  • Two stories: Default (three files) and SingleFile.

API

None, recipe: no props of its own. The sample helper below is story-only and is not ported (L9).

Story-only helper CodeDiffSample (_story-helpers/CodeDiffSample.tsx), the composition written once so the recipe, the Panel's approval report and the Chat with an agent recipe do not repeat it:

Prop Type Default Purpose
className string none Additional class names.
copyButtonLabel string none Aria-label and tooltip of each diff's copy button.
files CodeDiffSampleFile[] required The changed files, one expandable row each.
hasBorder boolean (the Panel List's) true Outside border; passed to the Panel List.
hasCopyButton boolean false Copy button on each diff (the Code Block's).
paddingSize '2xs' | 'xs' | 's' | 'm' | 'l' (the Panel List's) '2xs' Block padding of each row; the Panel List's own default is m.

CodeDiffSampleFile: diff (required, unified diff text), id (required), name (required), additions and deletions (optional; the File Diff shows when both are set), expandButtonLabel (optional; the row's expand button name, to be given translated).

Variants and states: one list, rows collapsed by default (the package Panel Row starts collapsed). Options: hasBorder, paddingSize, the copy button, with or without the File Diff, one file or several.

Tokens used

From _story-helpers/code-diff-sample.css as it is now. All story-only; the recipe has no component CSS, so read this as the compact-row styling to copy, not as tokens to port:

  • --pds-spacing-2xl (row minimum height, 2rem)
  • --pds-spacing-2xs (gap between the file icon and name)
  • --pds-spacing-s (row side padding, 0.75rem)
  • --pds-typography-ff-code (file name)
  • --pds-typography-size-s (file name, 0.875rem)

Raw value kept: the stats width, 7.5rem, a width for the File Diff slot (not listed in custom.md; see the lead note in the report). Check not rerun in this pass.

Impact

From impact.md: no existing PDS component is reached and no other proposal depends on it. Note: the sample's rules, scoped to .code-diff-sample, override .pds-panel-row and .pds-panel-row__main; they apply only inside a Code Diff sample. The generated impact.md does not list them because the CSS lives in _story-helpers/. Two other stories use the helper (the Panel's approval report and the Chat with an agent recipe), so a change to the helper changes both.

Reused vs net-new

  • Reused, from the package (beta.21): PanelList, PanelRow, CodeBlock, FileDiff. Reused, local: the Icon wrapper (../Icon/Icon, only for the fileDiff icon at size='s'; the package Icon also has fileDiff).
  • Net-new: none, recipe (the sample's code-diff-sample classes are story-only). See custom.md.

Accessibility

a11y panel not run; light and dark not checked by eye; keyboard not tested in a browser. What the code does:

  • Each row's expand button takes expandButtonLabel (given to the Panel Row as expandButtonAriaLabel), which should name the file ("Show changes to composer.json"). Panel Row owns the expand and collapse semantics (aria-expanded on the button) and keyboard behavior. The label does not change between expanded and collapsed; the state comes from aria-expanded.
  • The copy button takes copyButtonLabel for its name and tooltip, and is off by default.
  • Diff colors come from the package's Code Block syntax tokens (--pds-color-code-block-syntax-inserted and -deleted). Added and removed lines are also marked by the + and - characters in the unified diff text, so color is not the only cue; whether they read clearly in light and dark is not checked.
  • The file name is truncated with an ellipsis (text-overflow) and has no tooltip or full-name fallback; the expand button's label carries the full name.
  • Not run: axe in light and dark.

Decisions and open questions

Each carries a recommendation (the designer decides; the first two are changes to a PDS component, not to this recipe).

  • Initially expanded rows. The reference shows rows already expanded, but the package Panel Row starts collapsed and has no prop for it at beta.21. Recommendation: add an isDefaultExpanded prop to Panel Row (default false).
  • Row size. A size prop on Panel Row or Panel List would remove the CSS overrides. Recommendation: make the Panel List's paddingSize also set the row's inline padding and minimum height, or accept the package's 48px and 20px and drop compactness.
  • Narrow containers. At the Panel Row's default stackBelow='m' the name and the File Diff stack when the row is under 48rem wide (container query), so in a chat drawer the compact one-line row will not hold. The sample does not set stackBelow. Recommendation: pass stackBelow='s' (30rem) in the sample and check it in the chat drawer; whether that is narrow enough is not checked.
  • File icon. fileDiff is a guess from the reference; it exists in the package at beta.21. Recommendation: keep it unless the designer wants another.
  • Diff colors. Check that the added, removed and hunk-header colors match the reference. Recommendation: keep the package's tokens; do not add a diff color of our own.

Extension or new component

None, recipe: not a component and not an extension. The one thing that would be an extension is the Panel Row isDefaultExpanded above, and that is a request to PDS, not part of this recipe.

Footprint

  • The recipe draws nothing outside its box. The Panel Row has overflow: hidden, and its expand button is absolutely positioned (right: 0, top: 0 stacked, or centered on the row side by side) inside .pds-panel-row__main. The override sets that block's minimum height to --pds-spacing-2xl (2rem); if the expand button is taller than that, the row's overflow: hidden would clip it. The button's height was not measured (not verified).
  • The stats slot is a fixed 7.5rem wide; very long counts would not fit it. Not checked.
  • The file name is min-width: 0 with an ellipsis inside a flex row, so it shrinks before the stats do; it needs the Panel Row's left slot to be allowed to shrink. Not checked in a narrow parent.
  • The diff text sits in the Code Block inside the Panel Row's items-below area, which the package hides and shows with inline styles. A parent with a fixed height would clip an expanded diff. The Code Block has a maxHeight prop (not set here); how it scrolls was not checked.
  • The side-by-side and stacked layouts depend on the row's own width, not the viewport (see Narrow containers).
  • Next-to-neighbors check: not done.

Dark mode and per-size values

Value Source Light Dark
Row side padding --pds-spacing-s (package default is --pds-spacing-l, 20px) 0.75rem same (no per-theme override)
Row minimum height --pds-spacing-2xl (package default 3rem) 2rem same
Row block padding Panel List paddingSize, default 2xs 0.5rem same
File icon to name gap --pds-spacing-2xs 0.5rem same
File name size --pds-typography-size-s, --pds-typography-ff-code 0.875rem same
File Diff slot width raw 7.5rem 7.5rem same
Diff added and removed colors package --pds-color-code-block-syntax-inserted, -deleted #a0f76e, #f8495d #a0f76e, #f8495d (same in both token files)

Single size; the only size control is paddingSize. No colors of its own: the file name, row and expand button take the Panel Row's colors, which switch with the theme. Not checked by eye in either theme.

Expect to change

  1. Compact-row overrides of Panel Row internals (.pds-panel-row side padding, .pds-panel-row__main minimum height: private class names and a private 3rem). Recommendation: the engineer may add a size option on Panel List or ignore compactness; either way, do not port the override rules. Prefer a prop over a selector.
  2. paddingSize default of 2xs in the sample, while the Panel List's default is m. Recommendation: keep the default in the package and pass paddingSize='2xs' where this recipe is used.
  3. File Diff shown only when both additions and deletions are set. Two optional numbers where "both or neither" is implied. Recommendation: helper-only, so keep; do not carry it into a component API.
  4. isDefaultExpanded on Panel Row (above). Recommendation: default off, flat boolean, the toolkit's is* naming.
  5. Story-only helper with its own props (CodeDiffSample). Recommendation: do not port it as a component; copy the composition into the screen that needs it.

Not an issue: the expand button's name is a top-level translatable prop on the row (expandButtonAriaLabel), not a field inside another prop's object (L3).

Target-version check

Checked against .pds-reference/src at v2.0.0-beta.21.

Item In beta.21?
PanelList hasBorder, paddingSize (2xs to l) yes
PanelRow isExpandable, expandButtonAriaLabel, slots items-left, items-right, items-below yes
PanelRow stackBelow (s, m, l, xl, default m) yes (new since the old handoff was written against beta.18; the sample does not set it)
PanelRow isDefaultExpanded or any default-expanded prop no
CodeBlock language='diff', hasCopyButton, copyButtonLabel yes
FileDiff additions, deletions yes
Icon fileDiff yes
--pds-color-code-block-syntax-inserted, -deleted yes (light and dark token files)

CHANGELOG.mdx has no entry that adds an expanded-by-default option to Panel Row.

Port notes

Nothing to port as a component. Copy the composition from _story-helpers/CodeDiffSample.tsx where it is needed (the nearest home is next to Panel List in src/components/panels/, if the team wants it as a component later; then use npm run generate:component). Swap the local Icon wrapper and the local mergeClasses stand-in for the real ones. Keep the story as documentation; for a recipe, keep tags: ['!manifest'] on the story if its variants are not useful alone, and do not put it on the .mdx <Meta>.

Preview

npm run storybook, then Recipes/Code diff (stories Default, SingleFile; Usage page Usage).

Figma: https://www.figma.com/design/AMGWJbraJoi2PKWnxo29Ah/PDS-Proposals?node-id=374-46