@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.
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
14
+ var _react = _interopRequireDefault(require("react"));
15
+
16
+ var _consoleComponents = require("@alicloud/console-components");
17
+
18
+ var _consoleComponentsTruncate = _interopRequireDefault(require("@alicloud/console-components-truncate"));
19
+
20
+ var _excluded = ["intl", "tagKey", "disableTruncate", "showDot", "tagValue", "showLabel", "closable"];
21
+
22
+ var Empty = function Empty(_ref) {
23
+ var children = _ref.children;
24
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, children);
25
+ };
26
+
27
+ var PureTag = function PureTag(props) {
28
+ var intl = props.intl,
29
+ tagKey = props.tagKey,
30
+ disableTruncate = props.disableTruncate,
31
+ showDot = props.showDot,
32
+ tagValue = props.tagValue,
33
+ showLabel = props.showLabel,
34
+ _props$closable = props.closable,
35
+ closable = _props$closable === void 0 ? true : _props$closable,
36
+ resetProps = (0, _objectWithoutProperties2.default)(props, _excluded);
37
+ var defaultTruncateProps = {
38
+ threshold: 20,
39
+ showTooltip: false
40
+ };
41
+ var TruncateWrapper = disableTruncate ? Empty : _consoleComponentsTruncate.default;
42
+ var DotWrapper = showDot ? _consoleComponents.Badge : Empty;
43
+ var TagWrapper = closable ? _consoleComponents.Tag.Closeable : _consoleComponents.Tag;
44
+ var transformedTagValue = tagValue;
45
+
46
+ if (tagValue === '') {
47
+ transformedTagValue = '空值';
48
+ } else if (tagValue === undefined || tagValue === null) {
49
+ transformedTagValue = '全部值';
50
+ }
51
+
52
+ return (
53
+ /*#__PURE__*/
54
+ //@ts-ignore
55
+ _react.default.createElement(DotWrapper, {
56
+ title: "\u5373\u5C06\u65B0\u5EFA",
57
+ className: "console-tags-tag-dot",
58
+ dot: true
59
+ }, /*#__PURE__*/_react.default.createElement(TagWrapper, (0, _extends2.default)({
60
+ title: "".concat(tagKey, ":").concat(tagValue),
61
+ className: "console-tags-tag"
62
+ }, resetProps), showLabel && /*#__PURE__*/_react.default.createElement("label", {
63
+ className: "console-tags-tag-label"
64
+ }, "\u6807\u7B7E"), /*#__PURE__*/_react.default.createElement(TruncateWrapper, defaultTruncateProps, tagKey), ":", tagValue ? /*#__PURE__*/_react.default.createElement(TruncateWrapper, defaultTruncateProps, tagValue) : /*#__PURE__*/_react.default.createElement("span", {
65
+ className: "console-tags-tag_empty"
66
+ }, transformedTagValue)))
67
+ );
68
+ };
69
+
70
+ var _default = PureTag;
71
+ exports.default = _default;
@@ -19,6 +19,8 @@ var _style = require("../style");
19
19
 
20
20
  var _constants = require("../constants");
21
21
 
22
+ var _PureTag = _interopRequireDefault(require("./PureTag"));
23
+
22
24
  var TagGroup = _consoleComponents.Tag.Group,
23
25
  ClosableTag = _consoleComponents.Tag.Closeable;
24
26
 
@@ -27,6 +29,7 @@ var SearchTagList = function SearchTagList(props) {
27
29
  className = props.className,
28
30
  style = props.style,
29
31
  onChange = props.onChange,
32
+ onClear = props.onClear,
30
33
  _props$prefix = props.prefix,
31
34
  prefix = _props$prefix === void 0 ? "next-" : _props$prefix;
32
35
 
@@ -37,14 +40,14 @@ var SearchTagList = function SearchTagList(props) {
37
40
  var resFindIndex = newTagList.findIndex(function (x) {
38
41
  return x.dataIndex === item.dataIndex;
39
42
  });
40
- newTagList.splice(resFindIndex, 1);
41
- onChange(newTagList);
43
+ var deletedTags = newTagList.splice(resFindIndex, 1);
44
+ onChange(deletedTags[0], newTagList);
42
45
  }
43
46
  }
