-
Notifications
You must be signed in to change notification settings - Fork 14
/
index.js
45 lines (41 loc) · 1.04 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import React from 'react';
import PropTypes from 'prop-types';
import diffHelper, { defaultOptions, genPrettyHtml } from './utils';
import {
branch,
compose,
defaultProps,
mapProps,
onlyUpdateForPropTypes,
setPropTypes
} from 'recompose';
import 'diff2html/bundles/css/diff2html.min.css';
const RenderDiffResult = ({ genDiffHTML }) => (
<div dangerouslySetInnerHTML={{ __html: genDiffHTML }} />
);
const ReactGhLikeDiff = compose(
defaultProps({
diffString: '',
past: '',
current: '',
options: defaultOptions
}),
onlyUpdateForPropTypes,
setPropTypes({
past: PropTypes.string,
current: PropTypes.string,
options: PropTypes.object,
diffString: PropTypes.string
}),
branch(
({ diffString }) => diffString.length !== 0,
() => props => <RenderDiffResult genDiffHTML={genPrettyHtml(props)} />,
mapProps(props => ({
genDiffHTML: diffHelper(props)
}))
)
)(RenderDiffResult);
RenderDiffResult.propTypes = {
genDiffHTML: PropTypes.string
};
export { RenderDiffResult, ReactGhLikeDiff };