@zohodesk/components 1.2.4 → 1.2.6

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.
Files changed (202) hide show
  1. package/README.md +8 -0
  2. package/coverage/Button/Button.js.html +1 -1
  3. package/coverage/Button/css/Button.module.css.html +1 -1
  4. package/coverage/Button/css/cssJSLogic.js.html +1 -1
  5. package/coverage/Button/css/index.html +1 -1
  6. package/coverage/Button/index.html +1 -1
  7. package/coverage/Button/props/defaultProps.js.html +1 -1
  8. package/coverage/Button/props/index.html +1 -1
  9. package/coverage/Button/props/propTypes.js.html +1 -1
  10. package/coverage/Buttongroup/Buttongroup.js.html +1 -1
  11. package/coverage/Buttongroup/Buttongroup.module.css.html +1 -1
  12. package/coverage/Buttongroup/index.html +1 -1
  13. package/coverage/Buttongroup/props/defaultProps.js.html +1 -1
  14. package/coverage/Buttongroup/props/index.html +1 -1
  15. package/coverage/Buttongroup/props/propTypes.js.html +1 -1
  16. package/coverage/index.html +1 -1
  17. package/coverage/utils/dummyFunction.js.html +1 -1
  18. package/coverage/utils/index.html +1 -1
  19. package/es/AppContainer/AppContainer.js +3 -0
  20. package/es/v1/Accordion/Accordion.js +65 -0
  21. package/es/v1/Accordion/AccordionItem.js +57 -0
  22. package/es/v1/Accordion/index.js +2 -0
  23. package/es/v1/Animation/Animation.js +127 -0
  24. package/es/v1/AppContainer/AppContainer.js +137 -0
  25. package/es/v1/Avatar/Avatar.js +189 -0
  26. package/es/v1/AvatarTeam/AvatarTeam.js +70 -0
  27. package/es/v1/Button/Button.js +68 -0
  28. package/es/v1/Buttongroup/Buttongroup.js +31 -0
  29. package/es/v1/Card/Card.js +271 -0
  30. package/es/v1/CheckBox/CheckBox.js +155 -0
  31. package/es/v1/DateTime/CalendarView.js +218 -0
  32. package/es/v1/DateTime/DateTime.js +783 -0
  33. package/es/v1/DateTime/DateTimePopupFooter.js +47 -0
  34. package/es/v1/DateTime/DateTimePopupHeader.js +105 -0
  35. package/es/v1/DateTime/DateWidget.js +1098 -0
  36. package/es/v1/DateTime/DaysRow.js +31 -0
  37. package/es/v1/DateTime/Time.js +166 -0
  38. package/es/v1/DateTime/YearView.js +264 -0
  39. package/es/v1/DateTime/index.js +1 -0
  40. package/es/v1/DropBox/DropBox.js +91 -0
  41. package/es/v1/DropBox/DropBoxElement/DropBoxElement.js +132 -0
  42. package/es/v1/DropDown/DropDown.js +73 -0
  43. package/es/v1/DropDown/DropDownHeading.js +44 -0
  44. package/es/v1/DropDown/DropDownItem.js +76 -0
  45. package/es/v1/DropDown/DropDownSearch.js +63 -0
  46. package/es/v1/DropDown/DropDownSeparator.js +15 -0
  47. package/es/v1/Heading/Heading.js +32 -0
  48. package/es/v1/Label/Label.js +40 -0
  49. package/es/v1/Layout/Box.js +115 -0
  50. package/es/v1/Layout/Container.js +132 -0
  51. package/es/v1/Layout/index.js +2 -0
  52. package/es/v1/ListItem/ListContainer.js +102 -0
  53. package/es/v1/ListItem/ListItem.js +124 -0
  54. package/es/v1/ListItem/ListItemWithAvatar.js +145 -0
  55. package/es/v1/ListItem/ListItemWithCheckBox.js +104 -0
  56. package/es/v1/ListItem/ListItemWithIcon.js +127 -0
  57. package/es/v1/ListItem/ListItemWithRadio.js +105 -0
  58. package/es/v1/ListItem/index.js +6 -0
  59. package/es/v1/Modal/Modal.js +154 -0
  60. package/es/v1/MultiSelect/AdvancedGroupMultiSelect.js +1079 -0
  61. package/es/v1/MultiSelect/AdvancedMultiSelect.js +568 -0
  62. package/es/v1/MultiSelect/EmptyState.js +64 -0
  63. package/es/v1/MultiSelect/MobileHeader/MobileHeader.js +50 -0
  64. package/es/v1/MultiSelect/MultiSelect.js +1120 -0
  65. package/es/v1/MultiSelect/MultiSelectHeader.js +32 -0
  66. package/es/v1/MultiSelect/MultiSelectWithAvatar.js +216 -0
  67. package/es/v1/MultiSelect/SelectedOptions.js +82 -0
  68. package/es/v1/MultiSelect/Suggestions.js +142 -0
  69. package/es/v1/MultiSelect/index.js +4 -0
  70. package/es/v1/PopOver/PopOver.js +211 -0
  71. package/es/v1/Popup/Popup.js +645 -0
  72. package/es/v1/Radio/Radio.js +115 -0
  73. package/es/v1/Responsive/CustomResponsive.js +195 -0
  74. package/es/v1/Responsive/RefWrapper.js +39 -0
  75. package/es/v1/Responsive/ResizeComponent.js +197 -0
  76. package/es/v1/Responsive/ResizeObserver.js +140 -0
  77. package/es/v1/Responsive/Responsive.js +194 -0
  78. package/es/v1/Responsive/index.js +9 -0
  79. package/es/v1/ResponsiveDropBox/ResponsiveDropBox.js +58 -0
  80. package/es/v1/Ribbon/Ribbon.js +33 -0
  81. package/es/v1/RippleEffect/RippleEffect.js +24 -0
  82. package/es/v1/Select/GroupSelect.js +803 -0
  83. package/es/v1/Select/Select.js +969 -0
  84. package/es/v1/Select/SelectWithAvatar.js +344 -0
  85. package/es/v1/Select/SelectWithIcon.js +535 -0
  86. package/es/v1/Select/index.js +4 -0
  87. package/es/v1/Stencils/Stencils.js +26 -0
  88. package/es/v1/Switch/Switch.js +94 -0
  89. package/es/v1/Tab/Tab.js +108 -0
  90. package/es/v1/Tab/TabContent.js +30 -0
  91. package/es/v1/Tab/TabContentWrapper.js +29 -0
  92. package/es/v1/Tab/TabWrapper.js +57 -0
  93. package/es/v1/Tab/Tabs.js +612 -0
  94. package/es/v1/Tab/index.js +5 -0
  95. package/es/v1/Tag/Tag.js +134 -0
  96. package/es/v1/TextBox/TextBox.js +154 -0
  97. package/es/v1/TextBoxIcon/TextBoxIcon.js +158 -0
  98. package/es/v1/Textarea/Textarea.js +102 -0
  99. package/es/v1/Tooltip/Tooltip.js +518 -0
  100. package/es/v1/Typography/Typography.js +38 -0
  101. package/es/v1/Typography/css/Typography.module.css +376 -0
  102. package/es/v1/Typography/css/cssJSLogic.js +46 -0
  103. package/es/v1/Typography/css/letterSpacingMap.js +12 -0
  104. package/es/v1/Typography/props/defaultProps.js +8 -0
  105. package/es/v1/Typography/props/propTypes.js +24 -0
  106. package/es/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +69 -0
  107. package/es/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +100 -0
  108. package/es/v1/semantic/Button/Button.js +53 -0
  109. package/es/v1/semantic/index.js +1 -0
  110. package/lib/AppContainer/AppContainer.js +5 -0
  111. package/lib/v1/Accordion/Accordion.js +96 -0
  112. package/lib/v1/Accordion/AccordionItem.js +68 -0
  113. package/lib/v1/Accordion/index.js +23 -0
  114. package/lib/v1/Animation/Animation.js +143 -0
  115. package/lib/v1/AppContainer/AppContainer.js +209 -0
  116. package/lib/v1/Avatar/Avatar.js +246 -0
  117. package/lib/v1/AvatarTeam/AvatarTeam.js +81 -0
  118. package/lib/v1/Button/Button.js +82 -0
  119. package/lib/v1/Buttongroup/Buttongroup.js +44 -0
  120. package/lib/v1/Card/Card.js +365 -0
  121. package/lib/v1/CheckBox/CheckBox.js +166 -0
  122. package/lib/v1/DateTime/CalendarView.js +285 -0
  123. package/lib/v1/DateTime/DateTime.js +872 -0
  124. package/lib/v1/DateTime/DateTimePopupFooter.js +96 -0
  125. package/lib/v1/DateTime/DateTimePopupHeader.js +166 -0
  126. package/lib/v1/DateTime/DateWidget.js +1125 -0
  127. package/lib/v1/DateTime/DaysRow.js +80 -0
  128. package/lib/v1/DateTime/Time.js +254 -0
  129. package/lib/v1/DateTime/YearView.js +325 -0
  130. package/lib/v1/DateTime/index.js +15 -0
  131. package/lib/v1/DropBox/DropBox.js +119 -0
  132. package/lib/v1/DropBox/DropBoxElement/DropBoxElement.js +145 -0
  133. package/lib/v1/DropDown/DropDown.js +170 -0
  134. package/lib/v1/DropDown/DropDownHeading.js +93 -0
  135. package/lib/v1/DropDown/DropDownItem.js +127 -0
  136. package/lib/v1/DropDown/DropDownSearch.js +113 -0
  137. package/lib/v1/DropDown/DropDownSeparator.js +64 -0
  138. package/lib/v1/Heading/Heading.js +49 -0
  139. package/lib/v1/Label/Label.js +51 -0
  140. package/lib/v1/Layout/Box.js +128 -0
  141. package/lib/v1/Layout/Container.js +145 -0
  142. package/lib/v1/Layout/index.js +23 -0
  143. package/lib/v1/ListItem/ListContainer.js +120 -0
  144. package/lib/v1/ListItem/ListItem.js +138 -0
  145. package/lib/v1/ListItem/ListItemWithAvatar.js +162 -0
  146. package/lib/v1/ListItem/ListItemWithCheckBox.js +125 -0
  147. package/lib/v1/ListItem/ListItemWithIcon.js +143 -0
  148. package/lib/v1/ListItem/ListItemWithRadio.js +126 -0
  149. package/lib/v1/ListItem/index.js +55 -0
  150. package/lib/v1/Modal/Modal.js +212 -0
  151. package/lib/v1/MultiSelect/AdvancedGroupMultiSelect.js +1167 -0
  152. package/lib/v1/MultiSelect/AdvancedMultiSelect.js +634 -0
  153. package/lib/v1/MultiSelect/EmptyState.js +112 -0
  154. package/lib/v1/MultiSelect/MobileHeader/MobileHeader.js +62 -0
  155. package/lib/v1/MultiSelect/MultiSelect.js +1201 -0
  156. package/lib/v1/MultiSelect/MultiSelectHeader.js +78 -0
  157. package/lib/v1/MultiSelect/MultiSelectWithAvatar.js +270 -0
  158. package/lib/v1/MultiSelect/SelectedOptions.js +126 -0
  159. package/lib/v1/MultiSelect/Suggestions.js +195 -0
  160. package/lib/v1/MultiSelect/index.js +39 -0
  161. package/lib/v1/PopOver/PopOver.js +293 -0
  162. package/lib/v1/Popup/Popup.js +715 -0
  163. package/lib/v1/Radio/Radio.js +126 -0
  164. package/lib/v1/Responsive/CustomResponsive.js +242 -0
  165. package/lib/v1/Responsive/RefWrapper.js +57 -0
  166. package/lib/v1/Responsive/ResizeComponent.js +268 -0
  167. package/lib/v1/Responsive/ResizeObserver.js +168 -0
  168. package/lib/v1/Responsive/Responsive.js +274 -0
  169. package/lib/v1/Responsive/index.js +55 -0
  170. package/lib/v1/ResponsiveDropBox/ResponsiveDropBox.js +79 -0
  171. package/lib/v1/Ribbon/Ribbon.js +44 -0
  172. package/lib/v1/RippleEffect/RippleEffect.js +39 -0
  173. package/lib/v1/Select/GroupSelect.js +877 -0
  174. package/lib/v1/Select/Select.js +1013 -0
  175. package/lib/v1/Select/SelectWithAvatar.js +394 -0
  176. package/lib/v1/Select/SelectWithIcon.js +597 -0
  177. package/lib/v1/Select/index.js +39 -0
  178. package/lib/v1/Stencils/Stencils.js +43 -0
  179. package/lib/v1/Switch/Switch.js +108 -0
  180. package/lib/v1/Tab/Tab.js +132 -0
  181. package/lib/v1/Tab/TabContent.js +42 -0
  182. package/lib/v1/Tab/TabContentWrapper.js +42 -0
  183. package/lib/v1/Tab/TabWrapper.js +89 -0
  184. package/lib/v1/Tab/Tabs.js +680 -0
  185. package/lib/v1/Tab/index.js +47 -0
  186. package/lib/v1/Tag/Tag.js +154 -0
  187. package/lib/v1/TextBox/TextBox.js +168 -0
  188. package/lib/v1/TextBoxIcon/TextBoxIcon.js +196 -0
  189. package/lib/v1/Textarea/Textarea.js +118 -0
  190. package/lib/v1/Tooltip/Tooltip.js +586 -0
  191. package/lib/v1/Typography/Typography.js +56 -0
  192. package/lib/v1/Typography/css/Typography.module.css +376 -0
  193. package/lib/v1/Typography/css/cssJSLogic.js +41 -0
  194. package/lib/v1/Typography/css/letterSpacingMap.js +20 -0
  195. package/lib/v1/Typography/props/defaultProps.js +15 -0
  196. package/lib/v1/Typography/props/propTypes.js +35 -0
  197. package/lib/v1/VelocityAnimation/VelocityAnimation/VelocityAnimation.js +90 -0
  198. package/lib/v1/VelocityAnimation/VelocityAnimationGroup/VelocityAnimationGroup.js +126 -0
  199. package/lib/v1/semantic/Button/Button.js +63 -0
  200. package/lib/v1/semantic/index.js +15 -0
  201. package/package.json +1 -1
  202. package/result.json +1 -1
