@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,1120 @@
1
+ /**** Libraries ****/
2
+ import React from 'react';
3
+ import { MultiSelect_propTypes } from '../../MultiSelect/props/propTypes';
4
+ import { MultiSelect_defaultProps } from '../../MultiSelect/props/defaultProps';
5
+ /**** Components ****/
6
+
7
+ import Popup from '../Popup/Popup';
8
+ import TextBoxIcon from '../TextBoxIcon/TextBoxIcon';
9
+ import { Container, Box } from '../Layout';
10
+ import Card, { CardContent, CardHeader, CardFooter } from '../Card/Card';
11
+ import SelectedOptions from './SelectedOptions';
12
+ import Suggestions from './Suggestions';
13
+ import EmptyState from './EmptyState';
14
+ import MobileHeader from './MobileHeader/MobileHeader';
15
+ import MultiSelectHeader from './MultiSelectHeader';
16
+ import CssProvider from '../../Provider/CssProvider';
17
+ import { getUniqueId } from '../../Provider/IdProvider';
18
+ import ResponsiveDropBox from '../ResponsiveDropBox/ResponsiveDropBox';
19
+ import { ResponsiveReceiver } from '../Responsive/CustomResponsive';
20
+ import Loader from '@zohodesk/svg/lib/Loader/Loader';
21
+ /**** Icons ****/
22
+
23
+ import { Icon } from '@zohodesk/icons';
24
+ /**** CSS ****/
25
+
26
+ import style from '../../MultiSelect/MultiSelect.module.css';
27
+ /**** Methods ****/
28
+
29
+ import { debounce, scrollTo, bind, getIsEmptyValue, getSearchString, findScrollEnd } from '../../utils/Common.js';
30
+ import { makeFormatOptions, makeGetMultiSelectFilterSuggestions as makeGetFilterSuggestions, makeGetMultiSelectSelectedOptions as makeGetSelectedOptions, makeObjectConcat, filterSelectedOptions, makeGetIsShowClearIcon } from '../../utils/dropDownUtils';
31
+ import { getLibraryConfig } from '../../Provider/Config';
32
+ /* eslint-disable react/forbid-component-props */
33
+
34
+ /* eslint-disable react/no-unused-prop-types */
35
+
36
+ const dummyArray = [];
37
+ export class MultiSelectComponent extends React.Component {
38
+ constructor(props) {
39
+ super(props);
40
+ this.getNextAriaId = getUniqueId(this);
41
+ this.getFilterSuggestions = makeGetFilterSuggestions();
42
+ this.formatOptions = makeFormatOptions();
43
+ this.getSelectedOptions = makeGetSelectedOptions();
44
+ this.getIsShowClearIcon = makeGetIsShowClearIcon(); //Use in AdvancedMultiSelect component
45
+
46
+ this.objectConcat = makeObjectConcat();
47
+ this.formatSelectedOptions = makeFormatOptions();
48
+ const {
49
+ selectedOptions,
50
+ searchDebounceTime = 500
51
+ } = this.props;
52
+ const {
53
+ allOptions,
54
+ normalizedAllOptions,
55
+ normalizedFormatOptions
56
+ } = this.handleFormatOptions(this.props);
57
+ const {
58
+ formatSelectedOptions,
59
+ normalizedSelectedOptions,
60
+ selectedOptionIds
61
+ } = this.handleGetSelectedOptions(selectedOptions, normalizedFormatOptions, this.props);
62
+ this.state = {
63
+ options: allOptions,
64
+ optionsNormalize: normalizedAllOptions,
65
+ selectedOptions: formatSelectedOptions,
66
+ selectedOptionIds,
67
+ searchStr: '',
68
+ hoverOption: 0,
69
+ isFetchingOptions: false,
70
+ highLightedSelectOptions: [],
71
+ lastHighLightedSelectOption: '',
72
+ shiftKeyPressHighLighted: 0,
73
+ isActive: false
74
+ };
75
+ this.allSelectedOptionsDetails = normalizedSelectedOptions;
76
+ this.suggestionsOrder = [];
77
+ this._isMounted = false;
78
+ bind.apply(this, ['handleInputCick', 'handleFilterSuggestions', 'handleKeyDown', 'handleSelectAll', 'handleDeselectAll', 'handleSelectOption', 'handleRemoveOption', 'handleSearch', 'handleClickSelectedOption', 'handleChange', 'handlePopupClose', 'togglePopup', 'selectedOptionRef', 'searchInputRef', 'suggestionContainerRef', 'suggestionItemRef', 'selectedOptionContainerRef', 'handleActive', 'handleInactive', 'handleMouseEnter', 'handleFetchOptions', 'handleFormatOptions', 'handleGetSelectedOptions', 'handleComponentDidUpdate', 'handleInputFocus', 'handleExposedPublicMethods', 'getSelectionUI', 'moveFocusToTextbox']);
79
+ this.handleSearchOptions = debounce(this.handleSearchOptions.bind(this), searchDebounceTime);
80
+ this.handleScroll = this.handleScroll.bind(this);
81
+ this.handleScrollFuncCall = debounce(this.handleScrollFuncCall.bind(this), 500);
82
+ }
83
+
84
+ componentDidMount() {
85
+ // let { suggestionContainer } = this;
86
+ this._isMounted = true;
87
+ this.handleExposedPublicMethods(); // suggestionContainer &&
88
+ // suggestionContainer.addEventListener('scroll', this.handleScroll);
89
+ }
90
+
91
+ UNSAFE_componentWillReceiveProps(nextProps) {
92
+ const {
93
+ selectedOptions,
94
+ options,
95
+ valueField,
96
+ textField,
97
+ prefixText
98
+ } = nextProps;
99
+ const oldProps = this.props;
100
+
101
+ if (selectedOptions !== oldProps.selectedOptions || options !== oldProps.options || valueField !== oldProps.valueField || textField !== oldProps.textField || prefixText !== oldProps.prefixText //For GroupMultiSelect component
102
+ ) {
103
+ const {
104
+ allOptions,
105
+ normalizedAllOptions,
106
+ normalizedFormatOptions
107
+ } = this.handleFormatOptions(nextProps);
108
+ const {
109
+ allSelectedOptionsDetails: oldAllSelectedOptionsDetails
110
+ } = this;
111
+ const optionsDetails = Object.assign({}, oldAllSelectedOptionsDetails, normalizedFormatOptions);
112
+ const {
113
+ formatSelectedOptions,
114
+ normalizedSelectedOptions,
115
+ selectedOptionIds
116
+ } = this.handleGetSelectedOptions(selectedOptions, optionsDetails, nextProps);
117
+ this.allSelectedOptionsDetails = Object.assign(oldAllSelectedOptionsDetails, normalizedSelectedOptions);
118
+ this.setState({
119
+ options: allOptions,
120
+ optionsNormalize: normalizedAllOptions,
121
+ selectedOptions: formatSelectedOptions,
122
+ selectedOptionIds
123
+ }, () => {
124
+ const {
125
+ hoverOption
126
+ } = this.state;
127
+ const suggestions = this.handleFilterSuggestions();
128
+ const suggestionsLen = suggestions.length;
129
+ const {
130
+ id
131
+ } = suggestions[hoverOption] || {};
132
+ const newHoverOption = !getIsEmptyValue(id) ? hoverOption : suggestionsLen ? suggestionsLen - 1 : 0;
133
+ this.setState({
134
+ hoverOption: newHoverOption
135
+ });
136
+ });
137
+ }
138
+ }
139
+
140
+ componentDidUpdate(prevProps, prevState) {
141
+ const {
142
+ suggestionContainer,
143
+ selectedOptionContainer,
144
+ suggestionsOrder
145
+ } = this;
146
+ const {
147
+ hoverOption,
148
+ highLightedSelectOptions,
149
+ selectedOptions,
150
+ searchStr
151
+ } = this.state;
152
+ const {
153
+ needLocalSearch,
154
+ isPopupOpen,
155
+ onDropBoxClose,
156
+ onDropBoxOpen,
157
+ isSearchClearOnClose
158
+ } = this.props; //handle dropbox open & close
159
+
160
+ if (prevProps.isPopupOpen !== isPopupOpen) {
161
+ isPopupOpen && onDropBoxOpen && this.handleFetchOptions(onDropBoxOpen, searchStr);
162
+
163
+ if (!isPopupOpen) {
164
+ this.setState({
165
+ hoverOption: 0
166
+ });
167
+ isSearchClearOnClose && searchStr && this.handleSearch('');
168
+ onDropBoxClose && onDropBoxClose();
169
+ }
170
+ } //scrollTo handling
171
+
172
+
173
+ const hoverId = suggestionsOrder[hoverOption] || '';
174
+ const selectedSuggestion = this[`suggestion_${hoverId}`];
175
+ const lastHighLightedSelectOption = highLightedSelectOptions.slice(-1).length ? highLightedSelectOptions.slice(-1)[0] : null;
176
+ const selectedOption = this[`selectedOption_${lastHighLightedSelectOption}`];
177
+ isPopupOpen && scrollTo(suggestionContainer, selectedSuggestion);
178
+ selectedOptions.length && selectedOption && scrollTo(selectedOptionContainer, selectedOption); //When suggestions length less than 5, getNextOptions function call
179
+
180
+ const {
181
+ isNextOptions,
182
+ getNextOptions
183
+ } = this.props; // let { searchStr } = this.state;
184
+
185
+ const suggestions = this.handleFilterSuggestions();
186
+ const suggestionsLen = suggestions.length;
187
+
188
+ if (isPopupOpen && suggestionsLen <= 5 && isNextOptions && getNextOptions && !needLocalSearch) {
189
+ this.handleFetchOptions(getNextOptions, searchStr);
190
+ } //Need To MultiselectNew Component
191
+
192
+
193
+ this.handleComponentDidUpdate(prevProps, prevState);
194
+ }
195
+
196
+ componentWillUnmount() {
197
+ // let { suggestionContainer } = this;
198
+ this._isMounted = false; // suggestionContainer &&
199
+ // suggestionContainer.removeEventListener('scroll', this.handleScroll);
200
+ }
201
+
202
+ handleComponentDidUpdate() {
203
+ return;
204
+ }
205
+
206
+ handleFormatOptions(props) {
207
+ const {
208
+ options,
209
+ valueField,
210
+ textField,
211
+ prefixText,
212
+ disabledOptions
213
+ } = props;
214
+ return this.formatOptions({
215
+ options,
216
+ valueField,
217
+ textField,
218
+ prefixText,
219
+ optionType: 'default',
220
+ disabledOptions
221
+ });
222
+ }
223
+
224
+ handleGetSelectedOptions(selectedOptions, normalizedFormatOptions) {
225
+ return this.getSelectedOptions({
226
+ selectedOptions,
227
+ normalizedFormatOptions
228
+ });
229
+ }
230
+
231
+ handleInputCick(e) {
232
+ const {
233
+ removeClose
234
+ } = this.props;
235
+ const {
236
+ highLightedSelectOptions,
237
+ searchStr = ''
238
+ } = this.state;
239
+
240
+ if (highLightedSelectOptions.length) {
241
+ this.setState({
242
+ highLightedSelectOptions: [],
243
+ shiftKeyPressHighLighted: 0,
244
+ lastHighLightedSelectOption: ''
245
+ });
246
+ removeClose(e);
247
+ } else if (searchStr.length) {
248
+ removeClose(e);
249
+ } else {
250
+ this.togglePopup(e);
251
+ }
252
+ }
253
+
254
+ handleFilterSuggestions() {
255
+ const {
256
+ options = dummyArray,
257
+ searchStr = ''
258
+ } = this.state;
259
+ const {
260
+ selectedOptions,
261
+ needLocalSearch,
262
+ keepSelectedOptions
263
+ } = this.props;
264
+ const {
265
+ suggestions,
266
+ suggestionIds
267
+ } = this.getFilterSuggestions({
268
+ options,
269
+ selectedOptions,
270
+ searchStr: getSearchString(searchStr),
271
+ needSearch: needLocalSearch,
272
+ keepSelectedOptions
273
+ });
274
+ this.suggestionsOrder = suggestionIds;
275
+ return suggestions;
276
+ }
277
+
278
+ handleKeyDown(e) {
279
+ const {
280
+ keyCode,
281
+ ctrlKey,
282
+ metaKey,
283
+ shiftKey
284
+ } = e;
285
+ let suggestions = [];
286
+ let {
287
+ hoverOption,
288
+ searchStr,
289
+ highLightedSelectOptions,
290
+ lastHighLightedSelectOption,
291
+ shiftKeyPressHighLighted,
292
+ selectedOptionIds: selectedOptions
293
+ } = this.state;
294
+ const {
295
+ isNextOptions,
296
+ getNextOptions,
297
+ isPopupOpen,
298
+ isPopupOpenOnEnter,
299
+ onKeyDown
300
+ } = this.props;
301
+ const highLightedSelectOptionsLen = highLightedSelectOptions.length;
302
+
303
+ if (isPopupOpen && (keyCode === 38 || keyCode === 40 || keyCode === 13 || keyCode === 27 || keyCode === 9)) {
304
+ suggestions = this.handleFilterSuggestions();
305
+ }
306
+
307
+ if (!isPopupOpen && !isPopupOpenOnEnter) {
308
+ onKeyDown && onKeyDown(e);
309
+ }
310
+
311
+ if (!isPopupOpen && keyCode === 40) {
312
+ //down arrow press popup open
313
+ e.preventDefault(); //prevent body scroll
314
+
315
+ this.togglePopup(e);
316
+ }
317
+
318
+ const suggestionsLen = suggestions.length;
319
+
320
+ if (suggestionsLen && isPopupOpen && keyCode === 38) {
321
+ //up arrow
322
+
323
+ /*if (hoverOption === 0) { //disable first to last option higlight
324
+ !isNextOptions && this.setState({ hoverOption: suggestionsLen - 1 });
325
+ }*/
326
+ if (hoverOption) {
327
+ this.setState({
328
+ hoverOption: hoverOption - 1
329
+ });
330
+ }
331
+ } else if (suggestionsLen && isPopupOpen && keyCode === 40) {
332
+ //down arrow
333
+
334
+ /*else if (hoverOption === suggestionsLen - 1 || hoverOption === null) {
335
+ //disable last to first option higlight
336
+ !isNextOptions && this.setState({ hoverOption: 0 });
337
+ }*/
338
+ if (isNextOptions && suggestionsLen >= 5 && hoverOption === suggestionsLen - 3) {
339
+ getNextOptions && this.handleFetchOptions(getNextOptions, searchStr);
340
+ this.setState({
341
+ hoverOption: hoverOption + 1
342
+ });
343
+ } else if (suggestionsLen - 1 > hoverOption) {
344
+ this.setState({
345
+ hoverOption: hoverOption + 1
346
+ });
347
+ }
348
+ } else if (keyCode === 13) {
349
+ //enter key
350
+ const selectedOption = suggestions[hoverOption] || {};
351
+ const {
352
+ id
353
+ } = selectedOption;
354
+ isPopupOpen && !getIsEmptyValue(id) && this.handleSelectOption(id, e);
355
+ !isPopupOpen && isPopupOpenOnEnter && this.togglePopup(e);
356
+ } else if (selectedOptions.length && keyCode === 8 && !searchStr.length) {
357
+ //backspace key
358
+ if (highLightedSelectOptionsLen) {
359
+ this.handleRemoveOption(highLightedSelectOptions);
360
+ } else {
361
+ this.handleRemoveOption(selectedOptions.slice(-1)); // this.setState({
362
+ // highLightedSelectOptions: selectedOptions.slice(-1)
363
+ // });
364
+ }
365
+ } else if (selectedOptions && keyCode === 65 && (ctrlKey || metaKey) && !searchStr.length) {
366
+ //ctrl+a key
367
+ this.setState({
368
+ highLightedSelectOptions: selectedOptions,
369
+ shiftKeyPressHighLighted: 0
370
+ });
371
+ } else if (keyCode === 39 && shiftKey && selectedOptions.length && !searchStr.length) {
372
+ //shift+right arrow=39
373
+ const lastHighLightedSelectOptionIndex = lastHighLightedSelectOption && selectedOptions.indexOf(lastHighLightedSelectOption) >= 0 ? selectedOptions.indexOf(lastHighLightedSelectOption) : 0;
374
+ const newShiftKeyPressHighLighted = shiftKeyPressHighLighted ? shiftKeyPressHighLighted : shiftKeyPressHighLighted + 1;
375
+ const newHighLightedSelectOption = lastHighLightedSelectOptionIndex !== null ? selectedOptions[lastHighLightedSelectOptionIndex + newShiftKeyPressHighLighted] : selectedOptions[0];
376
+
377
+ if (!getIsEmptyValue(newHighLightedSelectOption)) {
378
+ const newLastHighLightedSelectOption = lastHighLightedSelectOption ? lastHighLightedSelectOption : selectedOptions[0];
379
+ highLightedSelectOptions = !shiftKeyPressHighLighted ? [newLastHighLightedSelectOption] : highLightedSelectOptions;
380
+ const isRemove = highLightedSelectOptions.indexOf(newHighLightedSelectOption) >= 0 && newHighLightedSelectOption !== lastHighLightedSelectOption ? true : false;
381
+ const newHighLightedSelectOptions = isRemove ? highLightedSelectOptions.filter(option => option !== newHighLightedSelectOption) : [...highLightedSelectOptions, newHighLightedSelectOption];
382
+ this.setState({
383
+ highLightedSelectOptions: newHighLightedSelectOptions,
384
+ shiftKeyPressHighLighted: newShiftKeyPressHighLighted + 1,
385
+ lastHighLightedSelectOption: newLastHighLightedSelectOption
386
+ });
387
+ }
388
+ } else if (keyCode === 37 && shiftKey && selectedOptions.length && !searchStr.length) {
389
+ // shift+left arrow=37
390
+ const lastHighLightedSelectOptionIndex = lastHighLightedSelectOption ? selectedOptions.indexOf(lastHighLightedSelectOption) : selectedOptions.length - 1;
391
+ const newShiftKeyPressHighLighted = shiftKeyPressHighLighted !== 1 ? shiftKeyPressHighLighted : shiftKeyPressHighLighted - 1;
392
+ const newHighLightedSelectOption = selectedOptions[lastHighLightedSelectOptionIndex + newShiftKeyPressHighLighted - 1];
393
+
394
+ if (!getIsEmptyValue(newHighLightedSelectOption)) {
395
+ const newLastHighLightedSelectOption = lastHighLightedSelectOption ? lastHighLightedSelectOption : selectedOptions.slice(-1)[0];
396
+ highLightedSelectOptions = !shiftKeyPressHighLighted ? [newLastHighLightedSelectOption] : highLightedSelectOptions;
397
+ const isRemove = highLightedSelectOptions.indexOf(newHighLightedSelectOption) >= 0 && newHighLightedSelectOption !== lastHighLightedSelectOption ? true : false;
398
+ const newHighLightedSelectOptions = isRemove ? highLightedSelectOptions.filter(option => option !== newHighLightedSelectOption) : [...highLightedSelectOptions, newHighLightedSelectOption];
399
+ this.setState({
400
+ highLightedSelectOptions: newHighLightedSelectOptions,
401
+ shiftKeyPressHighLighted: newShiftKeyPressHighLighted - 1,
402
+ lastHighLightedSelectOption: newLastHighLightedSelectOption
403
+ });
404
+ }
405
+ } else if ((keyCode === 39 || keyCode === 37) && selectedOptions.length && !searchStr.length) {
406
+ const isRightArrow = keyCode === 39 ? true : false; // let isLefttArrow = keyCode === 37 ? true : false;
407
+
408
+ if (highLightedSelectOptions.length) {
409
+ const [lastHighLightedSelectOption] = highLightedSelectOptions.slice(-1);
410
+ const lastHighLightedSelectOptionIndex = selectedOptions.indexOf(lastHighLightedSelectOption);
411
+ const newLastHighLightedSelectOptionIndex = isRightArrow ? lastHighLightedSelectOptionIndex === selectedOptions.length - 1 ? lastHighLightedSelectOptionIndex : lastHighLightedSelectOptionIndex + 1 : lastHighLightedSelectOptionIndex - 1;
412
+ const newLastHighLightedSelectOption = selectedOptions[newLastHighLightedSelectOptionIndex];
413
+ const isEmptyHighlighted = isRightArrow && highLightedSelectOptions.length === 1 && selectedOptions.slice(-1)[0] === lastHighLightedSelectOption ? true : false;
414
+
415
+ if (!getIsEmptyValue(newLastHighLightedSelectOption)) {
416
+ this.setState({
417
+ lastHighLightedSelectOption: isEmptyHighlighted ? '' : newLastHighLightedSelectOption,
418
+ highLightedSelectOptions: isEmptyHighlighted ? [] : [newLastHighLightedSelectOption],
419
+ shiftKeyPressHighLighted: 0
420
+ });
421
+ }
422
+ } else {
423
+ const [newLastHighLightedSelectOption] = isRightArrow ? selectedOptions : selectedOptions.slice(-1);
424
+ this.setState({
425
+ lastHighLightedSelectOption: newLastHighLightedSelectOption,
426
+ highLightedSelectOptions: [newLastHighLightedSelectOption],
427
+ shiftKeyPressHighLighted: 0
428
+ });
429
+ }
430
+ } // eslint-disable-next-line
431
+ else if (keyCode === 27) {// this.handlePopupClose(e);
432
+ } else if (keyCode === 9) {
433
+ this.handlePopupClose(e);
434
+ }
435
+ }
436
+
437
+ handleSelectAll(e) {
438
+ e && e.preventDefault();
439
+ const suggestions = this.handleFilterSuggestions();
440
+ const {
441
+ selectedOptions
442
+ } = this.props;
443
+ const newSelectedOptions = [];
444
+ suggestions.forEach(option => {
445
+ const {
446
+ id
447
+ } = option;
448
+
449
+ if (selectedOptions.indexOf(id) === -1) {
450
+ newSelectedOptions.push(id);
451
+ }
452
+ });
453
+ this.handleChange([...selectedOptions, ...newSelectedOptions]); // this.handlePopupClose(e);
454
+ }
455
+
456
+ handleDeselectAll(e) {
457
+ e && e.preventDefault();
458
+ const {
459
+ removeClose
460
+ } = this.props;
461
+ const {
462
+ highLightedSelectOptions
463
+ } = this.state;
464
+
465
+ if (highLightedSelectOptions.length) {
466
+ this.setState({
467
+ highLightedSelectOptions: [],
468
+ lastHighLightedSelectOption: ''
469
+ });
470
+ }
471
+
472
+ removeClose(e);
473
+ this.handleChange([]);
474
+ }
475
+
476
+ handleSelectOption(option, value, index, e) {
477
+ const {
478
+ selectedOptions,
479
+ isSearchClearOnSelect,
480
+ keepSelectedOptions
481
+ } = this.props;
482
+ const {
483
+ searchStr
484
+ } = this.state;
485
+
486
+ if (searchStr.trim() != '' && isSearchClearOnSelect) {
487
+ this.handleSearch('');
488
+ }
489
+
490
+ if (keepSelectedOptions && selectedOptions.indexOf(option) != -1) {
491
+ let newSelectedOptions = selectedOptions.filter(id => {
492
+ return id != option;
493
+ });
494
+ this.handleChange(newSelectedOptions, e);
495
+ } else {
496
+ this.handleChange([...selectedOptions, option], e);
497
+ }
498
+ }
499
+
500
+ handleRemoveOption(options) {
501
+ const newOptions = !getIsEmptyValue(options) && !Array.isArray(options) ? [options] : options;
502
+ const {
503
+ selectedOptions,
504
+ isReadOnly
505
+ } = this.props;
506
+ const {
507
+ highLightedSelectOptions,
508
+ lastHighLightedSelectOption,
509
+ shiftKeyPressHighLighted
510
+ } = this.state;
511
+
512
+ if (newOptions.length && !isReadOnly) {
513
+ const newSelectedOptions = selectedOptions.filter(option => newOptions.indexOf(option) === -1);
514
+ const newHighLightedSelectOptions = highLightedSelectOptions.filter(option => newSelectedOptions.indexOf(option) >= 0);
515
+ let isHighlightedRemoved = false;
516
+ const newOptionsLen = newOptions.length;
517
+
518
+ for (let i = 0; i < newOptionsLen; i++) {
519
+ const removedOption = newOptions[i];
520
+
521
+ if (highLightedSelectOptions.indexOf(removedOption) >= 0) {
522
+ isHighlightedRemoved = true;
523
+ break;
524
+ }
525
+ }
526
+
527
+ this.setState({
528
+ lastHighLightedSelectOption: newSelectedOptions.indexOf(lastHighLightedSelectOption) >= 0 && !isHighlightedRemoved ? lastHighLightedSelectOption : '',
529
+ highLightedSelectOptions: isHighlightedRemoved ? [] : newHighLightedSelectOptions,
530
+ shiftKeyPressHighLighted: isHighlightedRemoved ? 0 : shiftKeyPressHighLighted
531
+ });
532
+ this.handleChange(newSelectedOptions);
533
+ }
534
+
535
+ this.moveFocusToTextbox();
536
+ }
537
+
538
+ handleMouseEnter(id, val, hoverOptionIndex, e) {
539
+ e && e.preventDefault();
540
+ const {
541
+ hoverOption
542
+ } = this.state;
543
+ const {
544
+ suggestionsOrder
545
+ } = this;
546
+ const newHoverIndex = suggestionsOrder.indexOf(id);
547
+
548
+ if (newHoverIndex !== hoverOption) {
549
+ this.setState({
550
+ hoverOption: newHoverIndex
551
+ });
552
+ }
553
+ }
554
+
555
+ handleFetchOptions() {
556
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
557
+ args[_key] = arguments[_key];
558
+ }
559
+
560
+ const [APICall, searchStr] = args;
561
+ const {
562
+ isFetchingOptions
563
+ } = this.state;
564
+ const {
565
+ _isMounted
566
+ } = this;
567
+ const isForce = isFetchingOptions && searchStr ? true : false;
568
+
569
+ if (!isFetchingOptions && APICall || isForce) {
570
+ this.setState({
571
+ isFetchingOptions: true
572
+ });
573
+
574
+ try {
575
+ return APICall(searchStr).then(() => {
576
+ _isMounted && this.setState({
577
+ isFetchingOptions: false
578
+ });
579
+ }, () => {
580
+ _isMounted && this.setState({
581
+ isFetchingOptions: false
582
+ });
583
+ });
584
+ } catch (e) {
585
+ _isMounted && this.setState({
586
+ isFetchingOptions: false
587
+ });
588
+ }
589
+ }
590
+ }
591
+
592
+ handleSearchOptions() {
593
+ const {
594
+ onSearch
595
+ } = this.props;
596
+ const {
597
+ searchStr
598
+ } = this.state;
599
+ searchStr && this.handleFetchOptions(onSearch, searchStr);
600
+ }
601
+
602
+ handleSearch(value, e) {
603
+ const {
604
+ onSearch,
605
+ isPopupOpen
606
+ } = this.props;
607
+ !isPopupOpen && e && this.togglePopup(e);
608
+ const {
609
+ searchStr = ''
610
+ } = this.state;
611
+ const searchStrRegex = getSearchString(searchStr);
612
+ const valueStrRegex = getSearchString(value);
613
+ const isSearch = searchStrRegex !== valueStrRegex ? true : false;
614
+ this.setState({
615
+ searchStr: value
616
+ }, () => {
617
+ if (!value) {
618
+ onSearch && onSearch('');
619
+ } else if (isSearch && onSearch) {
620
+ this.handleSearchOptions();
621
+ }
622
+ });
623
+ }
624
+
625
+ handleClickSelectedOption() {
626
+ let id = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
627
+ let e = arguments.length > 1 ? arguments[1] : undefined;
628
+ const {
629
+ selectedOptions
630
+ } = this.props;
631
+ let {
632
+ highLightedSelectOptions,
633
+ lastHighLightedSelectOption
634
+ } = this.state;
635
+ const {
636
+ metaKey,
637
+ ctrlKey,
638
+ shiftKey
639
+ } = e;
640
+
641
+ if (e && shiftKey) {
642
+ //shift+click
643
+ let from = selectedOptions.indexOf(lastHighLightedSelectOption) >= 0 ? selectedOptions.indexOf(lastHighLightedSelectOption) : 0;
644
+ let to = id && selectedOptions.indexOf(id) >= 0 ? selectedOptions.indexOf(id) : null;
645
+
646
+ if (to >= 0 && to < from) {
647
+ [to] = [from, from = to];
648
+ }
649
+
650
+ to += 1;
651
+ const newSelectedHighlights = to ? selectedOptions.slice(from, to) : [];
652
+ to && this.setState({
653
+ highLightedSelectOptions: newSelectedHighlights,
654
+ lastHighLightedSelectOption: id
655
+ });
656
+ } else if (e && (ctrlKey || metaKey)) {
657
+ //ctrl+click
658
+ const isRemove = highLightedSelectOptions.indexOf(id) >= 0;
659
+ let newSelectedHighlights = [];
660
+
661
+ if (isRemove) {
662
+ lastHighLightedSelectOption = id === lastHighLightedSelectOption ? '' : lastHighLightedSelectOption;
663
+ newSelectedHighlights = highLightedSelectOptions.filter(option => option !== id);
664
+ } else {
665
+ lastHighLightedSelectOption = id;
666
+ newSelectedHighlights = [...highLightedSelectOptions, id];
667
+ }
668
+
669
+ this.setState({
670
+ highLightedSelectOptions: newSelectedHighlights,
671
+ lastHighLightedSelectOption
672
+ });
673
+ } else {
674
+ this.setState({
675
+ highLightedSelectOptions: [id],
676
+ lastHighLightedSelectOption: id
677
+ });
678
+ }
679
+
680
+ this.setState({
681
+ shiftKeyPressHighLighted: 0
682
+ });
683
+ this.moveFocusToTextbox();
684
+ }
685
+
686
+ handleScroll(e) {
687
+ let ele = e.target;
688
+ let isScrollReachedBottom = findScrollEnd(ele);
689
+ isScrollReachedBottom && this.handleScrollFuncCall();
690
+ }
691
+
692
+ handleScrollFuncCall() {
693
+ const {
694
+ getNextOptions,
695
+ isNextOptions
696
+ } = this.props;
697
+ const {
698
+ searchStr
699
+ } = this.state;
700
+ isNextOptions && getNextOptions && this.handleFetchOptions(getNextOptions, searchStr);
701
+ }
702
+
703
+ handleChange() {
704
+ let selectedOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
705
+ let e = arguments.length > 1 ? arguments[1] : undefined;
706
+ const {
707
+ optionsNormalize
708
+ } = this.state;
709
+ const {
710
+ onChange,
711
+ needToCloseOnSelect,
712
+ togglePopup,
713
+ selectedOptions: propSelectedOptions,
714
+ disabledOptions = dummyArray
715
+ } = this.props;
716
+ const {
717
+ newSelectedOptions
718
+ } = filterSelectedOptions({
719
+ selectedOptions,
720
+ propSelectedOptions,
721
+ disabledOptions
722
+ });
723
+ const selectedOptionsLen = newSelectedOptions.length;
724
+ const allSelectedOptionsDetails = [];
725
+
726
+ for (let i = 0; i < selectedOptionsLen; i++) {
727
+ const id = newSelectedOptions[i];
728
+ allSelectedOptionsDetails.push(optionsNormalize[id]);
729
+ }
730
+
731
+ onChange && onChange(newSelectedOptions, allSelectedOptionsDetails); // this.setState({ searchStr: '' });
732
+
733
+ this.moveFocusToTextbox();
734
+
735
+ if (needToCloseOnSelect) {
736
+ togglePopup(e);
737
+ }
738
+ }
739
+
740
+ togglePopup(e) {
741
+ const {
742
+ togglePopup,
743
+ defaultDropBoxPosition,
744
+ isReadOnly
745
+ } = this.props;
746
+ !isReadOnly && togglePopup(e, defaultDropBoxPosition ? `${defaultDropBoxPosition}` : null);
747
+ }
748
+
749
+ handlePopupClose(e) {
750
+ const {
751
+ closePopupOnly
752
+ } = this.props;
753
+ closePopupOnly(e);
754
+ }
755
+
756
+ searchInputRef(el) {
757
+ const {
758
+ getRef
759
+ } = this.props;
760
+ this.searchInput = el;
761
+ getRef && getRef(el);
762
+ }
763
+
764
+ selectedOptionContainerRef(el) {
765
+ const {
766
+ getTargetRef
767
+ } = this.props;
768
+ this.selectedOptionContainer = el;
769
+ getTargetRef(el);
770
+ }
771
+
772
+ selectedOptionRef(el, id) {
773
+ this[`selectedOption_${id}`] = el;
774
+ }
775
+
776
+ suggestionContainerRef(el) {
777
+ this.suggestionContainer = el;
778
+ }
779
+
780
+ suggestionItemRef(el, index, id) {
781
+ this[`suggestion_${id}`] = el;
782
+ }
783
+
784
+ handleActive(e) {
785
+ const {
786
+ searchStr,
787
+ isActive
788
+ } = this.state;
789
+
790
+ if (!isActive) {
791
+ this.setState({
792
+ isActive: true
793
+ });
794
+ }
795
+
796
+ const {
797
+ target
798
+ } = e || {};
799
+ target && target.setSelectionRange(target, 0);
800
+ const {
801
+ onFocus
802
+ } = this.props;
803
+ onFocus && onFocus(searchStr);
804
+ }
805
+
806
+ handleInactive() {
807
+ const {
808
+ isActive
809
+ } = this.state;
810
+
811
+ if (isActive) {
812
+ this.setState({
813
+ isActive: false
814
+ });
815
+ }
816
+ }
817
+
818
+ handleInputFocus() {
819
+ const {
820
+ isDisabled,
821
+ isReadOnly
822
+ } = this.props;
823
+ !isDisabled && !isReadOnly && this.moveFocusToTextbox();
824
+ }
825
+
826
+ moveFocusToTextbox() {
827
+ this.searchInput && this.searchInput.focus({
828
+ preventScroll: true
829
+ });
830
+ }
831
+
832
+ handleExposedPublicMethods() {
833
+ const {
834
+ getPublicMethods,
835
+ openPopupOnly
836
+ } = this.props;
837
+ getPublicMethods && getPublicMethods({
838
+ openPopupOnly
839
+ });
840
+ }
841
+
842
+ responsiveFunc(_ref) {
843
+ let {
844
+ mediaQueryOR
845
+ } = _ref;
846
+ return {
847
+ tabletMode: mediaQueryOR([{
848
+ maxWidth: 700
849
+ }])
850
+ };
851
+ }
852
+
853
+ getSelectionUI() {
854
+ let isResponsive = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : false;
855
+ let {
856
+ size,
857
+ needBorder,
858
+ disableAction,
859
+ borderColor,
860
+ placeHolder,
861
+ textBoxSize,
862
+ variant,
863
+ textBoxClass,
864
+ needAutoFocus,
865
+ htmlId,
866
+ children,
867
+ customChildrenClass,
868
+ autoComplete,
869
+ a11y,
870
+ disabledOptions,
871
+ i18nKeys,
872
+ isReadOnly,
873
+ isDisabled,
874
+ palette,
875
+ dataId,
876
+ setAriaId,
877
+ isPopupOpen,
878
+ ariaErrorId
879
+ } = this.props;
880
+ let {
881
+ isActive,
882
+ selectedOptions,
883
+ highLightedSelectOptions,
884
+ searchStr
885
+ } = this.state;
886
+ const {
887
+ clearText = 'Clear all'
888
+ } = i18nKeys;
889
+ const {
890
+ clearLabel = 'Clear all',
891
+ ariaLabelledby
892
+ } = a11y;
893
+ let {
894
+ isShowClearIcon: isShowClear
895
+ } = this.getIsShowClearIcon({
896
+ selectedOptions,
897
+ disabledOptions
898
+ });
899
+ const isShowClearIcon = !isReadOnly && !isDisabled && !disableAction && isShowClear;
900
+ return /*#__PURE__*/React.createElement(Container, {
901
+ align: "vertical",
902
+ alignBox: "row",
903
+ className: `${style.container} ${style[size]} ${needBorder ? !disableAction ? style[`borderColor_${borderColor}`] : style.borderColor_transparent : ''} ${isActive && needBorder || isResponsive ? style.active : ''} ${textBoxClass} ${needBorder ? style.hasBorder : ''}`,
904
+ eleRef: this.selectedOptionContainerRef,
905
+ wrap: "wrap"
906
+ }, /*#__PURE__*/React.createElement(SelectedOptions, {
907
+ selectedOptions: selectedOptions,
908
+ highLightedSelectOptions: highLightedSelectOptions,
909
+ isReadOnly: isReadOnly,
910
+ getRef: this.selectedOptionRef,
911
+ onRemove: this.handleRemoveOption,
912
+ onSelect: this.handleClickSelectedOption,
913
+ size: size,
914
+ palette: palette
915
+ }), /*#__PURE__*/React.createElement(Box, {
916
+ flexible: true,
917
+ className: style.wrapper,
918
+ adjust: true,
919
+ shrink: true
920
+ }, /*#__PURE__*/React.createElement("span", {
921
+ className: ` ${style.custmSpan} ${textBoxSize === 'xmedium' ? style.custmSpanXmedium : style.custmSpanMedium} ${isShowClearIcon ? style.clearIconSpace : ''}
922
+ ${customChildrenClass ? customChildrenClass : ''}`
923
+ }, searchStr), /*#__PURE__*/React.createElement(TextBoxIcon, {
924
+ isDisabled: isDisabled,
925
+ inputRef: this.searchInputRef,
926
+ needBorder: false,
927
+ onBlur: this.handleInactive,
928
+ onChange: this.handleSearch,
929
+ onClick: !isResponsive ? this.handleInputCick : undefined,
930
+ onFocus: this.handleActive,
931
+ onKeyDown: this.handleKeyDown,
932
+ autofocus: needAutoFocus,
933
+ placeHolder: selectedOptions.length >= 1 ? '' : placeHolder,
934
+ size: textBoxSize,
935
+ value: searchStr,
936
+ variant: variant,
937
+ dataId: `${dataId}_textBox`,
938
+ isReadOnly: isReadOnly,
939
+ tabindex: isDisabled && '-1',
940
+ customClass: {
941
+ customTBoxWrap: style.custmInputWrapper
942
+ },
943
+ htmlId: htmlId,
944
+ a11y: {
945
+ role: 'combobox',
946
+ ariaOwns: setAriaId,
947
+ ariaControls: setAriaId,
948
+ ariaExpanded: !isReadOnly && !isDisabled && !disableAction && isPopupOpen ? true : false,
949
+ ariaHaspopup: true,
950
+ ariaRequired: true,
951
+ ariaDescribedby: ariaErrorId,
952
+ ariaLabelledby: ariaLabelledby
953
+ },
954
+ autoComplete: autoComplete
955
+ }, /*#__PURE__*/React.createElement(Container, {
956
+ alignBox: "row",
957
+ align: "vertical"
958
+ }, isShowClearIcon ? /*#__PURE__*/React.createElement(Box, {
959
+ className: `${style.delete} ${style[`${palette}Delete`]}`,
960
+ dataId: `${dataId}_clearIcon`,
961
+ "data-title": clearText,
962
+ onClick: this.handleDeselectAll,
963
+ tagName: "button",
964
+ "aria-label": clearLabel
965
+ }, /*#__PURE__*/React.createElement(Icon, {
966
+ name: "ZD-delete",
967
+ size: "15"
968
+ })) : null, children ? /*#__PURE__*/React.createElement(Box, {
969
+ dataId: `${dataId}_children`
970
+ }, children) : null))));
971
+ }
972
+
973
+ render() {
974
+ let {
975
+ isReadOnly,
976
+ searchEmptyMessage,
977
+ emptyMessage,
978
+ noMoreOptionsMessage,
979
+ dropBoxSize,
980
+ isPopupOpen,
981
+ isPopupReady,
982
+ position,
983
+ defaultDropBoxPosition,
984
+ getContainerRef,
985
+ removeClose,
986
+ isAnimate,
987
+ animationStyle,
988
+ isDisabled,
989
+ title,
990
+ needResponsive,
991
+ dataId,
992
+ dataSelectorId,
993
+ isSearching,
994
+ borderColor,
995
+ disableAction,
996
+ isBoxPaddingNeed,
997
+ palette,
998
+ i18nKeys,
999
+ getFooter,
1000
+ needEffect,
1001
+ boxSize,
1002
+ isLoading,
1003
+ selectAllText,
1004
+ needSelectAll
1005
+ } = this.props;
1006
+ const {
1007
+ selectedOptions,
1008
+ searchStr,
1009
+ hoverOption,
1010
+ options,
1011
+ isFetchingOptions,
1012
+ selectedOptionIds
1013
+ } = this.state;
1014
+ const {
1015
+ searchText = 'Searching...'
1016
+ } = i18nKeys;
1017
+ const suggestions = this.handleFilterSuggestions();
1018
+ const setAriaId = this.getNextAriaId();
1019
+ const ariaErrorId = this.getNextAriaId();
1020
+ i18nKeys = Object.assign({}, MobileHeader_defaultProps.i18nKeys, i18nKeys, {
1021
+ emptyText: i18nKeys.emptyText || emptyMessage,
1022
+ searchEmptyText: i18nKeys.searchEmptyText || searchEmptyMessage,
1023
+ noMoreText: i18nKeys.noMoreText || noMoreOptionsMessage
1024
+ });
1025
+ return /*#__PURE__*/React.createElement("div", {
1026
+ className: `${style.wrapper} ${isDisabled ? style.disabled : ''} ${isReadOnly ? style.readOnly : ''} ${disableAction ? CssProvider('isBlock') : ''} ${borderColor === 'transparent' ? style.transparentContainer : ''} ${needEffect && !(isDisabled || isReadOnly) ? style.effect : ''}`,
1027
+ "data-id": `${isDisabled ? `${dataId}_disabled` : isReadOnly ? `${dataId}_readOnly` : dataId}`,
1028
+ "data-test-id": `${isDisabled ? `${dataId}_disabled` : isReadOnly ? `${dataId}_readOnly` : dataId}`,
1029
+ "data-title": isDisabled ? title : null,
1030
+ onClick: this.handleInputFocus,
1031
+ "data-selector-id": dataSelectorId
1032
+ }, this.getSelectionUI(), !isReadOnly && !isDisabled && !disableAction && isPopupOpen ? /*#__PURE__*/React.createElement(ResponsiveReceiver, {
1033
+ query: this.responsiveFunc,
1034
+ responsiveId: "Helmet"
1035
+ }, _ref2 => {
1036
+ let {
1037
+ tabletMode
1038
+ } = _ref2;
1039
+ return /*#__PURE__*/React.createElement(ResponsiveDropBox, {
1040
+ animationStyle: animationStyle,
1041
+ boxPosition: position || `${defaultDropBoxPosition}`,
1042
+ getRef: getContainerRef,
1043
+ isActive: isPopupReady,
1044
+ isAnimate: isAnimate,
1045
+ isArrow: false,
1046
+ onClick: removeClose,
1047
+ needResponsive: needResponsive,
1048
+ isPadding: false,
1049
+ isBoxPaddingNeed: isBoxPaddingNeed,
1050
+ palette: palette,
1051
+ htmlId: setAriaId,
1052
+ a11y: {
1053
+ role: 'listbox',
1054
+ ariaMultiselectable: true
1055
+ },
1056
+ size: boxSize,
1057
+ alignBox: "row",
1058
+ isResponsivePadding: getFooter ? false : true
1059
+ }, /*#__PURE__*/React.createElement(Box, {
1060
+ flexible: true
1061
+ }, /*#__PURE__*/React.createElement(Card, {
1062
+ customClass: `${style.box} ${style[`${palette}Box`]}`,
1063
+ onScroll: this.handleScroll
1064
+ }, tabletMode && /*#__PURE__*/React.createElement(MobileHeader, {
1065
+ selectedOptions: selectedOptions,
1066
+ i18nKeys: i18nKeys,
1067
+ onClick: this.handlePopupClose
1068
+ }, /*#__PURE__*/React.createElement("div", {
1069
+ className: style.effect
1070
+ }, this.getSelectionUI(true))), needSelectAll ? /*#__PURE__*/React.createElement(CardHeader, null, /*#__PURE__*/React.createElement(MultiSelectHeader, {
1071
+ onSelect: this.handleSelectAll,
1072
+ selectAllText: selectAllText,
1073
+ suggestions: suggestions,
1074
+ dataId: dataId
1075
+ })) : null, isLoading ? /*#__PURE__*/React.createElement(Container, {
1076
+ align: "both",
1077
+ className: style.loader
1078
+ }, /*#__PURE__*/React.createElement(Loader, null)) : /*#__PURE__*/React.createElement(CardContent, {
1079
+ shrink: true,
1080
+ customClass: !tabletMode && dropBoxSize ? style[dropBoxSize] : '',
1081
+ eleRef: this.suggestionContainerRef
1082
+ }, isSearching ? /*#__PURE__*/React.createElement("div", {
1083
+ className: style[palette]
1084
+ }, searchText) : suggestions.length ? /*#__PURE__*/React.createElement(Suggestions, {
1085
+ suggestions: suggestions,
1086
+ getRef: this.suggestionItemRef,
1087
+ hoverOption: hoverOption,
1088
+ onClick: this.handleSelectOption,
1089
+ onMouseEnter: this.handleMouseEnter,
1090
+ needBorder: false,
1091
+ dataId: `${dataId}_Options`,
1092
+ palette: palette,
1093
+ selectedOptions: selectedOptionIds,
1094
+ a11y: {
1095
+ role: 'option'
1096
+ }
1097
+ }) : /*#__PURE__*/React.createElement(EmptyState, {
1098
+ isLoading: isFetchingOptions,
1099
+ options: options,
1100
+ searchString: searchStr,
1101
+ suggestions: suggestions,
1102
+ dataId: dataId,
1103
+ palette: palette,
1104
+ i18nKeys: i18nKeys,
1105
+ htmlId: ariaErrorId
1106
+ }), isFetchingOptions && /*#__PURE__*/React.createElement(Container, {
1107
+ isCover: false,
1108
+ align: "both"
1109
+ }, /*#__PURE__*/React.createElement(Loader, null))), getFooter ? /*#__PURE__*/React.createElement(CardFooter, null, getFooter()) : null)));
1110
+ }) : null);
1111
+ }
1112
+
1113
+ }
1114
+ MultiSelectComponent.propTypes = MultiSelect_propTypes;
1115
+ MultiSelectComponent.defaultProps = MultiSelect_defaultProps;
1116
+ MultiSelectComponent.displayName = 'MultiSelect';
1117
+ const MultiSelect = Popup(MultiSelectComponent);
1118
+ MultiSelect.propTypes = MultiSelectComponent.propTypes;
1119
+ MultiSelect.defaultProps = MultiSelectComponent.defaultProps;
1120
+ export default MultiSelect;