intelicoreact 1.4.40 → 1.4.41
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/dist/Atomic/UI/TagList/TagList.js +165 -99
- package/package.json +1 -1
|
@@ -25,119 +25,185 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
25
25
|
|
|
26
26
|
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; }
|
|
27
27
|
|
|
28
|
-
const
|
|
28
|
+
const TagList = _ref => {
|
|
29
|
+
var _wrapperRef$current$g, _wrapperRef$current, _wrapperRef$current$g2;
|
|
30
|
+
|
|
29
31
|
let {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
32
|
+
disabled,
|
|
33
|
+
className,
|
|
34
|
+
onTagClick,
|
|
35
|
+
removeItem = null,
|
|
36
|
+
items = [],
|
|
37
|
+
withToggle = true,
|
|
38
|
+
disableShowMore = false,
|
|
39
|
+
shownItemsCount = "auto",
|
|
40
|
+
testId = "test-taglist",
|
|
41
|
+
refProp,
|
|
42
|
+
renderOrder,
|
|
43
|
+
onEditClick,
|
|
44
|
+
onToggleRenderAll
|
|
36
45
|
} = _ref;
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const [isLoading, setIsLoading] = (0, _react.useState)(false);
|
|
48
|
-
const tagListRef = (0, _react.useRef)(null);
|
|
49
|
-
|
|
50
|
-
const onConfirmChangesClick = () => {
|
|
51
|
-
if (isValueChanged) {
|
|
52
|
-
var _Promise;
|
|
53
|
-
|
|
54
|
-
setIsLoading(true);
|
|
55
|
-
setIsValueChanged(false);
|
|
56
|
-
(_Promise = new Promise(r => {
|
|
57
|
-
const onChangeResult = onChange(options.filter(_ref3 => {
|
|
58
|
-
let {
|
|
59
|
-
value
|
|
60
|
-
} = _ref3;
|
|
61
|
-
return newValue.includes(value);
|
|
62
|
-
}));
|
|
63
|
-
|
|
64
|
-
if (onChangeResult instanceof Promise) {
|
|
65
|
-
onChangeResult.then(data => r(data));
|
|
66
|
-
} else {
|
|
67
|
-
r();
|
|
68
|
-
}
|
|
69
|
-
})) === null || _Promise === void 0 ? void 0 : _Promise.finally(() => {
|
|
70
|
-
setIsEditMode(false);
|
|
71
|
-
setIsLoading(false);
|
|
72
|
-
});
|
|
73
|
-
} else {
|
|
74
|
-
setIsEditMode(false);
|
|
75
|
-
}
|
|
46
|
+
const wrapperRef = (0, _react.useRef)(null);
|
|
47
|
+
const [tagList, setTagList] = (0, _react.useState)([]);
|
|
48
|
+
const [staticTagsCount, setStaticTagsCount] = (0, _react.useState)(-1);
|
|
49
|
+
const [renderItemsCount, setRenderItemsCount] = (0, _react.useState)(-1);
|
|
50
|
+
const [renderAll, setRenderAll] = (0, _react.useState)(!withToggle);
|
|
51
|
+
const wrapperWidth = (_wrapperRef$current$g = wrapperRef === null || wrapperRef === void 0 ? void 0 : (_wrapperRef$current = wrapperRef.current) === null || _wrapperRef$current === void 0 ? void 0 : (_wrapperRef$current$g2 = _wrapperRef$current.getBoundingClientRect()) === null || _wrapperRef$current$g2 === void 0 ? void 0 : _wrapperRef$current$g2.width) !== null && _wrapperRef$current$g !== void 0 ? _wrapperRef$current$g : -1;
|
|
52
|
+
|
|
53
|
+
const setRenderAllInterceptor = v => {
|
|
54
|
+
setRenderAll(v);
|
|
55
|
+
onToggleRenderAll === null || onToggleRenderAll === void 0 ? void 0 : onToggleRenderAll(v);
|
|
76
56
|
};
|
|
77
57
|
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
58
|
+
const getStaticTagsCount = () => {
|
|
59
|
+
var _window$getComputedSt;
|
|
60
|
+
|
|
61
|
+
if (typeof shownItemsCount === "number") return shownItemsCount;
|
|
62
|
+
let computedWidth = wrapperWidth || parseInt((_window$getComputedSt = window.getComputedStyle(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current)) === null || _window$getComputedSt === void 0 ? void 0 : _window$getComputedSt.width);
|
|
63
|
+
if (isNaN(computedWidth)) return -1;
|
|
64
|
+
const result = tagList.map(_ref2 => {
|
|
65
|
+
let {
|
|
66
|
+
itemRef
|
|
67
|
+
} = _ref2;
|
|
68
|
+
return itemRef;
|
|
69
|
+
}).reduce((result, itemRef) => {
|
|
70
|
+
const itemStyle = window.getComputedStyle(itemRef === null || itemRef === void 0 ? void 0 : itemRef.current);
|
|
71
|
+
const itemWidth = [parseInt(itemStyle === null || itemStyle === void 0 ? void 0 : itemStyle.width, 10), parseInt(itemStyle === null || itemStyle === void 0 ? void 0 : itemStyle.marginLeft, 10), parseInt(itemStyle === null || itemStyle === void 0 ? void 0 : itemStyle.marginRight, 10)].reduce((result, item) => {
|
|
72
|
+
if (!isNaN(item)) result += item;
|
|
73
|
+
return result;
|
|
74
|
+
}, 0);
|
|
75
|
+
|
|
76
|
+
if (!isNaN(itemWidth) && itemWidth > 0 && itemWidth + result.width < wrapperWidth - 32) {
|
|
77
|
+
result = {
|
|
78
|
+
count: result.count + 1,
|
|
79
|
+
width: result.width + itemWidth,
|
|
80
|
+
items: [...result.items, {
|
|
81
|
+
w: itemWidth,
|
|
82
|
+
r: itemRef === null || itemRef === void 0 ? void 0 : itemRef.current
|
|
83
|
+
}]
|
|
84
|
+
};
|
|
98
85
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
}
|
|
86
|
+
|
|
87
|
+
return result;
|
|
88
|
+
}, {
|
|
89
|
+
count: 0,
|
|
90
|
+
width: 0,
|
|
91
|
+
items: []
|
|
92
|
+
});
|
|
93
|
+
return result === null || result === void 0 ? void 0 : result.count;
|
|
102
94
|
};
|
|
103
95
|
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
items: value,
|
|
110
|
-
onEditClick: () => setIsEditMode(v => !v)
|
|
111
|
-
}, props));
|
|
96
|
+
const cancelDefault = function (e) {
|
|
97
|
+
let cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => {};
|
|
98
|
+
e === null || e === void 0 ? void 0 : e.preventDefault();
|
|
99
|
+
e === null || e === void 0 ? void 0 : e.stopPropagation();
|
|
100
|
+
cb(e);
|
|
112
101
|
};
|
|
113
102
|
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
103
|
+
const renderTags = () => {
|
|
104
|
+
const tagsRenderOrder = renderOrder !== null && renderOrder !== void 0 ? renderOrder : tagList.map(_ref3 => {
|
|
105
|
+
let {
|
|
106
|
+
value,
|
|
107
|
+
id
|
|
108
|
+
} = _ref3;
|
|
109
|
+
return value !== null && value !== void 0 ? value : id;
|
|
110
|
+
});
|
|
111
|
+
return tagsRenderOrder.map((v, i) => {
|
|
112
|
+
var _item$id, _item$id2;
|
|
113
|
+
|
|
114
|
+
const item = tagList.find(_ref4 => {
|
|
122
115
|
let {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
inputRef
|
|
116
|
+
value,
|
|
117
|
+
id
|
|
126
118
|
} = _ref4;
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
119
|
+
return (value !== null && value !== void 0 ? value : id) === v;
|
|
120
|
+
});
|
|
121
|
+
if (!item) return null;
|
|
122
|
+
const isHidden = renderItemsCount !== -1 && staticTagsCount !== -1 ? i >= renderItemsCount : false;
|
|
123
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
124
|
+
className: "tag-list_wrapper_item ".concat(isHidden ? "tag-list_wrapper_item--hidden" : ""),
|
|
125
|
+
key: "tag-list-item-".concat((_item$id = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id !== void 0 ? _item$id : item === null || item === void 0 ? void 0 : item.value),
|
|
126
|
+
ref: (0, _utils.checkedRef)(item === null || item === void 0 ? void 0 : item.itemRef)
|
|
127
|
+
}, /*#__PURE__*/_react.default.createElement(_Tag.default, (0, _extends2.default)({
|
|
128
|
+
testId: "test-taglist-item-".concat((_item$id2 = item === null || item === void 0 ? void 0 : item.id) !== null && _item$id2 !== void 0 ? _item$id2 : item === null || item === void 0 ? void 0 : item.value)
|
|
129
|
+
}, item, {
|
|
130
|
+
onClick: onTagClick,
|
|
131
|
+
removeItem: removeItem
|
|
132
|
+
})));
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
const renderMoreTags = () => {
|
|
137
|
+
if ((tagList === null || tagList === void 0 ? void 0 : tagList.length) < shownItemsCount || !(tagList !== null && tagList !== void 0 && tagList.length) || disableShowMore) return null;
|
|
138
|
+
const restItems = tagList.length - renderItemsCount;
|
|
139
|
+
if (restItems === 0 || !withToggle || staticTagsCount === -1) return null;
|
|
140
|
+
return /*#__PURE__*/_react.default.createElement(_Tag.default, {
|
|
141
|
+
label: "+".concat(restItems),
|
|
142
|
+
className: "tag-list_wrapper_render-more",
|
|
143
|
+
onClick: disableShowMore ? () => {} : e => cancelDefault(e, () => setRenderAllInterceptor(true))
|
|
135
144
|
});
|
|
136
145
|
};
|
|
137
146
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
147
|
+
const renderHideTags = () => {
|
|
148
|
+
if (renderItemsCount !== (tagList === null || tagList === void 0 ? void 0 : tagList.length) || !withToggle || staticTagsCount === -1 || staticTagsCount === (tagList === null || tagList === void 0 ? void 0 : tagList.length)) return null;
|
|
149
|
+
return /*#__PURE__*/_react.default.createElement(_Tag.default, {
|
|
150
|
+
label: "...",
|
|
151
|
+
className: "tag-list_wrapper_hide-more",
|
|
152
|
+
onClick: e => cancelDefault(e, () => setRenderAllInterceptor(false))
|
|
153
|
+
});
|
|
154
|
+
}; // Set TagList Items
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
(0, _react.useEffect)(() => {
|
|
158
|
+
setStaticTagsCount(-1);
|
|
159
|
+
setRenderItemsCount(-1);
|
|
160
|
+
setRenderAllInterceptor(false);
|
|
161
|
+
setTagList(items.map(item => ({ ...item,
|
|
162
|
+
itemRef: /*#__PURE__*/(0, _react.createRef)()
|
|
163
|
+
})));
|
|
164
|
+
}, [items]); // Count Row Tags
|
|
165
|
+
|
|
166
|
+
(0, _react.useLayoutEffect)(() => {
|
|
167
|
+
if (withToggle && wrapperWidth !== -1 && staticTagsCount === -1) {
|
|
168
|
+
let computedWidth = wrapperWidth;
|
|
169
|
+
|
|
170
|
+
if (computedWidth === 0) {
|
|
171
|
+
var _window$getComputedSt2;
|
|
172
|
+
|
|
173
|
+
computedWidth = parseInt((_window$getComputedSt2 = window.getComputedStyle(wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current)) === null || _window$getComputedSt2 === void 0 ? void 0 : _window$getComputedSt2.width);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
if (!isNaN(computedWidth)) {
|
|
177
|
+
setStaticTagsCount(getStaticTagsCount());
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, [tagList, wrapperWidth, wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current]); //
|
|
181
|
+
|
|
182
|
+
(0, _react.useLayoutEffect)(() => {
|
|
183
|
+
setRenderItemsCount(staticTagsCount);
|
|
184
|
+
}, [staticTagsCount]); // Toggle Show/Hide More Tags
|
|
185
|
+
|
|
186
|
+
(0, _react.useEffect)(() => {
|
|
187
|
+
setRenderItemsCount(renderAll ? tagList === null || tagList === void 0 ? void 0 : tagList.length : staticTagsCount);
|
|
188
|
+
}, [renderAll]);
|
|
189
|
+
(0, _react.useEffect)(() => {
|
|
190
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
191
|
+
if (wrapperRef !== null && wrapperRef !== void 0 && wrapperRef.current && refProp) refProp.current = wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current;
|
|
192
|
+
}, [wrapperRef === null || wrapperRef === void 0 ? void 0 : wrapperRef.current]);
|
|
193
|
+
return /*#__PURE__*/_react.default.createElement("div", {
|
|
194
|
+
className: (0, _classnames.default)("tag-list_wrapper", "".concat(renderItemsCount !== (tagList === null || tagList === void 0 ? void 0 : tagList.length) || !withToggle || staticTagsCount === -1 || staticTagsCount === (tagList === null || tagList === void 0 ? void 0 : tagList.length) ? "tag-list_wrapper--only-static-items" : "tag-list_wrapper--all-items"), className, {
|
|
195
|
+
"tag-list_wrapper--disabled": disabled
|
|
196
|
+
}),
|
|
197
|
+
style: {
|
|
198
|
+
visibility: staticTagsCount === -1 ? "hidden" : "visible",
|
|
199
|
+
zIndex: staticTagsCount === -1 ? "-1" : "auto"
|
|
200
|
+
},
|
|
201
|
+
ref: wrapperRef
|
|
202
|
+
}, renderTags(), renderMoreTags(), renderHideTags(), typeof onEditClick === "function" && /*#__PURE__*/_react.default.createElement("div", {
|
|
203
|
+
className: "tag-list__edit-trigger"
|
|
204
|
+
}, /*#__PURE__*/_react.default.createElement(_reactFeather.Edit3, {
|
|
205
|
+
onClick: onEditClick
|
|
206
|
+
})));
|
|
141
207
|
};
|
|
142
208
|
|
|
143
209
|
var _default = TagList;
|