@hi-ui/highlighter 4.1.0-alpha.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @hi-ui/highlighter
2
2
 
3
+ ## 4.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#3102](https://github.com/XiaoMi/hiui/pull/3102) [`414c96a86`](https://github.com/XiaoMi/hiui/commit/414c96a86c6311c5b103733749092108cad03760) Thanks [@zyprepare](https://github.com/zyprepare)! - feat(highlighter): keyword 参数支持传入正则表达式 (#3075)
8
+
9
+ - [#3103](https://github.com/XiaoMi/hiui/pull/3103) [`13b169670`](https://github.com/XiaoMi/hiui/commit/13b16967026f8389cc66315d376ef77029f4ba2b) Thanks [@zyprepare](https://github.com/zyprepare)! - feat(highlighter): 支持设置高亮样式 (#3076)
10
+
3
11
  ## 4.0.9
4
12
 
5
13
  ### Patch Changes
@@ -32,9 +32,11 @@ var Highlighter = /*#__PURE__*/React.forwardRef(function (_a, ref) {
32
32
  prefixCls = _a$prefixCls === void 0 ? HIGHLIGHTER_PREFIX : _a$prefixCls,
33
33
  className = _a.className,
34
34
  keyword = _a.keyword,
35
+ highlightClassName = _a.highlightClassName,
36
+ highlightStyle = _a.highlightStyle,
35
37
  _a$children = _a.children,
36
38
  children = _a$children === void 0 ? null : _a$children,
37
- rest = tslib.__rest(_a, ["prefixCls", "className", "keyword", "children"]);
39
+ rest = tslib.__rest(_a, ["prefixCls", "className", "keyword", "highlightClassName", "highlightStyle", "children"]);
38
40
  var startIndex = React.useRef(0);
39
41
  if (!keyword) return children;
40
42
  if (typeof children !== 'string') return children;
@@ -55,7 +57,8 @@ var Highlighter = /*#__PURE__*/React.forwardRef(function (_a, ref) {
55
57
  acc.push(part);
56
58
  acc.push( /*#__PURE__*/React__default["default"].createElement("span", {
57
59
  key: index,
58
- className: prefixCls + "--matched"
60
+ className: prefixCls + "--matched " + highlightClassName,
61
+ style: highlightStyle
59
62
  }, children.substring(startIndex.current, startIndex.current + matched.length)));
60
63
  startIndex.current += matched.length;
61
64
  return acc;
@@ -20,9 +20,11 @@ var Highlighter = /*#__PURE__*/forwardRef(function (_a, ref) {
20
20
  prefixCls = _a$prefixCls === void 0 ? HIGHLIGHTER_PREFIX : _a$prefixCls,
21
21
  className = _a.className,
22
22
  keyword = _a.keyword,
23
+ highlightClassName = _a.highlightClassName,
24
+ highlightStyle = _a.highlightStyle,
23
25
  _a$children = _a.children,
24
26
  children = _a$children === void 0 ? null : _a$children,
25
- rest = __rest(_a, ["prefixCls", "className", "keyword", "children"]);
27
+ rest = __rest(_a, ["prefixCls", "className", "keyword", "highlightClassName", "highlightStyle", "children"]);
26
28
  var startIndex = useRef(0);
27
29
  if (!keyword) return children;
28
30
  if (typeof children !== 'string') return children;
@@ -43,7 +45,8 @@ var Highlighter = /*#__PURE__*/forwardRef(function (_a, ref) {
43
45
  acc.push(part);
44
46
  acc.push( /*#__PURE__*/React.createElement("span", {
45
47
  key: index,
46
- className: prefixCls + "--matched"
48
+ className: prefixCls + "--matched " + highlightClassName,
49
+ style: highlightStyle
47
50
  }, children.substring(startIndex.current, startIndex.current + matched.length)));
48
51
  startIndex.current += matched.length;
49
52
  return acc;
@@ -9,4 +9,12 @@ export interface HighlighterProps extends HiBaseHTMLProps<'span'> {
9
9
  * 匹配高亮关键词
10
10
  */
11
11
  keyword?: string | RegExp;
12
+ /**
13
+ * 高亮类名
14
+ */
15
+ highlightClassName?: string;
16
+ /**
17
+ * 高亮样式
18
+ */
19
+ highlightStyle?: React.CSSProperties;
12
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hi-ui/highlighter",
3
- "version": "4.1.0-alpha.0",
3
+ "version": "4.1.0",
4
4
  "description": "A sub-package for @hi-ui/hiui.",
5
5
  "keywords": [],
6
6
  "author": "HiUI <mi-hiui@xiaomi.com>",