-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathHighlighter.js
51 lines (45 loc) · 1.12 KB
/
Highlighter.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
46
47
48
49
50
51
/**
* Highlighter
*/
import React from 'react';
import PropTypes from 'prop-types';
import ReactHighlightWords from 'react-highlight-words';
import css from './Highlighter.css';
const HighlightMark = ({ children, className }) => (
<mark className={className.trim() || css.mark} data-test-highlighter-mark>{children}</mark>
);
HighlightMark.propTypes = {
children: PropTypes.node,
className: PropTypes.string,
};
const Highlighter = ({
autoEscape = true,
className,
highlightClassName,
searchWords = [],
sanitize,
style,
text = '',
}) => (
<ReactHighlightWords
data-test-highlighter
autoEscape={autoEscape}
className={className}
highlightTag={HighlightMark}
highlightClassName={highlightClassName}
sanitize={sanitize}
searchWords={searchWords}
style={style}
textToHighlight={text}
/>
);
Highlighter.propTypes = {
autoEscape: PropTypes.bool,
className: PropTypes.string,
highlightClassName: PropTypes.string,
sanitize: PropTypes.func,
searchWords: PropTypes.arrayOf(PropTypes.string),
style: PropTypes.object,
text: PropTypes.string,
};
export default Highlighter;