@homecode/ui 4.20.0-beta-0 → 4.20.0-beta-1
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.
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
2
2
|
import { mapById, isMultiple, renderLabel } from './Select.helpers.js';
|
|
3
3
|
import { useRef, useState, useMemo, useEffect, useCallback } from 'react';
|
|
4
4
|
import { INTERACTION_MODE, getInteractionMode } from '../../tools/dom.js';
|
|
@@ -7,13 +7,14 @@ import omit from 'lodash.omit';
|
|
|
7
7
|
import { AssistiveText } from '../AssistiveText/AssistiveText.js';
|
|
8
8
|
import { Button } from '../Button/Button.js';
|
|
9
9
|
import { Input } from '../Input/Input.js';
|
|
10
|
+
import { Icon } from '../Icon/Icon.js';
|
|
10
11
|
import { Label } from '../Label/Label.js';
|
|
11
12
|
import { Popup } from '../Popup/Popup.js';
|
|
12
13
|
import { RequiredStar } from '../RequiredStar/RequiredStar.js';
|
|
13
|
-
import S from './Select.styl.js';
|
|
14
14
|
import { Scroll } from '../Scroll/Scroll.js';
|
|
15
15
|
import { useThrottle } from '../../hooks/useThrottle.js';
|
|
16
16
|
import useEvent from '../../hooks/useEvent.js';
|
|
17
|
+
import S from './Select.styl.js';
|
|
17
18
|
|
|
18
19
|
function Select2(props) {
|
|
19
20
|
const { className, value, onChange, onSearchChange, inputProps, popupProps, size = 'm', optionClassName, additionalOptions = [], options, variant, label, error, blur, disabled, trigger, required, hideRequiredStar, isSearchable, presets = [], selectAllButton, clearButton, showSelectedCount, disableLabel, } = props;
|
|
@@ -167,13 +168,15 @@ function Select2(props) {
|
|
|
167
168
|
.join(', '));
|
|
168
169
|
}, [isMultiple$1, value]);
|
|
169
170
|
// console.log('selectedLabel::', selectedLabel);
|
|
170
|
-
const
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
const triggerArrow = useMemo(() => {
|
|
172
|
+
if (inputProps?.hasClear && searchVal)
|
|
173
|
+
return null;
|
|
174
|
+
return (jsx(Icon, { type: "chevronDown", className: cn(S.triggerArrow, isOpen && S.isOpen), size: size }));
|
|
175
|
+
}, [isOpen, searchVal]);
|
|
173
176
|
const renderTriggerInput = () => {
|
|
174
177
|
return (jsx(Input, { ...triggerProps, ...inputProps,
|
|
175
178
|
// TODO: autoComplete
|
|
176
|
-
addonRight:
|
|
179
|
+
addonRight: triggerArrow, error: isErrorVisible, value: isFocused ? searchVal : selectedLabel, onChange: handleSearchChange, label: getFieldLabel(label) }));
|
|
177
180
|
};
|
|
178
181
|
const renderAdditionalLabel = () => {
|
|
179
182
|
return null;
|
|
@@ -185,9 +188,8 @@ function Select2(props) {
|
|
|
185
188
|
const hasSelected = fullSelectedLabel.length > 0;
|
|
186
189
|
const displayLabel = hasSelected ? fullSelectedLabel : label;
|
|
187
190
|
const title = hasSelected ? fullSelectedLabel : null;
|
|
188
|
-
const triggerArrow = renderTriggerArrow();
|
|
189
191
|
const isError = isErrorVisible;
|
|
190
|
-
const classes = cn(S.triggerButton, isError && S.isError, triggerArrow , className);
|
|
192
|
+
const classes = cn(S.triggerButton, isError && S.isError, triggerArrow && S.hasTriggerArrow, className);
|
|
191
193
|
return (jsxs("div", { children: [jsxs(Button, { className: classes, variant: "default", ...props, style: { clipPath: labelClipPath }, title: title?.join?.(', '), children: [jsx("div", { className: cn(S.triggerButtonLabel, hasSelected && S.hasSelected), children: displayLabel }), triggerArrow] }), jsx(Label, { size: size, isOnTop: hasSelected, isError: isError, onClipPathChange: setLabelClipPath, children: getFieldLabel(label) })] }));
|
|
192
194
|
};
|
|
193
195
|
const renderTrigger = () => {
|