kamotive_ui 1.2.2 → 1.2.4

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 (70) hide show
  1. package/dist/Icons/IconClose/IconClose10.d.ts +2 -1
  2. package/dist/Icons/IconClose/IconClose10.js +2 -2
  3. package/dist/Icons/IconFile/IconFile.d.ts +6 -0
  4. package/dist/Icons/IconFile/IconFile.js +5 -0
  5. package/dist/Icons/IconUpload/IconUpload.d.ts +6 -0
  6. package/dist/Icons/IconUpload/IconUpload.js +5 -0
  7. package/dist/Icons/index.d.ts +2 -0
  8. package/dist/Icons/index.js +2 -0
  9. package/dist/colors.css +5 -1
  10. package/dist/components/Button/Button.d.ts +1 -1
  11. package/dist/components/Button/Button.js +87 -35
  12. package/dist/components/Button/Button.module.css +101 -49
  13. package/dist/components/Checkbox/Checkbox.d.ts +1 -1
  14. package/dist/components/Checkbox/Checkbox.js +5 -3
  15. package/dist/components/Checkbox/Checkbox.module.css +0 -11
  16. package/dist/components/ColorPicker/ColorPicker.d.ts +1 -1
  17. package/dist/components/ColorPicker/ColorPicker.js +89 -44
  18. package/dist/components/ColorPicker/ColorPicker.module.css +25 -42
  19. package/dist/components/Dropdown/Dropdown.d.ts +12 -8
  20. package/dist/components/Dropdown/Dropdown.js +239 -77
  21. package/dist/components/Dropdown/Dropdown.module.css +152 -89
  22. package/dist/components/FileAttach/FileAttach.d.ts +3 -0
  23. package/dist/components/FileAttach/FileAttach.js +79 -0
  24. package/dist/components/FileAttach/FileAttach.module.css +36 -0
  25. package/dist/components/Input/Input.d.ts +1 -1
  26. package/dist/components/Input/Input.js +36 -25
  27. package/dist/components/Input/Input.module.css +92 -45
  28. package/dist/components/Loader/Loader.d.ts +3 -0
  29. package/dist/components/Loader/Loader.js +18 -0
  30. package/dist/components/Loader/Loader.module.css +75 -0
  31. package/dist/components/ProgressBar/ProgressBar.d.ts +1 -1
  32. package/dist/components/ProgressBar/ProgressBar.js +5 -4
  33. package/dist/components/ProgressBar/ProgressBar.module.css +4 -11
  34. package/dist/components/ProgressLoader/ProgressLoader.d.ts +1 -1
  35. package/dist/components/ProgressLoader/ProgressLoader.js +3 -2
  36. package/dist/components/ProgressLoader/ProgressLoader.module.css +2 -11
  37. package/dist/components/RadioButton/RadioButton.d.ts +1 -1
  38. package/dist/components/RadioButton/RadioButton.js +5 -3
  39. package/dist/components/RadioButton/RadioButton.module.css +2 -15
  40. package/dist/components/SettingTag/SettingTag.d.ts +1 -1
  41. package/dist/components/SettingTag/SettingTag.js +7 -6
  42. package/dist/components/SettingTag/SettingTag.module.css +0 -9
  43. package/dist/components/Snackbar/Snackbar.d.ts +1 -1
  44. package/dist/components/Snackbar/Snackbar.js +3 -2
  45. package/dist/components/Snackbar/Snackbar.module.css +1 -9
  46. package/dist/components/Spinner/Spinner.d.ts +3 -0
  47. package/dist/components/Spinner/Spinner.js +30 -0
  48. package/dist/components/Spinner/Spinner.module.css +20 -0
  49. package/dist/components/Tab/Tab.d.ts +1 -1
  50. package/dist/components/Tab/Tab.js +7 -4
  51. package/dist/components/Tab/Tab.module.css +4 -17
  52. package/dist/components/Tabs/Tabs.d.ts +1 -1
  53. package/dist/components/Tabs/Tabs.js +2 -1
  54. package/dist/components/Tabs/Tabs.module.css +0 -6
  55. package/dist/components/Tag/Tag.d.ts +1 -1
  56. package/dist/components/Tag/Tag.js +74 -13
  57. package/dist/components/Tag/Tag.module.css +89 -74
  58. package/dist/components/ToggleButton/ToggleButton.d.ts +1 -1
  59. package/dist/components/ToggleButton/ToggleButton.js +6 -4
  60. package/dist/components/ToggleButton/ToggleButton.module.css +0 -5
  61. package/dist/components/Typography/Typography.d.ts +1 -1
  62. package/dist/components/Typography/Typography.js +3 -2
  63. package/dist/components/Typography/Typography.module.css +8 -13
  64. package/dist/components/Typography/enums.d.ts +2 -0
  65. package/dist/components/Typography/enums.js +2 -0
  66. package/dist/index.d.ts +11 -7
  67. package/dist/index.js +10 -7
  68. package/dist/types/index.d.ts +310 -0
  69. package/dist/types/index.js +1 -0
  70. package/package.json +4 -2
