zcomponents-ui 1.0.1 → 1.1.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.
Files changed (54) hide show
  1. package/README.md +25 -0
  2. package/dist/index-4tf38bQw.js +782 -0
  3. package/dist/index-4tf38bQw.js.map +1 -0
  4. package/dist/index-Ck9QayZm.js +779 -0
  5. package/dist/index-Ck9QayZm.js.map +1 -0
  6. package/dist/index.cjs.css +1 -1
  7. package/dist/index.cjs.css.map +1 -1
  8. package/dist/index.cjs.js +6 -756
  9. package/dist/index.cjs.js.map +1 -1
  10. package/dist/index.d.ts +5 -224
  11. package/dist/index.esm.css +1 -1
  12. package/dist/index.esm.css.map +1 -1
  13. package/dist/index.esm.js +4 -759
  14. package/dist/index.esm.js.map +1 -1
  15. package/dist/react-hook-form.cjs.js +11 -0
  16. package/dist/react-hook-form.cjs.js.map +1 -0
  17. package/dist/react-hook-form.d.ts +239 -0
  18. package/dist/react-hook-form.esm.js +5 -0
  19. package/dist/react-hook-form.esm.js.map +1 -0
  20. package/dist/types/components/ZDrop/integrations/react-hook-form/ZDropField/index.d.ts +13 -0
  21. package/dist/types/components/ZDrop/types/zDropTypes.d.ts +2 -1
  22. package/dist/types/index.d.ts +1 -0
  23. package/dist/types/integrations-react-hook-form.d.ts +2 -0
  24. package/package.json +9 -2
  25. package/dist/types/stories/ZComponents/ZDrop/staticData/numbers/zDropNumbersData.d.ts +0 -6
  26. package/dist/types/stories/ZComponents/ZDrop/staticData/objects/zDropObjectsData.d.ts +0 -4
  27. package/dist/types/stories/ZComponents/ZDrop/staticData/strings/ZDropStringsData.d.ts +0 -6
  28. package/dist/types/stories/ZComponents/ZDrop/staticData/zDropData.d.ts +0 -1
  29. package/dist/types/stories/ZComponents/ZDrop/store/loadingInitialState.d.ts +0 -3
  30. package/dist/types/stories/ZComponents/ZDrop/store/storageKeys.d.ts +0 -1
  31. package/dist/types/stories/ZComponents/ZDrop/store/zDropDefaultState.d.ts +0 -27
  32. package/dist/types/stories/ZComponents/ZDrop/store/zDropStore.d.ts +0 -8
  33. package/dist/types/stories/ZComponents/ZDrop/stories/basic/BasicCustomSearch.d.ts +0 -5
  34. package/dist/types/stories/ZComponents/ZDrop/stories/basic/BasicSurvivorsNumbers.d.ts +0 -5
  35. package/dist/types/stories/ZComponents/ZDrop/stories/basic/BasicWeaponsStrings.d.ts +0 -5
  36. package/dist/types/stories/ZComponents/ZDrop/stories/basic/BasicZombiesObjects.d.ts +0 -5
  37. package/dist/types/stories/ZComponents/ZDrop/stories/numbers/SurvivorsNumbers.d.ts +0 -5
  38. package/dist/types/stories/ZComponents/ZDrop/stories/numbers/WeaponsNumbers.d.ts +0 -5
  39. package/dist/types/stories/ZComponents/ZDrop/stories/numbers/ZombiesNumbers.d.ts +0 -5
  40. package/dist/types/stories/ZComponents/ZDrop/stories/objects/SurvivorsObjects.d.ts +0 -5
  41. package/dist/types/stories/ZComponents/ZDrop/stories/objects/WeaponsObjects.d.ts +0 -5
  42. package/dist/types/stories/ZComponents/ZDrop/stories/objects/ZombiesObjects.d.ts +0 -5
  43. package/dist/types/stories/ZComponents/ZDrop/stories/strings/SurvivorsStrings.d.ts +0 -5
  44. package/dist/types/stories/ZComponents/ZDrop/stories/strings/WeaponsStrings.d.ts +0 -5
  45. package/dist/types/stories/ZComponents/ZDrop/stories/strings/ZombiesStrings.d.ts +0 -5
  46. package/dist/types/stories/ZComponents/ZDrop/visualComponents/SbNotFound/index.d.ts +0 -2
  47. package/dist/types/stories/ZComponents/ZDrop/visualComponents/SbPoster/index.d.ts +0 -11
  48. package/dist/types/stories/ZComponents/ZDrop/visualComponents/SbSelection/SbSelectionElement/index.d.ts +0 -8
  49. package/dist/types/stories/ZComponents/ZDrop/visualComponents/SbSelection/index.d.ts +0 -6
  50. package/dist/types/stories/ZComponents/ZDrop/visualComponents/index.d.ts +0 -7
  51. package/dist/types/stories/ZDrop.stories.d.ts +0 -901
  52. package/dist/types/stories/storybookLinks.d.ts +0 -2
  53. package/dist/types/stories/types/visualComponentsTypes.d.ts +0 -2
  54. package/dist/types/stories/types/zDropStoriesStateTypes.d.ts +0 -34
