@alicloud/console-components-search 0.2.1 → 0.2.2

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.
@@ -1 +1 @@
1
- html body .xconsole-rcsearch-multi-pop .next-select-menu-item{padding-left:0!important}html body .xconsole-rcsearch-multi-pop .next-select-menu-item .next-menu-icon-selected{display:none}html body .xconsole-rcsearch-multi-pop .next-menu-group-label{padding-left:0}html body .xconsole-rc-search-popup{margin-top:4px}
1
+ html body .xconsole-rcsearch-multi-pop.xconsole-rcsearch-multi-pop>ul{padding:8px}html body .xconsole-rcsearch-multi-pop .next-select-menu-item{padding-left:0!important}html body .xconsole-rcsearch-multi-pop .next-select-menu-item .next-menu-icon-selected{display:none}html body .xconsole-rcsearch-multi-pop .next-menu-group-label{padding-left:0}html body .xconsole-rc-search-popup{margin-top:4px}html .console-tags-tag.console-tags-tag{font-weight:600;color:var(--color-text1-9,#333)!important}html .console-tags-tag.console-tags-tag .console-tags-tag-label{color:var(--color-text1-6,grey);margin-right:8px}html .console-tags-tag.console-tags-tag[class*=tag-closable]>[class*=tag-close-btn]{margin-left:12px}html .console-tags-tag.console-tags-tag.console-tags-tag.console-tags-tag:hover [class*=-icon-close]{color:#181818}html .console-tags-tag.console-tags-tag.console-tags-tag.console-tags-tag [class*=-icon-close]:before{content:var(--icon-content-delete-filling)}html .console-tags-tag:not(:last-child){margin-right:8px}html .console-tags-tag_empty{color:var(--color-text1-6,grey)}html .console-tags-tag-dot.console-tags-tag-dot [class*=-badge-dot]{right:4px;top:0}
@@ -1,13 +1,13 @@
1
1
  开始构建微应用external依赖...
2
2
  BreezrPluginStyledComponentsIsolation The plugin will trying to use the package's name as isolation id of styled-components. This behavior usually occurred on dev mode. And if you were received this warning on publish mode then you should to set `options.styledComponentStyleSheetId` implicitly.
3
3
  ℹ Compiling Webpack
4
- ✔ Webpack: Compiled successfully in 14.67s
4
+ ✔ Webpack: Compiled successfully in 12.79s
5
5
  WARN asset size limit: The following asset(s) exceed the recommended size limit (244 KiB).
6
6
  This can impact web performance.
7
7
  Assets:
8
- main.js (2.46 MiB),entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
8
+ main.js (2.49 MiB),entrypoint size limit: The following entrypoint(s) combined asset size exceeds the recommended limit (244 KiB). This can impact web performance.
9
9
  Entrypoints:
10
- main (2.46 MiB)
10
+ main (2.49 MiB)
11
11
  main.css
12
12
  main.js
13
13
  ,webpack performance recommendations:
package/es/constants.js CHANGED
@@ -3,4 +3,7 @@ export var baseTagListClassName = "".concat(baseClassName, "-taglist"); // expor
3
3
  // export const titleContainerClassName = `${titleClassName}-container`
4
4
  // export const titleExtraClassName = `${titleClassName}-extra`
5
5
  // export const titleChildrenClassName = `${titleClassName}-children`
6
- // export const contentClassName = `${baseClassName}-content`
6
+ // export const contentClassName = `${baseClassName}-content`
7
+
8
+ export var SEARCH_FILTER_FIELD = 'filterInputValue';
9
+ export var SEARCH_FILTER_VALUE_FIELD = 'searchValue';
@@ -15,6 +15,7 @@ import React, { useState, useRef } from "react";
15
15
  import { Button, Icon, Select, ConfigProvider, Field, Checkbox } from '@alicloud/console-components';
16
16
  import { SearchWarp, MultiBtnWarp } from "../style";
17
17
  import SearchConditionSelectPrefix from "./InputPrefix";
18
+ import { SEARCH_FILTER_FIELD, SEARCH_FILTER_VALUE_FIELD } from "../constants";
18
19
  var AutoComplete = Select.AutoComplete;
19
20
  /**
20
21
  *
@@ -68,12 +69,9 @@ var normalizeSearchOptions = function normalizeSearchOptions(dataIndex, value, o
68
69
  }
69
70
 
70
71
  if ((opt === null || opt === void 0 ? void 0 : opt.template) === 'multiple') {
71
- var _opt$templateProps2, _opt$templateProps3;
72
+ var _opt$templateProps2;
72
73
 
73
- console.log((_opt$templateProps2 = opt.templateProps) === null || _opt$templateProps2 === void 0 ? void 0 : _opt$templateProps2.dataSource.filter(function (d) {
74
- return value.indexOf(d.value) !== -1;
75
- }));
76
- valueLabel = (_opt$templateProps3 = opt.templateProps) === null || _opt$templateProps3 === void 0 ? void 0 : _opt$templateProps3.dataSource.filter(function (d) {
74
+ valueLabel = (_opt$templateProps2 = opt.templateProps) === null || _opt$templateProps2 === void 0 ? void 0 : _opt$templateProps2.dataSource.filter(function (d) {
77
75
  return value.indexOf(d.value) !== -1;
78
76
  }).map(function (d) {
79
77
  return d.label;
@@ -88,6 +86,18 @@ var normalizeSearchOptions = function normalizeSearchOptions(dataIndex, value, o
88
86
  };
89
87
  };
90
88
 
89
+ var highlightKeyword = function highlightKeyword(value, keywords) {
90
+ var idx = value.toLowerCase().indexOf(keywords.toLowerCase());
91
+ var startValue = value.slice(0, idx);
92
+ var highlightValue = value.slice(idx, idx + keywords.length);
93
+ var endValue = value.slice(idx + keywords.length);
94
+ return /*#__PURE__*/React.createElement(React.Fragment, null, startValue, /*#__PURE__*/React.createElement("span", {
95
+ style: {
96
+ color: 'var(--color-brand1-6)'
97
+ }
98
+ }, highlightValue), endValue);
99
+ };
100
+
91
101
  var ComplexSearch = function ComplexSearch(props) {
92
102
  var options = props.options,
93
103
  fuzzy = props.fuzzy,
@@ -125,14 +135,25 @@ var ComplexSearch = function ComplexSearch(props) {
125
135
  }
126
136
  }; //计算视图,根据内部状态和输入的 props 决定一些值
127
137
 
128
- var isFuzzy = (!!defaultDataIndex || fuzzy) && !!getValue('filterInputValue');
138
+ var isFuzzy = (!!defaultDataIndex || fuzzy) && !!getValue(SEARCH_FILTER_FIELD);
129
139
  var defaultFilter = options.find(function (t) {
130
140
  return t.dataIndex === defaultDataIndex;
131
141
  });
142
+
143
+ var highlightItem = function highlightItem(item, searchKey) {
144
+ var label = item.label;
145
+
146
+ if (searchKey && searchKey.length) {
147
+ label = highlightKeyword(item.label, searchKey);
148
+ }
149
+
150
+ return label;
151
+ };
132
152
  /**
133
153
  * 处理筛选类型选中的情况
134
154
  */
135
155
 
156
+
136
157
  var handlerFilterTypeChange = function handlerFilterTypeChange(type) {
137
158
  var resetValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
138
159
  setSelectedFilterType(options.find(function (o) {
@@ -146,7 +167,7 @@ var ComplexSearch = function ComplexSearch(props) {
146
167
 
147
168
 
148
169
  var handlerFilterTypeInput = function handlerFilterTypeInput(value, actionType, isFuzzy) {
149
- var isFuzzySearch = isFuzzy && getValue('filterInputValue'); // 如果是模糊搜索,则直接处理
170
+ var isFuzzySearch = isFuzzy && getValue(SEARCH_FILTER_FIELD); // 如果是模糊搜索,则直接处理
150
171
 
151
172
  if (isFuzzySearch) {
152
173
  if (actionType !== 'change') {
@@ -169,10 +190,10 @@ var ComplexSearch = function ComplexSearch(props) {
169
190
 
170
191
  var handleSearch = function handleSearch() {
171
192
  if (onSearch) {
172
- var value = getValue('searchValue');
193
+ var value = getValue(SEARCH_FILTER_VALUE_FIELD);
173
194
 
174
195
  if (defaultDataIndex && !selectedFilterType) {
175
- onSearch(getValue('filterInputValue'), defaultDataIndex, normalizeSearchOptions(defaultDataIndex, getValue('filterInputValue'), options));
196
+ onSearch(getValue(SEARCH_FILTER_FIELD), defaultDataIndex, normalizeSearchOptions(defaultDataIndex, getValue(SEARCH_FILTER_FIELD), options));
176
197
  }
177
198
 
178
199
  if (selectedFilterType) {
@@ -181,6 +202,7 @@ var ComplexSearch = function ComplexSearch(props) {
181
202
  }
182
203
 
183
204
  reset();
205
+ document.body.click();
184
206
  setFocused(false);
185
207
  };
186
208
 
@@ -192,7 +214,7 @@ var ComplexSearch = function ComplexSearch(props) {
192
214
  };
193
215
 
194
216
  var renderMultipleSelectorItem = function renderMultipleSelectorItem(item) {
195
- var searchValue = getValue('searchValue');
217
+ var searchValue = getValue(SEARCH_FILTER_VALUE_FIELD);
196
218
  var checked = isArray(searchValue) && searchValue.some(function (v) {
197
219
  return v === item.value;
198
220
  });
@@ -205,7 +227,7 @@ var ComplexSearch = function ComplexSearch(props) {
205
227
  var _selectedFilterType$t, _selectedFilterType$t2;
206
228
 
207
229
  var type = selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template;
208
- var searchValue = getValue('searchValue');
230
+ var searchValue = getValue(SEARCH_FILTER_VALUE_FIELD);
209
231
 
210
232
  var props = _objectSpread({
211
233
  hasBorder: false,
@@ -225,7 +247,7 @@ var ComplexSearch = function ComplexSearch(props) {
225
247
 
226
248
  switch (type) {
227
249
  case 'input':
228
- return /*#__PURE__*/React.createElement(AutoComplete, _extends({}, init('searchValue', {}), {
250
+ return /*#__PURE__*/React.createElement(AutoComplete, _extends({}, init(SEARCH_FILTER_VALUE_FIELD, {}), {
229
251
  className: classNames('main-input', 'multi')
230
252
  }, props, {
231
253
  onKeyUp: handleKeyUp
@@ -234,7 +256,7 @@ var ComplexSearch = function ComplexSearch(props) {
234
256
  case 'select':
235
257
  return /*#__PURE__*/React.createElement(Select, _extends({
236
258
  className: classNames('main-input', 'select')
237
- }, init('searchValue', {
259
+ }, init(SEARCH_FILTER_VALUE_FIELD, {
238
260
  props: {
239
261
  onChange: handleSearch
240
262
  }
@@ -243,7 +265,7 @@ var ComplexSearch = function ComplexSearch(props) {
243
265
  case 'multiple':
244
266
  return /*#__PURE__*/React.createElement(Select, _extends({
245
267
  className: classNames('main-input', 'multi')
246
- }, init('searchValue', {}), props, selectProps, {
268
+ }, init(SEARCH_FILTER_VALUE_FIELD, {}), props, selectProps, {
247
269
  itemRender: renderMultipleSelectorItem,
248
270
  popupClassName: "xconsole-rcsearch-multi-pop",
249
271
  mode: "multiple",
@@ -265,6 +287,7 @@ var ComplexSearch = function ComplexSearch(props) {
265
287
  type: "normal",
266
288
  onClick: function onClick() {
267
289
  reset();
290
+ document.body.click();
268
291
  }
269
292
  }, "\u53D6\u6D88"))
270
293
  }
@@ -276,7 +299,7 @@ var ComplexSearch = function ComplexSearch(props) {
276
299
  };
277
300
 
278
301
  var renderSelectFilterCloseIcon = function renderSelectFilterCloseIcon() {
279
- var hasFilterTypeClearBtn = !!selectedFilterType && !((selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template) === 'input' && !!getValue('searchValue'));
302
+ var hasFilterTypeClearBtn = !!selectedFilterType && !((selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template) === 'input' && !!getValue(SEARCH_FILTER_VALUE_FIELD));
280
303
  return hasFilterTypeClearBtn && /*#__PURE__*/React.createElement("div", {
281
304
  className: "clear-level1"
282
305
  }, /*#__PURE__*/React.createElement("span", {
@@ -310,7 +333,7 @@ var ComplexSearch = function ComplexSearch(props) {
310
333
  }
311
334
  }) : null), /*#__PURE__*/React.createElement("div", {
312
335
  className: classNames('forms')
313
- }, !selectedFilterType ? /*#__PURE__*/React.createElement(AutoComplete, _extends({}, init('filterInputValue', {
336
+ }, !selectedFilterType ? /*#__PURE__*/React.createElement(AutoComplete, _extends({}, init(SEARCH_FILTER_FIELD, {
314
337
  props: {
315
338
  // @ts-ignore
316
339
  onChange: function onChange(value, actionType) {
@@ -318,7 +341,8 @@ var ComplexSearch = function ComplexSearch(props) {
318
341
  }
319
342
  }
320
343
  }), {
321
- ref: autoRef,
344
+ // @ts-ignore
345
+ itemRender: highlightItem,
322
346
  placeholder: placeholder ? placeholder : defaultFilter !== null && defaultFilter !== void 0 && defaultFilter.label ? "\u9ED8\u8BA4\u6309".concat(defaultFilter === null || defaultFilter === void 0 ? void 0 : defaultFilter.label, "\u641C\u7D22") : '请搜索',
323
347
  className: classNames('main-input', 'multi'),
324
348
  hasBorder: false,
@@ -330,7 +354,8 @@ var ComplexSearch = function ComplexSearch(props) {
330
354
  width: 'auto'
331
355
  }
332
356
  }, focusProps)) : null, renderSelectedFilter(), renderSelectFilterCloseIcon())), /*#__PURE__*/React.createElement("div", {
333
- className: classNames('right-wrap')
357
+ className: classNames('right-wrap'),
358
+ ref: autoRef
334
359
  }, /*#__PURE__*/React.createElement(Button, {
335
360
  className: classNames('search-btn', {
336
361
  'focus': focused
@@ -0,0 +1,57 @@
1
+ import _extends from "@babel/runtime/helpers/esm/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["intl", "tagKey", "disableTruncate", "showDot", "tagValue", "showLabel", "closable"];
4
+ import React from 'react';
5
+ import { Tag, Badge } from '@alicloud/console-components';
6
+ import Truncate from '@alicloud/console-components-truncate';
7
+
8
+ var Empty = function Empty(_ref) {
9
+ var children = _ref.children;
10
+ return /*#__PURE__*/React.createElement(React.Fragment, null, children);
11
+ };
12
+
13
+ var PureTag = function PureTag(props) {
14
+ var intl = props.intl,
15
+ tagKey = props.tagKey,
16
+ disableTruncate = props.disableTruncate,
17
+ showDot = props.showDot,
18
+ tagValue = props.tagValue,
19
+ showLabel = props.showLabel,
20
+ _props$closable = props.closable,
21
+ closable = _props$closable === void 0 ? true : _props$closable,
22
+ resetProps = _objectWithoutProperties(props, _excluded);
23
+
24
+ var defaultTruncateProps = {
25
+ threshold: 20,
26
+ showTooltip: false
27
+ };
28
+ var TruncateWrapper = disableTruncate ? Empty : Truncate;
29
+ var DotWrapper = showDot ? Badge : Empty;
30
+ var TagWrapper = closable ? Tag.Closeable : Tag;
31
+ var transformedTagValue = tagValue;
32
+
33
+ if (tagValue === '') {
34
+ transformedTagValue = '空值';
35
+ } else if (tagValue === undefined || tagValue === null) {
36
+ transformedTagValue = '全部值';
37
+ }
38
+
39
+ return (
40
+ /*#__PURE__*/
41
+ //@ts-ignore
42
+ React.createElement(DotWrapper, {
43
+ title: "\u5373\u5C06\u65B0\u5EFA",
44
+ className: "console-tags-tag-dot",
45
+ dot: true
46
+ }, /*#__PURE__*/React.createElement(TagWrapper, _extends({
47
+ title: "".concat(tagKey, ":").concat(tagValue),
48
+ className: "console-tags-tag"
49
+ }, resetProps), showLabel && /*#__PURE__*/React.createElement("label", {
50
+ className: "console-tags-tag-label"
51
+ }, "\u6807\u7B7E"), /*#__PURE__*/React.createElement(TruncateWrapper, defaultTruncateProps, tagKey), ":", tagValue ? /*#__PURE__*/React.createElement(TruncateWrapper, defaultTruncateProps, tagValue) : /*#__PURE__*/React.createElement("span", {
52
+ className: "console-tags-tag_empty"
53
+ }, transformedTagValue)))
54
+ );
55
+ };
56
+
57
+ export default PureTag;
@@ -4,6 +4,7 @@ import classNames from 'classnames';
4
4
  import { ConfigProvider, Tag } from '@alicloud/console-components';
5
5
  import { TagListWrap } from '../style';
6
6
  import { baseTagListClassName } from '../constants';
7
+ import PureTag from "./PureTag";
7
8
  var TagGroup = Tag.Group,
8
9
  ClosableTag = Tag.Closeable;
9
10
 
@@ -12,6 +13,7 @@ var SearchTagList = function SearchTagList(props) {
12
13
  className = props.className,
13
14
  style = props.style,
14
15
  onChange = props.onChange,
16
+ onClear = props.onClear,
15
17
  _props$prefix = props.prefix,
16
18
  prefix = _props$prefix === void 0 ? "next-" : _props$prefix;
17
19
 
@@ -22,14 +24,14 @@ var SearchTagList = function SearchTagList(props) {
22
24
  var resFindIndex = newTagList.findIndex(function (x) {
23
25
  return x.dataIndex === item.dataIndex;
24
26
  });
25
- newTagList.splice(resFindIndex, 1);
26
- onChange(newTagList);
27
+ var deletedTags = newTagList.splice(resFindIndex, 1);
28
+ onChange(deletedTags[0], newTagList);
27
29
  }
28
30
  }
29
31
 
30
32
  function onRemoveAllTag() {
31
- if (onChange) {
32
- onChange([]);
33
+ if (onClear) {
34
+ onClear();
33
35
  }
34
36
  }
35
37
 
@@ -38,7 +40,24 @@ var SearchTagList = function SearchTagList(props) {
38
40
  className: classNames(baseTagListClassName, className),
39
41
  style: style
40
42
  }, /*#__PURE__*/React.createElement(TagGroup, null, dataSource && dataSource.length > 0 && dataSource.map(function (tagItem) {
43
+ var value = tagItem.value;
44
+ var isTag = !!value.tagKey;
45
+
46
+ if (isTag) {
47
+ return /*#__PURE__*/React.createElement(PureTag, {
48
+ showLabel: true,
49
+ tagKey: value.tagKey,
50
+ tagValue: value.tagKey,
51
+ closable: true,
52
+ onClose: function onClose() {
53
+ onRemoveTag(tagItem);
54
+ return true;
55
+ }
56
+ });
57
+ }
58
+
41
59
  return /*#__PURE__*/React.createElement(ClosableTag, {
60
+ className: "console-tags-tag",
42
61
  key: tagItem.dataIndex + tagItem.value,
43
62
  type: "normal",
44
63
  size: "medium",
@@ -46,7 +65,9 @@ var SearchTagList = function SearchTagList(props) {
46
65
  onRemoveTag(tagItem);
47
66
  return true;
48
67
  }
49
- }, tagItem.label, ":", tagItem.valueLabel);
68
+ }, /*#__PURE__*/React.createElement("label", {
69
+ className: "console-tags-tag-label"
70
+ }, tagItem.label), tagItem.value || tagItem.valueLabel);
50
71
  }), dataSource && dataSource.length > 0 && /*#__PURE__*/React.createElement("a", {
51
72
  className: "remove-btn",
52
73
  onClick: onRemoveAllTag
package/es/style.js CHANGED
@@ -15,5 +15,5 @@ var MultiBtnWarp = styled.div.withConfig({
15
15
  })(["padding:\"0 4px\";text-align:\"center\";.pri-btn{margin-right:8px;width:auto;min-width:auto;padding:3px 12px;}.cancel-btn{padding:3px 12px;width:auto;min-width:auto;}", "btn", "small:not(.isOnlyIcon):not(", "btn-text){min-width:auto;}"], prefix, prefix, prefix);
16
16
  var TagListWrap = styled.div.withConfig({
17
17
  componentId: "sc-1afc1cn-3"
18
- })(["", "tag-medium", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:6px;}", "tag-medium", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:16px;}&& [class*='-icon-close']:hover::before{color:#181818;}&& [class*='-icon-close']::before{color:#808080;content:var(--icon-content-delete-filling);}.remove-btn{margin-bottom:8px;line-height:24px;display:inline-block;vertical-align:middle;cursor:pointer;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
18
+ })(["", "tag-medium", "tag-closable > ", "tag-close-btn{margin-left:8px;padding-right:6px;}", "tag-medium", "tag-closable > ", "tag-body{max-width:calc(100% - 8px - 8px - var(--tag-size-m-padding-lr,8px));}", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon:before,", "tag-medium", "tag-closable > ", "tag-close-btn ", "icon ", "icon-remote{font-size:16px;}&& [class*='-icon-close']:hover::before{color:#181818;}&& [class*='-icon-close']::before{color:#808080;font-size:12px !important;}.remove-btn{margin-bottom:8px;line-height:24px;display:inline-block;vertical-align:middle;cursor:pointer;}"], prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix, prefix);
19
19
  export { SearchWarp, MultiBtnWarp, TagListWrap, MenuContentWrap };
@@ -1,2 +1,4 @@
1
1
  export declare const baseClassName = "rc-search";
2
2
  export declare const baseTagListClassName: string;
3
+ export declare const SEARCH_FILTER_FIELD = "filterInputValue";
4
+ export declare const SEARCH_FILTER_VALUE_FIELD = "searchValue";
package/lib/constants.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.baseTagListClassName = exports.baseClassName = void 0;
6
+ exports.baseTagListClassName = exports.baseClassName = exports.SEARCH_FILTER_VALUE_FIELD = exports.SEARCH_FILTER_FIELD = void 0;
7
7
  var baseClassName = 'rc-search';
8
8
  exports.baseClassName = baseClassName;
9
9
  var baseTagListClassName = "".concat(baseClassName, "-taglist"); // export const titleClassName = `${baseClassName}-title`
@@ -12,4 +12,8 @@ var baseTagListClassName = "".concat(baseClassName, "-taglist"); // export const
12
12
  // export const titleChildrenClassName = `${titleClassName}-children`
13
13
  // export const contentClassName = `${baseClassName}-content`
14
14
 
15
- exports.baseTagListClassName = baseTagListClassName;
15
+ exports.baseTagListClassName = baseTagListClassName;
16
+ var SEARCH_FILTER_FIELD = 'filterInputValue';
17
+ exports.SEARCH_FILTER_FIELD = SEARCH_FILTER_FIELD;
18
+ var SEARCH_FILTER_VALUE_FIELD = 'searchValue';
19
+ exports.SEARCH_FILTER_VALUE_FIELD = SEARCH_FILTER_VALUE_FIELD;
package/lib/index.d.ts CHANGED
@@ -4,4 +4,5 @@ import { IRcSearchProps } from "./types/IRcSearchProps.type";
4
4
  import { IRcSearchTagListProps } from "./types/IRcSearchTagListProps.type";
5
5
  import { IRcSearchTagItemProps } from './types/IRcSearchTagItemProps.type';
6
6
  import { IRcSearchOptionsProps } from './types/IRcSearchOptions.type';
7
+ import './index.less';
7
8
  export { Search, SearchTagList as SearchFilter, IRcSearchProps, IRcSearchTagListProps, IRcSearchOptionsProps, IRcSearchTagItemProps };
@@ -33,6 +33,8 @@ var _style = require("../style");
33
33
 
34
34
  var _InputPrefix = _interopRequireDefault(require("./InputPrefix"));
35
35
 
36
+ var _constants = require("../constants");
37
+
36
38
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
37
39
 
38
40
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -94,12 +96,9 @@ var normalizeSearchOptions = function normalizeSearchOptions(dataIndex, value, o
94
96
  }
95
97
 
96
98
  if ((opt === null || opt === void 0 ? void 0 : opt.template) === 'multiple') {
97
- var _opt$templateProps2, _opt$templateProps3;
99
+ var _opt$templateProps2;
98
100
 
99
- console.log((_opt$templateProps2 = opt.templateProps) === null || _opt$templateProps2 === void 0 ? void 0 : _opt$templateProps2.dataSource.filter(function (d) {
100
- return value.indexOf(d.value) !== -1;
101
- }));
102
- valueLabel = (_opt$templateProps3 = opt.templateProps) === null || _opt$templateProps3 === void 0 ? void 0 : _opt$templateProps3.dataSource.filter(function (d) {
101
+ valueLabel = (_opt$templateProps2 = opt.templateProps) === null || _opt$templateProps2 === void 0 ? void 0 : _opt$templateProps2.dataSource.filter(function (d) {
103
102
  return value.indexOf(d.value) !== -1;
104
103
  }).map(function (d) {
105
104
  return d.label;
@@ -114,6 +113,18 @@ var normalizeSearchOptions = function normalizeSearchOptions(dataIndex, value, o
114
113
  };
115
114
  };
116
115
 
116
+ var highlightKeyword = function highlightKeyword(value, keywords) {
117
+ var idx = value.toLowerCase().indexOf(keywords.toLowerCase());
118
+ var startValue = value.slice(0, idx);
119
+ var highlightValue = value.slice(idx, idx + keywords.length);
120
+ var endValue = value.slice(idx + keywords.length);
121
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, startValue, /*#__PURE__*/_react.default.createElement("span", {
122
+ style: {
123
+ color: 'var(--color-brand1-6)'
124
+ }
125
+ }, highlightValue), endValue);
126
+ };
127
+
117
128
  var ComplexSearch = function ComplexSearch(props) {
118
129
  var options = props.options,
119
130
  fuzzy = props.fuzzy,
@@ -153,14 +164,25 @@ var ComplexSearch = function ComplexSearch(props) {
153
164
  }
154
165
  }; //计算视图,根据内部状态和输入的 props 决定一些值
155
166
 
156
- var isFuzzy = (!!defaultDataIndex || fuzzy) && !!getValue('filterInputValue');
167
+ var isFuzzy = (!!defaultDataIndex || fuzzy) && !!getValue(_constants.SEARCH_FILTER_FIELD);
157
168
  var defaultFilter = options.find(function (t) {
158
169
  return t.dataIndex === defaultDataIndex;
159
170
  });
171
+
172
+ var highlightItem = function highlightItem(item, searchKey) {
173
+ var label = item.label;
174
+
175
+ if (searchKey && searchKey.length) {
176
+ label = highlightKeyword(item.label, searchKey);
177
+ }
178
+
179
+ return label;
180
+ };
160
181
  /**
161
182
  * 处理筛选类型选中的情况
162
183
  */
163
184
 
185
+
164
186
  var handlerFilterTypeChange = function handlerFilterTypeChange(type) {
165
187
  var resetValue = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
166
188
  setSelectedFilterType(options.find(function (o) {
@@ -174,7 +196,7 @@ var ComplexSearch = function ComplexSearch(props) {
174
196
 
175
197
 
176
198
  var handlerFilterTypeInput = function handlerFilterTypeInput(value, actionType, isFuzzy) {
177
- var isFuzzySearch = isFuzzy && getValue('filterInputValue'); // 如果是模糊搜索,则直接处理
199
+ var isFuzzySearch = isFuzzy && getValue(_constants.SEARCH_FILTER_FIELD); // 如果是模糊搜索,则直接处理
178
200
 
179
201
  if (isFuzzySearch) {
180
202
  if (actionType !== 'change') {
@@ -197,10 +219,10 @@ var ComplexSearch = function ComplexSearch(props) {
197
219
 
198
220
  var handleSearch = function handleSearch() {
199
221
  if (onSearch) {
200
- var value = getValue('searchValue');
222
+ var value = getValue(_constants.SEARCH_FILTER_VALUE_FIELD);
201
223
 
202
224
  if (defaultDataIndex && !selectedFilterType) {
203
- onSearch(getValue('filterInputValue'), defaultDataIndex, normalizeSearchOptions(defaultDataIndex, getValue('filterInputValue'), options));
225
+ onSearch(getValue(_constants.SEARCH_FILTER_FIELD), defaultDataIndex, normalizeSearchOptions(defaultDataIndex, getValue(_constants.SEARCH_FILTER_FIELD), options));
204
226
  }
205
227
 
206
228
  if (selectedFilterType) {
@@ -209,6 +231,7 @@ var ComplexSearch = function ComplexSearch(props) {
209
231
  }
210
232
 
211
233
  reset();
234
+ document.body.click();
212
235
  setFocused(false);
213
236
  };
214
237
 
@@ -220,7 +243,7 @@ var ComplexSearch = function ComplexSearch(props) {
220
243
  };
221
244
 
222
245
  var renderMultipleSelectorItem = function renderMultipleSelectorItem(item) {
223
- var searchValue = getValue('searchValue');
246
+ var searchValue = getValue(_constants.SEARCH_FILTER_VALUE_FIELD);
224
247
  var checked = (0, _isArray.default)(searchValue) && searchValue.some(function (v) {
225
248
  return v === item.value;
226
249
  });
@@ -233,7 +256,7 @@ var ComplexSearch = function ComplexSearch(props) {
233
256
  var _selectedFilterType$t, _selectedFilterType$t2;
234
257
 
235
258
  var type = selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template;
236
- var searchValue = getValue('searchValue');
259
+ var searchValue = getValue(_constants.SEARCH_FILTER_VALUE_FIELD);
237
260
 
238
261
  var props = _objectSpread({
239
262
  hasBorder: false,
@@ -253,7 +276,7 @@ var ComplexSearch = function ComplexSearch(props) {
253
276
 
254
277
  switch (type) {
255
278
  case 'input':
256
- return /*#__PURE__*/_react.default.createElement(AutoComplete, (0, _extends2.default)({}, init('searchValue', {}), {
279
+ return /*#__PURE__*/_react.default.createElement(AutoComplete, (0, _extends2.default)({}, init(_constants.SEARCH_FILTER_VALUE_FIELD, {}), {
257
280
  className: (0, _classnames.default)('main-input', 'multi')
258
281
  }, props, {
259
282
  onKeyUp: handleKeyUp
@@ -262,7 +285,7 @@ var ComplexSearch = function ComplexSearch(props) {
262
285
  case 'select':
263
286
  return /*#__PURE__*/_react.default.createElement(_consoleComponents.Select, (0, _extends2.default)({
264
287
  className: (0, _classnames.default)('main-input', 'select')
265
- }, init('searchValue', {
288
+ }, init(_constants.SEARCH_FILTER_VALUE_FIELD, {
266
289
  props: {
267
290
  onChange: handleSearch
268
291
  }
@@ -271,7 +294,7 @@ var ComplexSearch = function ComplexSearch(props) {
271
294
  case 'multiple':
272
295
  return /*#__PURE__*/_react.default.createElement(_consoleComponents.Select, (0, _extends2.default)({
273
296
  className: (0, _classnames.default)('main-input', 'multi')
274
- }, init('searchValue', {}), props, selectProps, {
297
+ }, init(_constants.SEARCH_FILTER_VALUE_FIELD, {}), props, selectProps, {
275
298
  itemRender: renderMultipleSelectorItem,
276
299
  popupClassName: "xconsole-rcsearch-multi-pop",
277
300
  mode: "multiple",
@@ -293,6 +316,7 @@ var ComplexSearch = function ComplexSearch(props) {
293
316
  type: "normal",
294
317
  onClick: function onClick() {
295
318
  reset();
319
+ document.body.click();
296
320
  }
297
321
  }, "\u53D6\u6D88"))
298
322
  }
@@ -304,7 +328,7 @@ var ComplexSearch = function ComplexSearch(props) {
304
328
  };
305
329
 
306
330
  var renderSelectFilterCloseIcon = function renderSelectFilterCloseIcon() {
307
- var hasFilterTypeClearBtn = !!selectedFilterType && !((selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template) === 'input' && !!getValue('searchValue'));
331
+ var hasFilterTypeClearBtn = !!selectedFilterType && !((selectedFilterType === null || selectedFilterType === void 0 ? void 0 : selectedFilterType.template) === 'input' && !!getValue(_constants.SEARCH_FILTER_VALUE_FIELD));
308
332
  return hasFilterTypeClearBtn && /*#__PURE__*/_react.default.createElement("div", {
309
333
  className: "clear-level1"
310
334
  }, /*#__PURE__*/_react.default.createElement("span", {
@@ -338,7 +362,7 @@ var ComplexSearch = function ComplexSearch(props) {
338
362
  }
339
363
  }) : null), /*#__PURE__*/_react.default.createElement("div", {
340
364
  className: (0, _classnames.default)('forms')
341
- }, !selectedFilterType ? /*#__PURE__*/_react.default.createElement(AutoComplete, (0, _extends2.default)({}, init('filterInputValue', {
365
+ }, !selectedFilterType ? /*#__PURE__*/_react.default.createElement(AutoComplete, (0, _extends2.default)({}, init(_constants.SEARCH_FILTER_FIELD, {
342
366
  props: {
343
367
  // @ts-ignore
344
368
  onChange: function onChange(value, actionType) {
@@ -346,7 +370,8 @@ var ComplexSearch = function ComplexSearch(props) {
346
370
  }
347
371
  }
348
372
  }), {
349
- ref: autoRef,
373
+ // @ts-ignore
374
+ itemRender: highlightItem,
350
375
  placeholder: placeholder ? placeholder : defaultFilter !== null && defaultFilter !== void 0 && defaultFilter.label ? "\u9ED8\u8BA4\u6309".concat(defaultFilter === null || defaultFilter === void 0 ? void 0 : defaultFilter.label, "\u641C\u7D22") : '请搜索',
351
376
  className: (0, _classnames.default)('main-input', 'multi'),
352
377
  hasBorder: false,
@@ -358,7 +383,8 @@ var ComplexSearch = function ComplexSearch(props) {
358
383
  width: 'auto'
359
384
  }
360
385
  }, focusProps)) : null, renderSelectedFilter(), renderSelectFilterCloseIcon())), /*#__PURE__*/_react.default.createElement("div", {
361
- className: (0, _classnames.default)('right-wrap')
386
+ className: (0, _classnames.default)('right-wrap'),
387
+ ref: autoRef
362
388
  }, /*#__PURE__*/_react.default.createElement(_consoleComponents.Button, {
363
389
  className: (0, _classnames.default)('search-btn', {
364
390
  'focus': focused
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { CloseableProps } from '@alifd/next/lib/tag';
3
+ import './index.less';
4
+ export interface PureTagProps extends CloseableProps {
5
+ tagKey: string;
6
+ tagValue: string;
7
+ disableTruncate?: boolean;
8
+ closable?: boolean;
9
+ showDot?: boolean;
10
+ showLabel?: boolean | string;
11
+ intl?: any;
12
+ }
13
+ declare const PureTag: React.FC<PureTagProps>;
14
+ export default PureTag;