@@ -31,7 +31,7 @@ export interface ReactDiffViewerProps {
3131 // Enable/Disable word diff.
3232 disableWordDiff ?: boolean ;
3333 // JsDiff text diff method from https://github.com/kpdecker/jsdiff/tree/v4.0.1#api
34- compareMethod ?: string ;
34+ compareMethod ?: DiffMethod ;
3535 // Number of unmodified lines surrounding each line diff.
3636 extraLinesSurroundingDiff ?: number ;
3737 // Show/hide line number.
@@ -55,6 +55,12 @@ export interface ReactDiffViewerProps {
5555 highlightLines ?: string [ ] ;
5656 // Style overrides.
5757 styles ?: ReactDiffViewerStylesOverride ;
58+ // Use dark theme.
59+ useDarkTheme ?: boolean ;
60+ // Title for left column
61+ leftTitle ?: string | JSX . Element ;
62+ // Title for left column
63+ rightTitle ?: string | JSX . Element ;
5864}
5965
6066export interface ReactDiffViewerState {
@@ -76,6 +82,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
7682 hideLineNumbers : false ,
7783 extraLinesSurroundingDiff : 3 ,
7884 showDiffOnly : true ,
85+ useDarkTheme : false ,
7986 } ;
8087
8188 public static propTypes = {
@@ -91,6 +98,14 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
9198 hideLineNumbers : PropTypes . bool ,
9299 showDiffOnly : PropTypes . bool ,
93100 highlightLines : PropTypes . arrayOf ( PropTypes . string ) ,
101+ leftTitle : PropTypes . oneOfType ( [
102+ PropTypes . string ,
103+ PropTypes . element ,
104+ ] ) ,
105+ rightTitle : PropTypes . oneOfType ( [
106+ PropTypes . string ,
107+ PropTypes . element ,
108+ ] ) ,
94109 } ;
95110
96111 public constructor ( props : ReactDiffViewerProps ) {
@@ -136,6 +151,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
136151 */
137152 private computeStyles : (
138153 styles : ReactDiffViewerStylesOverride ,
154+ useDarkTheme : boolean ,
139155 ) => ReactDiffViewerStyles = memoize ( computeStyles ) ;
140156
141157 /**
@@ -228,7 +244,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
228244 [ this . styles . highlightedGutter ] : highlightLine ,
229245 } ) }
230246 >
231- < pre > { lineNumber } </ pre >
247+ < pre className = { this . styles . lineNumber } > { lineNumber } </ pre >
232248 </ td >
233249 ) }
234250 { ! this . props . splitView && ! this . props . hideLineNumbers && (
@@ -244,7 +260,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
244260 [ this . styles . highlightedGutter ] : highlightLine ,
245261 } ) }
246262 >
247- < pre > { additionalLineNumber } </ pre >
263+ < pre className = { this . styles . lineNumber } > { additionalLineNumber } </ pre >
248264 </ td >
249265 ) }
250266 < td
@@ -261,14 +277,14 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
261277 </ pre >
262278 </ td >
263279 < td
264- className = { cn ( {
280+ className = { cn ( this . styles . content , {
265281 [ this . styles . emptyLine ] : ! content ,
266282 [ this . styles . diffAdded ] : added ,
267283 [ this . styles . diffRemoved ] : removed ,
268284 [ this . styles . highlightedLine ] : highlightLine ,
269285 } ) }
270286 >
271- < pre > { content } </ pre >
287+ < pre className = { this . styles . contentText } > { content } </ pre >
272288 </ td >
273289 </ React . Fragment >
274290 ) ;
@@ -399,7 +415,7 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
399415 const message = this . props . codeFoldMessageRenderer
400416 ? this . props
401417 . codeFoldMessageRenderer ( num , leftBlockLineNumber , rightBlockLineNumber )
402- : < pre > Expand { num } lines ...</ pre > ;
418+ : < pre className = { this . styles . codeFoldContent } > Expand { num } lines ...</ pre > ;
403419 const content = (
404420 < td >
405421 < a onClick = { this . onBlockClickProxy ( blockNumber ) } tabIndex = { 0 } >
@@ -489,18 +505,36 @@ class DiffViewer extends React.Component<ReactDiffViewerProps, ReactDiffViewerSt
489505 }
490506
491507 public render = ( ) : JSX . Element => {
492- const { oldValue, newValue } = this . props ;
508+ const {
509+ oldValue,
510+ newValue,
511+ useDarkTheme,
512+ leftTitle,
513+ rightTitle,
514+ splitView,
515+ } = this . props ;
493516
494517 if ( typeof oldValue !== 'string' || typeof newValue !== 'string' ) {
495518 throw Error ( '"oldValue" and "newValue" should be strings' ) ;
496519 }
497520
498- this . styles = this . computeStyles ( this . props . styles ) ;
521+ this . styles = this . computeStyles ( this . props . styles , useDarkTheme ) ;
499522 const nodes = this . renderDiff ( ) ;
500523
524+ const title = ( leftTitle || rightTitle )
525+ && < tr >
526+ < td colSpan = { splitView ? 3 : 5 } className = { this . styles . titleBlock } > { leftTitle } </ td >
527+ { splitView
528+ && < td colSpan = { 3 } className = { this . styles . titleBlock } > { rightTitle } </ td >
529+ }
530+ </ tr > ;
531+
501532 return (
502533 < table className = { this . styles . diffContainer } >
503- < tbody > { nodes } </ tbody >
534+ < tbody >
535+ { title }
536+ { nodes }
537+ </ tbody >
504538 </ table >
505539 ) ;
506540 } ;
0 commit comments