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