44
47
 
45
48
  function onRemoveAllTag() {
46
- if (onChange) {
47
- onChange([]);
49
+ if (onClear) {
50
+ onClear();
48
51
  }
49
52
  }
50
53
 
@@ -53,7 +56,24 @@ var SearchTagList = function SearchTagList(props) {
53
56
  className: (0, _classnames.default)(_constants.baseTagListClassName, className),
54
57
  style: style
55
58
  }, /*#__PURE__*/_react.default.createElement(TagGroup, null, dataSource && dataSource.length > 0 && dataSource.map(function (tagItem) {
59
+ var value = tagItem.value;
60
+ var isTag = !!value.tagKey;
61
+
62
+ if (isTag) {
63
+ return /*#__PURE__*/_react.default.createElement(_PureTag.default, {
64
+ showLabel: true,
65
+ tagKey: value.tagKey,
66
+ tagValue: value.tagKey,
67
+ closable: true,
68
+ onClose: function onClose() {
69
+ onRemoveTag(tagItem);
70
+ return true;
71
+ }
72
+ });
73
+ }
74
+
56
75
  return /*#__PURE__*/_react.default.createElement(ClosableTag, {
76
+ className: "console-tags-tag",
57
77
  key: tagItem.dataIndex + tagItem.value,
58
78
  type: "normal",
59
79
  size: "medium",
@@ -61,7 +81,9 @@ var SearchTagList = function SearchTagList(props) {
61
81
  onRemoveTag(tagItem);
62
82
  return true;
63
83
  }
64
- }, tagItem.label, ":", tagItem.valueLabel);
84
+ }, /*#__PURE__*/_react.default.createElement("label", {
85
+ className: "console-tags-tag-label"
86
+ }, tagItem.label), tagItem.value || tagItem.valueLabel);
65
87
  }), dataSource && dataSource.length > 0 && /*#__PURE__*/_react.default.createElement("a", {
66
88
  className: "remove-btn",
67
89
  onClick: onRemoveAllTag
package/lib/style.js CHANGED
@@ -33,6 +33,6 @@ exports.MultiBtnWarp = MultiBtnWarp;
33
33
 
34
34
  var TagListWrap = _styledComponents.default.div.withConfig({
35
35
  componentId: "sc-1afc1cn-3"
36
- })(["", "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);
36
+ })(["", "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);
37
37
 
38
38
  exports.TagListWrap = TagListWrap;
@@ -11,7 +11,7 @@ export interface IRcSearchTagItemProps {
11
11
  /**
12
12
  * tag的类别的key
13
13
  */
14
- dataIndex: string;
14
+ dataIndex?: string;
15
15
  /**
16
16
  * tag的类别的值
17
17
  */
@@ -19,5 +19,5 @@ export interface IRcSearchTagItemProps {
19
19
  /**
20
20
  * tag的类别的展示值
21
21
  */
22
- valueLabel: string;
22
+ valueLabel?: string;
23
23
  }
@@ -26,7 +26,11 @@ export interface IRcSearchTagListProps {
26
26
  */
27
27
  resourceType?: string;
28
28
  /**
29
- * 当删减tag时, 返回新的taglist, 可直接赋值给rc-search组件
29
+ * 当删减 tag 时, 返回新的筛选项
30
30
  */
31
- onChange?: (newTags: any) => void;
31
+ onChange?: (deletedFilter: IRcSearchTagItemProps, remainFilters: IRcSearchTagItemProps[]) => void;
32
+ /**
33
+ * 清除山选项
34
+ */
35
+ onClear?: () => void;
32
36
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alicloud/console-components-search",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "license": "MIT",
@@ -35,6 +35,7 @@
35
35
  "access": "public"
36
36
  },
37
37
  "dependencies": {
38
+ "@alicloud/console-components-truncate": "^1.0.16",
38
39
  "@alicloud/console-logger-sls": "^1.2.31"
39
40
  }
40
41
  }