@zohodesk/components 1.4.9 → 1.4.10-exp-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.
@@ -7,12 +7,14 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports["default"] = void 0;
9
9
 
10
- var _react = _interopRequireDefault(require("react"));
10
+ var _react = _interopRequireWildcard(require("react"));
11
11
 
12
12
  var _propTypes = require("./props/propTypes");
13
13
 
14
14
  var _defaultProps = require("./props/defaultProps");
15
15
 
16
+ var _virtualizer = require("@zohodesk/virtualizer");
17
+
16
18
  var _ListItem = _interopRequireDefault(require("../ListItem/ListItem"));
17
19
 
18
20
  var _ListItemWithAvatar = _interopRequireDefault(require("../ListItem/ListItemWithAvatar"));
@@ -21,8 +23,14 @@ var _ListItemWithIcon = _interopRequireDefault(require("../ListItem/ListItemWith
21
23
 
22
24
  var _Layout = require("../Layout");
23
25
 
26
+ var _Common = require("../utils/Common");
27
+
24
28
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
25
29
 
30
+ 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); }
31
+
32
+ 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; }
33
+
26
34
  function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
27
35
 
28
36
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@@ -51,22 +59,39 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
51
59
 
52
60
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
53
61
 
62
+ function SuggestionsVirtualizerContainer(_ref) {
63
+ var eleRef = _ref.eleRef,
64
+ children = _ref.children,
65
+ setVirtualizerContainerRefFunction = _ref.setVirtualizerContainerRefFunction;
66
+ (0, _react.useMemo)(function () {
67
+ typeof setVirtualizerContainerRefFunction === 'function' && setVirtualizerContainerRefFunction(eleRef);
68
+ }, [eleRef, setVirtualizerContainerRefFunction]);
69
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, children);
70
+ }
71
+
54
72
  var Suggestions = /*#__PURE__*/function (_React$PureComponent) {
55
73
  _inherits(Suggestions, _React$PureComponent);
56
74
 
57
75
  var _super = _createSuper(Suggestions);
58
76
 
59
- function Suggestions() {
77
+ function Suggestions(props) {
78
+ var _this;
79
+
60
80
  _classCallCheck(this, Suggestions);
61
81
 
62
- return _super.apply(this, arguments);
82
+ _this = _super.call(this, props);
83
+ _this.renderSuggestionList = _this.renderSuggestionList.bind(_assertThisInitialized(_this));
84
+ _this.renderVirtualizerSuggestionListItem = _this.renderVirtualizerSuggestionListItem.bind(_assertThisInitialized(_this));
85
+ return _this;
63
86
  }
64
87
 
65
88
  _createClass(Suggestions, [{
66
- key: "render",
67
- value: function render() {
89
+ key: "renderSuggestionList",
90
+ value: function renderSuggestionList(_ref2) {
91
+ var suggestion = _ref2.suggestion,
92
+ index = _ref2.index,
93
+ ref = _ref2.ref;
68
94
  var _this$props = this.props,
69
- suggestions = _this$props.suggestions,
70
95
  getRef = _this$props.getRef,
71
96
  hoverOption = _this$props.hoverOption,
72
97
  onClick = _this$props.onClick,
@@ -74,118 +99,69 @@ var Suggestions = /*#__PURE__*/function (_React$PureComponent) {
74
99
  needTick = _this$props.needTick,
75
100
  needBorder = _this$props.needBorder,
76
101
  _this$props$selectedO = _this$props.selectedOptions,
77
- selectedOptions = _this$props$selectedO === void 0 ? [] : _this$props$selectedO,
102
+ selectedOptions = _this$props$selectedO === void 0 ? _Common.DUMMY_ARRAY : _this$props$selectedO,
78
103
  activeId = _this$props.activeId,
79
104
  hoverId = _this$props.hoverId,
80
- dataId = _this$props.dataId,
81
105
  listItemSize = _this$props.listItemSize,
82
- className = _this$props.className,
83
106
  avatarPalette = _this$props.avatarPalette,
84
107
  palette = _this$props.palette,
85
- htmlId = _this$props.htmlId,
86
108
  a11y = _this$props.a11y,
87
109
  needMultiLineText = _this$props.needMultiLineText,
88
110
  limit = _this$props.limit,
89
111
  limitReachedMessage = _this$props.limitReachedMessage;
90
- var ariaParentRole = a11y.ariaParentRole,
91
- ariaMultiselectable = a11y.ariaMultiselectable;
112
+ var id = suggestion.id,
113
+ value = suggestion.value,
114
+ secondaryValue = suggestion.secondaryValue,
115
+ photoURL = suggestion.photoURL,
116
+ icon = suggestion.icon,
117
+ optionType = suggestion.optionType,
118
+ iconSize = suggestion.iconSize,
119
+ isDisabled = suggestion.isDisabled,
120
+ listItemProps = suggestion.listItemProps,
121
+ _suggestion$listItemC = suggestion.listItemCustomProps,
122
+ listItemCustomProps = _suggestion$listItemC === void 0 ? _Common.DUMMY_OBJECT : _suggestion$listItemC;
123
+ var isActive = activeId === id || selectedOptions.indexOf(id) >= 0;
124
+ var isHighlight = hoverOption === index || id === hoverId ? true : false;
92
125
  var selectedOptionsLength = selectedOptions.length;
93
- return /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
94
- isCover: false,
95
- role: ariaParentRole,
96
- id: htmlId,
97
- tabindex: "0",
98
- "aria-multiselectable": ariaMultiselectable
99
- }, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
100
- dataId: "".concat(dataId),
101
- className: className ? className : ''
102
- }, suggestions.map(function (suggestion, index) {
103
- var id = suggestion.id,
104
- value = suggestion.value,
105
- secondaryValue = suggestion.secondaryValue,
106
- photoURL = suggestion.photoURL,
107
- icon = suggestion.icon,
108
- optionType = suggestion.optionType,
109
- iconSize = suggestion.iconSize,
110
- isDisabled = suggestion.isDisabled,
111
- listItemProps = suggestion.listItemProps,
112
- _suggestion$listItemC = suggestion.listItemCustomProps,
113
- listItemCustomProps = _suggestion$listItemC === void 0 ? {} : _suggestion$listItemC;
114
- var isActive = activeId === id || selectedOptions.indexOf(id) >= 0;
115
- var isHighlight = hoverOption === index || id === hoverId ? true : false;
116
- var isLimitReached = selectedOptionsLength >= limit && !isActive;
117
- var list_a11y = Object.assign({}, a11y, {
118
- ariaSelected: isActive,
119
- ariaLabel: value,
120
- 'data-a11y-list-active': isHighlight
121
- });
122
-
123
- var commonProps = _objectSpread({
124
- isDisabled: isDisabled ? isDisabled : isLimitReached,
125
- needMultiLineText: needMultiLineText
126
- }, listItemCustomProps);
127
-
128
- if (listItemProps) {
129
- commonProps.customProps = {
130
- ListItemProps: _objectSpread({}, listItemProps)
131
- };
132
- }
133
-
134
- if (isLimitReached) {
135
- commonProps.disableTitle = limitReachedMessage;
126
+ var isLimitReached = selectedOptionsLength >= limit && !isActive;
127
+ var list_a11y = Object.assign({}, a11y, {
128
+ ariaSelected: isActive,
129
+ ariaLabel: value,
130
+ 'data-a11y-list-active': isHighlight
131
+ });
132
+
133
+ var commonProps = _objectSpread({
134
+ isDisabled: isDisabled ? isDisabled : isLimitReached,
135
+ needMultiLineText: needMultiLineText
136
+ }, listItemCustomProps);
137
+
138
+ if (listItemProps) {
139
+ commonProps.customProps = {
140
+ ListItemProps: _objectSpread({}, listItemProps)
141
+ };
142
+ }
143
+
144
+ if (isLimitReached) {
145
+ commonProps.disableTitle = limitReachedMessage;
146
+ }
147
+
148
+ function getListItemRef(ele, index, id) {
149
+ ref && ref(ele);
150
+
151
+ if (typeof getRef === 'function') {
152
+ getRef(ele, index, id);
136
153
  }
154
+ }
137
155
 
138
- if (optionType === 'avatar') {
139
- return /*#__PURE__*/_react["default"].createElement(_ListItemWithAvatar["default"], _extends({}, commonProps, {
140
- autoHover: false,
141
- getRef: getRef,
142
- highlight: isHighlight,
143
- id: id,
144
- imgSrc: photoURL,
145
- key: "".concat(id, "avatarListItem"),
146
- name: value,
147
- onClick: onClick,
148
- onMouseEnter: onMouseEnter,
149
- value: value,
150
- title: value,
151
- needTick: needTick,
152
- needBorder: needBorder,
153
- active: isActive,
154
- size: listItemSize,
155
- avatarPalette: avatarPalette,
156
- palette: palette,
157
- a11y: list_a11y,
158
- secondaryValue: secondaryValue
159
- }));
160
- } else if (optionType === 'icon') {
161
- return /*#__PURE__*/_react["default"].createElement(_ListItemWithIcon["default"], _extends({}, commonProps, {
162
- autoHover: false,
163
- getRef: getRef,
164
- highlight: isHighlight,
165
- id: id,
166
- key: "".concat(id, "iconListItem"),
167
- onClick: onClick,
168
- onMouseEnter: onMouseEnter,
169
- value: value,
170
- title: value,
171
- iconName: icon,
172
- needTick: needTick,
173
- needBorder: needBorder,
174
- active: isActive,
175
- iconSize: iconSize,
176
- size: listItemSize,
177
- palette: palette,
178
- a11y: list_a11y,
179
- secondaryValue: secondaryValue
180
- }));
181
- }
182
-
183
- return /*#__PURE__*/_react["default"].createElement(_ListItem["default"], _extends({}, commonProps, {
156
+ if (optionType === 'avatar') {
157
+ return /*#__PURE__*/_react["default"].createElement(_ListItemWithAvatar["default"], _extends({}, commonProps, {
184
158
  autoHover: false,
185
- getRef: getRef,
159
+ getRef: getListItemRef,
186
160
  highlight: isHighlight,
187
161
  id: id,
188
- key: "".concat(id, "listItem"),
162
+ imgSrc: photoURL,
163
+ key: "".concat(id, "avatarListItem"),
164
+ name: value,
189
165
  onClick: onClick,
190
166
  onMouseEnter: onMouseEnter,
191
167
  value: value,
@@ -194,9 +170,101 @@ var Suggestions = /*#__PURE__*/function (_React$PureComponent) {
194
170
  needBorder: needBorder,
195
171
  active: isActive,
196
172
  size: listItemSize,
173
+ avatarPalette: avatarPalette,
197
174
  palette: palette,
198
- a11y: list_a11y
175
+ a11y: list_a11y,
176
+ secondaryValue: secondaryValue
199
177
  }));
178
+ } else if (optionType === 'icon') {
179
+ return /*#__PURE__*/_react["default"].createElement(_ListItemWithIcon["default"], _extends({}, commonProps, {
180
+ autoHover: false,
181
+ getRef: getListItemRef,
182
+ highlight: isHighlight,
183
+ id: id,
184
+ key: "".concat(id, "iconListItem"),
185
+ onClick: onClick,
186
+ onMouseEnter: onMouseEnter,
187
+ value: value,
188
+ title: value,
189
+ iconName: icon,
190
+ needTick: needTick,
191
+ needBorder: needBorder,
192
+ active: isActive,
193
+ iconSize: iconSize,
194
+ size: listItemSize,
195
+ palette: palette,
196
+ a11y: list_a11y,
197
+ secondaryValue: secondaryValue
198
+ }));
199
+ }
200
+
201
+ return /*#__PURE__*/_react["default"].createElement(_ListItem["default"], _extends({}, commonProps, {
202
+ autoHover: false,
203
+ getRef: getListItemRef,
204
+ highlight: isHighlight,
205
+ id: id,
206
+ key: "".concat(id, "listItem"),
207
+ onClick: onClick,
208
+ onMouseEnter: onMouseEnter,
209
+ value: value,
210
+ title: value,
211
+ needTick: needTick,
212
+ needBorder: needBorder,
213
+ active: isActive,
214
+ size: listItemSize,
215
+ palette: palette,
216
+ a11y: list_a11y
217
+ }));
218
+ }
219
+ }, {
220
+ key: "renderVirtualizerSuggestionListItem",
221
+ value: function renderVirtualizerSuggestionListItem(_ref3) {
222
+ var index = _ref3.index,
223
+ ref = _ref3.ref;
224
+ var suggestions = this.props.suggestions;
225
+ var suggestion = suggestions[index];
226
+ return this.renderSuggestionList({
227
+ suggestion: suggestion,
228
+ index: index,
229
+ ref: ref
230
+ });
231
+ }
232
+ }, {
233
+ key: "render",
234
+ value: function render() {
235
+ var _this2 = this;
236
+
237
+ var _this$props2 = this.props,
238
+ suggestions = _this$props2.suggestions,
239
+ dataId = _this$props2.dataId,
240
+ className = _this$props2.className,
241
+ isVirtualizerEnabled = _this$props2.isVirtualizerEnabled,
242
+ htmlId = _this$props2.htmlId,
243
+ a11y = _this$props2.a11y,
244
+ setVirtualizerContainerRefFunction = _this$props2.setVirtualizerContainerRefFunction;
245
+ var ariaParentRole = a11y.ariaParentRole,
246
+ ariaMultiselectable = a11y.ariaMultiselectable;
247
+ return /*#__PURE__*/_react["default"].createElement(_Layout.Container, {
248
+ isCover: false,
249
+ role: ariaParentRole,
250
+ id: htmlId,
251
+ tabindex: "0",
252
+ "aria-multiselectable": ariaMultiselectable
253
+ }, /*#__PURE__*/_react["default"].createElement(_Layout.Box, {
254
+ dataId: "".concat(dataId),
255
+ className: className ? className : ''
256
+ }, isVirtualizerEnabled ? /*#__PURE__*/_react["default"].createElement(_virtualizer.Virtualizer, {
257
+ containerType: SuggestionsVirtualizerContainer,
258
+ elementRenderer: this.renderVirtualizerSuggestionListItem,
259
+ elementsCount: suggestions.length,
260
+ isElementsFixedHeight: false,
261
+ dataId: "".concat(dataId, "_virtualizer"),
262
+ setVirtualizerContainerRefFunction: setVirtualizerContainerRefFunction
263
+ }) : suggestions.map(function (suggestion, index) {
264
+ return _this2.renderSuggestionList({
265
+ suggestion: suggestion,
266
+ index: index
267
+ });
200
268
  })));
201
269
  }
202
270
  }]);
@@ -97,6 +97,7 @@ var MultiSelect_defaultProps = {
97
97
  autoComplete: (0, _Config.getLibraryConfig)('autoComplete'),
98
98
  dataId: 'multiSelect',
99
99
  dropBoxSize: 'small',
100
+ isVirtualizerEnabled: false,
100
101
  isAnimate: true,
101
102
  isDisabled: false,
102
103
  isPopupOpenOnEnter: false,
@@ -182,6 +183,7 @@ var SelectedOptions_defaultProps = {
182
183
  exports.SelectedOptions_defaultProps = SelectedOptions_defaultProps;
183
184
  var Suggestions_defaultProps = {
184
185
  a11y: {},
186
+ isVirtualizerEnabled: false,
185
187
  needMultiLineText: false
186
188
  };
187
189
  exports.Suggestions_defaultProps = Suggestions_defaultProps;
@@ -50,6 +50,7 @@ var MultiSelect_propTypes = {
50
50
  disableAction: _propTypes["default"].bool,
51
51
  dropBoxSize: _propTypes["default"].oneOf(['small', 'medium', 'large']),
52
52
  emptyMessage: _propTypes["default"].string.isRequired,
53
+ isVirtualizerEnabled: _propTypes["default"].bool,
53
54
  getContainerRef: _propTypes["default"].func,
54
55
  getNextOptions: _propTypes["default"].func,
55
56
  getPublicMethods: _propTypes["default"].func,
@@ -192,6 +193,8 @@ var Suggestions_propTypes = {
192
193
  avatarPalette: _propTypes["default"].string,
193
194
  className: _propTypes["default"].string,
194
195
  dataId: _propTypes["default"].string,
196
+ isVirtualizerEnabled: _propTypes["default"].bool,
197
+ setVirtualizerContainerRefFunction: _propTypes["default"].func,
195
198
  getRef: _propTypes["default"].func,
196
199
  hoverId: _propTypes["default"].oneOfType([_propTypes["default"].string, _propTypes["default"].number]),
197
200
  hoverOption: _propTypes["default"].number,
@@ -168,6 +168,7 @@ var SelectComponent = /*#__PURE__*/function (_Component) {
168
168
  _this.handleAddNewOption = _this.handleAddNewOption.bind(_assertThisInitialized(_this));
169
169
  _this.handleExposePopupHandlers = _this.handleExposePopupHandlers.bind(_assertThisInitialized(_this));
170
170
  _this.handleGetAddNewOptionText = _this.handleGetAddNewOptionText.bind(_assertThisInitialized(_this));
171
+ _this.setSuggestionsVirtualizerContainerRefFunction = _this.setSuggestionsVirtualizerContainerRefFunction.bind(_assertThisInitialized(_this));
171
172
  _this.valueInputTypeString = '';
172
173
  _this.valueInputSearchString = '';
173
174
  _this.autoSelectSuggestions = [];
@@ -309,9 +310,9 @@ var SelectComponent = /*#__PURE__*/function (_Component) {
309
310
  textField = props.textField,
310
311
  allowValueFallback = props.allowValueFallback,
311
312
  _props$customProps = props.customProps,
312
- customProps = _props$customProps === void 0 ? {} : _props$customProps;
313
+ customProps = _props$customProps === void 0 ? _dropDownUtils.dummyObj : _props$customProps;
313
314
  var _customProps$listItem = customProps.listItemProps,
314
- listItemProps = _customProps$listItem === void 0 ? {} : _customProps$listItem;
315
+ listItemProps = _customProps$listItem === void 0 ? _dropDownUtils.dummyObj : _customProps$listItem;
315
316
  return this.formatOptions({
316
317
  options: options,
317
318
  valueField: valueField,
@@ -574,6 +575,7 @@ var SelectComponent = /*#__PURE__*/function (_Component) {
574
575
  key: "suggestionContainerRef",
575
576
  value: function suggestionContainerRef(el) {
576
577
  this.suggestionContainer = el;
578
+ typeof this.setSuggestionsVirtualizerRef === 'function' && this.setSuggestionsVirtualizerRef(el);
577
579
  }
578
580
  }, {
579
581
  key: "suggestionItemRef",
@@ -721,6 +723,12 @@ var SelectComponent = /*#__PURE__*/function (_Component) {
721
723
  onAddNewOption: this.handleAddNewOption
722
724
  });
723
725
  }
726
+ }, {
727
+ key: "setSuggestionsVirtualizerContainerRefFunction",
728
+ value: function setSuggestionsVirtualizerContainerRefFunction(refFunc) {
729
+ this.setSuggestionsVirtualizerRef = refFunc;
730
+ this.suggestionContainer && refFunc(this.suggestionContainer);
731
+ }
724
732
  }, {
725
733
  key: "render",
726
734
  value: function render() {
@@ -777,6 +785,7 @@ var SelectComponent = /*#__PURE__*/function (_Component) {
777
785
  targetOffset = _this$props11.targetOffset,
778
786
  isRestrictScroll = _this$props11.isRestrictScroll,
779
787
  dropBoxPortalId = _this$props11.dropBoxPortalId,
788
+ isVirtualizerEnabled = _this$props11.isVirtualizerEnabled,
780
789
  renderCustomToggleIndicator = _this$props11.renderCustomToggleIndicator,
781
790
  renderCustomSearchClearComponent = _this$props11.renderCustomSearchClearComponent;
782
791
  var _i18nKeys = i18nKeys,
@@ -976,6 +985,8 @@ var SelectComponent = /*#__PURE__*/function (_Component) {
976
985
  eleRef: _this7.suggestionContainerRef
977
986
  }, suggestions.length ? /*#__PURE__*/_react["default"].createElement(_Suggestions["default"], _extends({
978
987
  activeId: selectedId,
988
+ isVirtualizerEnabled: isVirtualizerEnabled,
989
+ setVirtualizerContainerRefFunction: _this7.setSuggestionsVirtualizerContainerRefFunction,
979
990
  suggestions: suggestions,
980
991
  getRef: _this7.suggestionItemRef,
981
992
  hoverOption: hoverIndex,
@@ -261,7 +261,7 @@ var SelectWithIcon = /*#__PURE__*/function (_Component) {
261
261
 
262
262
  if (options.length) {
263
263
  datas = options.filter(function (obj) {
264
- return obj[valueKey].toLowerCase().includes(searchValue.toLowerCase());
264
+ return obj[valueKey].toLowerCase().includes(searchValue.toLowerCase().trim());
265
265
  });
266
266
  }
267
267