@@ -0,0 +1,803 @@
1
+ /**** Libraries ****/
2
+ import React, { PureComponent } from 'react';
3
+ import { GroupSelect_defaultProps } from '../../Select/props/defaultProps';
4
+ import { GroupSelect_propTypes } from '../../Select/props/propTypes';
5
+ /**** Components ****/
6
+
7
+ import Popup from '../Popup/Popup';
8
+ import TextBoxIcon from '../TextBoxIcon/TextBoxIcon';
9
+ import Textbox from '../TextBox/TextBox';
10
+ import Card, { CardHeader, CardContent, CardFooter } from '../Card/Card';
11
+ import Suggestions from '../MultiSelect/Suggestions';
12
+ import EmptyState from '../MultiSelect/EmptyState';
13
+ import { Icon } from '@zohodesk/icons';
14
+ import Loader from '@zohodesk/svg/lib/Loader/Loader';
15
+ import DropDownHeading from '../DropDown/DropDownHeading';
16
+ import { Container, Box } from '../Layout';
17
+ import { getUniqueId } from '../../Provider/IdProvider';
18
+ import ResponsiveDropBox from '../ResponsiveDropBox/ResponsiveDropBox';
19
+ import { ResponsiveReceiver } from '../Responsive/CustomResponsive';
20
+ import style from '../../Select/Select.module.css';
21
+ /**** Methods ****/
22
+
23
+ import { makeGetGroupSelectOptions, optionIdGrouping, makeGetGroupSelectFilterSuggestions, extractOptionId } from '../../utils/dropDownUtils';
24
+ import { getIsEmptyValue, scrollTo, debounce, getSearchString, findScrollEnd } from '../../utils/Common';
25
+ /* eslint-disable react/no-unused-prop-types */
26
+
27
+ /* eslint-disable react/sort-prop-types */
28
+
29
+ /* eslint-disable react/forbid-component-props */
30
+
31
+ export class GroupSelectComponent extends PureComponent {
32
+ constructor(props) {
33
+ super(props);
34
+ this.getNextAriaId = getUniqueId(this);
35
+ let {
36
+ autoSelectDebouneTime = 350,
37
+ searchDebounceTime = 500
38
+ } = props;
39
+ this.getGroupSelectOptions = makeGetGroupSelectOptions();
40
+ this.getFilterSuggestions = makeGetGroupSelectFilterSuggestions();
41
+ this.handleGetGroupSelectOptions = this.handleGetGroupSelectOptions.bind(this);
42
+ this.handleGetSelectedId = this.handleGetSelectedId.bind(this);
43
+ this.handleFilterSuggestions = this.handleFilterSuggestions.bind(this);
44
+ this.handleSearch = this.handleSearch.bind(this);
45
+ this.handleKeyDown = this.handleKeyDown.bind(this);
46
+ this.handleMouseEnter = this.handleMouseEnter.bind(this);
47
+ this.handleChange = this.handleChange.bind(this);
48
+ this.togglePopup = this.togglePopup.bind(this);
49
+ this.handlePopupClose = this.handlePopupClose.bind(this);
50
+ this.suggestionContainerRef = this.suggestionContainerRef.bind(this);
51
+ this.suggestionItemRef = this.suggestionItemRef.bind(this);
52
+ this.searchInputRef = this.searchInputRef.bind(this);
53
+ this.valueInputRef = this.valueInputRef.bind(this);
54
+ this.handleSelectFocus = this.handleSelectFocus.bind(this);
55
+ this.handleClearSearch = this.handleClearSearch.bind(this);
56
+ this.handleValueInputChange = this.handleValueInputChange.bind(this);
57
+ this.handleChangeOnType = debounce(this.handleChangeOnType.bind(this), autoSelectDebouneTime);
58
+ this.handleFetchOptions = this.handleFetchOptions.bind(this);
59
+ this.handleGetNextOptions = this.handleGetNextOptions.bind(this);
60
+ this.handleScroll = this.handleScroll.bind(this);
61
+ this.handleSearchOptions = debounce(this.handleSearchOptions.bind(this), searchDebounceTime);
62
+ this.valueInputTypeString = '';
63
+ this.valueInputSearchString = '';
64
+ this.autoSelectSuggestions = [];
65
+ this.autoSelectIndex = 0;
66
+ let {
67
+ revampedGroups,
68
+ normalizedAllOptions,
69
+ normalizedFormatOptions,
70
+ allOptionIds
71
+ } = this.handleGetGroupSelectOptions(props);
72
+ let {
73
+ selectedId,
74
+ hoverIndex
75
+ } = this.handleGetSelectedId(props, allOptionIds);
76
+ this.normalizedAllOptions = normalizedAllOptions;
77
+ this.normalizedFormatOptions = normalizedFormatOptions;
78
+ this.state = {
79
+ revampedGroups,
80
+ allOptionIds,
81
+ selectedId,
82
+ hoverIndex,
83
+ searchStr: '',
84
+ isFetchingOptions: false
85
+ };
86
+ this._isMounted = false;
87
+ }
88
+
89
+ componentDidMount() {
90
+ this._isMounted = true;
91
+ }
92
+
93
+ componentDidUpdate(prevProps) {
94
+ let {
95
+ groupedOptions,
96
+ selectedOption,
97
+ isPopupOpen,
98
+ needSearch,
99
+ isSearchClearOnClose
100
+ } = this.props;
101
+ let {
102
+ allOptionIds,
103
+ hoverIndex,
104
+ selectedId,
105
+ searchStr
106
+ } = this.state;
107
+ let {
108
+ suggestionContainer
109
+ } = this;
110
+ let newOptionIds = allOptionIds;
111
+ let newSelectedId = selectedId;
112
+
113
+ if (groupedOptions !== prevProps.groupedOptions) {
114
+ let {
115
+ revampedGroups,
116
+ normalizedAllOptions,
117
+ allOptionIds,
118
+ normalizedFormatOptions
119
+ } = this.handleGetGroupSelectOptions(this.props);
120
+ this.normalizedAllOptions = normalizedAllOptions;
121
+ this.normalizedFormatOptions = normalizedFormatOptions;
122
+ newOptionIds = allOptionIds;
123
+ this.setState({
124
+ revampedGroups,
125
+ allOptionIds
126
+ });
127
+ }
128
+
129
+ if (selectedOption !== prevProps.selectedOption) {
130
+ let {
131
+ selectedId,
132
+ hoverIndex
133
+ } = this.handleGetSelectedId(this.props, newOptionIds);
134
+ newSelectedId = selectedId;
135
+ this.setState({
136
+ selectedId,
137
+ hoverIndex
138
+ });
139
+ }
140
+
141
+ let {
142
+ suggestionOptionIds
143
+ } = this.handleFilterSuggestions();
144
+ let hoverId = getIsEmptyValue(suggestionOptionIds[hoverIndex]) ? '' : suggestionOptionIds[hoverIndex];
145
+ let selSuggestion = this[`suggestion_${hoverId}`];
146
+ isPopupOpen && scrollTo(suggestionContainer, selSuggestion);
147
+
148
+ if (isPopupOpen !== prevProps.isPopupOpen) {
149
+ if (isPopupOpen) {
150
+ setTimeout(() => {
151
+ this.searchInput && this.searchInput.focus({
152
+ preventScroll: true
153
+ });
154
+ }, 10);
155
+ } else {
156
+ // needSearch && this.valueInput && this.valueInput.focus({preventScroll:true});
157
+ isSearchClearOnClose && searchStr && this.handleSearch('');
158
+ let hoverIndex = newOptionIds.indexOf(newSelectedId);
159
+ hoverIndex = hoverIndex >= 0 ? hoverIndex : 0;
160
+ this.setState({
161
+ hoverIndex
162
+ });
163
+ }
164
+ }
165
+ }
166
+
167
+ componentWillUnmount() {
168
+ this._isMounted = false;
169
+ }
170
+
171
+ handleGetGroupSelectOptions(props) {
172
+ let {
173
+ groupedOptions
174
+ } = props;
175
+ return this.getGroupSelectOptions({
176
+ groupedOptions
177
+ });
178
+ }
179
+
180
+ handleGetSelectedId(props, allOptionIds) {
181
+ let {
182
+ selectedOption,
183
+ isDefaultSelectValue
184
+ } = props;
185
+ let {
186
+ selected,
187
+ groupId
188
+ } = selectedOption;
189
+ let selectedId = optionIdGrouping(selected, groupId);
190
+ let selectedIdIndex = allOptionIds.indexOf(selectedId);
191
+
192
+ if (selectedIdIndex === -1) {
193
+ selectedIdIndex = 0;
194
+
195
+ if (isDefaultSelectValue) {
196
+ [selectedId] = allOptionIds;
197
+ } else {
198
+ selectedId = '';
199
+ }
200
+ }
201
+
202
+ return {
203
+ selectedId,
204
+ hoverIndex: selectedIdIndex
205
+ };
206
+ }
207
+
208
+ handleFilterSuggestions() {
209
+ let {
210
+ needSearch,
211
+ needLocalSearch
212
+ } = this.props;
213
+ let {
214
+ revampedGroups,
215
+ searchStr = '',
216
+ allOptionIds
217
+ } = this.state;
218
+
219
+ if (needSearch && searchStr && searchStr.trim().length) {
220
+ searchStr = getSearchString(searchStr);
221
+ let {
222
+ suggestionGroups,
223
+ suggestionOptionIds
224
+ } = this.getFilterSuggestions({
225
+ revampedGroups,
226
+ searchStr,
227
+ needSearch: needLocalSearch
228
+ });
229
+ return {
230
+ suggestionGroups,
231
+ suggestionOptionIds
232
+ };
233
+ }
234
+
235
+ return {
236
+ suggestionGroups: revampedGroups,
237
+ suggestionOptionIds: allOptionIds
238
+ };
239
+ }
240
+
241
+ handleSearchOptions() {
242
+ let {
243
+ onSearch
244
+ } = this.props;
245
+ let {
246
+ searchStr
247
+ } = this.state;
248
+ searchStr && this.handleFetchOptions(onSearch, searchStr);
249
+ }
250
+
251
+ handleSearch(value) {
252
+ // let { value = '' } = e.target;
253
+ let {
254
+ searchStr = ''
255
+ } = this.state;
256
+ let {
257
+ onSearch
258
+ } = this.props;
259
+ let searchStrRegex = getSearchString(searchStr);
260
+ let valueStrRegex = getSearchString(value);
261
+ let isSearch = searchStrRegex !== valueStrRegex ? true : false;
262
+ this.setState({
263
+ searchStr: value,
264
+ hoverIndex: 0
265
+ }, () => {
266
+ if (!value) {
267
+ onSearch && this.handleFetchOptions(onSearch, '');
268
+ } else if (isSearch && onSearch) {
269
+ this.handleSearchOptions();
270
+ }
271
+ });
272
+ }
273
+
274
+ handleKeyDown(e) {
275
+ let {
276
+ isPopupOpen,
277
+ isPopupOpenOnEnter,
278
+ onKeyDown
279
+ } = this.props;
280
+ let {
281
+ hoverIndex
282
+ } = this.state;
283
+ let {
284
+ suggestionOptionIds
285
+ } = this.handleFilterSuggestions();
286
+ let {
287
+ keyCode
288
+ } = e;
289
+
290
+ if (!isPopupOpen && !isPopupOpenOnEnter) {
291
+ onKeyDown && onKeyDown(e);
292
+ }
293
+
294
+ if (isPopupOpen && (keyCode === 38 || keyCode === 40) && e.preventDefault) {
295
+ e.preventDefault(); //prevent body scroll
296
+ } else if (!isPopupOpen && keyCode === 40) {
297
+ e.preventDefault(); //prevent body scroll
298
+
299
+ this.togglePopup(e);
300
+ }
301
+
302
+ if (keyCode === 38 && isPopupOpen && suggestionOptionIds.length) {
303
+ // eslint-disable-next-line
304
+ if (hoverIndex === 0) {// hoverIndex = options.length - 1;
305
+ } else {
306
+ hoverIndex -= 1;
307
+ }
308
+
309
+ this.setState({
310
+ hoverIndex
311
+ });
312
+ } else if (keyCode === 40 && isPopupOpen && suggestionOptionIds.length) {
313
+ // eslint-disable-next-line
314
+ if (hoverIndex === suggestionOptionIds.length - 1) {// hoverIndex = 0;
315
+ } else {
316
+ if (hoverIndex === suggestionOptionIds.length - 3) {
317
+ this.handleGetNextOptions();
318
+ }
319
+
320
+ hoverIndex += 1;
321
+ }
322
+
323
+ this.setState({
324
+ hoverIndex
325
+ });
326
+ } else if (keyCode === 13) {
327
+ let id = suggestionOptionIds[hoverIndex];
328
+ isPopupOpen && this.handleChange(id, null, null, e);
329
+ !isPopupOpen && isPopupOpenOnEnter && this.togglePopup(e);
330
+ } else if (keyCode === 27) {
331
+ this.valueInput && this.valueInput.focus({
332
+ preventScroll: true
333
+ }); // this.handlePopupClose(e);
334
+ }
335
+ }
336
+
337
+ handleMouseEnter(id) {
338
+ let {
339
+ hoverIndex
340
+ } = this.state;
341
+ let {
342
+ suggestionOptionIds
343
+ } = this.handleFilterSuggestions();
344
+ let newHoverIndex = suggestionOptionIds.indexOf(id);
345
+ hoverIndex !== newHoverIndex && this.setState({
346
+ hoverIndex: newHoverIndex
347
+ });
348
+ }
349
+
350
+ handleChange(id, value, index, e) {
351
+ e && e.preventDefault && e.preventDefault();
352
+ let {
353
+ onChange,
354
+ isReadOnly
355
+ } = this.props;
356
+ let {
357
+ normalizedAllOptions
358
+ } = this;
359
+ let {
360
+ id: selected,
361
+ groupId
362
+ } = extractOptionId(id);
363
+
364
+ if (!getIsEmptyValue(id) && !isReadOnly) {
365
+ onChange && onChange({
366
+ groupId,
367
+ selected
368
+ }, normalizedAllOptions[id]);
369
+ this.handlePopupClose(); // this.valueInput && this.valueInput.focus({preventScroll:true});
370
+ }
371
+ }
372
+
373
+ togglePopup(e) {
374
+ let {
375
+ togglePopup,
376
+ isReadOnly,
377
+ defaultDropBoxPosition
378
+ } = this.props;
379
+ !isReadOnly && togglePopup(e, defaultDropBoxPosition ? `${defaultDropBoxPosition}Center` : null);
380
+ }
381
+
382
+ handlePopupClose(e) {
383
+ let {
384
+ closePopupOnly,
385
+ isPopupOpen
386
+ } = this.props;
387
+ this.valueInput && this.valueInput.focus({
388
+ preventScroll: true
389
+ });
390
+ isPopupOpen && closePopupOnly(e);
391
+ }
392
+
393
+ suggestionContainerRef(el) {
394
+ this.suggestionContainer = el;
395
+ }
396
+
397
+ suggestionItemRef(el, index, id) {
398
+ this[`suggestion_${id}`] = el;
399
+ }
400
+
401
+ searchInputRef(el) {
402
+ this.searchInput = el;
403
+ }
404
+
405
+ valueInputRef(el) {
406
+ let {
407
+ getRef
408
+ } = this.props;
409
+ this.valueInput = el;
410
+ getRef && getRef(el);
411
+ }
412
+
413
+ handleSelectFocus(e) {
414
+ let {
415
+ target
416
+ } = e || {};
417
+ target && target.setSelectionRange(target, 0);
418
+ }
419
+
420
+ handleClearSearch() {
421
+ this.handleSearch('');
422
+ setTimeout(() => {
423
+ this.searchInput && this.searchInput.focus({
424
+ preventScroll: true
425
+ });
426
+ }, 1);
427
+ }
428
+
429
+ handleValueInputChange(e) {
430
+ let {
431
+ which
432
+ } = e;
433
+ let typeString = String.fromCharCode(which);
434
+ let {
435
+ isPopupOpen,
436
+ autoSelectOnType
437
+ } = this.props;
438
+
439
+ if (!isPopupOpen && autoSelectOnType) {
440
+ this.valueInputTypeString += (typeString || '').trim();
441
+ this.handleChangeOnType();
442
+ }
443
+ }
444
+
445
+ handleChangeOnType() {
446
+ let {
447
+ revampedGroups
448
+ } = this.state;
449
+ let typeString = this.valueInputTypeString;
450
+ this.valueInputTypeString = '';
451
+
452
+ let changeValue = () => {
453
+ let id = this.autoSelectSuggestions[this.autoSelectIndex];
454
+ let {
455
+ suggestionOptionIds
456
+ } = this.handleFilterSuggestions();
457
+
458
+ if (!getIsEmptyValue(id)) {
459
+ this.handleChange(id);
460
+ let hoverIndex = suggestionOptionIds.indexOf(id);
461
+ this.setState({
462
+ hoverIndex
463
+ });
464
+ }
465
+ };
466
+
467
+ if (typeString && typeString === this.valueInputSearchString) {
468
+ if (this.autoSelectIndex < this.autoSelectSuggestions.length - 1) {
469
+ this.autoSelectIndex += 1;
470
+ } else {
471
+ this.autoSelectIndex = 0;
472
+ }
473
+
474
+ changeValue();
475
+ } else if (typeString) {
476
+ this.valueInputSearchString = typeString;
477
+ let {
478
+ suggestionOptionIds
479
+ } = this.getFilterSuggestions({
480
+ revampedGroups,
481
+ searchStr: typeString,
482
+ needSearch: true,
483
+ isStartsWithSearch: true
484
+ });
485
+ this.autoSelectIndex = 0;
486
+ this.autoSelectSuggestions = suggestionOptionIds;
487
+ changeValue();
488
+ }
489
+ }
490
+
491
+ handleScroll(e) {
492
+ let ele = e.target;
493
+ let isScrollReachedBottom = findScrollEnd(ele);
494
+ isScrollReachedBottom && this.handleGetNextOptions();
495
+ }
496
+
497
+ handleFetchOptions(APICall) {
498
+ let searchStr = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
499
+ // let funcArgs = args.slice(1, args.length);
500
+ let {
501
+ isFetchingOptions = false
502
+ } = this.state;
503
+ let {
504
+ _isMounted
505
+ } = this;
506
+
507
+ if (!isFetchingOptions && APICall) {
508
+ this.setState({
509
+ isFetchingOptions: true
510
+ });
511
+
512
+ try {
513
+ return APICall(searchStr).then(() => {
514
+ _isMounted && this.setState({
515
+ isFetchingOptions: false
516
+ });
517
+ }, () => {
518
+ _isMounted && this.setState({
519
+ isFetchingOptions: false
520
+ });
521
+ });
522
+ } catch (e) {
523
+ _isMounted && this.setState({
524
+ isFetchingOptions: false
525
+ });
526
+ }
527
+ }
528
+ }
529
+
530
+ handleGetNextOptions() {
531
+ let {
532
+ isNextOptions,
533
+ getNextOptions
534
+ } = this.props;
535
+ let {
536
+ searchStr
537
+ } = this.state;
538
+ isNextOptions && getNextOptions && this.handleFetchOptions(getNextOptions, searchStr);
539
+ }
540
+
541
+ responsiveFunc(_ref) {
542
+ let {
543
+ mediaQueryOR
544
+ } = _ref;
545
+ return {
546
+ tabletMode: mediaQueryOR([{
547
+ maxWidth: 700
548
+ }])
549
+ };
550
+ }
551
+
552
+ render() {
553
+ let {
554
+ isDisabled,
555
+ isReadOnly,
556
+ needSearch,
557
+ emptyMessage,
558
+ needSelectDownIcon,
559
+ maxLength,
560
+ needBorder,
561
+ placeHolder,
562
+ defaultDropBoxPosition,
563
+ searchBoxPlaceHolder,
564
+ searchEmptyMessage,
565
+ dataId,
566
+ dataIdSlctComp,
567
+ dataIdDownIcon,
568
+ dataIdSrchEmptyMsg,
569
+ needResponsive,
570
+ className,
571
+ size,
572
+ title,
573
+ textBoxSize,
574
+ textBoxVariant,
575
+ animationStyle,
576
+ dropBoxSize,
577
+ searchBoxSize,
578
+ getTargetRef,
579
+ isPopupOpen,
580
+ position,
581
+ getContainerRef,
582
+ isPopupReady,
583
+ removeClose,
584
+ borderColor,
585
+ needTick,
586
+ children,
587
+ getFooter,
588
+ i18nKeys,
589
+ htmlId,
590
+ iconOnHover,
591
+ isLoading,
592
+ dataSelectorId
593
+ } = this.props;
594
+ i18nKeys = Object.assign({}, i18nKeys, {
595
+ emptyText: i18nKeys.emptyText || emptyMessage,
596
+ searchEmptyText: i18nKeys.searchEmptyText || searchEmptyMessage
597
+ });
598
+ let {
599
+ selectedId,
600
+ hoverIndex,
601
+ searchStr,
602
+ revampedGroups,
603
+ isFetchingOptions
604
+ } = this.state;
605
+ let {
606
+ normalizedFormatOptions
607
+ } = this;
608
+ let {
609
+ suggestionGroups,
610
+ suggestionOptionIds
611
+ } = this.handleFilterSuggestions();
612
+ let {
613
+ value: selected = ''
614
+ } = normalizedFormatOptions[selectedId] || {};
615
+ let setAriaId = this.getNextAriaId();
616
+ let ariaErrorId = this.getNextAriaId();
617
+ return /*#__PURE__*/React.createElement("div", {
618
+ className: `${style.container} ${style[`box_${size}`]} ${isReadOnly ? style.readonly : ''} ${borderColor === 'transparent' ? style.transparentContainer : ''} ${iconOnHover && (isReadOnly || isDisabled) ? style.iconOnHoverReadonly : iconOnHover && !(isReadOnly || isDisabled) ? style.iconOnHoverStyle : ''}`,
619
+ "data-id": dataIdSlctComp,
620
+ "data-test-id": dataIdSlctComp,
621
+ "data-title": isDisabled ? title : null,
622
+ "data-selector-id": dataSelectorId
623
+ }, /*#__PURE__*/React.createElement("div", {
624
+ className: `${className ? className : ''}`,
625
+ onClick: isDisabled || isReadOnly ? null : this.togglePopup,
626
+ ref: getTargetRef
627
+ }, children ? children : /*#__PURE__*/React.createElement(React.Fragment, null, needSelectDownIcon ? /*#__PURE__*/React.createElement(TextBoxIcon, {
628
+ isDisabled: isDisabled,
629
+ iconRotated: isPopupOpen,
630
+ inputRef: this.valueInputRef,
631
+ maxLength: maxLength,
632
+ needBorder: needBorder,
633
+ onFocus: this.handleSelectFocus,
634
+ onKeyDown: this.handleKeyDown,
635
+ placeHolder: placeHolder,
636
+ isReadOnly: true,
637
+ size: textBoxSize,
638
+ value: selected,
639
+ variant: textBoxVariant,
640
+ needReadOnlyStyle: isReadOnly ? true : false,
641
+ dataId: dataId,
642
+ onKeyPress: this.handleValueInputChange,
643
+ needEffect: isReadOnly || isDisabled ? false : true,
644
+ borderColor: borderColor,
645
+ htmlId: htmlId,
646
+ a11y: {
647
+ role: 'combobox',
648
+ ariaControls: setAriaId,
649
+ ariaExpanded: !isReadOnly && !isDisabled && isPopupOpen ? true : false,
650
+ ariaHaspopup: true,
651
+ ariaReadonly: true,
652
+ ariaActivedescendant: selectedId,
653
+ ariaOwns: setAriaId
654
+ },
655
+ isFocus: isPopupReady,
656
+ autoComplete: false
657
+ }, /*#__PURE__*/React.createElement(Container, {
658
+ align: "both",
659
+ dataId: dataIdDownIcon
660
+ }, /*#__PURE__*/React.createElement(Icon, {
661
+ name: "ZD-down",
662
+ size: "7",
663
+ iconClass: style.arrowIcon
664
+ }))) : /*#__PURE__*/React.createElement(Textbox, {
665
+ isDisabled: isDisabled,
666
+ inputRef: this.valueInputRef,
667
+ maxLength: maxLength,
668
+ needBorder: needBorder,
669
+ onFocus: this.handleSelectFocus,
670
+ onKeyDown: this.handleKeyDown,
671
+ placeHolder: placeHolder,
672
+ isReadOnly: true,
673
+ needEffect: isReadOnly || isDisabled ? false : true,
674
+ size: textBoxSize,
675
+ value: selected,
676
+ variant: textBoxVariant,
677
+ needReadOnlyStyle: isReadOnly ? true : false,
678
+ dataId: dataId,
679
+ onKeyPress: this.handleValueInputChange,
680
+ borderColor: borderColor,
681
+ htmlId: htmlId,
682
+ a11y: {
683
+ role: 'combobox',
684
+ ariaLabel: TextBox_ally_label,
685
+ ariaControls: setAriaId,
686
+ ariaExpanded: !isReadOnly && !isDisabled && isPopupOpen ? true : false,
687
+ ariaHaspopup: true,
688
+ ariaReadonly: true,
689
+ ariaActivedescendant: selectedId,
690
+ ariaOwns: setAriaId
691
+ },
692
+ autoComplete: false,
693
+ isFocus: isPopupReady
694
+ }))), !isReadOnly && !isDisabled && isPopupOpen ? /*#__PURE__*/React.createElement(ResponsiveReceiver, {
695
+ query: this.responsiveFunc,
696
+ responsiveId: "Helmet"
697
+ }, _ref2 => {
698
+ let {
699
+ tabletMode
700
+ } = _ref2;
701
+ return /*#__PURE__*/React.createElement(ResponsiveDropBox, {
702
+ animationStyle: animationStyle,
703
+ boxPosition: position || `${defaultDropBoxPosition}Center`,
704
+ getRef: getContainerRef,
705
+ isActive: isPopupReady,
706
+ isAnimate: true,
707
+ isArrow: false,
708
+ onClick: removeClose,
709
+ needResponsive: needResponsive,
710
+ isPadding: false,
711
+ isResponsivePadding: getFooter ? false : true,
712
+ alignBox: "row"
713
+ }, isLoading ? /*#__PURE__*/React.createElement(Container, {
714
+ align: "both",
715
+ className: style.loader
716
+ }, /*#__PURE__*/React.createElement(Loader, null)) : /*#__PURE__*/React.createElement(Box, {
717
+ flexible: true
718
+ }, /*#__PURE__*/React.createElement(Card, {
719
+ customClass: style.box,
720
+ onScroll: this.handleScroll
721
+ }, needSearch ? /*#__PURE__*/React.createElement(CardHeader, null, /*#__PURE__*/React.createElement("div", {
722
+ className: `${style.search} ${style[size]}`
723
+ }, /*#__PURE__*/React.createElement(TextBoxIcon, {
724
+ inputRef: this.searchInputRef,
725
+ maxLength: maxLength,
726
+ onChange: this.handleSearch,
727
+ onKeyDown: this.handleKeyDown,
728
+ placeHolder: searchBoxPlaceHolder,
729
+ size: searchBoxSize,
730
+ value: searchStr,
731
+ onClear: this.handleClearSearch,
732
+ a11y: {
733
+ ariaControls: setAriaId,
734
+ ariaAutocomplete: 'list',
735
+ ariaDescribedby: ariaErrorId
736
+ },
737
+ autoComplete: false
738
+ }))) : null, /*#__PURE__*/React.createElement(CardContent, {
739
+ shrink: true,
740
+ customClass: !tabletMode && dropBoxSize ? style[dropBoxSize] : '',
741
+ eleRef: this.suggestionContainerRef
742
+ }, suggestionGroups.length ? suggestionGroups.map(group => {
743
+ let {
744
+ id: groupId,
745
+ name: groupName,
746
+ options
747
+ } = group;
748
+ let hoverId = suggestionOptionIds[hoverIndex];
749
+ return /*#__PURE__*/React.createElement(React.Fragment, {
750
+ key: groupId
751
+ }, groupName && /*#__PURE__*/React.createElement("div", {
752
+ className: style.groupTitle
753
+ }, /*#__PURE__*/React.createElement(DropDownHeading, {
754
+ text: groupName,
755
+ a11y: {
756
+ role: 'heading'
757
+ }
758
+ })), /*#__PURE__*/React.createElement(Suggestions, {
759
+ activeId: selectedId,
760
+ suggestions: options,
761
+ getRef: this.suggestionItemRef,
762
+ hoverId: hoverId,
763
+ onClick: this.handleChange,
764
+ onMouseEnter: this.handleMouseEnter,
765
+ selectedOptions: [selectedId],
766
+ needTick: needTick,
767
+ needBorder: false,
768
+ htmlId: setAriaId,
769
+ a11y: {
770
+ ariaParentRole: 'listbox',
771
+ role: 'option'
772
+ }
773
+ }));
774
+ }) : /*#__PURE__*/React.createElement(EmptyState, {
775
+ options: revampedGroups,
776
+ searchString: searchStr,
777
+ suggestions: suggestionGroups,
778
+ dataId: dataIdSrchEmptyMsg,
779
+ isLoading: isFetchingOptions,
780
+ i18nKeys: i18nKeys,
781
+ htmlId: ariaErrorId
782
+ }), isFetchingOptions && /*#__PURE__*/React.createElement(Container, {
783
+ isCover: false,
784
+ align: "both"
785
+ }, /*#__PURE__*/React.createElement(Loader, null))), getFooter ? /*#__PURE__*/React.createElement(CardFooter, null, getFooter()) : null)));
786
+ }) : null);
787
+ }
788
+
789
+ }
790
+ GroupSelectComponent.propTypes = GroupSelect_propTypes;
791
+ GroupSelectComponent.defaultProps = GroupSelect_defaultProps;
792
+ GroupSelectComponent.displayName = 'GroupSelect';
793
+ let GroupSelect = Popup(GroupSelectComponent);
794
+ GroupSelect.defaultProps = GroupSelectComponent.defaultProps;
795
+ GroupSelect.propTypes = GroupSelectComponent.propTypes;
796
+ export default GroupSelect; // if (__DOCS__) {
797
+ // GroupSelect.docs = {
798
+ // componentGroup: 'Form Elements',
799
+ // folderName: 'Style Guide'
800
+ // };
801
+ // // eslint-disable-next-line react/forbid-foreign-prop-types
802
+ // GroupSelect.propTypes = GroupSelectComponent.propTypes;
803
+ // }