You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+38-24Lines changed: 38 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -1,19 +1,22 @@
1
-
> I'm working on the new version of React Diff Viewer. It will be a full code and design refresh. If you feel something should be added, please create an issue.
A simple and beautiful text diff viewer component made with [Diff](https://github.com/kpdecker/jsdiff) and [React](https://reactjs.org).
13
18
14
-
A simple and beautiful text diff viewer made with [Diff](https://github.com/kpdecker/jsdiff) and [React](https://reactjs.org).
15
-
16
-
Inspired from Github's diff viewer, it includes features like split view, unified view, word diff and line highlight. It is highly customizable and it supports almost all languages. Check out the [demo](https://praneshravi.in/react-diff-viewer/).
19
+
Inspired from Github's diff viewer, it includes features like split view, inline view, word diff, line highlight and more. It is highly customizable and it supports almost all languages. Check out the [demo](https://praneshravi.in/react-diff-viewer/).
17
20
18
21
## Install
19
22
@@ -68,15 +71,22 @@ class Diff extends PureComponent {
|splitView |`boolean`|`true`|Switch between `unified` and `split` view. |
73
76
|disableWordDiff |`boolean`|`false`|Show and hide word diff in a diff line. |
74
77
|hideLineNumbers |`boolean`|`false`|Show and hide line numbers. |
75
78
|renderContent |`function`|`undefined`|Render Prop API to render code in the diff viewer. Helpful for [syntax highlighting](#syntax-highlighting)|
76
79
|onLineNumberClick |`function`|`undefined`|Event handler for line number click. `(lineId: string) => void`|
77
-
|hightlightLines |`array[string]`|`[]`|List of lines to be highlighted. Works together with `onLineNumberClick`. Line number are prefixed with `L` and `R` for the left and right section of the diff viewer, respectively. For example, `L-20` means 20th line in the left pane. To highlight a range of line numbers, pass the prefixed line number as an array. For example, `[L-2, L-3, L-4, L-5]` will highlight the lines `2-5` in the left pane. |
80
+
|highlightLines |`array[string]`|`[]`|List of lines to be highlighted. Works together with `onLineNumberClick`. Line number are prefixed with `L` and `R` for the left and right section of the diff viewer, respectively. For example, `L-20` means 20th line in the left pane. To highlight a range of line numbers, pass the prefixed line number as an array. For example, `[L-2, L-3, L-4, L-5]` will highlight the lines `2-5` in the left pane. |
81
+
|showDiffOnly |`boolean`|`true`|Shows only the diffed lines and folds the unchanged lines|
82
+
|extraLinesSurroundingDiff|`number`|`3`|Number of extra unchanged lines surrounding the diff. Works along with `showDiffOnly`.|
83
+
|codeFoldMessageRenderer|`function`|`Expand {number} of lines ...`|Render Prop API to render code fold message.|
78
84
|styles |`object`|`{}`|To override style variables and styles. Learn more about [overriding styles](#overriding-styles)|
79
85
86
+
## Instance Methods
87
+
88
+
`resetCodeBlocks()` - Resets the expanded code blocks to it's initial state. Return `true` on successful reset and `false` during unsuccessful reset.
89
+
80
90
## Syntax Highlighting
81
91
82
92
Syntax highlighting is a bit tricky when combined with diff. Here, React Diff Viewer provides a simple render prop API to handle syntax highlighting. Use `renderContent(content: string) => JSX.Element` and your favorite syntax highlighting library to acheive this.
@@ -147,6 +157,7 @@ Below are the default style variables and style object keys.
147
157
148
158
constdefaultStyles= {
149
159
variables: {
160
+
diffViewerBackground:'#fff',
150
161
addedBackground:'#e6ffed',
151
162
addedColor:'#24292e',
152
163
removedBackground:'#ffeef0',
@@ -159,26 +170,29 @@ const defaultStyles = {
159
170
gutterBackgroundDark:'#f3f1f1',
160
171
highlightBackground:'#fffbdd',
161
172
highlightGutterBackground:'#fff5b1',
173
+
codeFoldGutterBackground:'#dbedff',
174
+
codeFoldBackground:'#f1f8ff',
175
+
emptyLineBackground:'#fafbfc',
162
176
},
163
-
diffContainer: {}, //style object
164
-
diffRemoved: {}, //style object
165
-
diffAdded: {}, //style object
166
-
marker: {}, //style object
167
-
gutter: {}, //style object
168
-
leftGutter: {}, //style object
169
-
rightGutter: {}, //style object
170
-
hightlightedLine: {}, //style object
171
-
hightlightedGutter: {}, //style object
172
-
line: {}, //style object
173
-
wordDiff: {}, //style object
174
-
wordAdded: {}, //style object
175
-
wordRemoved: {}, //style object
177
+
diffContainer?: {}, //style object
178
+
diffRemoved?: {}, //style object
179
+
diffAdded?: {}, //style object
180
+
marker?: {}, //style object
181
+
highlightedLine?: {}, //style object
182
+
highlightedGutter?: {}, //style object
183
+
gutter?: {}, //style object
184
+
line?: {}, //style object
185
+
wordDiff?: {}, //style object
186
+
wordAdded?: {}, //style object
187
+
wordRemoved?: {}, //style object
188
+
codeFoldGutter?: {}, //style object
189
+
emptyLine?: {}, //style object
176
190
}
177
191
```
178
192
179
193
To override any style, just pass the new style object to the `styles` prop. New style will be computed using `Object.assign(default, override)`.
180
194
181
-
For keys other than `variables`, the value can either be an object or string interpolation. Emotion's dynamic styles are not yet supported.
195
+
For keys other than `variables`, the value can either be an object or string interpolation.
0 commit comments