Skip to content

Commit e08074f

Browse files
committed
feat: add diff viewer component
1 parent a4f784c commit e08074f

File tree

7 files changed

+171
-25
lines changed

7 files changed

+171
-25
lines changed

package-lock.json

Lines changed: 59 additions & 25 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
"fast-json-patch": "^3.1.1",
9898
"jsonpath-plus": "^10.0.0",
9999
"react-dates": "^21.8.0",
100+
"react-diff-viewer-continued": "^3.4.0",
100101
"react-monaco-editor": "^0.54.0",
101102
"sass": "^1.69.7",
102103
"tslib": "2.7.0"
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import ReactDiffViewer, { DiffMethod } from 'react-diff-viewer-continued'
2+
import { diffViewerStyles } from './constants'
3+
import { DiffViewerProps } from './types'
4+
5+
const DiffViewer = ({ oldValue, newValue, leftTitle, rightTitle }: DiffViewerProps) => (
6+
<ReactDiffViewer
7+
splitView
8+
oldValue={oldValue}
9+
newValue={newValue}
10+
useDarkTheme={false}
11+
leftTitle={leftTitle}
12+
rightTitle={rightTitle}
13+
compareMethod={DiffMethod.WORDS}
14+
styles={diffViewerStyles}
15+
/>
16+
)
17+
18+
export default DiffViewer
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
// Default variables and style keys
2+
3+
import { ReactDiffViewerProps } from 'react-diff-viewer-continued'
4+
5+
export const diffViewerStyles: ReactDiffViewerProps['styles'] = {
6+
variables: {
7+
light: {
8+
diffViewerBackground: 'var(--N0)',
9+
diffViewerColor: 'var(--N900)',
10+
addedBackground: 'var(--G50)',
11+
addedColor: 'var(--N900)',
12+
removedBackground: 'var(--R50)',
13+
removedColor: 'var(--N900)',
14+
wordAddedBackground: 'var(--G200)',
15+
wordRemovedBackground: 'var(--R200)',
16+
addedGutterBackground: 'var(--G100)',
17+
removedGutterBackground: 'var(--R100)',
18+
gutterBackground: 'var(--N50)',
19+
gutterBackgroundDark: 'var(--N50)',
20+
highlightBackground: 'var(--N100)',
21+
highlightGutterBackground: 'var(--N100)',
22+
codeFoldGutterBackground: 'var(--B100)',
23+
codeFoldBackground: 'var(--B50)',
24+
emptyLineBackground: 'var(--N0)',
25+
gutterColor: 'var(--N500)',
26+
addedGutterColor: 'var(--N700)',
27+
removedGutterColor: 'var(--N700)',
28+
codeFoldContentColor: 'var(--B600)',
29+
diffViewerTitleBackground: 'var(--N100)',
30+
diffViewerTitleColor: 'var(--N700)',
31+
diffViewerTitleBorderColor: 'var(--N200)',
32+
},
33+
},
34+
diffContainer: {
35+
fontSize: '13px',
36+
fontWeight: 400,
37+
lineHeight: '20px',
38+
39+
pre: {
40+
lineHeight: '20px',
41+
fontFamily: 'Inconsolata, monospace',
42+
},
43+
},
44+
marker: {
45+
pre: {
46+
display: 'none',
47+
},
48+
},
49+
gutter: {
50+
padding: `0 6px`,
51+
minWidth: '36px',
52+
53+
pre: {
54+
opacity: 1,
55+
},
56+
},
57+
wordDiff: {
58+
padding: 0,
59+
},
60+
wordAdded: {
61+
paddingInline: '2px',
62+
},
63+
wordRemoved: {
64+
paddingInline: '2px',
65+
},
66+
codeFold: {
67+
fontSize: '13px',
68+
fontWeight: 400,
69+
lineHeight: '20px',
70+
height: '32px',
71+
72+
a: {
73+
textDecoration: 'none !important',
74+
},
75+
},
76+
titleBlock: {
77+
padding: '8px 12px',
78+
fontSize: '12px',
79+
lineHeight: '20px',
80+
fontWeight: 600,
81+
borderBottom: 'none',
82+
83+
pre: {
84+
fontFamily: 'Open Sans',
85+
},
86+
},
87+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default as DiffViewer } from './DiffViewer.component'
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { ReactDiffViewerProps } from 'react-diff-viewer-continued'
2+
3+
export interface DiffViewerProps
4+
extends Pick<ReactDiffViewerProps, 'oldValue' | 'newValue' | 'leftTitle' | 'rightTitle'> {}

src/Shared/Components/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ export * from './Collapse'
5757
export * from './Security'
5858
export * from './Button'
5959
export * from './InvalidYAMLTippy'
60+
export * from './DiffViewer'

0 commit comments

Comments
 (0)