@@ -2,24 +2,19 @@ require('./style.scss');
22import * as React from 'react' ;
33import * as ReactDOM from 'react-dom' ;
44
5- import ReactDiff from '../../lib/index' ;
5+ import ReactDiff , { DiffMethod } from '../../lib/index' ;
66
7- const oldJson = require ( './diff/json/old.json' ) ;
8- const newJson = require ( './diff/json/new.json' ) ;
9- const oldXml = require ( './diff/xml/old.xml' ) . default ;
10- const newXml = require ( './diff/xml/new.xml' ) . default ;
117const oldJs = require ( './diff/javascript/old.rjs' ) . default ;
128const newJs = require ( './diff/javascript/new.rjs' ) . default ;
139
1410const logo = require ( '../../logo.png' ) ;
15- const logoStandalone = require ( '../../logo-standalone.png' ) ;
1611
1712interface ExampleState {
1813 splitView ?: boolean ;
1914 highlightLine ?: string [ ] ;
2015 language ?: string ;
2116 enableSyntaxHighlighting ?: boolean ;
22- compareMethod ?: string ;
17+ compareMethod ?: DiffMethod ;
2318}
2419
2520const P = ( window as any ) . Prism ;
@@ -28,28 +23,11 @@ class Example extends React.Component<{}, ExampleState> {
2823 public constructor ( props : any ) {
2924 super ( props ) ;
3025 this . state = {
31- splitView : true ,
3226 highlightLine : [ ] ,
33- language : 'javascript' ,
3427 enableSyntaxHighlighting : true ,
35- compareMethod : 'diffChars'
3628 } ;
3729 }
3830
39- private toggleSyntaxHighlighting = ( ) : void =>
40- this . setState ( {
41- enableSyntaxHighlighting : ! this . state . enableSyntaxHighlighting ,
42- } ) ;
43-
44- private onChange = ( ) : void =>
45- this . setState ( { splitView : ! this . state . splitView } ) ;
46-
47- private onLanguageChange = ( e : any ) : void =>
48- this . setState ( { language : e . target . value , highlightLine : [ ] } ) ;
49-
50- private onCompareMethodChange = ( e : any ) : void =>
51- this . setState ( { compareMethod : e . target . value } ) ;
52-
5331 private onLineNumberClick = (
5432 id : string ,
5533 e : React . MouseEvent < HTMLTableCellElement > ,
@@ -74,66 +52,18 @@ class Example extends React.Component<{}, ExampleState> {
7452
7553 private syntaxHighlight = ( str : string ) : any => {
7654 if ( ! str ) return ;
77- let language ;
78- switch ( this . state . language ) {
79- case 'xml' :
80- language = P . highlight ( str , P . languages . markup ) ;
81- break ;
82- case 'json' :
83- language = P . highlight ( str , P . languages . json ) ;
84- break ;
85- case 'javascript' :
86- language = P . highlight ( str , P . languages . javascript ) ;
87- break ;
88- default :
89- break ;
90- }
55+ const language = P . highlight ( str , P . languages . javascript ) ;
9156 return < span dangerouslySetInnerHTML = { { __html : language } } /> ;
9257 } ;
9358
9459 public render ( ) : JSX . Element {
95- let oldValue ;
96- let newValue ;
9760
98- switch ( this . state . language ) {
99- case 'xml' :
100- oldValue = oldXml ;
101- newValue = newXml ;
102- break ;
103- case 'json' :
104- oldValue = JSON . stringify ( oldJson , null , 4 ) ;
105- newValue = JSON . stringify ( newJson , null , 4 ) ;
106- break ;
107- case 'javascript' :
108- oldValue = oldJs ;
109- newValue = newJs ;
110- break ;
111- default :
112- break ;
113- }
114-
115- switch ( this . state . language ) {
116- case 'xml' :
117- oldValue = oldXml ;
118- newValue = newXml ;
119- break ;
120- case 'json' :
121- oldValue = JSON . stringify ( oldJson , null , 4 ) ;
122- newValue = JSON . stringify ( newJson , null , 4 ) ;
123- break ;
124- case 'javascript' :
125- oldValue = oldJs ;
126- newValue = newJs ;
127- break ;
128- default :
129- break ;
130- }
13161 return (
13262 < div className = "react-diff-viewer-example" >
63+ < div className = "radial" > </ div >
13364 < div className = "banner" >
13465 < div className = "img-container" >
13566 < img src = { logo } alt = "React Diff Viewer Logo" />
136- < img src = { logoStandalone } alt = "React Diff Viewer Logo" className = "mobile" />
13767 </ div >
13868 < p >
13969 A simple and beautiful text diff viewer made with{ ' ' }
@@ -152,84 +82,19 @@ class Example extends React.Component<{}, ExampleState> {
15282 Documentation
15383 </ button >
15484 </ a >
155- < a href = "https://github.com/praneshr/react-diff-viewer" >
156- < button type = "button" className = "btn btn-primary btn-lg" >
157- Github
158- </ button >
159- </ a >
16085 </ div >
16186 </ div >
162- < div className = "controls" >
163- < span >
164- < label htmlFor = "js_diff_compare_method" > JsDiff Compare Method</ label >
165- { ' ' }
166- (< a href = "https://github.com/kpdecker/jsdiff/tree/v4.0.1#api" > Learn More</ a > )
167- { ' ' }
168- < select
169- name = "js_diff_compare_method"
170- id = "js_diff_compare_method"
171- onChange = { this . onCompareMethodChange }
172- value = { this . state . compareMethod }
173- >
174- < option value = "disabled" > DISABLE</ option >
175- < option value = "diffChars" > diffChars</ option >
176- < option value = "diffWords" > diffWords</ option >
177- < option value = "diffWordsWithSpace" > diffWordsWithSpace</ option >
178- < option value = "diffLines" > diffLines</ option >
179- < option value = "diffTrimmedLines" > diffTrimmedLines</ option >
180- < option value = "diffCss" > diffCss</ option >
181- < option value = "diffSentences" > diffSentences</ option >
182- </ select >
183- </ span >
184- < span >
185- < label htmlFor = "language" > Language</ label >
186- { ' ' }
187- < select
188- name = "language"
189- id = "language"
190- onChange = { this . onLanguageChange }
191- value = { this . state . language }
192- >
193- < option value = "json" > JSON</ option >
194- < option value = "xml" > XML</ option >
195- < option value = "javascript" > Javascript</ option >
196- </ select >
197- </ span >
198- < span >
199- < label >
200- < input
201- type = "checkbox"
202- name = "toggle-2"
203- id = "toggle-2"
204- onChange = { this . toggleSyntaxHighlighting }
205- checked = { this . state . enableSyntaxHighlighting }
206- /> { ' ' }
207- Syntax Highlighting
208- </ label >
209- < label >
210- < input
211- type = "checkbox"
212- name = "toggle-1"
213- id = "toggle-1"
214- onChange = { this . onChange }
215- checked = { this . state . splitView }
216- /> { ' ' }
217- Split View
218- </ label >
219- </ span >
220- </ div >
22187 < div className = "diff-viewer" >
22288 < ReactDiff
223- disableWordDiff = { this . state . compareMethod === 'disabled' }
224- compareMethod = { this . state . compareMethod }
22589 highlightLines = { this . state . highlightLine }
22690 onLineNumberClick = { this . onLineNumberClick }
227- oldValue = { oldValue }
228- splitView = { this . state . splitView }
229- newValue = { newValue }
230- renderContent = {
231- this . state . enableSyntaxHighlighting && this . syntaxHighlight
232- }
91+ oldValue = { oldJs }
92+ splitView
93+ newValue = { newJs }
94+ renderContent = { this . syntaxHighlight }
95+ useDarkTheme
96+ leftTitle = "webpack.config.js master@2178133 - pushed 2 hours ago."
97+ rightTitle = "webpack.config.js master@64207ee - pushed 13 hours ago."
23398 />
23499 </ div >
235100 < footer >
0 commit comments