@@ -0,0 +1,779 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { Controller } from 'react-hook-form';
3
+ import { useEffect, useState, useCallback, useRef } from 'react';
4
+
5
+ const classNames = (...params) => {
6
+ const classes = [];
7
+ params.forEach((param) => {
8
+ if (typeof param === "string" && param) {
9
+ classes.push(param);
10
+ }
11
+ else if (param && typeof param === "object") {
12
+ Object.entries(param).forEach(([key, value]) => {
13
+ if (value) {
14
+ classes.push(key);
15
+ }
16
+ });
17
+ }
18
+ });
19
+ return classes.join(" ");
20
+ };
21
+
22
+ const useOutsideClose = (ref, onOutsideClose) => {
23
+ useEffect(() => {
24
+ const handleClick = (e) => {
25
+ if (ref &&
26
+ ref.current &&
27
+ !ref.current.contains(e.target)) {
28
+ onOutsideClose(e);
29
+ }
30
+ };
31
+ const handleKey = (e) => {
32
+ if (e.key === "Escape") {
33
+ onOutsideClose(e);
34
+ }
35
+ };
36
+ document.addEventListener("click", handleClick);
37
+ document.addEventListener("keydown", handleKey);
38
+ return () => {
39
+ document.removeEventListener("click", handleClick);
40
+ document.removeEventListener("keydown", handleKey);
41
+ };
42
+ }, [onOutsideClose, ref]);
43
+ };
44
+
45
+ var styles = {"container":"ZDrop-module_container__FMb26","label":"ZDrop-module_label__WDDr6","inputField":"ZDrop-module_inputField__QPEyq","inputField--multiple":"ZDrop-module_inputField--multiple__ceTgA","inputField--disabled":"ZDrop-module_inputField--disabled__Iocv1","input":"ZDrop-module_input__k-MBA","inputSingle":"ZDrop-module_inputSingle__zZmCf","inputSingleSearch":"ZDrop-module_inputSingleSearch__oIk6K","inputMultiple":"ZDrop-module_inputMultiple__oF9wt","inputMultipleValue":"ZDrop-module_inputMultipleValue__lSYME","inputMultipleValueRemoveBtn":"ZDrop-module_inputMultipleValueRemoveBtn__gbFkS","inputMultipleValueRemoveBtnIcon":"ZDrop-module_inputMultipleValueRemoveBtnIcon__i4VBS","inputMultipleSearchWrapper":"ZDrop-module_inputMultipleSearchWrapper__vmS7x","inputMultipleSearch":"ZDrop-module_inputMultipleSearch__-lQrC","inputMultiplePlaceholder":"ZDrop-module_inputMultiplePlaceholder__GbBo7","inputClearBtnWrapper":"ZDrop-module_inputClearBtnWrapper__S3uiC","inputClearBtn":"ZDrop-module_inputClearBtn__JY5Gm","inputClearBtnIcon":"ZDrop-module_inputClearBtnIcon__PXRiJ","expandToggle":"ZDrop-module_expandToggle__zJYI1","expandToggleIcon":"ZDrop-module_expandToggleIcon__63Yog","expandToggleIcon--active":"ZDrop-module_expandToggleIcon--active__h2I5u","listWrapper":"ZDrop-module_listWrapper__FGHRj","list":"ZDrop-module_list__162r4","option":"ZDrop-module_option__ZfKFl","noData":"ZDrop-module_noData__-70Uu","option--active":"ZDrop-module_option--active__OXcv5","errorMessage":"ZDrop-module_errorMessage__8YOT7"};
46
+
47
+ const ZDropLabel = (props) => {
48
+ const { name, label, className } = props;
49
+ const labelClasses = classNames(styles.label, className);
50
+ if (typeof label === "string") {
51
+ return (jsx("label", { htmlFor: name, className: labelClasses, children: label }));
52
+ }
53
+ return jsx("div", { className: className, children: label });
54
+ };
55
+
56
+ const ZDropListItem = (props) => {
57
+ const { option, index, labelKey, innerRef, onOptionClick, onOptionKeyDown, className, children, } = props;
58
+ const onListItemClick = (e) => {
59
+ onOptionClick(e, option);
60
+ };
61
+ const onListItemKeyDown = (e) => {
62
+ onOptionKeyDown(e, option, index);
63
+ };
64
+ return (jsx("li", { tabIndex: 0, ref: innerRef, className: className, onClick: onListItemClick, onKeyDown: onListItemKeyDown, children: children || (labelKey && option[labelKey]) || option }));
65
+ };
66
+
67
+ const ZDropListNoData = (props) => {
68
+ const { noDataContent, className } = props;
69
+ const noDataClasses = classNames(styles.noData, className);
70
+ return jsx("li", { className: noDataClasses, children: noDataContent });
71
+ };
72
+
73
+ const checkIsValueEqualToOption = (selectedValue, option, valueKey) => {
74
+ if (selectedValue === undefined || option === undefined) {
75
+ return false;
76
+ }
77
+ if (Array.isArray(selectedValue)) {
78
+ return selectedValue.some((value) => checkIsValueEqualToOption(value, option, valueKey));
79
+ }
80
+ const optionIsObject = typeof option === "object" && option !== null;
81
+ const selectedIsObject = typeof selectedValue === "object" && selectedValue !== null;
82
+ if (selectedValue === option) {
83
+ return true;
84
+ }
85
+ if (!selectedIsObject && optionIsObject) {
86
+ return selectedValue === option[valueKey];
87
+ }
88
+ if (selectedIsObject && optionIsObject) {
89
+ return selectedValue[valueKey] === option[valueKey];
90
+ }
91
+ return false;
92
+ };
93
+
94
+ const checkIsEqualMultiple = (checkIsInputValueEqualToOptionValue, value, option, valueKey) => value.some((value) => checkIsInputValueEqualToOptionValue(value, option, valueKey));
95
+ const ZDropList = (props) => {
96
+ const { options = [], selectedValue, valueKey, labelKey, optionsRef, optionRenderer, onOptionClick, onOptionKeyDown, noDataContent, currentSearchedValue, listStyleClasses, } = props;
97
+ const dropdownListClasses = classNames(styles.list, listStyleClasses === null || listStyleClasses === void 0 ? void 0 : listStyleClasses.list);
98
+ const getListItemClasses = (option) => {
99
+ if (Array.isArray(selectedValue)) {
100
+ return classNames(styles.option, listStyleClasses === null || listStyleClasses === void 0 ? void 0 : listStyleClasses.listItem, {
101
+ [styles["option--active"]]: checkIsEqualMultiple(checkIsValueEqualToOption, selectedValue, option, valueKey),
102
+ });
103
+ }
104
+ return classNames(styles.option, listStyleClasses === null || listStyleClasses === void 0 ? void 0 : listStyleClasses.listItem, {
105
+ [styles["option--active"]]: checkIsValueEqualToOption(selectedValue, option, valueKey),
106
+ });
107
+ };
108
+ if (options.length === 0) {
109
+ return (jsx(ZDropListNoData, { noDataContent: noDataContent, className: listStyleClasses === null || listStyleClasses === void 0 ? void 0 : listStyleClasses.noData }));
110
+ }
111
+ return (jsx("ul", { className: dropdownListClasses, children: options.map((option, index) => (jsx(ZDropListItem, { innerRef: (el) => {
112
+ optionsRef.current[index] = el;
113
+ }, option: option, index: index, labelKey: labelKey, onOptionClick: onOptionClick, onOptionKeyDown: onOptionKeyDown, className: getListItemClasses(option), children: optionRenderer === null || optionRenderer === void 0 ? void 0 : optionRenderer(option, Array.isArray(selectedValue)
114
+ ? checkIsEqualMultiple(checkIsValueEqualToOption, selectedValue, option, valueKey)
115
+ : checkIsValueEqualToOption(selectedValue, option, valueKey), currentSearchedValue) }, (option === null || option === void 0 ? void 0 : option[valueKey]) || index))) }));
116
+ };
117
+
118
+ const ZDropListVisibilityToggle = (props) => {
119
+ const { expandToggleRenderer, onClick, isListVisible, toggleStyleClasses } = props;
120
+ const toggleClasses = classNames(styles.expandToggle, toggleStyleClasses === null || toggleStyleClasses === void 0 ? void 0 : toggleStyleClasses.expandToggle);
121
+ const iconClasses = classNames(styles.expandToggleIcon, toggleStyleClasses === null || toggleStyleClasses === void 0 ? void 0 : toggleStyleClasses.expandToggleIcon, {
122
+ [styles["expandToggleIcon--active"]]: isListVisible,
123
+ });
124
+ return (jsx("div", { className: toggleClasses, onClick: onClick, children: expandToggleRenderer ? (jsx("span", { children: expandToggleRenderer(isListVisible) })) : (jsx("span", { className: iconClasses })) }));
125
+ };
126
+
127
+ const checkIsClearHidden = (hasValueChanged, currentSearchedValue, isListVisible, isClearableOnlyWhenChange, isClearableOnlyWhenSearch) => {
128
+ if (isClearableOnlyWhenChange && !isListVisible && hasValueChanged) {
129
+ return false;
130
+ }
131
+ if (isClearableOnlyWhenSearch && isListVisible && currentSearchedValue) {
132
+ return false;
133
+ }
134
+ if (!isClearableOnlyWhenChange &&
135
+ !isClearableOnlyWhenSearch &&
136
+ (currentSearchedValue || hasValueChanged)) {
137
+ return false;
138
+ }
139
+ return true;
140
+ };
141
+
142
+ const ZDropClearButton = (props) => {
143
+ const { hasValueChanged, currentSearchedValue, onInputClear, isListVisible, isClearableOnlyWhenChange, isClearableOnlyWhenSearch, className, clearIcon, } = props;
144
+ const clearButtonClasses = classNames(styles.inputClearBtn, className);
145
+ const onClear = (e) => {
146
+ e.preventDefault();
147
+ e.stopPropagation();
148
+ e.nativeEvent.stopImmediatePropagation();
149
+ onInputClear();
150
+ };
151
+ if (checkIsClearHidden(hasValueChanged, currentSearchedValue, isListVisible, isClearableOnlyWhenChange, isClearableOnlyWhenSearch)) {
152
+ return null;
153
+ }
154
+ return (jsx("div", { className: styles.inputClearBtnWrapper, children: jsx("button", { tabIndex: -1, className: clearButtonClasses, onClick: onClear, children: clearIcon || jsx("span", { className: styles.inputClearBtnIcon }) }) }));
155
+ };
156
+
157
+ const ZDropMultipleInputValue = (props) => {
158
+ const { option, labelType, onInputOptionRemove, valueRenderer, inputMultipleValueClassName, isDisabled, } = props;
159
+ const inputItemClasses = classNames(styles.inputMultipleValue, inputMultipleValueClassName);
160
+ if (option === null || option === undefined) {
161
+ return null;
162
+ }
163
+ if (valueRenderer) {
164
+ return (jsx("li", { tabIndex: 0, className: inputItemClasses, onKeyDown: (e) => {
165
+ if (["Enter", " "].includes(e.key)) {
166
+ onInputOptionRemove(e, option);
167
+ }
168
+ }, children: valueRenderer === null || valueRenderer === void 0 ? void 0 : valueRenderer({
169
+ option,
170
+ onRemove: (e) => onInputOptionRemove(e, option),
171
+ }) }));
172
+ }
173
+ return (jsxs("li", { tabIndex: -1, className: inputItemClasses, children: [jsx("span", { children: typeof option === "object" && option !== null
174
+ ? option[labelType] || option
175
+ : option }), onInputOptionRemove && !isDisabled && (jsx("button", { tabIndex: 0, className: styles.inputMultipleValueRemoveBtn, onClick: (e) => onInputOptionRemove(e, option), children: jsx("span", { className: styles.inputMultipleValueRemoveBtnIcon }) }))] }));
176
+ };
177
+
178
+ const ZDropMultipleInput = (props) => {
179
+ const { isListVisible, setIsListVisible, name, selectedValue, valueKey, labelKey, placeholder, isDisabled, isSearchable, currentSearchedValue, valueRenderer, inputRefMultipleValueRenderer, onInputClick, onInputKeyDown, onInputChange, onInputOptionRemove, inputClassName, inputMultipleValueClassName, inputMultipleSearchClassName, } = props;
180
+ const inputSelectClasses = classNames(styles.input, styles.inputMultiple, inputClassName);
181
+ const inputMultipleSearchClasses = classNames(styles.inputMultipleSearch);
182
+ const inputMultipleSearchWrapperClasses = classNames(styles.inputMultiple, styles.inputMultipleSearchWrapper, inputMultipleSearchClassName);
183
+ const onKeyDown = (e) => {
184
+ if (["Enter"].includes(e.key)) {
185
+ e.preventDefault();
186
+ }
187
+ };
188
+ const onPlaceholderClick = (e) => {
189
+ e.preventDefault();
190
+ e.stopPropagation();
191
+ setIsListVisible(true);
192
+ };
193
+ return (jsxs("ul", { tabIndex: 0, className: inputSelectClasses, onClick: onInputClick, onKeyDown: onInputKeyDown, ...(isDisabled && { style: { pointerEvents: "none" } }), children: [selectedValue.map((option) => (jsx(ZDropMultipleInputValue, { option: option, labelType: labelKey, onInputOptionRemove: onInputOptionRemove, valueRenderer: valueRenderer, inputMultipleValueClassName: inputMultipleValueClassName, isDisabled: isDisabled }, typeof option === "object" && !Array.isArray(option)
194
+ ? option[valueKey]
195
+ : option))), ((!isListVisible && selectedValue.length === 0) ||
196
+ ((selectedValue.length === 0 || !selectedValue) && !isSearchable)) && (jsx("span", { className: styles.inputMultiplePlaceholder, onClick: onPlaceholderClick, children: placeholder })), isSearchable && isListVisible && (jsx("li", { className: inputMultipleSearchWrapperClasses, children: jsx("input", { ref: inputRefMultipleValueRenderer, name: name, className: inputMultipleSearchClasses, placeholder: "search ...", value: currentSearchedValue, onChange: onInputChange, onKeyDown: onKeyDown }) }))] }));
197
+ };
198
+
199
+ const ZDropSingleInputValueRenderer = (props) => {
200
+ const { name, isInputItemVisible, isSearchable, selectedValue, selectedOption, valueRenderer, inputValue, isListVisible, placeholder, inputRefSingleValueRenderer, onChange, onInputItemClick, onInputOptionRemove, inputValueClassName, } = props;
201
+ const inputValueClasses = classNames(styles.inputSingleSearch, inputValueClassName);
202
+ return (jsxs(Fragment, { children: [isInputItemVisible && selectedOption !== undefined && (jsx("div", { onClick: onInputItemClick, children: valueRenderer({
203
+ option: selectedOption,
204
+ onRemove: (e) => onInputOptionRemove(e, selectedOption),
205
+ }) })), ((!isListVisible &&
206
+ !isSearchable &&
207
+ (typeof selectedValue === "undefined" || selectedValue === "")) ||
208
+ (isListVisible && !isSearchable)) &&
209
+ placeholder, isSearchable && !isInputItemVisible && (jsx("input", { ref: inputRefSingleValueRenderer, name: name, tabIndex: isInputItemVisible ? 0 : -1, value: inputValue, onChange: onChange, className: inputValueClasses, placeholder: placeholder }))] }));
210
+ };
211
+
212
+ const getLabelFromOption = (options, selectedValue, valueKey, labelKey) => {
213
+ const foundOption = options.find((option) => {
214
+ if (typeof option === "object" &&
215
+ option !== null &&
216
+ (typeof selectedValue === "string" || typeof selectedValue === "number")) {
217
+ return option[valueKey] === selectedValue;
218
+ }
219
+ if (typeof option === "object" &&
220
+ option !== null &&
221
+ typeof selectedValue === "object" &&
222
+ selectedValue !== null) {
223
+ return option[valueKey] === selectedValue[valueKey];
224
+ }
225
+ return option === selectedValue;
226
+ });
227
+ if (foundOption !== undefined && foundOption !== null) {
228
+ return typeof foundOption === "object"
229
+ ? foundOption[labelKey]
230
+ : foundOption;
231
+ }
232
+ return "";
233
+ };
234
+ const ZDropSingleInput = (props) => {
235
+ const { options, name, selectedValue, currentSearchedValue, setCurrentSearchedValue, valueKey, labelKey, isListVisible, placeholder, isDisabled, isSearchable = false, valueRenderer, inputRef, inputRefSingleValueRenderer, onInputClick, onInputItemClick, onInputKeyDown, onInputChange, onInputOptionRemove, isInputItemVisible, inputValueClassName, inputClassName, } = props;
236
+ const [inputValue, setInputValue] = useState(getLabelFromOption(options, selectedValue, valueKey, valueKey));
237
+ const inputSelectClasses = classNames(styles.input, inputClassName, {
238
+ [styles.inputSingle]: !!valueRenderer,
239
+ });
240
+ const selectedOption = options.find((option) => {
241
+ if (typeof option === "object" &&
242
+ option !== null &&
243
+ typeof selectedValue === "object" &&
244
+ selectedValue !== null) {
245
+ return option[valueKey] === selectedValue[valueKey];
246
+ }
247
+ if (typeof option === "object" &&
248
+ option !== null &&
249
+ selectedValue !== undefined &&
250
+ (typeof selectedValue === "string" || typeof selectedValue === "number")) {
251
+ return option[valueKey] === selectedValue;
252
+ }
253
+ return option === selectedValue;
254
+ });
255
+ const onClick = (e) => {
256
+ onInputClick(e);
257
+ if (isSearchable && !isListVisible) {
258
+ setInputValue("");
259
+ }
260
+ };
261
+ const onChange = (e) => {
262
+ onInputChange(e);
263
+ setInputValue(e.target.value);
264
+ setCurrentSearchedValue === null || setCurrentSearchedValue === void 0 ? void 0 : setCurrentSearchedValue(e.target.value);
265
+ };
266
+ useEffect(() => {
267
+ if (selectedValue !== undefined) {
268
+ setInputValue(getLabelFromOption(options, selectedValue, valueKey, labelKey));
269
+ }
270
+ }, [selectedValue]);
271
+ useEffect(() => {
272
+ if (!isListVisible && isSearchable) {
273
+ setInputValue(getLabelFromOption(options, selectedValue, valueKey, labelKey));
274
+ return;
275
+ }
276
+ currentSearchedValue !== undefined && setInputValue(currentSearchedValue);
277
+ }, [isListVisible]);
278
+ useEffect(() => {
279
+ if (currentSearchedValue === "") {
280
+ setInputValue("");
281
+ }
282
+ }, [currentSearchedValue]);
283
+ if (valueRenderer) {
284
+ return (jsx("div", { tabIndex: 0, className: inputSelectClasses, onClick: onInputClick, onKeyDown: onInputKeyDown, ...(isDisabled && {
285
+ style: { pointerEvents: "none" },
286
+ }), children: jsx(ZDropSingleInputValueRenderer, { name: name, isInputItemVisible: isInputItemVisible, isSearchable: isSearchable, selectedValue: selectedValue, selectedOption: selectedOption, valueRenderer: valueRenderer, inputValue: inputValue, isListVisible: isListVisible, placeholder: placeholder, inputRefSingleValueRenderer: inputRefSingleValueRenderer, onChange: onChange, onInputItemClick: onInputItemClick, onInputOptionRemove: onInputOptionRemove, inputValueClassName: inputValueClassName }) }));
287
+ }
288
+ return (jsx("input", { ref: inputRef, className: inputSelectClasses, name: name, type: "text", value: inputValue, placeholder: placeholder, disabled: isDisabled, onClick: onClick, onChange: onChange, onKeyDown: onInputKeyDown, readOnly: !isSearchable }));
289
+ };
290
+
291
+ const ZDropInput = (props) => {
292
+ const { name, options, selectedValue, currentSearchedValue, setCurrentSearchedValue, valueKey, labelKey, placeholder, isMultiple, isDisabled, isSearchable, isListVisible, setIsListVisible, isInputItemVisible, valueRenderer, inputRef, inputRefMultipleValueRenderer, inputRefSingleValueRenderer, onInputClick, onInputItemClick, onInputKeyDown, onInputChange, onInputOptionRemove, inputStyleClasses, } = props;
293
+ if (isMultiple && Array.isArray(selectedValue)) {
294
+ return (jsx(ZDropMultipleInput, { isListVisible: isListVisible, setIsListVisible: setIsListVisible, name: name, selectedValue: selectedValue, valueKey: valueKey, labelKey: labelKey, placeholder: placeholder, isDisabled: isDisabled, isSearchable: isSearchable, currentSearchedValue: currentSearchedValue, valueRenderer: valueRenderer, inputRefMultipleValueRenderer: inputRefMultipleValueRenderer, onInputClick: onInputClick, onInputKeyDown: onInputKeyDown, onInputChange: onInputChange, onInputOptionRemove: onInputOptionRemove, inputClassName: inputStyleClasses === null || inputStyleClasses === void 0 ? void 0 : inputStyleClasses.input, inputMultipleValueClassName: inputStyleClasses === null || inputStyleClasses === void 0 ? void 0 : inputStyleClasses.inputMultipleValue, inputMultipleSearchClassName: inputStyleClasses === null || inputStyleClasses === void 0 ? void 0 : inputStyleClasses.inputMultipleSearch }));
295
+ }
296
+ return (jsx(ZDropSingleInput, { options: options, name: name, selectedValue: selectedValue, currentSearchedValue: currentSearchedValue, setCurrentSearchedValue: setCurrentSearchedValue, valueKey: valueKey, labelKey: labelKey, isListVisible: isListVisible, placeholder: placeholder, isDisabled: isDisabled, isSearchable: isSearchable, valueRenderer: valueRenderer, isInputItemVisible: isInputItemVisible, inputRef: inputRef, inputRefSingleValueRenderer: inputRefSingleValueRenderer, onInputClick: onInputClick, onInputItemClick: onInputItemClick, onInputKeyDown: onInputKeyDown, onInputChange: onInputChange, onInputOptionRemove: onInputOptionRemove, inputClassName: inputStyleClasses === null || inputStyleClasses === void 0 ? void 0 : inputStyleClasses.input, inputValueClassName: inputStyleClasses === null || inputStyleClasses === void 0 ? void 0 : inputStyleClasses.inputValue }));
297
+ };
298
+
299
+ const isObj = (x) => typeof x === "object" && x !== null;
300
+ const findOption = (options = [], selected, valueKey) => {
301
+ const key = isObj(selected) && valueKey in selected ? selected[valueKey] : selected;
302
+ const found = options.find((option) => {
303
+ return isObj(option)
304
+ ? valueKey in option && option[valueKey] === key
305
+ : option === key;
306
+ });
307
+ return found;
308
+ };
309
+
310
+ const defaultSearchFilter = (props) => {
311
+ const { options, currentValue, labelKey } = props;
312
+ const searchedValue = currentValue || "";
313
+ if (options.every((option) => typeof option === "string" || typeof option === "number")) {
314
+ return options.filter((option) => option.toString().toLowerCase().includes(searchedValue.toLowerCase()));
315
+ }
316
+ return options === null || options === void 0 ? void 0 : options.filter((option) => {
317
+ var _a;
318
+ return typeof option === "object" &&
319
+ option !== null &&
320
+ ((_a = option[labelKey]) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().includes(searchedValue.toLowerCase()));
321
+ });
322
+ };
323
+
324
+ const getCurrentMultipleValue = (selected, selectedValue, options, valueKey) => {
325
+ const isSelectedValueArray = Array.isArray(selectedValue);
326
+ if (isSelectedValueArray &&
327
+ selectedValue.some((val) => val === findOption(selectedValue, selected, valueKey))) {
328
+ return selectedValue;
329
+ }
330
+ if (Array.isArray(selected)) {
331
+ return options.filter((option) => findOption(selected, option, valueKey) ||
332
+ findOption(selected, option, valueKey) === 0);
333
+ }
334
+ return [...(isSelectedValueArray ? selectedValue : []), selected];
335
+ };
336
+
337
+ const getElementOffsetTop = (element) => {
338
+ var _a, _b, _c;
339
+ if (!element)
340
+ return 0;
341
+ const rect = element.getBoundingClientRect();
342
+ const scrollTop = (_c = (_b = (_a = window.pageYOffset) !== null && _a !== void 0 ? _a : document.documentElement.scrollTop) !== null && _b !== void 0 ? _b : document.body.scrollTop) !== null && _c !== void 0 ? _c : 0;
343
+ return rect.top + scrollTop;
344
+ };
345
+ const getReferenceElementDimensions = (element, elementParentClass) => {
346
+ const parent = element === null || element === void 0 ? void 0 : element.parentElement;
347
+ if (!parent)
348
+ return;
349
+ if (parent.classList.contains(elementParentClass)) {
350
+ const top = getElementOffsetTop(parent);
351
+ const height = parent.scrollHeight;
352
+ return {
353
+ top,
354
+ bottom: top + height,
355
+ height,
356
+ };
357
+ }
358
+ return getReferenceElementDimensions(parent, elementParentClass);
359
+ };
360
+
361
+ const distanceGap = 0;
362
+ const marginTop = 10;
363
+ const minUsableHeight = 50;
364
+ const calculateHeightForTop = (scrollHeight, maxHeightLimiter, wrapperMaxHeight) => {
365
+ const currentHeightLimiter = maxHeightLimiter < wrapperMaxHeight ? maxHeightLimiter : wrapperMaxHeight;
366
+ return scrollHeight > currentHeightLimiter
367
+ ? currentHeightLimiter
368
+ : scrollHeight;
369
+ };
370
+ const ZDropListWrapper = (props) => {
371
+ const { referenceElementClassName, positionToReferenceElement = "bottom", listMaxHeightLimiter, children, } = props;
372
+ const [maxSpaceAbove, setMaxSpaceAbove] = useState(0);
373
+ const [maxSpaceBelow, setMaxSpaceBelow] = useState(0);
374
+ const [scrollHeight, setScrollHeight] = useState(0);
375
+ const hasTopSpace = maxSpaceAbove > minUsableHeight;
376
+ const hasBottomSpace = maxSpaceBelow > minUsableHeight;
377
+ let finalPosition;
378
+ if (positionToReferenceElement === "top") {
379
+ if (hasTopSpace) {
380
+ finalPosition = "top";
381
+ }
382
+ else if (hasBottomSpace) {
383
+ finalPosition = "bottom";
384
+ }
385
+ else {
386
+ finalPosition = maxSpaceAbove >= maxSpaceBelow ? "top" : "bottom";
387
+ }
388
+ }
389
+ else {
390
+ if (hasBottomSpace) {
391
+ finalPosition = "bottom";
392
+ }
393
+ else if (hasTopSpace) {
394
+ finalPosition = "top";
395
+ }
396
+ else {
397
+ finalPosition = maxSpaceBelow >= maxSpaceAbove ? "bottom" : "top";
398
+ }
399
+ }
400
+ const heightForBottom = Math.min(scrollHeight, maxSpaceBelow, listMaxHeightLimiter !== null && listMaxHeightLimiter !== void 0 ? listMaxHeightLimiter : maxSpaceBelow);
401
+ const heightForTop = calculateHeightForTop(scrollHeight, listMaxHeightLimiter !== null && listMaxHeightLimiter !== void 0 ? listMaxHeightLimiter : maxSpaceAbove, maxSpaceAbove);
402
+ const finalHeight = finalPosition === "top" ? heightForTop : heightForBottom;
403
+ const setWrapperMaxSpaces = (element, referenceElementClassName) => {
404
+ const wrapperListOffsetTop = getElementOffsetTop(element);
405
+ const referenceElement = getReferenceElementDimensions(element, referenceElementClassName);
406
+ if (referenceElement) {
407
+ const above = Math.max(wrapperListOffsetTop - referenceElement.top - distanceGap, 0);
408
+ const below = Math.max(referenceElement.bottom - wrapperListOffsetTop - distanceGap, 0);
409
+ setMaxSpaceAbove(above);
410
+ setMaxSpaceBelow(below);
411
+ const content = element.children[0];
412
+ setScrollHeight(content ? content.scrollHeight : 0);
413
+ }
414
+ };
415
+ const listWrapperRef = useCallback((node) => {
416
+ if (node) {
417
+ setWrapperMaxSpaces(node, referenceElementClassName);
418
+ }
419
+ }, [referenceElementClassName]);
420
+ const wrapperStyle = {
421
+ position: "absolute",
422
+ height: `${finalHeight}px`,
423
+ maxHeight: `${finalHeight}px`,
424
+ ...(finalPosition === "top"
425
+ ? { top: `-${finalHeight + marginTop}px` }
426
+ : { top: "100%" }),
427
+ };
428
+ return (jsx("div", { className: styles.listWrapper, ref: listWrapperRef, style: wrapperStyle, children: children }));
429
+ };
430
+
431
+ const deepEqual = (a, b) => {
432
+ if (a === b)
433
+ return true;
434
+ if (a == null || b == null)
435
+ return false;
436
+ if (typeof a !== "object" || typeof b !== "object")
437
+ return false;
438
+ if (Array.isArray(a) && Array.isArray(b)) {
439
+ if (a.length !== b.length)
440
+ return false;
441
+ return a.every((el, i) => deepEqual(el, b[i]));
442
+ }
443
+ const keysA = Object.keys(a);
444
+ const keysB = Object.keys(b);
445
+ if (keysA.length !== keysB.length)
446
+ return false;
447
+ return keysA.every((key) => deepEqual(a[key], b[key]));
448
+ };
449
+
450
+ const ZDrop = (props) => {
451
+ const { name, options = [], value, valueKey = "value", label, labelKey = "label", placeholder, isMultiple = false, isDisabled = false, isSearchable = false, clear = "none", searchFilterDelay, searchFilter = defaultSearchFilter, shouldReturnObjectOnChange = false, onChange, onBlur, onClear, valueRenderer, optionRenderer, expandToggleRenderer, clearIcon, noDataContent, referenceElementClassName, positionToReferenceElement, listMaxHeightLimiter, styleClasses, } = props;
452
+ const containerRef = useRef(null);
453
+ const inputRef = useRef(null);
454
+ const inputRefSingleValueRenderer = useRef(null);
455
+ const inputRefMultipleValueRenderer = useRef(null);
456
+ const optionsRef = useRef([]);
457
+ const timerRef = useRef(null);
458
+ const isValueCorrect = value !== undefined && value !== null && value !== "";
459
+ const isClearable = ["always", "whenChanged", "whenSearched"].includes(clear);
460
+ const isClearableOnlyWhenChange = clear === "whenChanged";
461
+ const isClearableOnlyWhenSearch = clear === "whenSearched";
462
+ const [optionsData, setOptionsData] = useState([]);
463
+ const [selectedValue, setSelectedValue] = useState(isMultiple ? [] : "");
464
+ const [isListVisible, setIsListVisible] = useState(false);
465
+ const [isInputItemVisible, setIsInputItemVisible] = useState(isValueCorrect);
466
+ const [currentSearchedValue, setCurrentSearchedValue] = useState("");
467
+ const [hasValueChanged, setHasValueChanged] = useState(false);
468
+ const isSelectedValueCorrect = selectedValue !== undefined &&
469
+ selectedValue !== null &&
470
+ selectedValue !== "";
471
+ const containerClasses = classNames(styles.container, styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.container);
472
+ const inputFieldClasses = classNames(styles.inputField, styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.inputField, {
473
+ [styles["inputField--multiple"]]: isMultiple,
474
+ [styles["inputField--disabled"]]: isDisabled,
475
+ });
476
+ const updateOptionsDataBySearch = (options, currentValue, labelKey) => {
477
+ const searchResult = searchFilter({
478
+ options,
479
+ currentValue,
480
+ labelKey,
481
+ });
482
+ setOptionsData(searchResult ? searchResult : options);
483
+ };
484
+ const setCurrentValue = (selected) => {
485
+ if (isMultiple) {
486
+ const currentMultipleSelected = getCurrentMultipleValue(selected, selectedValue, options, valueKey);
487
+ setSelectedValue(currentMultipleSelected);
488
+ onChange === null || onChange === void 0 ? void 0 : onChange(currentMultipleSelected);
489
+ return;
490
+ }
491
+ setCurrentSearchedValue("");
492
+ setIsListVisible(false);
493
+ setOptionsData(options || []);
494
+ setSelectedValue(selected);
495
+ if (shouldReturnObjectOnChange && typeof selected === "object") {
496
+ onChange === null || onChange === void 0 ? void 0 : onChange(selected);
497
+ return;
498
+ }
499
+ onChange === null || onChange === void 0 ? void 0 : onChange((typeof selected === "object" && (selected === null || selected === void 0 ? void 0 : selected[valueKey])) ||
500
+ selected);
501
+ };
502
+ const defaultInputValue = useCallback((defaultValue) => {
503
+ var _a;
504
+ if (isMultiple && Array.isArray(defaultValue)) {
505
+ const multipleValues = options === null || options === void 0 ? void 0 : options.filter((option) => defaultValue.some((valueItem) => checkIsValueEqualToOption(valueItem, option, valueKey)));
506
+ return multipleValues || [];
507
+ }
508
+ return (_a = findOption(options, defaultValue, valueKey)) !== null && _a !== void 0 ? _a : "";
509
+ }, [isMultiple, options, value, selectedValue, valueKey]);
510
+ const onExpandToggleClick = (e) => {
511
+ e.preventDefault();
512
+ e.stopPropagation();
513
+ if (isDisabled) {
514
+ return;
515
+ }
516
+ setIsListVisible((prev) => !prev);
517
+ if (!isMultiple && isSelectedValueCorrect && valueRenderer) {
518
+ setIsInputItemVisible((prev) => !prev);
519
+ }
520
+ };
521
+ const onInputFieldClick = (e) => {
522
+ e.preventDefault();
523
+ e.stopPropagation();
524
+ if (e.target.tagName === "INPUT") {
525
+ return;
526
+ }
527
+ if (isDisabled) {
528
+ return;
529
+ }
530
+ if (isListVisible) {
531
+ setIsListVisible(false);
532
+ }
533
+ if (isListVisible &&
534
+ !isMultiple &&
535
+ valueRenderer &&
536
+ isSelectedValueCorrect) {
537
+ setIsInputItemVisible(true);
538
+ }
539
+ };
540
+ const onInputClick = (e) => {
541
+ e.preventDefault();
542
+ if (!isListVisible) {
543
+ setIsListVisible(true);
544
+ }
545
+ if (!isListVisible && !isMultiple && valueRenderer) {
546
+ setIsInputItemVisible(false);
547
+ }
548
+ if (!isListVisible && isSearchable && isSelectedValueCorrect) {
549
+ updateOptionsDataBySearch(options || [], currentSearchedValue, labelKey);
550
+ }
551
+ };
552
+ const onInputChange = useCallback((e) => {
553
+ const currentValue = e.target.value;
554
+ if (isSearchable) {
555
+ setCurrentSearchedValue(currentValue);
556
+ }
557
+ const inputSelectChange = (currentValue) => {
558
+ if (!isListVisible) {
559
+ setIsListVisible(true);
560
+ }
561
+ if (isSearchable) {
562
+ updateOptionsDataBySearch(options || [], currentValue, labelKey);
563
+ }
564
+ };
565
+ if (searchFilterDelay && searchFilterDelay > 0) {
566
+ if (timerRef.current)
567
+ clearTimeout(timerRef.current);
568
+ timerRef.current = setTimeout(() => inputSelectChange(currentValue), searchFilterDelay);
569
+ }
570
+ else {
571
+ inputSelectChange(currentValue);
572
+ }
573
+ }, [
574
+ selectedValue,
575
+ isMultiple,
576
+ isSearchable,
577
+ isListVisible,
578
+ labelKey,
579
+ options,
580
+ searchFilter,
581
+ searchFilterDelay,
582
+ ]);
583
+ const onInputKeyDown = (e) => {
584
+ var _a;
585
+ if (!isListVisible && ["Enter", " "].includes(e.key)) {
586
+ if (e.currentTarget !== e.target) {
587
+ return;
588
+ }
589
+ e.preventDefault();
590
+ setIsListVisible((prev) => !prev);
591
+ }
592
+ if (e.key === "ArrowDown" && isListVisible) {
593
+ e.preventDefault();
594
+ (_a = optionsRef.current[0]) === null || _a === void 0 ? void 0 : _a.focus();
595
+ }
596
+ if (!isListVisible && isSearchable && !isMultiple && valueRenderer) {
597
+ setIsInputItemVisible(false);
598
+ }
599
+ };
600
+ const applyInputSelectFocus = useCallback(() => {
601
+ var _a, _b, _c;
602
+ if (isMultiple) {
603
+ (_a = inputRefMultipleValueRenderer.current) === null || _a === void 0 ? void 0 : _a.focus();
604
+ return;
605
+ }
606
+ if (valueRenderer) {
607
+ (_b = inputRefSingleValueRenderer.current) === null || _b === void 0 ? void 0 : _b.focus();
608
+ return;
609
+ }
610
+ (_c = inputRef.current) === null || _c === void 0 ? void 0 : _c.focus();
611
+ }, [isMultiple, valueRenderer]);
612
+ const onInputItemClick = (e) => {
613
+ e.preventDefault();
614
+ e.stopPropagation();
615
+ setIsInputItemVisible(false);
616
+ setIsListVisible(true);
617
+ };
618
+ const onInputOptionRemove = (e, option) => {
619
+ e.stopPropagation();
620
+ e.preventDefault();
621
+ e.nativeEvent.stopImmediatePropagation();
622
+ if (!isMultiple) {
623
+ setSelectedValue("");
624
+ onChange === null || onChange === void 0 ? void 0 : onChange("");
625
+ }
626
+ else {
627
+ const selectedOptions = [
628
+ ...selectedValue.filter((value) => value !== (option === null || option === void 0 ? void 0 : option[valueKey]) && value !== option),
629
+ ];
630
+ setSelectedValue(selectedOptions);
631
+ onChange === null || onChange === void 0 ? void 0 : onChange(selectedOptions);
632
+ }
633
+ if (!isListVisible) {
634
+ setIsListVisible(true);
635
+ }
636
+ if (isInputItemVisible) {
637
+ setIsInputItemVisible(false);
638
+ }
639
+ };
640
+ const onInputClear = (e) => {
641
+ if (isSearchable && options) {
642
+ setCurrentSearchedValue("");
643
+ setOptionsData(options);
644
+ applyInputSelectFocus();
645
+ }
646
+ if (valueRenderer) {
647
+ (clear === "always" || clear === "whenChanged") &&
648
+ setIsInputItemVisible(false);
649
+ }
650
+ if (!isListVisible) {
651
+ setIsListVisible(true);
652
+ }
653
+ if (isClearable && !isClearableOnlyWhenSearch) {
654
+ setSelectedValue(isMultiple ? [] : "");
655
+ setHasValueChanged(false);
656
+ onChange === null || onChange === void 0 ? void 0 : onChange(isMultiple ? [] : undefined);
657
+ }
658
+ onClear === null || onClear === void 0 ? void 0 : onClear();
659
+ };
660
+ const onOptionClick = (e, option) => {
661
+ var _a, _b, _c;
662
+ e.stopPropagation();
663
+ e.preventDefault();
664
+ e.nativeEvent.stopImmediatePropagation();
665
+ if ((_c = (_b = (_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.closest("div")) === null || _b === void 0 ? void 0 : _b.dataset) === null || _c === void 0 ? void 0 : _c.separator) {
666
+ return;
667
+ }
668
+ setCurrentValue(option);
669
+ setIsListVisible(false);
670
+ if (isClearable && !isClearableOnlyWhenSearch) {
671
+ setHasValueChanged(true);
672
+ }
673
+ if (valueRenderer) {
674
+ setIsInputItemVisible(true);
675
+ }
676
+ };
677
+ const onOptionKeyDown = (e, option, index) => {
678
+ var _a, _b, _c, _d;
679
+ if (["Enter", " "].includes(e.key)) {
680
+ e.preventDefault();
681
+ if ((_b = (_a = e.target.children[0]) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.separator) {
682
+ return;
683
+ }
684
+ setCurrentValue(option);
685
+ if (isClearable && !isClearableOnlyWhenSearch) {
686
+ setHasValueChanged(true);
687
+ }
688
+ if (valueRenderer) {
689
+ setIsInputItemVisible(true);
690
+ }
691
+ }
692
+ if (e.key === "ArrowUp" && index > 0) {
693
+ e.preventDefault();
694
+ (_c = optionsRef.current[index - 1]) === null || _c === void 0 ? void 0 : _c.focus();
695
+ }
696
+ if (e.key === "ArrowDown" && index < optionsData.length - 1) {
697
+ e.preventDefault();
698
+ (_d = optionsRef.current[index + 1]) === null || _d === void 0 ? void 0 : _d.focus();
699
+ }
700
+ if (e.key === "ArrowUp" && index === 0) {
701
+ e.preventDefault();
702
+ applyInputSelectFocus();
703
+ }
704
+ if (e.key === "Backspace") {
705
+ onInputOptionRemove(e, option);
706
+ }
707
+ };
708
+ useOutsideClose(containerRef, () => {
709
+ if (!isListVisible) {
710
+ return;
711
+ }
712
+ setIsListVisible(false);
713
+ if (isSearchable && !currentSearchedValue) {
714
+ setOptionsData(options || []);
715
+ }
716
+ if (valueRenderer && isSelectedValueCorrect) {
717
+ setIsInputItemVisible(true);
718
+ }
719
+ });
720
+ useEffect(() => {
721
+ if (options) {
722
+ setOptionsData(options);
723
+ }
724
+ }, [options]);
725
+ useEffect(() => {
726
+ if (optionsData) {
727
+ optionsRef.current = optionsRef.current.slice(0, optionsData === null || optionsData === void 0 ? void 0 : optionsData.length);
728
+ }
729
+ }, [optionsData]);
730
+ useEffect(() => {
731
+ if (isValueCorrect && !deepEqual(value, selectedValue)) {
732
+ setCurrentValue(defaultInputValue(value));
733
+ valueRenderer && setIsInputItemVisible(true);
734
+ }
735
+ }, []);
736
+ useEffect(() => {
737
+ if (isListVisible && isSearchable) {
738
+ applyInputSelectFocus();
739
+ }
740
+ }, [applyInputSelectFocus, isSearchable, isListVisible]);
741
+ const zDropList = (jsx(ZDropList, { options: optionsData, selectedValue: selectedValue, valueKey: valueKey, labelKey: labelKey, optionsRef: optionsRef, optionRenderer: optionRenderer, onOptionClick: onOptionClick, onOptionKeyDown: onOptionKeyDown, noDataContent: noDataContent, currentSearchedValue: currentSearchedValue, listStyleClasses: {
742
+ list: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.list,
743
+ listItem: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.listItem,
744
+ noData: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.noData,
745
+ } }));
746
+ return (jsxs("div", { ref: containerRef, className: containerClasses, onBlur: onBlur, children: [label && (jsx(ZDropLabel, { name: name, label: label, className: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.label })), jsxs("div", { className: inputFieldClasses, onClick: onInputFieldClick, children: [jsx(ZDropInput, { name: name, options: options, selectedValue: selectedValue, ...(isSearchable && {
747
+ currentSearchedValue: currentSearchedValue,
748
+ setCurrentSearchedValue: setCurrentSearchedValue,
749
+ }), valueKey: valueKey, labelKey: labelKey, placeholder: placeholder, isMultiple: isMultiple, isDisabled: isDisabled, isSearchable: isSearchable, isListVisible: isListVisible, setIsListVisible: setIsListVisible, isInputItemVisible: isInputItemVisible, valueRenderer: valueRenderer, onInputClick: onInputClick, onInputItemClick: onInputItemClick, onInputKeyDown: onInputKeyDown, onInputChange: onInputChange, onInputOptionRemove: onInputOptionRemove, inputRef: inputRef, inputRefMultipleValueRenderer: inputRefMultipleValueRenderer, inputRefSingleValueRenderer: inputRefSingleValueRenderer, inputStyleClasses: {
750
+ input: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.input,
751
+ inputValue: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.inputValue,
752
+ inputMultipleValue: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.inputMultipleValue,
753
+ inputMultipleSearch: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.inputMultipleSearch,
754
+ } }), isClearable && (jsx(ZDropClearButton, { hasValueChanged: hasValueChanged, currentSearchedValue: currentSearchedValue, onInputClear: onInputClear, isListVisible: isListVisible, isClearableOnlyWhenChange: isClearableOnlyWhenChange, isClearableOnlyWhenSearch: isClearableOnlyWhenSearch, className: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.clearButton, clearIcon: clearIcon })), jsx(ZDropListVisibilityToggle, { expandToggleRenderer: expandToggleRenderer, isListVisible: isListVisible, onClick: onExpandToggleClick, toggleStyleClasses: {
755
+ expandToggle: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.expandToggle,
756
+ expandToggleIcon: styleClasses === null || styleClasses === void 0 ? void 0 : styleClasses.expandToggleIcon,
757
+ } })] }), isListVisible && !referenceElementClassName && zDropList, isListVisible && referenceElementClassName && (jsx(ZDropListWrapper, { referenceElementClassName: referenceElementClassName, positionToReferenceElement: positionToReferenceElement, listMaxHeightLimiter: listMaxHeightLimiter, children: zDropList }))] }));
758
+ };
759
+
760
+ function ZDropField(props) {
761
+ const { control, name, rules, onChangeTransform, valueSelector, errorClassName, errorRenderer, ...zDropProps } = props;
762
+ const errorMessageClasses = classNames(styles.errorMessage, errorClassName);
763
+ return (jsx(Controller, { control: control, name: name, rules: rules, render: ({ field, fieldState }) => {
764
+ var _a;
765
+ const { onChange, value, name: fieldName, onBlur } = field;
766
+ const zDropValue = typeof valueSelector === "function" ? valueSelector(value) : value;
767
+ const handleChange = (newValue) => {
768
+ onChange(typeof onChangeTransform === "function"
769
+ ? onChangeTransform(newValue)
770
+ : newValue);
771
+ };
772
+ return (jsxs(Fragment, { children: [jsx(ZDrop, { ...zDropProps, name: fieldName, value: zDropValue, onChange: handleChange, onBlur: onBlur }), ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) && (jsx("div", { className: errorMessageClasses, children: errorRenderer
773
+ ? errorRenderer(fieldState.error.message)
774
+ : fieldState.error.message }))] }));
775
+ } }));
776
+ }
777
+
778
+ export { ZDrop as Z, ZDropField as a };
779
+ //# sourceMappingURL=index-Ck9QayZm.js.map