← 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/CodeDiff.mdx41 lines · View on GitHub
import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';

import * as CodeDiffStories from './CodeDiff.stories';

<Meta of={CodeDiffStories} name='Usage' />

<Title />

## Purpose

Shows the files an agent (or a person) changed, each expandable to its diff.

## Usage

This is a recipe, not a component. Use it wherever a change needs review: the proposed fix in an approval report, the result of an edit in a chat, a list of changed files on a branch. Each file is one row. Collapsed rows keep the list short; expand a row to read its diff.

Do not use it for a single code sample with no file context (use the Code Block), or to compare two versions of content that is not code (use Content Diff).

## Accessibility

- Each row's expand button is a native button with `aria-expanded`, owned by the Panel Row. Give it a label that names the file, such as "Show changes to composer.json", and provide it translated.
- The copy button, when on, needs a label (`copyButtonLabel`).
- Added and removed lines are marked by the `+` and `-` characters in the diff text as well as by color, so color is not the only cue.
- Not checked: the a11y panel has not been run, and light and dark have not been checked by eye.

## Implementation

It is the PDS Panel List with expandable Panel Rows, from the package:

- the file name (with a `fileDiff` icon) is the row's `items-left` slot, in the code font;
- the PDS File Diff (counts and bar) is the `items-right` slot, shown when the file has counts;
- the Code Block with `language='diff'` is the `items-below` slot, with an optional copy button. Pass each file's diff as unified diff text; the Code Block colors added and removed lines;
- the Panel List takes `paddingSize='2xs'`, and the story's CSS gives the rows a smaller side padding and minimum height to keep the list compact. The Panel Row sets those itself and no prop changes them, so the override is story-only.

The story's sample helper (`_story-helpers/CodeDiffSample`) writes the composition once; the engineer copies it. See the Panel List page for the row slots and props.

<hr />

<Canvas of={CodeDiffStories.Default} />
<Controls of={CodeDiffStories.Default} />