@redneckz/wildless-cms-uni-blocks 0.14.909 → 0.14.910
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/bundle/bundle.umd.js +85 -69
- package/bundle/bundle.umd.min.js +1 -1
- package/bundle/ui-kit/Select/Select.d.ts +6 -0
- package/bundle/ui-kit/Select/SelectPopup.d.ts +1 -0
- package/bundle/ui-kit/Select/filterOptions.d.ts +1 -1
- package/bundle/ui-kit/Select/renderIcon.d.ts +2 -0
- package/bundle/ui-kit/Select/renderOptionText.d.ts +9 -0
- package/bundle/ui-kit/Select/renderSearchInput.d.ts +9 -0
- package/bundle/ui-kit/Select/renderSelectContainer.d.ts +15 -0
- package/bundle/ui-kit/Select/useSelectPopup.d.ts +2 -1
- package/dist/ui-kit/FormField/Fields/InnDadataField.js +5 -2
- package/dist/ui-kit/FormField/Fields/InnDadataField.js.map +1 -1
- package/dist/ui-kit/Select/Select.d.ts +6 -0
- package/dist/ui-kit/Select/Select.js +31 -40
- package/dist/ui-kit/Select/Select.js.map +1 -1
- package/dist/ui-kit/Select/SelectPopup.d.ts +1 -0
- package/dist/ui-kit/Select/SelectPopup.js +1 -1
- package/dist/ui-kit/Select/SelectPopup.js.map +1 -1
- package/dist/ui-kit/Select/filterOptions.d.ts +1 -1
- package/dist/ui-kit/Select/filterOptions.js +2 -2
- package/dist/ui-kit/Select/filterOptions.js.map +1 -1
- package/dist/ui-kit/Select/renderIcon.d.ts +2 -0
- package/dist/ui-kit/Select/renderIcon.js +8 -0
- package/dist/ui-kit/Select/renderIcon.js.map +1 -0
- package/dist/ui-kit/Select/renderOptionText.d.ts +9 -0
- package/dist/ui-kit/Select/renderOptionText.js +11 -0
- package/dist/ui-kit/Select/renderOptionText.js.map +1 -0
- package/dist/ui-kit/Select/renderSearchInput.d.ts +9 -0
- package/dist/ui-kit/Select/renderSearchInput.js +7 -0
- package/dist/ui-kit/Select/renderSearchInput.js.map +1 -0
- package/dist/ui-kit/Select/renderSelectContainer.d.ts +15 -0
- package/dist/ui-kit/Select/renderSelectContainer.js +18 -0
- package/dist/ui-kit/Select/renderSelectContainer.js.map +1 -0
- package/dist/ui-kit/Select/useSelectPopup.d.ts +2 -1
- package/dist/ui-kit/Select/useSelectPopup.js +6 -5
- package/dist/ui-kit/Select/useSelectPopup.js.map +1 -1
- package/lib/common.css +1 -1
- package/lib/ui-kit/FormField/Fields/InnDadataField.js +5 -2
- package/lib/ui-kit/FormField/Fields/InnDadataField.js.map +1 -1
- package/lib/ui-kit/Select/Select.d.ts +6 -0
- package/lib/ui-kit/Select/Select.js +32 -41
- package/lib/ui-kit/Select/Select.js.map +1 -1
- package/lib/ui-kit/Select/SelectPopup.d.ts +1 -0
- package/lib/ui-kit/Select/SelectPopup.js +1 -1
- package/lib/ui-kit/Select/SelectPopup.js.map +1 -1
- package/lib/ui-kit/Select/filterOptions.d.ts +1 -1
- package/lib/ui-kit/Select/filterOptions.js +2 -2
- package/lib/ui-kit/Select/filterOptions.js.map +1 -1
- package/lib/ui-kit/Select/renderIcon.d.ts +2 -0
- package/lib/ui-kit/Select/renderIcon.js +5 -0
- package/lib/ui-kit/Select/renderIcon.js.map +1 -0
- package/lib/ui-kit/Select/renderOptionText.d.ts +9 -0
- package/lib/ui-kit/Select/renderOptionText.js +8 -0
- package/lib/ui-kit/Select/renderOptionText.js.map +1 -0
- package/lib/ui-kit/Select/renderSearchInput.d.ts +9 -0
- package/lib/ui-kit/Select/renderSearchInput.js +4 -0
- package/lib/ui-kit/Select/renderSearchInput.js.map +1 -0
- package/lib/ui-kit/Select/renderSelectContainer.d.ts +15 -0
- package/lib/ui-kit/Select/renderSelectContainer.js +15 -0
- package/lib/ui-kit/Select/renderSelectContainer.js.map +1 -0
- package/lib/ui-kit/Select/useSelectPopup.d.ts +2 -1
- package/lib/ui-kit/Select/useSelectPopup.js +6 -5
- package/lib/ui-kit/Select/useSelectPopup.js.map +1 -1
- package/mobile/bundle/bundle.umd.js +85 -69
- package/mobile/bundle/bundle.umd.min.js +1 -1
- package/mobile/bundle/ui-kit/Select/Select.d.ts +6 -0
- package/mobile/bundle/ui-kit/Select/SelectPopup.d.ts +1 -0
- package/mobile/bundle/ui-kit/Select/filterOptions.d.ts +1 -1
- package/mobile/bundle/ui-kit/Select/renderIcon.d.ts +2 -0
- package/mobile/bundle/ui-kit/Select/renderOptionText.d.ts +9 -0
- package/mobile/bundle/ui-kit/Select/renderSearchInput.d.ts +9 -0
- package/mobile/bundle/ui-kit/Select/renderSelectContainer.d.ts +15 -0
- package/mobile/bundle/ui-kit/Select/useSelectPopup.d.ts +2 -1
- package/mobile/dist/ui-kit/FormField/Fields/InnDadataField.js +5 -2
- package/mobile/dist/ui-kit/FormField/Fields/InnDadataField.js.map +1 -1
- package/mobile/dist/ui-kit/Select/Select.d.ts +6 -0
- package/mobile/dist/ui-kit/Select/Select.js +31 -40
- package/mobile/dist/ui-kit/Select/Select.js.map +1 -1
- package/mobile/dist/ui-kit/Select/SelectPopup.d.ts +1 -0
- package/mobile/dist/ui-kit/Select/SelectPopup.js +1 -1
- package/mobile/dist/ui-kit/Select/SelectPopup.js.map +1 -1
- package/mobile/dist/ui-kit/Select/filterOptions.d.ts +1 -1
- package/mobile/dist/ui-kit/Select/filterOptions.js +2 -2
- package/mobile/dist/ui-kit/Select/filterOptions.js.map +1 -1
- package/mobile/dist/ui-kit/Select/renderIcon.d.ts +2 -0
- package/mobile/dist/ui-kit/Select/renderIcon.js +8 -0
- package/mobile/dist/ui-kit/Select/renderIcon.js.map +1 -0
- package/mobile/dist/ui-kit/Select/renderOptionText.d.ts +9 -0
- package/mobile/dist/ui-kit/Select/renderOptionText.js +11 -0
- package/mobile/dist/ui-kit/Select/renderOptionText.js.map +1 -0
- package/mobile/dist/ui-kit/Select/renderSearchInput.d.ts +9 -0
- package/mobile/dist/ui-kit/Select/renderSearchInput.js +7 -0
- package/mobile/dist/ui-kit/Select/renderSearchInput.js.map +1 -0
- package/mobile/dist/ui-kit/Select/renderSelectContainer.d.ts +15 -0
- package/mobile/dist/ui-kit/Select/renderSelectContainer.js +18 -0
- package/mobile/dist/ui-kit/Select/renderSelectContainer.js.map +1 -0
- package/mobile/dist/ui-kit/Select/useSelectPopup.d.ts +2 -1
- package/mobile/dist/ui-kit/Select/useSelectPopup.js +6 -5
- package/mobile/dist/ui-kit/Select/useSelectPopup.js.map +1 -1
- package/mobile/lib/common.css +1 -1
- package/mobile/lib/ui-kit/FormField/Fields/InnDadataField.js +5 -2
- package/mobile/lib/ui-kit/FormField/Fields/InnDadataField.js.map +1 -1
- package/mobile/lib/ui-kit/Select/Select.d.ts +6 -0
- package/mobile/lib/ui-kit/Select/Select.js +32 -41
- package/mobile/lib/ui-kit/Select/Select.js.map +1 -1
- package/mobile/lib/ui-kit/Select/SelectPopup.d.ts +1 -0
- package/mobile/lib/ui-kit/Select/SelectPopup.js +1 -1
- package/mobile/lib/ui-kit/Select/SelectPopup.js.map +1 -1
- package/mobile/lib/ui-kit/Select/filterOptions.d.ts +1 -1
- package/mobile/lib/ui-kit/Select/filterOptions.js +2 -2
- package/mobile/lib/ui-kit/Select/filterOptions.js.map +1 -1
- package/mobile/lib/ui-kit/Select/renderIcon.d.ts +2 -0
- package/mobile/lib/ui-kit/Select/renderIcon.js +5 -0
- package/mobile/lib/ui-kit/Select/renderIcon.js.map +1 -0
- package/mobile/lib/ui-kit/Select/renderOptionText.d.ts +9 -0
- package/mobile/lib/ui-kit/Select/renderOptionText.js +8 -0
- package/mobile/lib/ui-kit/Select/renderOptionText.js.map +1 -0
- package/mobile/lib/ui-kit/Select/renderSearchInput.d.ts +9 -0
- package/mobile/lib/ui-kit/Select/renderSearchInput.js +4 -0
- package/mobile/lib/ui-kit/Select/renderSearchInput.js.map +1 -0
- package/mobile/lib/ui-kit/Select/renderSelectContainer.d.ts +15 -0
- package/mobile/lib/ui-kit/Select/renderSelectContainer.js +15 -0
- package/mobile/lib/ui-kit/Select/renderSelectContainer.js.map +1 -0
- package/mobile/lib/ui-kit/Select/useSelectPopup.d.ts +2 -1
- package/mobile/lib/ui-kit/Select/useSelectPopup.js +6 -5
- package/mobile/lib/ui-kit/Select/useSelectPopup.js.map +1 -1
- package/mobile/src/ui-kit/FormField/Fields/InnDadataField.tsx +7 -2
- package/mobile/src/ui-kit/Select/Select.tsx +46 -105
- package/mobile/src/ui-kit/Select/SelectPopup.tsx +12 -2
- package/mobile/src/ui-kit/Select/filterOptions.ts +6 -2
- package/mobile/src/ui-kit/Select/renderIcon.tsx +13 -0
- package/mobile/src/ui-kit/Select/renderOptionText.tsx +22 -0
- package/mobile/src/ui-kit/Select/renderSearchInput.tsx +28 -0
- package/mobile/src/ui-kit/Select/renderSelectContainer.tsx +60 -0
- package/mobile/src/ui-kit/Select/useSelectPopup.tsx +11 -7
- package/package.json +1 -1
- package/src/ui-kit/FormField/Fields/InnDadataField.tsx +7 -2
- package/src/ui-kit/Select/Select.tsx +46 -105
- package/src/ui-kit/Select/SelectPopup.tsx +12 -2
- package/src/ui-kit/Select/filterOptions.ts +6 -2
- package/src/ui-kit/Select/renderIcon.tsx +13 -0
- package/src/ui-kit/Select/renderOptionText.tsx +22 -0
- package/src/ui-kit/Select/renderSearchInput.tsx +28 -0
- package/src/ui-kit/Select/renderSelectContainer.tsx +60 -0
- package/src/ui-kit/Select/useSelectPopup.tsx +11 -7
|
@@ -4,14 +4,13 @@ import { useBool } from '@redneckz/uni-jsx/lib/hooks/useBool';
|
|
|
4
4
|
import { type ControlProps } from '../../model/ControlProps';
|
|
5
5
|
import { type DefaultControlType } from '../../model/DefaultControlType';
|
|
6
6
|
import { type IconVersion } from '../../model/IconVersion';
|
|
7
|
-
import { type PlaceholderProps } from '../../model/PlaceholderProps';
|
|
8
7
|
import { debounce } from '../../utils/debounce';
|
|
8
|
+
import { noop } from '../../utils/noop';
|
|
9
9
|
import { style } from '../../utils/style';
|
|
10
|
-
import { Icon } from '../Icon/Icon';
|
|
11
|
-
import { Input } from '../Input/Input';
|
|
12
10
|
import { renderLabel } from '../Input/renderLabel';
|
|
13
|
-
import { formatOption } from './formatOption';
|
|
14
11
|
import { type Option } from './Option';
|
|
12
|
+
import { renderSearchInput } from './renderSearchInput';
|
|
13
|
+
import { renderSelectContainer } from './renderSelectContainer';
|
|
15
14
|
import { useSelectPopup } from './useSelectPopup';
|
|
16
15
|
|
|
17
16
|
export interface SelectProps extends DefaultControlType, ControlProps<Option> {
|
|
@@ -21,13 +20,14 @@ export interface SelectProps extends DefaultControlType, ControlProps<Option> {
|
|
|
21
20
|
isSearch?: boolean;
|
|
22
21
|
isManualInput?: boolean;
|
|
23
22
|
iconVersion?: IconVersion;
|
|
23
|
+
inputProps?: InputTypeProps;
|
|
24
|
+
disableFilterOptions?: boolean;
|
|
24
25
|
onSearchQuery?: (value: string) => void;
|
|
25
26
|
}
|
|
26
27
|
|
|
27
|
-
type
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
value?: Option;
|
|
28
|
+
export type InputTypeProps = {
|
|
29
|
+
isInteger?: boolean;
|
|
30
|
+
maxLength?: number;
|
|
31
31
|
};
|
|
32
32
|
|
|
33
33
|
export const Select = JSX<SelectProps>(
|
|
@@ -36,133 +36,74 @@ export const Select = JSX<SelectProps>(
|
|
|
36
36
|
label,
|
|
37
37
|
options = [],
|
|
38
38
|
value,
|
|
39
|
-
valid = true,
|
|
40
|
-
isBorder = true,
|
|
41
|
-
placeholder = '',
|
|
42
39
|
isSearch = false,
|
|
43
40
|
isManualInput = false,
|
|
44
41
|
disabled = false,
|
|
45
42
|
iconVersion = 'black',
|
|
46
43
|
onChange,
|
|
47
|
-
onSearchQuery,
|
|
44
|
+
onSearchQuery = noop,
|
|
45
|
+
inputProps,
|
|
46
|
+
disableFilterOptions = false,
|
|
47
|
+
...rest
|
|
48
48
|
}) => {
|
|
49
49
|
const [isOpen, { setFalse: close, setTrue: open }] = useBool();
|
|
50
50
|
const [query, setQuery] = useState('');
|
|
51
|
-
|
|
52
|
-
const
|
|
53
|
-
const hasOpen = isOpen && !isDisabled;
|
|
51
|
+
|
|
52
|
+
const isDisabled = disabled || (!isManualInput && options.length === 0);
|
|
54
53
|
|
|
55
54
|
const debouncedOnSearchQuery = useMemo(
|
|
56
|
-
() =>
|
|
55
|
+
() => debounce((searchValue: string) => onSearchQuery(searchValue), 300),
|
|
57
56
|
[onSearchQuery],
|
|
58
57
|
);
|
|
59
58
|
|
|
60
59
|
const handleOpen = useCallback(() => {
|
|
61
|
-
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
open();
|
|
60
|
+
isDisabled ? noop() : open();
|
|
66
61
|
}, [isDisabled]);
|
|
67
62
|
|
|
68
|
-
const handleChangeQuery = (newQuery: string) => {
|
|
69
|
-
setQuery(newQuery);
|
|
70
|
-
isManualInput && setOption(newQuery, onChange);
|
|
71
|
-
debouncedOnSearchQuery && debouncedOnSearchQuery(newQuery);
|
|
72
|
-
};
|
|
73
|
-
|
|
74
63
|
const handleClose = useCallback(() => {
|
|
75
64
|
!isManualInput && setQuery('');
|
|
76
65
|
close();
|
|
77
|
-
}, []);
|
|
78
|
-
|
|
66
|
+
}, [isManualInput]);
|
|
67
|
+
|
|
68
|
+
const handleChangeQuery = useCallback(
|
|
69
|
+
(newQuery: string) => {
|
|
70
|
+
setQuery(newQuery);
|
|
71
|
+
isManualInput && onChange?.({ key: newQuery, text: newQuery, innDaData: {} });
|
|
72
|
+
debouncedOnSearchQuery?.(newQuery);
|
|
73
|
+
},
|
|
74
|
+
[isManualInput, onChange, debouncedOnSearchQuery],
|
|
75
|
+
);
|
|
76
|
+
const selectState = { query, value, options, isOpen, iconVersion };
|
|
79
77
|
const inputRef = useSelectPopup({
|
|
80
|
-
isOpen,
|
|
81
|
-
options,
|
|
82
|
-
value,
|
|
83
|
-
query,
|
|
84
78
|
onChange,
|
|
85
79
|
onClose: handleClose,
|
|
86
|
-
|
|
80
|
+
disableFilterOptions,
|
|
87
81
|
onChangeQuery: setQuery,
|
|
82
|
+
...selectState,
|
|
88
83
|
});
|
|
89
84
|
|
|
90
85
|
return (
|
|
91
86
|
<div className={style('space-y-xs', className)}>
|
|
92
87
|
{renderLabel(label)}
|
|
93
|
-
<div className={style('relative',
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
88
|
+
<div className={style('relative', isOpen ? 'z-20' : 'z-10')} ref={inputRef}>
|
|
89
|
+
{renderSelectContainer({
|
|
90
|
+
isDisabled,
|
|
91
|
+
onClose: handleClose,
|
|
92
|
+
onOpen: handleOpen,
|
|
93
|
+
isManualInput,
|
|
94
|
+
...selectState,
|
|
95
|
+
...rest,
|
|
96
|
+
})}
|
|
97
|
+
{isSearch && isOpen
|
|
98
|
+
? renderSearchInput({
|
|
99
|
+
query,
|
|
100
|
+
isDisabled,
|
|
101
|
+
inputProps,
|
|
102
|
+
onChangeQuery: handleChangeQuery,
|
|
103
|
+
})
|
|
104
|
+
: null}
|
|
107
105
|
</div>
|
|
108
106
|
</div>
|
|
109
107
|
);
|
|
110
108
|
},
|
|
111
109
|
);
|
|
112
|
-
|
|
113
|
-
const useRenderOptionText = (data: renderOptionTextProps) =>
|
|
114
|
-
useMemo(() => {
|
|
115
|
-
if (data.isManualInput && data.query) {
|
|
116
|
-
return data.query;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return formatOption(data.value) || data.placeholder;
|
|
120
|
-
}, [data.isManualInput, data.query, data.value, data.placeholder]);
|
|
121
|
-
|
|
122
|
-
const renderSearchInput = (
|
|
123
|
-
query: string,
|
|
124
|
-
isDisabled: boolean,
|
|
125
|
-
onChangeQuery: (value: string) => void,
|
|
126
|
-
) => (
|
|
127
|
-
<div className={style('absolute top-0 w-full z-20')}>
|
|
128
|
-
<Input
|
|
129
|
-
type="text"
|
|
130
|
-
value={query}
|
|
131
|
-
autoFocus
|
|
132
|
-
disabled={isDisabled}
|
|
133
|
-
onChange={(value) => onChangeQuery(value)}
|
|
134
|
-
/>
|
|
135
|
-
</div>
|
|
136
|
-
);
|
|
137
|
-
|
|
138
|
-
const renderIcon = (isOpen: boolean, iconVersion?: IconVersion) => (
|
|
139
|
-
<Icon
|
|
140
|
-
className={style('absolute right-0 flex self-center', { 'rotate-180': !isOpen })}
|
|
141
|
-
iconVersion={iconVersion}
|
|
142
|
-
name="ArrowUpIcon"
|
|
143
|
-
width="16"
|
|
144
|
-
height="16"
|
|
145
|
-
/>
|
|
146
|
-
);
|
|
147
|
-
|
|
148
|
-
const getStyle = (isBorder: boolean, valid: boolean, disabled: boolean) =>
|
|
149
|
-
style(
|
|
150
|
-
isBorder ? 'border rounded-md ' : '',
|
|
151
|
-
isBorder && !disabled ? 'hover:border-primary-hover' : '',
|
|
152
|
-
disabled ? 'bg-main-divider' : 'cursor-pointer ',
|
|
153
|
-
valid ? 'border-gray' : 'border-error',
|
|
154
|
-
);
|
|
155
|
-
|
|
156
|
-
// TODO Нужен рефактор и декомпозиция компонента getDisabled, setOption, getIconHidden
|
|
157
|
-
const getDisabled = (disabled: boolean, length: number, isManualInput: boolean) =>
|
|
158
|
-
disabled || (!isManualInput && length === 0);
|
|
159
|
-
|
|
160
|
-
const setOption = (query: string, onChange?: (data: Option) => void) => {
|
|
161
|
-
onChange && query.trim() !== '' && onChange({ key: query, text: query, innDaData: {} });
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
const getIconHidden = (isManualInput: boolean, options: Option[]) =>
|
|
165
|
-
isManualInput && !options.length;
|
|
166
|
-
|
|
167
|
-
const getDebouncedSearchQuery = (onSearchQuery: (value: string) => void) =>
|
|
168
|
-
debounce((searchValue: string) => onSearchQuery(searchValue), 300);
|
|
@@ -14,17 +14,27 @@ export interface SelectPopupProps extends ControlProps<Option> {
|
|
|
14
14
|
popupRef?: { current: HTMLDivElement | null };
|
|
15
15
|
query?: string;
|
|
16
16
|
onChangeQuery?: (value: string) => void;
|
|
17
|
+
disableFilterOptions?: boolean;
|
|
17
18
|
}
|
|
18
19
|
|
|
19
20
|
export const SelectPopup = JSX<SelectPopupProps>(
|
|
20
|
-
({
|
|
21
|
+
({
|
|
22
|
+
popupRef,
|
|
23
|
+
options,
|
|
24
|
+
value,
|
|
25
|
+
query,
|
|
26
|
+
iconVersion,
|
|
27
|
+
disableFilterOptions,
|
|
28
|
+
onChange,
|
|
29
|
+
onChangeQuery,
|
|
30
|
+
}) =>
|
|
21
31
|
options?.length ? (
|
|
22
32
|
<div
|
|
23
33
|
className="bg-white text-l max-h-64 overflow-y-auto overflow-x-hidden rounded-md shadow-2xl"
|
|
24
34
|
role="list"
|
|
25
35
|
ref={popupRef}
|
|
26
36
|
>
|
|
27
|
-
{filterOptions(options, query).map((option) => (
|
|
37
|
+
{filterOptions(options, query, disableFilterOptions).map((option) => (
|
|
28
38
|
<div
|
|
29
39
|
key={option.key}
|
|
30
40
|
className="flex px-m py-s cursor-pointer hover:bg-main-divider pr-5xl relative"
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
import { type Option } from './Option';
|
|
2
2
|
|
|
3
|
-
export const filterOptions = (
|
|
4
|
-
|
|
3
|
+
export const filterOptions = (
|
|
4
|
+
options: Option[],
|
|
5
|
+
query: string | undefined,
|
|
6
|
+
disableFilterOptions?: boolean,
|
|
7
|
+
): Option[] => {
|
|
8
|
+
if (!options?.length || !query?.trim() || disableFilterOptions) {
|
|
5
9
|
return options;
|
|
6
10
|
}
|
|
7
11
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { IconVersion } from '../../model/IconVersion';
|
|
2
|
+
import { style } from '../../utils/style';
|
|
3
|
+
import { Icon } from '../Icon/Icon';
|
|
4
|
+
|
|
5
|
+
export const renderIcon = (isOpen: boolean, iconVersion?: IconVersion) => (
|
|
6
|
+
<Icon
|
|
7
|
+
className={style('absolute right-0 flex self-center', { 'rotate-180': !isOpen })}
|
|
8
|
+
iconVersion={iconVersion}
|
|
9
|
+
name="ArrowUpIcon"
|
|
10
|
+
width="16"
|
|
11
|
+
height="16"
|
|
12
|
+
/>
|
|
13
|
+
);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { type PlaceholderProps } from '../../model/PlaceholderProps';
|
|
2
|
+
import { formatOption } from './formatOption';
|
|
3
|
+
import { type Option } from './Option';
|
|
4
|
+
|
|
5
|
+
type RenderOptionTextProps = PlaceholderProps & {
|
|
6
|
+
isManualInput?: boolean;
|
|
7
|
+
query?: string;
|
|
8
|
+
value?: Option;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const renderOptionText = ({
|
|
12
|
+
isManualInput,
|
|
13
|
+
query,
|
|
14
|
+
value,
|
|
15
|
+
placeholder,
|
|
16
|
+
}: RenderOptionTextProps) => {
|
|
17
|
+
if (isManualInput && query) {
|
|
18
|
+
return query;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return formatOption(value) || placeholder;
|
|
22
|
+
};
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { InputControl } from '../Input/InputControl';
|
|
2
|
+
import { type InputTypeProps } from './Select';
|
|
3
|
+
|
|
4
|
+
type RenderSearchInputProps = {
|
|
5
|
+
query: string;
|
|
6
|
+
isDisabled: boolean;
|
|
7
|
+
onChangeQuery: (value: string) => void;
|
|
8
|
+
inputProps?: InputTypeProps;
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export const renderSearchInput = ({
|
|
12
|
+
query,
|
|
13
|
+
isDisabled,
|
|
14
|
+
onChangeQuery,
|
|
15
|
+
inputProps,
|
|
16
|
+
}: RenderSearchInputProps) => (
|
|
17
|
+
<div className="absolute top-0 w-full z-20">
|
|
18
|
+
<InputControl
|
|
19
|
+
type="text"
|
|
20
|
+
value={query}
|
|
21
|
+
autoFocus
|
|
22
|
+
disabled={isDisabled}
|
|
23
|
+
onChange={(value) => onChangeQuery(value)}
|
|
24
|
+
maxLength={inputProps?.maxLength}
|
|
25
|
+
isInteger={inputProps?.isInteger ?? false}
|
|
26
|
+
/>
|
|
27
|
+
</div>
|
|
28
|
+
);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import type { ControlProps } from '../../model/ControlProps';
|
|
2
|
+
import { type IconVersion } from '../../model/IconVersion';
|
|
3
|
+
import { type OnCloseProps } from '../../model/OnCloseProps';
|
|
4
|
+
import { style } from '../../utils/style';
|
|
5
|
+
import { type Option } from './Option';
|
|
6
|
+
import { renderIcon } from './renderIcon';
|
|
7
|
+
import { renderOptionText } from './renderOptionText';
|
|
8
|
+
import { type SelectProps } from './Select';
|
|
9
|
+
|
|
10
|
+
interface SelectContainerProps extends OnCloseProps, SelectProps, ControlProps<Option> {
|
|
11
|
+
isOpen?: boolean;
|
|
12
|
+
isDisabled?: boolean;
|
|
13
|
+
iconVersion?: IconVersion;
|
|
14
|
+
query?: string;
|
|
15
|
+
isIconHidden?: boolean;
|
|
16
|
+
onOpen?: () => void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const renderSelectContainer = ({
|
|
20
|
+
isBorder = true,
|
|
21
|
+
valid = true,
|
|
22
|
+
isDisabled = false,
|
|
23
|
+
isOpen = false,
|
|
24
|
+
onOpen,
|
|
25
|
+
onClose,
|
|
26
|
+
isManualInput = false,
|
|
27
|
+
query = '',
|
|
28
|
+
value,
|
|
29
|
+
placeholder = '',
|
|
30
|
+
iconVersion = 'black',
|
|
31
|
+
options = [],
|
|
32
|
+
}: SelectContainerProps) => {
|
|
33
|
+
const isIconHidden = getIconHidden(isManualInput, options, query);
|
|
34
|
+
|
|
35
|
+
return (
|
|
36
|
+
<div
|
|
37
|
+
className={style(
|
|
38
|
+
{ 'border rounded-md': isBorder },
|
|
39
|
+
{ 'hover:border-primary-hover': isBorder && !isDisabled },
|
|
40
|
+
isDisabled ? 'bg-main-divider' : 'cursor-pointer ',
|
|
41
|
+
valid ? 'border-gray' : 'border-error',
|
|
42
|
+
'h-14 [&>*]:p-m pr-6 text-l flex items-center justify-between text-primary-text relative z-10 overflow-hidden',
|
|
43
|
+
)}
|
|
44
|
+
onClick={isOpen ? onClose : onOpen}
|
|
45
|
+
>
|
|
46
|
+
<p className="line-clamp-2 text-ellipsis">
|
|
47
|
+
{renderOptionText({ isManualInput, query, value, placeholder })}
|
|
48
|
+
</p>
|
|
49
|
+
{isIconHidden ? '' : renderIcon(isOpen, iconVersion)}
|
|
50
|
+
</div>
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const getIconHidden = (isManualInput: boolean, options: Option[], query?: string) => {
|
|
55
|
+
if (isManualInput && query?.length) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return isManualInput && !options.length;
|
|
60
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useEffect, useRef } from '@redneckz/uni-jsx/lib/hooks';
|
|
2
2
|
import { useOutsideClick } from '@redneckz/uni-jsx/lib/hooks/useOutsideClick';
|
|
3
3
|
import type { OnCloseProps } from '../../model/OnCloseProps';
|
|
4
|
+
import { noop } from '../../utils/noop';
|
|
4
5
|
import { usePopupManager } from '../PopupManager/usePopupManager';
|
|
5
6
|
import { type Option } from './Option';
|
|
6
7
|
import { SelectPopup, type SelectPopupProps } from './SelectPopup';
|
|
@@ -8,6 +9,7 @@ import { SelectPopup, type SelectPopupProps } from './SelectPopup';
|
|
|
8
9
|
interface SelectPopupOptions extends SelectPopupProps, OnCloseProps {
|
|
9
10
|
isOpen?: boolean;
|
|
10
11
|
onChangeQuery?: (value: string) => void;
|
|
12
|
+
disableFilterOptions?: boolean;
|
|
11
13
|
}
|
|
12
14
|
|
|
13
15
|
export function useSelectPopup({
|
|
@@ -15,23 +17,24 @@ export function useSelectPopup({
|
|
|
15
17
|
options,
|
|
16
18
|
value,
|
|
17
19
|
query,
|
|
18
|
-
onChange,
|
|
19
|
-
onClose,
|
|
20
|
+
onChange = noop,
|
|
21
|
+
onClose = noop,
|
|
20
22
|
iconVersion,
|
|
21
|
-
|
|
23
|
+
disableFilterOptions = false,
|
|
24
|
+
onChangeQuery = noop,
|
|
22
25
|
}: SelectPopupOptions) {
|
|
23
26
|
const popup = usePopupManager();
|
|
24
27
|
|
|
25
28
|
const close = useCallback(() => {
|
|
26
29
|
popup.close();
|
|
27
|
-
onClose
|
|
30
|
+
onClose();
|
|
28
31
|
}, [onClose]);
|
|
29
32
|
|
|
30
33
|
const handleChange = useCallback(
|
|
31
34
|
(option: Option) => {
|
|
32
35
|
close();
|
|
33
|
-
onChange
|
|
34
|
-
onChangeQuery
|
|
36
|
+
onChange(option);
|
|
37
|
+
onChangeQuery('');
|
|
35
38
|
},
|
|
36
39
|
[close, onChange],
|
|
37
40
|
);
|
|
@@ -54,8 +57,9 @@ export function useSelectPopup({
|
|
|
54
57
|
options={options}
|
|
55
58
|
value={value}
|
|
56
59
|
query={query}
|
|
57
|
-
onChange={handleChange}
|
|
58
60
|
iconVersion={iconVersion}
|
|
61
|
+
disableFilterOptions={disableFilterOptions}
|
|
62
|
+
onChange={handleChange}
|
|
59
63
|
onChangeQuery={onChangeQuery}
|
|
60
64
|
/>
|
|
61
65
|
),
|