@@ -1,114 +1,276 @@
1
- import React, { useEffect, useRef, useState } from 'react';
1
+ import React, { useCallback, useEffect, useRef, useState } from 'react';
2
2
  import styles from './Dropdown.module.css';
3
3
  import classNames from 'classnames';
4
4
  import { ChevronDown10 } from '../../Icons/ChevronDown/ChevronDown10';
5
5
  import { ChevronUp10 } from '../../Icons/ChevronUp/ChevronUp10';
6
+ import { IconClose10 } from '../../Icons/IconClose/IconClose10';
6
7
  import { IconCheck10 } from '../../Icons/IconCheck/IconCheck10';
7
- export const DropdownListItem = ({ item, size = 'md', selectedItem, style, onChange }) => {
8
+ ;
9
+ import { Typography } from '../Typography/Typography';
10
+ function checkItem(item, getOptionLabel, disabled, isDivider) {
11
+ if (typeof item === 'object' && item !== null) {
12
+ //проверка на вложенные объекты с таким же типом
13
+ Object.keys(item).forEach((key) => {
14
+ const value = item[key];
15
+ if (typeof value === 'object' && value !== null && !React.isValidElement(value)) {
16
+ const nestedItem = checkItem(value, getOptionLabel, disabled, isDivider);
17
+ if (nestedItem) {
18
+ if (!item.children) {
19
+ item.children = [];
20
+ }
21
+ item.children.push(nestedItem);
22
+ delete item[key];
23
+ }
24
+ }
25
+ });
26
+ // проверка на наличие пользовательского поля для вывода(передаваемой функции getOptionLabel)
27
+ if (getOptionLabel) {
28
+ return Object.assign(Object.assign({}, item), { value: getOptionLabel(item), disabled: disabled !== null && disabled !== void 0 ? disabled : false, isDivider: isDivider !== null && isDivider !== void 0 ? isDivider : false });
29
+ }
30
+ if ('value' in item) {
31
+ return Object.assign(Object.assign({}, item), { disabled: disabled !== null && disabled !== void 0 ? disabled : false, isDivider: isDivider !== null && isDivider !== void 0 ? isDivider : false });
32
+ }
33
+ else if ('name' in item && !('value' in item)) {
34
+ return Object.assign(Object.assign({}, item), { value: item.name, disabled: disabled !== null && disabled !== void 0 ? disabled : false, isDivider: isDivider !== null && isDivider !== void 0 ? isDivider : false });
35
+ }
36
+ else if ('description' in item && !('value' in item)) {
37
+ return Object.assign(Object.assign({}, item), { value: item.description, disabled: disabled !== null && disabled !== void 0 ? disabled : false, isDivider: isDivider !== null && isDivider !== void 0 ? isDivider : false });
38
+ }
39
+ else {
40
+ const keys = Object.keys(item);
41
+ if (keys.length) {
42
+ const firstValue = item[keys[0]];
43
+ return Object.assign(Object.assign({}, item), { value: firstValue, disabled: disabled !== null && disabled !== void 0 ? disabled : false, isDivider: isDivider !== null && isDivider !== void 0 ? isDivider : false });
44
+ }
45
+ }
46
+ }
47
+ else if (typeof item === 'string' || typeof item === 'number') {
48
+ return { value: item, disabled: disabled !== null && disabled !== void 0 ? disabled : false, isDivider: isDivider !== null && isDivider !== void 0 ? isDivider : false };
49
+ }
50
+ else {
51
+ return null;
52
+ }
53
+ }
54
+ export const DropdownListItem = ({ item, getOptionLabel, size = 'md', selectedItem, style, onChange, isActive, activeIndex, index, }) => {
8
55
  var _a;
9
- const handleItemClick = (item, disabled) => {
10
- if (!disabled) {
11
- onChange(item);
56
+ const handleItemClick = useCallback((event) => {
57
+ event.preventDefault();
58
+ event.stopPropagation();
59
+ if (!(item === null || item === void 0 ? void 0 : item.disabled)) {
60
+ onChange(event, item);
12
61
  }
13
- };
14
- const itemClassess = classNames(styles[`item-block`], styles[`button--${size}`], { 'item-block--selected': (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) === (item === null || item === void 0 ? void 0 : item.value) || (typeof selectedItem === 'string' || typeof selectedItem === 'number') && selectedItem === item }, { 'item-block--disabled': item === null || item === void 0 ? void 0 : item.disabled });
15
- const itemBlock = classNames(styles[`item-block`], styles[`item-block-${style}`], { [`item-block-${style}--selected`]: (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) === item.value }, { 'item-block--disabled': item.disabled });
16
- return (React.createElement("div", { className: styles[`item--container`] },
17
- React.createElement("div", { className: styles[itemClassess], onClick: () => handleItemClick(item, item.disabled) },
62
+ }, [item, onChange]);
63
+ const itemContainerClasses = classNames(styles[`item--container`], { [styles['item--container--active']]: isActive });
64
+ const itemClassess = classNames(styles[`item-block`], styles[`button--${size}`], {
65
+ [styles['item-block--disabled']]: item === null || item === void 0 ? void 0 : item.disabled,
66
+ [styles['item-block--active']]: isActive,
67
+ });
68
+ const itemBlock = classNames(styles[`item-block`], styles[`item-block-${style}`], { [styles[`item-block-${style}--selected`]]: (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) === (item === null || item === void 0 ? void 0 : item.value) }, { [styles['item-block--disabled']]: item === null || item === void 0 ? void 0 : item.disabled });
69
+ return (React.createElement("div", { className: itemContainerClasses, onClick: handleItemClick },
70
+ React.createElement("div", { className: itemClassess },
18
71
  React.createElement("div", { className: itemBlock },
19
- style === 'default' && item.icon && React.cloneElement(item.icon, { strokeWidth: size === 'lg' ? '0.5' : size === 'md' ? '0.3' : '0.0' }),
20
- React.createElement("div", { className: styles["item"] },
21
- React.createElement("span", null, (item === null || item === void 0 ? void 0 : item.value) || item)),
22
- (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) === item.value && React.createElement(IconCheck10, { strokeWidth: size === 'lg' ? '0.5' : size === 'md' ? '0.3' : '0.0', htmlColor: '#0D99FF' })),
23
- item.isDivider && React.createElement("div", { className: styles["divider"] })),
24
- (item === null || item === void 0 ? void 0 : item.children) && (React.createElement("div", { className: styles["nestedMenu"] }, (_a = item.children) === null || _a === void 0 ? void 0 : _a.map((child, index) => (React.createElement(DropdownListItem, { key: index, item: child, size: size, selectedItem: selectedItem, onChange: onChange })))))));
72
+ style === 'icons' &&
73
+ (item === null || item === void 0 ? void 0 : item.icon) &&
74
+ React.cloneElement(item.icon, {
75
+ strokeWidth: size === 'lg' ? '0.5' : size === 'md' ? '0.3' : '0.0',
76
+ }),
77
+ React.createElement("div", { className: styles.item },
78
+ React.createElement("span", null, item === null || item === void 0 ? void 0 : item.value)),
79
+ (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) === (item === null || item === void 0 ? void 0 : item.value) && (React.createElement(IconCheck10, { strokeWidth: size === 'lg' ? '0.5' : size === 'md' ? '0.3' : '0.0', htmlColor: "#0D99FF" }))),
80
+ (item === null || item === void 0 ? void 0 : item.isDivider) && React.createElement("div", { className: styles.divider })),
81
+ (item === null || item === void 0 ? void 0 : item.children) && (React.createElement("div", { className: styles.nestedMenu }, (_a = item.children) === null || _a === void 0 ? void 0 : _a.map((child, childIndex) => {
82
+ var _a;
83
+ return (React.createElement(DropdownListItem, { key: (_a = child === null || child === void 0 ? void 0 : child.key) !== null && _a !== void 0 ? _a : childIndex, item: child, getOptionLabel: getOptionLabel, size: size, selectedItem: selectedItem, onChange: onChange, isActive: activeIndex === index, activeIndex: activeIndex, index: childIndex }));
84
+ })))));
25
85
  };
26
- export const Dropdown = ({ id, name, label, size = 'md', disabled, className, defaultValue, items, isOpened = false, style = 'default', readOnly = false, isLeftLabel = false }) => {
86
+ export const Dropdown = ({ id, label, placeholder, size = 'lg', options, getOptionLabel, value, defaultValue, style = 'text', className, disabled = false, readOnly = false, isOpened = false, noOptionsText = 'Нет вариатов для выбора', isLeftLabel = false, error = false, helperText, onChange, onClose, clearable = true, required = false, isDivider = false, }) => {
87
+ var _a;
27
88
  const [isOpen, setIsOpen] = useState(isOpened);
28
- const [selectedItem, setSelectedItem] = useState(defaultValue !== null && defaultValue !== void 0 ? defaultValue : null);
89
+ const [modifiedOptions, setModifiedOptions] = useState([]);
90
+ const [selectedItem, setSelectedItem] = useState(null);
91
+ const [errorInput, setErrorInput] = useState(false);
92
+ const [errorInputHelperText, setErrorInputHelperText] = useState(helperText);
93
+ const [activeIndex, setActiveIndex] = useState(-1);
29
94
  const containerRef = useRef(null);
30
95
  const [containerWidth, setContainerWidth] = useState(undefined);
31
- const icon = !isOpen ? React.createElement(ChevronDown10, null) : React.createElement(ChevronUp10, null);
32
- const handleToggle = () => {
33
- setIsOpen(prev => !prev);
96
+ const handleToggle = (event) => {
97
+ setIsOpen((prev) => !prev);
98
+ if (isOpen) {
99
+ onClose === null || onClose === void 0 ? void 0 : onClose(event);
100
+ }
34
101
  };
35
- const onChange = (item) => {
36
- if ((selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) !== item.value) {
102
+ const onChangeHandler = (event, item) => {
103
+ event.preventDefault();
104
+ event.stopPropagation();
105
+ const newEvent = Object.assign(Object.assign({}, event), { currentTarget: Object.assign(Object.assign({}, event.currentTarget), { value: item }) });
106
+ if ((selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) !== (item === null || item === void 0 ? void 0 : item.value)) {
37
107
  setSelectedItem(item);
38
108
  setIsOpen(false);
109
+ onChange === null || onChange === void 0 ? void 0 : onChange(newEvent, item);
110
+ onClose === null || onClose === void 0 ? void 0 : onClose(event);
111
+ }
112
+ if (item) {
113
+ setErrorInput(false);
39
114
  }
40
115
  else {
41
- setSelectedItem(null);
116
+ setErrorInput(true);
42
117
  }
43
118
  };
44
- const wrapperClassess = classNames(styles[`dropdown--container`], {
45
- 'wrapper--left': isLeftLabel,
46
- });
47
- const buttonClassess = classNames(styles['button'], className, styles[`button--${size}`], { 'button-item--selected': (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) && !disabled }, { 'button--readOnly': readOnly }, { 'button--disabled': disabled });
48
- const dropdownClassess = classNames(styles['dropdown'], className, {
49
- 'dropdown--disabled': disabled,
50
- });
51
- const labelClasses = classNames(styles['label'], { 'label--default': !isLeftLabel,
52
- 'label--left': isLeftLabel,
53
- });
54
- const checkItem = (item) => {
55
- if (typeof item === 'object') {
56
- if (item.value) {
57
- return item;
58
- }
59
- else if (item.name && !item.value) {
60
- return Object.assign(Object.assign({}, item), { value: name });
61
- }
62
- else if (item.description && !item.value) {
63
- return Object.assign(Object.assign({}, item), { value: item.description });
64
- }
65
- else {
66
- const keys = Object.keys(item);
67
- if (keys.length) {
68
- const firstValue = item[keys[0]];
69
- return Object.assign(Object.assign({}, item), { value: firstValue });
70
- }
119
+ //для выбора опции из списка с клавиатуры
120
+ const handleKeyDown = (event) => {
121
+ if (!isOpen) {
122
+ if (event.key === 'Enter' || event.key === 'ArrowDown') {
123
+ event.preventDefault();
124
+ event.stopPropagation();
125
+ setIsOpen(true);
126
+ setActiveIndex(0);
71
127
  }
128
+ return;
72
129
  }
73
- else if (typeof item === 'string' || typeof item === 'number') {
74
- return { value: item };
130
+ switch (event.key) {
131
+ case 'ArrowDown':
132
+ event.preventDefault();
133
+ modifiedOptions && setActiveIndex((prev) => (prev < modifiedOptions.length - 1 ? prev + 1 : prev));
134
+ break;
135
+ case 'ArrowUp':
136
+ event.preventDefault();
137
+ setActiveIndex((prev) => (prev > 0 ? prev - 1 : prev));
138
+ break;
139
+ case 'Enter':
140
+ event.preventDefault();
141
+ if (activeIndex >= 0) {
142
+ const selectedOption = modifiedOptions && modifiedOptions[activeIndex];
143
+ onChangeHandler(event, selectedOption);
144
+ setIsOpen(false);
145
+ onClose === null || onClose === void 0 ? void 0 : onClose(event);
146
+ setActiveIndex(-1);
147
+ }
148
+ break;
149
+ case 'Escape':
150
+ setIsOpen(false);
151
+ onClose === null || onClose === void 0 ? void 0 : onClose(event);
152
+ setActiveIndex(-1);
153
+ break;
75
154
  }
76
- else {
77
- return null;
155
+ };
156
+ //для сброса выбранного значения
157
+ const handleReset = (event) => {
158
+ event.preventDefault();
159
+ event.stopPropagation();
160
+ const startValue = defaultValue
161
+ ? checkItem(defaultValue)
162
+ : null;
163
+ setSelectedItem(startValue !== null && startValue !== void 0 ? startValue : null);
164
+ setIsOpen(false);
165
+ onChange === null || onChange === void 0 ? void 0 : onChange(event, startValue !== null && startValue !== void 0 ? startValue : null);
166
+ onClose === null || onClose === void 0 ? void 0 : onClose(event);
167
+ setActiveIndex(-1);
168
+ if (required) {
169
+ setErrorInput(true);
170
+ setErrorInputHelperText(helperText !== null && helperText !== void 0 ? helperText : 'Поле обязательно для заполнения');
78
171
  }
79
172
  };
173
+ const wrapperClassess = classNames({
174
+ [styles['dropdown--container']]: !isLeftLabel,
175
+ [styles['dropdown--container-left']]: isLeftLabel,
176
+ [styles['dropdown--container-label']]: label && !isLeftLabel && !required,
177
+ [styles['dropdown--container-helperText']]: errorInput,
178
+ });
179
+ const buttonClassess = classNames(styles.button, className, styles[`button--${size}`], {
180
+ [styles['button-item--selected']]: (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) && !disabled,
181
+ [styles['button--readOnly']]: readOnly,
182
+ [styles['button--disabled']]: disabled,
183
+ [styles['button--error']]: errorInput,
184
+ });
185
+ const dropdownClassess = classNames(styles.dropdown, className, {
186
+ [styles['dropdown--disabled']]: disabled,
187
+ });
188
+ const labelClasses = classNames(styles.label, styles[size], {
189
+ [styles['label--default']]: !isLeftLabel,
190
+ [styles['label--left']]: isLeftLabel,
191
+ [styles['label--required']]: required,
192
+ });
193
+ const selectedItemClassess = classNames({
194
+ [styles['item-selected']]: selectedItem,
195
+ [styles['item-placeholder']]: !selectedItem && ((placeholder !== null && placeholder !== void 0 ? placeholder : label) || (!placeholder && !label)),
196
+ [styles['button--icons--item-selected']]: style === 'icons' && (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.icon),
197
+ });
80
198
  const getDropdownMenu = () => {
81
- // const menu = withPortal ? (
82
- // ReactDOM.createPortal(<DropdownMenu withPortal >{children}</DropdownMenu>, portalContainer)
83
- // ) : <DropdownMenu>{children}</DropdownMenu>
84
- const menu = isOpen && React.createElement("div", { className: styles[dropdownClassess] }, items === null || items === void 0 ? void 0 : items.map((item, index) => {
199
+ const menu = isOpen && (React.createElement("div", { className: dropdownClassess }, modifiedOptions && modifiedOptions.length > 0 ? (modifiedOptions.map((modifiedOption, index) => {
85
200
  var _a;
86
- const modifiedItem = checkItem(item);
87
- return (React.createElement(DropdownListItem, { key: (_a = item === null || item === void 0 ? void 0 : item.key) !== null && _a !== void 0 ? _a : index, item: modifiedItem, size: size, selectedItem: selectedItem, style: style, onChange: onChange }));
88
- }));
201
+ return (React.createElement(DropdownListItem, { key: (_a = modifiedOption === null || modifiedOption === void 0 ? void 0 : modifiedOption.key) !== null && _a !== void 0 ? _a : index, item: modifiedOption, getOptionLabel: getOptionLabel, size: size, selectedItem: selectedItem, style: style, onChange: onChangeHandler, isActive: activeIndex === index, activeIndex: activeIndex, index: index }));
202
+ })) : (React.createElement("div", { className: styles['no-options'] }, noOptionsText))));
89
203
  return isOpen ? menu : null;
90
204
  };
91
205
  useEffect(() => {
206
+ var _a, _b, _c;
207
+ const handleClickOutside = (event) => {
208
+ if (containerRef.current && !containerRef.current.contains(event.target)) {
209
+ setIsOpen(false);
210
+ onClose === null || onClose === void 0 ? void 0 : onClose(event);
211
+ }
212
+ };
92
213
  if (containerRef.current) {
93
- const textWidth = Math.max(name === null || name === void 0 ? void 0 : name.length, (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value.length) || 0);
214
+ const text = (_a = label !== null && label !== void 0 ? label : placeholder) !== null && _a !== void 0 ? _a : '';
94
215
  let newWidth;
95
- if (textWidth === (name === null || name === void 0 ? void 0 : name.length)) {
96
- const inPixel = size === 'sm' ? 11 : size === 'md' ? 12 : 14;
97
- newWidth = selectedItem ? textWidth * inPixel : textWidth * inPixel;
216
+ if (!isLeftLabel) {
217
+ const textWidth = Math.max((text || '').length, (((_b = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) === null || _b === void 0 ? void 0 : _b.toString()) || '').length);
218
+ const inPixel = size === 'lg' ? 11 : 9;
219
+ newWidth = textWidth * inPixel;
98
220
  }
99
221
  else {
100
- const inPixel = size === 'sm' ? 9 : size === 'md' ? 10 : 12;
101
- newWidth = textWidth * inPixel;
222
+ const inPixel = size === 'lg' ? 11 : 9;
223
+ const selectedValue = ((_c = selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value) === null || _c === void 0 ? void 0 : _c.toString()) || '';
224
+ newWidth = (text.length + selectedValue.length) * inPixel + 40;
102
225
  }
103
226
  setContainerWidth(newWidth);
104
227
  }
105
- }, [selectedItem, name, isOpen, size]);
106
- return (React.createElement("div", { className: styles[wrapperClassess], ref: containerRef, style: { width: containerWidth ? `${containerWidth}px` : 'auto' } },
107
- selectedItem && label && (React.createElement("label", { className: labelClasses, htmlFor: id }, label)),
108
- React.createElement("button", { className: buttonClassess, onClick: readOnly ? undefined : handleToggle, disabled: disabled },
109
- React.createElement("div", { className: style === 'default' && (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.icon) ? styles[`button--default--item-selected`] : '' },
110
- style === 'default' && (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.icon) && React.cloneElement(selectedItem.icon, { strokeWidth: size === 'lg' ? '0.5' : size === 'md' ? '0.3' : '0.0' }),
111
- selectedItem ? selectedItem.value : name),
112
- icon && React.cloneElement(icon, { strokeWidth: size === 'lg' ? '0.5' : size === 'md' ? '0.3' : '0.0' })),
113
- getDropdownMenu()));
228
+ document.addEventListener('mousedown', handleClickOutside);
229
+ return () => {
230
+ document.removeEventListener('mousedown', handleClickOutside);
231
+ };
232
+ }, [selectedItem, label, isOpen, size, placeholder, onClose, isLeftLabel]);
233
+ useEffect(() => {
234
+ if (options) {
235
+ const modifiedOptions = options.map((option, index) => {
236
+ const modifiedOption = checkItem === null || checkItem === void 0 ? void 0 : checkItem(option, getOptionLabel, disabled, isDivider);
237
+ if (modifiedOption && modifiedOption.value === (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.value)) {
238
+ setActiveIndex(index);
239
+ }
240
+ return modifiedOption;
241
+ });
242
+ setModifiedOptions(modifiedOptions);
243
+ }
244
+ }, [options]);
245
+ useEffect(() => {
246
+ if (value || defaultValue) {
247
+ const startValue = value
248
+ ? checkItem(value)
249
+ : defaultValue
250
+ ? checkItem(defaultValue)
251
+ : null;
252
+ setSelectedItem(startValue !== null && startValue !== void 0 ? startValue : null);
253
+ }
254
+ else {
255
+ setSelectedItem(null);
256
+ }
257
+ }, [value, defaultValue, checkItem]);
258
+ useEffect(() => {
259
+ setErrorInput(error);
260
+ }, [error]);
261
+ return (React.createElement("div", { id: id, className: wrapperClassess, ref: containerRef, style: { width: isLeftLabel && containerWidth ? `${containerWidth}px` : '100%' } },
262
+ label && (React.createElement(Typography, { variant: "Caption", className: labelClasses }, label)),
263
+ React.createElement("button", { className: buttonClassess, onClick: readOnly ? undefined : handleToggle, disabled: disabled, tabIndex: 0, onKeyDown: handleKeyDown },
264
+ React.createElement("div", { className: selectedItemClassess },
265
+ style === 'icons' &&
266
+ (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.icon) &&
267
+ React.cloneElement(selectedItem.icon, {
268
+ strokeWidth: size === 'lg' ? '0.5' : size === 'md' ? '0.3' : '0.0',
269
+ }),
270
+ selectedItem ? selectedItem.value : ((_a = placeholder !== null && placeholder !== void 0 ? placeholder : label) !== null && _a !== void 0 ? _a : 'Выберите значение')),
271
+ clearable && !readOnly && !disabled && selectedItem && (React.createElement("div", { className: styles.resetButton },
272
+ React.createElement(IconClose10, { strokeWidth: "0.2", htmlColor: "var(--text-light)", onClick: handleReset }))),
273
+ React.createElement("div", { className: styles.dropdownIcon }, !isOpen ? (React.createElement(ChevronDown10, { strokeWidth: size === 'lg' ? '0.5' : '0.3' })) : (React.createElement(ChevronUp10, { strokeWidth: size === 'lg' ? '0.5' : '0.3' }))),
274
+ getDropdownMenu()),
275
+ errorInput && errorInputHelperText && (React.createElement(Typography, { variant: "Caption", className: classNames(styles.helperText, styles[size]) }, helperText !== null && helperText !== void 0 ? helperText : errorInputHelperText))));
114
276
  };