DocsComponentsTemplatesThemesGitHub

DiffView

Unified diff of a proposed code change with +/− counts.

Code

import * as React from 'react';
import { DiffView } from '@fruit-labs/design';

export default function Demo() {
  return (
    <div
      style={{
        maxWidth: 560,
      }}
    >
      <DiffView
        filename="src/billing/charge.ts"
        lines={[
          ' export async function charge(id) {',
          '-  const amount = getAmount(id)',
          '+  const amount = await getAmount(id)',
          "+  if (!amount) throw new Error('No amount')",
          '   return stripe.charge(amount)',
          ' }',
        ]}
      />
    </div>
  );
}

Install

From npm:

npm install @fruit-labs/design

import { DiffView } from '@fruit-labs/design';

Or copy the TypeScript source into your project:

npx shadcn@latest add https://design.fruitlabs.online/r/diff-view.json

Guidelines

  • Pair with an ApprovalCard before applying edits.

Props

PropTypeRequired
linesstring[]
each starts with '+', '-' or ' '
Yes
filenamestringNo
classNamestringNo

Edit this example on GitHub