Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# react-diff-component

Highlights differences between two strings, uses the [diff](https://www.npmjs.com/package/diff) module based on (https://github.com/cezary/react-diff)
Highlights differences between two strings, uses the [diff](https://www.npmjs.com/package/diff) module based on (https://github.com/Lefortov/react-diff)

## Installation

Expand All @@ -24,4 +24,4 @@ const Component = () => (

## License

MIT
MIT
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.3"
},
"author": "Lefortov",
"homepage": "https://github.com/Lefortov/react-diff",
"author": "Kunal",
"homepage": "https://github.com/kunalvashist/react-diff.git",
"repository": {
"type": "git",
"url": "git@github.com:Lefortov/react-diff.git"
"url": "git@github.com:kunalvashist/react-diff.git"
},
"dependencies": {
"diff": "^3.5.0"
Expand Down
13 changes: 10 additions & 3 deletions src/lib/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,21 @@ const getUntouchedRow = (value) => {
</Fragment>
};

const Diff = ({ inputA, inputB, type, options }) => {
const Diff = ({ inputA, inputB, type, highlight, options }) => {
index = 0;
const diff = fnMap[type](inputA, inputB, options);
const result = diff.map((part) => {
const result = diff.map((part, index) => {
if(highlight){
var className = part.added ? 'lightgreen' : part.removed ? 'salmon' : 'lightgrey';
return React.createElement('span', { key: index, className: className }, part.value);
}
else{
return part.added ?
getAddedRow(part.value) :
part.removed ?
getRemovedRow(part.value) :
getUntouchedRow(part.value);
}
});
return (
<pre className='diff-result'>
Expand All @@ -91,7 +97,8 @@ const Diff = ({ inputA, inputB, type, options }) => {
Diff.defaultProps = {
inputA: '',
inputB: '',
type: 'chars'
type: 'chars',
highlight: true
};

Diff.types = types;
Expand Down