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