1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
// @ts-nocheck
import * as mod from "./diff"
import { create } from "../storybook/scaffold"
import { diff } from "../storybook/fixtures"
const docs = `### Overview
Render a code diff with OpenCode styling using the Pierre diff engine.
Pair with \`DiffChanges\` for summary counts.
Use \`LineComment\` or external UI for annotation workflows.
### API
- Required: \`before\` and \`after\` file contents (name + contents).
- Optional: \`diffStyle\` ("unified" | "split"), \`annotations\`, \`selectedLines\`, \`commentedLines\`.
- Optional interaction: \`enableLineSelection\`, \`onLineSelectionEnd\`.
- Passes through Pierre FileDiff options (see component source).
### Variants and states
- Unified and split diff styles.
- Optional line selection + commented line highlighting.
### Behavior
- Re-renders when \`before\`/\`after\` or diff options change.
- Line selection uses mouse drag/selection when enabled.
### Accessibility
- TODO: confirm keyboard behavior from the Pierre diff engine.
- Provide surrounding labels or headings when used as a standalone view.
### Theming/tokens
- Uses \`data-component="diff"\` and Pierre CSS variables from \`styleVariables\`.
- Colors derive from theme tokens (diff add/delete, background, text).
`
const story = create({
title: "UI/Diff",
mod,
args: {
before: diff.before,
after: diff.after,
diffStyle: "unified",
},
})
export default {
title: "UI/Diff",
id: "components-diff",
component: story.meta.component,
tags: ["autodocs"],
parameters: {
docs: {
description: {
component: docs,
},
},
},
argTypes: {
diffStyle: {
control: "select",
options: ["unified", "split"],
},
enableLineSelection: {
control: "boolean",
},
},
}
export const Unified = story.Basic
export const Split = {
args: {
diffStyle: "split",
},
}
export const Selectable = {
args: {
enableLineSelection: true,
},
}
export const SelectedLines = {
args: {
selectedLines: { start: 2, end: 4 },
},
}
export const CommentedLines = {
args: {
commentedLines: [
{ start: 1, end: 1 },
{ start: 4, end: 4 },
],
},
}
|