Open History to see the last commit
1import React from "react"
2import { diffLines } from "diff"
3
4interface DiffViewProps {
5 oldValue: unknown
6 newValue: unknown
7}
8
9export function DiffView({ oldValue, newValue }: DiffViewProps) {
10 const diff = diffLines(
11 JSON.stringify(oldValue, null, 2),
12 JSON.stringify(newValue, null, 2)
13 )
14
15 return (
16 <pre className="text-sm font-mono bg-gray-50 p-2 rounded overflow-auto">
17 {diff.map((part, index) => (
18 <div
19 key={index}
20 className={`${
21 part.added
22 ? `bg-green-50 text-green-800 border-l-4 border-green-500`
23 : part.removed
24 ? `bg-red-50 text-red-800 border-l-4 border-red-500`
25 : `text-gray-800`
26 } px-2 whitespace-pre`}
27 >
28 {part.added ? `+ ` : part.removed ? `- ` : ` `}
29 {part.value}
30 </div>
31 ))}
32 </pre>
33 )
34}