import { Canvas, Controls, Meta, Title } from '@storybook/addon-docs/blocks';
import * as ContentDiffStories from './ContentDiff.stories';
<Meta of={ContentDiffStories} name='Usage' />
<Title />
## Purpose
Shows what changes in a piece of content: the current value and the new one, stacked like a text diff.
## Usage
- Use it for text and other content an agent proposes to change, such as page copy. Use the Code diff recipe for code.
- The old value (`before`) is on a red line with a minus, the new value (`after`) on a green line with a plus. Color is not the only cue: the minus and plus carry the meaning too.
- `beforeLabel` and `afterLabel` name the two values for screen readers ("Before", "After"). They are visually hidden, and required so they can be translated.
- It is a definition list, so give it a name from the screen around it (for example the field it belongs to). The Suggestion Card's `SuggestionChange` does that: it puts the field name above a Content Diff.
- `size` sets the text: `s` (default) or `xs`. Only the text changes; the minus and plus icons keep their size.
- Not for code: use the Code diff recipe. Keep the values to plain text; the block clips its content (`overflow: hidden`), so anything that draws outside a line, such as a focus ring or tooltip, would be cut off.
## Accessibility
- The block is a definition list (`dl`). Each value has a visually hidden term (`dt`) from `beforeLabel` or `afterLabel`, so a screen reader announces "Before" then the old value, then "After" then the new value. Provide both labels translated.
- The minus and plus icons are hidden from assistive technology (`aria-hidden`); the hidden terms carry the meaning. For sighted users the icons mean the same, so color is not the only cue.
- The `dl` has no role or label of its own. Name it from the screen around it, for example the field it belongs to.
- Nothing in it is interactive, so there is no tab stop or keyboard behavior, and nothing is announced when the values change.
- Contrast comes from the status tokens (foreground on background) and follows the theme. The Storybook a11y panel result is not recorded for this proposal (not checked).
## Implementation
See the table below for the available props.
<hr />
<Canvas of={ContentDiffStories.Default} />
<Controls of={ContentDiffStories.Default} />
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