File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ import * as Diff from "diff" ;
2
+ import "../styles/ComparatorDiff.css" ;
3
+
4
+ type Props = {
5
+ previous : string ;
6
+ current : string ;
7
+ } ;
8
+
9
+ export const ComparatorDiff = ( props : Props ) => {
10
+ const diff = Diff . diffWordsWithSpace ( props . previous , props . current ) ;
11
+ return (
12
+ < >
13
+ { diff . map ( ( part : any , i : number ) => (
14
+ < span
15
+ key = { `${ part . value } -${ i } ` }
16
+ className = {
17
+ part . added ? "text-addition" : part . removed ? "text-removal" : ""
18
+ }
19
+ >
20
+ { part . value }
21
+ </ span >
22
+ ) ) }
23
+ </ >
24
+ ) ;
25
+ } ;
Original file line number Diff line number Diff line change
1
+ .text-addition {
2
+ background-color : # acf2bd ;
3
+ }
4
+
5
+ .text-removal {
6
+ background-color : # fdb8c0 ;
7
+ text-decoration : line-through;
8
+ text-decoration-thickness : -2px ;
9
+ }
You can’t perform that action at this time.
0 commit comments