diff.stories.tsx 2.1 KB

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