From c00462912344d441a1d491313230064eb096a6a7 Mon Sep 17 00:00:00 2001 From: Kimmo Saari Date: Wed, 31 Jan 2024 08:05:07 +0200 Subject: [PATCH] feat: add `hideMarkers` (#37) Co-authored-by: Bart Riepe --- README.md | 3 ++- src/index.tsx | 46 +++++++++++++++++++++++++++++----------------- 2 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 1689494..c5bbf58 100644 --- a/README.md +++ b/README.md @@ -76,7 +76,8 @@ class Diff extends PureComponent { | compareMethod | `DiffMethod` | `DiffMethod.CHARS` | JsDiff text diff method used for diffing strings. Check out the [guide](https://github.com/praneshr/react-diff-viewer/tree/v3.0.0#text-block-diff-comparison) to use different methods. | | renderGutter | `(diffData) => ReactNode` | `undefined` | Function that can be used to render an extra gutter with various information next to the line number. | | hideLineNumbers | `boolean` | `false` | Show and hide line numbers. | -| alwaysShowLines | `string[]` | `[]` | List of lines to always be shown, regardless of diff status. 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. `extraLinesSurroundingDiff` applies to these lines as well. | +| hideMarkers | `boolean` | `false` | Show and hide `+`/`-` markers. | +| alwaysShowLines | `string[]` | `[]` | List of lines to always be shown, regardless of diff status. 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. `extraLinesSurroundingDiff` applies to these lines as well. | | renderContent | `function` | `undefined` | Render Prop API to render code in the diff viewer. Helpful for [syntax highlighting](#syntax-highlighting) | | onLineNumberClick | `function` | `undefined` | Event handler for line number click. `(lineId: string) => void` | | highlightLines | `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. | diff --git a/src/index.tsx b/src/index.tsx index 7cd9468..acf17e4 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -33,6 +33,8 @@ export interface ReactDiffViewerProps { extraLinesSurroundingDiff?: number; // Show/hide line number. hideLineNumbers?: boolean; + // Show/hide `+`/`-` markers. + hideMarkers?: boolean; /** * Show the lines indicated here. Specified as L20 or R18 for respectively line 20 on the left or line 18 on the right. */ @@ -96,6 +98,7 @@ class DiffViewer extends React.Component< compareMethod: DiffMethod.CHARS, styles: {}, hideLineNumbers: false, + hideMarkers: false, extraLinesSurroundingDiff: 3, showDiffOnly: true, useDarkTheme: false, @@ -272,20 +275,22 @@ class DiffViewer extends React.Component< styles: this.styles, }) : null} - -
-            {added && '+'}
-            {removed && '-'}
-          
- + {!this.props.hideMarkers && ( + +
+              {added && '+'}
+              {removed && '-'}
+            
+ + )}