@infomaximum/ui-kit 0.12.11 → 0.13.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.
- package/dist/components/BaseSelect/BaseSelect.d.ts +5 -0
- package/dist/components/BaseSelect/BaseSelect.js +360 -0
- package/dist/components/{Select/Select.styles.d.ts → BaseSelect/BaseSelect.styles.d.ts} +20 -4
- package/dist/components/{Select/Select.styles.js → BaseSelect/BaseSelect.styles.js} +23 -10
- package/dist/components/BaseSelect/BaseSelect.types.d.ts +99 -0
- package/dist/components/BaseSelect/BaseSelect.utils.d.ts +8 -0
- package/dist/components/BaseSelect/BaseSelect.utils.js +39 -0
- package/dist/components/BaseSelect/components/BaseSelectOptionList/BaseSelectOptionList.types.d.ts +11 -0
- package/dist/components/BaseSelect/components/SelectOptionList/SelectOptionList.d.ts +4 -0
- package/dist/components/BaseSelect/components/SelectOptionList/SelectOptionList.js +120 -0
- package/dist/components/{Select → BaseSelect}/components/SelectOptionList/SelectOptionList.styles.d.ts +13 -4
- package/dist/components/{Select → BaseSelect}/components/SelectOptionList/SelectOptionList.styles.js +13 -7
- package/dist/components/BaseSelect/components/SelectOptionList/SelectOptionList.types.d.ts +20 -0
- package/dist/components/BaseSelect/components/SelectTag/SelectTag.d.ts +4 -0
- package/dist/components/{Select → BaseSelect}/components/SelectTag/SelectTag.js +9 -5
- package/dist/components/BaseSelect/components/SelectTag/SelectTag.styles.d.ts +16 -0
- package/dist/components/{Select → BaseSelect}/components/SelectTag/SelectTag.styles.js +13 -3
- package/dist/components/BaseSelect/components/SelectTag/SelectTag.types.d.ts +11 -0
- package/dist/components/BaseSelect/contexts/BaseSelectContext.d.ts +33 -0
- package/dist/components/BaseSelect/contexts/BaseSelectContext.js +8 -0
- package/dist/components/BaseSelect/hooks/useCurrentValue.d.ts +7 -0
- package/dist/components/{Select → BaseSelect}/hooks/useCurrentValue.js +15 -0
- package/dist/components/BaseSelect/hooks/useDefaultCurrentValue.d.ts +2 -0
- package/dist/components/{Select → BaseSelect}/hooks/useDefaultCurrentValue.js +1 -1
- package/dist/components/BaseSelect/hooks/useDefaultSelectIndex.d.ts +2 -0
- package/dist/components/BaseSelect/hooks/useHideElements.d.ts +6 -0
- package/dist/components/{Select → BaseSelect}/hooks/useHideElements.js +11 -3
- package/dist/components/BaseSelect/hooks/useSearch.d.ts +10 -0
- package/dist/components/{Select → BaseSelect}/hooks/useSearch.js +4 -16
- package/dist/components/Checkbox/Checkbox.js +12 -8
- package/dist/components/Checkbox/Checkbox.utils.d.ts +2 -0
- package/dist/components/Checkbox/Checkbox.utils.js +5 -0
- package/dist/components/Checkbox/index.d.ts +1 -0
- package/dist/components/InputNumber/InputNumber.js +13 -6
- package/dist/components/InputNumber/InputNumber.styles.d.ts +9 -1
- package/dist/components/InputNumber/InputNumber.styles.js +10 -2
- package/dist/components/InputNumber/InputNumber.types.d.ts +5 -0
- package/dist/components/InputNumber/hooks/useChangeValue/useChangeValue.js +8 -5
- package/dist/components/InputNumber/hooks/useChangeValue/useChangeValue.types.d.ts +1 -0
- package/dist/components/InputNumber/hooks/useFocusBlurEvents/useFocusBlurEvents.js +2 -0
- package/dist/components/InputNumber/hooks/useFocusBlurEvents/useFocusBlurEvents.types.d.ts +2 -1
- package/dist/components/InputNumber/hooks/useKeyboardEvents/useKeyboardEvents.js +4 -0
- package/dist/components/InputNumber/hooks/useKeyboardEvents/useKeyboardEvents.types.d.ts +1 -0
- package/dist/components/InputNumber/hooks/useStep/useStep.js +2 -0
- package/dist/components/InputNumber/hooks/useStep/useStep.types.d.ts +1 -0
- package/dist/components/InputNumber/index.d.ts +1 -0
- package/dist/components/Select/Select.d.ts +2 -2
- package/dist/components/Select/Select.js +39 -281
- package/dist/components/Select/Select.types.d.ts +6 -85
- package/dist/components/Select/Select.utils.d.ts +1 -9
- package/dist/components/Select/Select.utils.js +1 -46
- package/dist/components/Select/components/SelectOption/SelectOption.js +20 -23
- package/dist/components/Select/components/SelectOption/SelectOption.styles.js +1 -1
- package/dist/components/Select/components/SelectOption/SelectOption.types.d.ts +13 -15
- package/dist/components/Select/hooks/useKeyControl.d.ts +7 -3
- package/dist/components/Select/hooks/useKeyControl.js +48 -13
- package/dist/components/TreeSelect/TreeSelect.d.ts +3 -0
- package/dist/components/TreeSelect/TreeSelect.js +189 -0
- package/dist/components/TreeSelect/TreeSelect.tokens.d.ts +30 -0
- package/dist/components/TreeSelect/TreeSelect.tokens.js +31 -0
- package/dist/components/TreeSelect/TreeSelect.types.d.ts +69 -0
- package/dist/components/TreeSelect/TreeSelect.utils.d.ts +13 -0
- package/dist/components/TreeSelect/TreeSelect.utils.js +192 -0
- package/dist/components/TreeSelect/components/TreeSelectOption/TreeSelectOption.d.ts +3 -0
- package/dist/components/TreeSelect/components/TreeSelectOption/TreeSelectOption.js +117 -0
- package/dist/components/TreeSelect/components/TreeSelectOption/TreeSelectOption.styles.d.ts +83 -0
- package/dist/components/TreeSelect/components/TreeSelectOption/TreeSelectOption.styles.js +111 -0
- package/dist/components/TreeSelect/components/TreeSelectOption/TreeSelectOption.types.d.ts +27 -0
- package/dist/components/TreeSelect/contexts/treeSelectContext.d.ts +14 -0
- package/dist/components/TreeSelect/contexts/treeSelectContext.js +5 -0
- package/dist/components/TreeSelect/forStories/dataForExamples.d.ts +32 -0
- package/dist/components/TreeSelect/hooks/useAsyncLoading.d.ts +8 -0
- package/dist/components/TreeSelect/hooks/useAsyncLoading.js +39 -0
- package/dist/components/TreeSelect/hooks/useElementSizesController.d.ts +6 -0
- package/dist/components/TreeSelect/hooks/useElementSizesController.js +21 -0
- package/dist/components/TreeSelect/hooks/useExtendController.d.ts +19 -0
- package/dist/components/TreeSelect/hooks/useExtendController.js +65 -0
- package/dist/components/TreeSelect/hooks/useKeyControl.d.ts +11 -0
- package/dist/components/TreeSelect/hooks/useKeyControl.js +75 -0
- package/dist/components/TreeSelect/hooks/useTreeCheckable.d.ts +6 -0
- package/dist/components/TreeSelect/hooks/useTreeCheckable.js +56 -0
- package/dist/components/TreeSelect/hooks/useTreeData.d.ts +8 -0
- package/dist/components/TreeSelect/hooks/useTreeData.js +33 -0
- package/dist/components/TreeSelect/index.d.ts +2 -0
- package/dist/index.d.ts +5 -4
- package/dist/index.js +6 -0
- package/package.json +1 -1
- package/dist/components/Select/components/SelectOptionList/SelectOptionList.d.ts +0 -3
- package/dist/components/Select/components/SelectOptionList/SelectOptionList.js +0 -139
- package/dist/components/Select/components/SelectOptionList/SelectOptionList.types.d.ts +0 -42
- package/dist/components/Select/components/SelectOptionList/SelectOptionList.utils.d.ts +0 -1
- package/dist/components/Select/components/SelectOptionList/SelectOptionList.utils.js +0 -4
- package/dist/components/Select/components/SelectTag/SelectTag.d.ts +0 -3
- package/dist/components/Select/components/SelectTag/SelectTag.styles.d.ts +0 -8
- package/dist/components/Select/components/SelectTag/SelectTag.types.d.ts +0 -10
- package/dist/components/Select/hooks/useCurrentValue.d.ts +0 -8
- package/dist/components/Select/hooks/useDefaultCurrentValue.d.ts +0 -3
- package/dist/components/Select/hooks/useDefaultSelectIndex.d.ts +0 -2
- package/dist/components/Select/hooks/useDefaultSelectIndex.js +0 -17
- package/dist/components/Select/hooks/useHideElements.d.ts +0 -5
- package/dist/components/Select/hooks/useSearch.d.ts +0 -11
- /package/dist/components/{Select/Select.tokens.d.ts → BaseSelect/BaseSelect.tokens.d.ts} +0 -0
- /package/dist/components/{Select/Select.tokens.js → BaseSelect/BaseSelect.tokens.js} +0 -0
- /package/dist/components/{Select → BaseSelect}/components/TagPlaceholder/TagPlaceholder.d.ts +0 -0
- /package/dist/components/{Select → BaseSelect}/components/TagPlaceholder/TagPlaceholder.js +0 -0
- /package/dist/components/{Select → BaseSelect}/components/TagPlaceholder/TagPlaceholder.styles.d.ts +0 -0
- /package/dist/components/{Select → BaseSelect}/components/TagPlaceholder/TagPlaceholder.styles.js +0 -0
- /package/dist/components/{Select → BaseSelect}/components/TagPlaceholder/TagPlaceholder.types.d.ts +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import { Theme } from 'themes';
|
|
2
|
-
import { maxTagCountType, SelectStatus, VariantType } from './
|
|
3
|
-
|
|
2
|
+
import { maxTagCountType, SelectStatus, VariantType } from './BaseSelect.types';
|
|
3
|
+
interface GetSelectDefaultStyleProps {
|
|
4
|
+
status: SelectStatus;
|
|
5
|
+
disabled: boolean;
|
|
6
|
+
variant: VariantType;
|
|
7
|
+
multiple: boolean;
|
|
8
|
+
isHover: boolean;
|
|
9
|
+
maxTagCount: maxTagCountType | undefined;
|
|
10
|
+
withPrefix: boolean;
|
|
11
|
+
isEmpty: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare const getSelectDefaultStyle: ({ status, disabled, variant, multiple, isHover, maxTagCount, withPrefix, isEmpty, }: GetSelectDefaultStyleProps) => {
|
|
4
14
|
wrapper: (theme: Theme) => {
|
|
5
15
|
readonly display: "inline-flex";
|
|
6
16
|
readonly flexDirection: "column";
|
|
@@ -9,9 +19,11 @@ export declare const getSelectDefaultStyle: (status: SelectStatus, disabled: boo
|
|
|
9
19
|
readonly border: string;
|
|
10
20
|
readonly outline: "none";
|
|
11
21
|
readonly height: 28 | "fit-content";
|
|
22
|
+
readonly minHeight: 28;
|
|
12
23
|
readonly boxSizing: "border-box";
|
|
13
24
|
readonly overflow: "hidden";
|
|
14
25
|
readonly justifyContent: "center";
|
|
26
|
+
readonly transition: "border-color .3s, box-shadow .3s";
|
|
15
27
|
readonly ":hover": {
|
|
16
28
|
readonly border: string;
|
|
17
29
|
};
|
|
@@ -101,16 +113,19 @@ export declare const getSelectDefaultStyle: (status: SelectStatus, disabled: boo
|
|
|
101
113
|
searchInput: (theme: Theme) => {
|
|
102
114
|
color: "#262626" | "#8C8C8C";
|
|
103
115
|
maxWidth: string;
|
|
104
|
-
|
|
116
|
+
padding: number;
|
|
105
117
|
background: string;
|
|
106
118
|
"::placeholder": {
|
|
119
|
+
fontFamily: "Roboto";
|
|
120
|
+
fontSize: 14;
|
|
121
|
+
lineHeight: "20px";
|
|
107
122
|
color: "#8C8C8C" | "#BFBFBF";
|
|
108
123
|
};
|
|
109
124
|
fontFamily: "Roboto";
|
|
110
125
|
fontSize: 14;
|
|
111
126
|
lineHeight: "20px";
|
|
112
127
|
border: string;
|
|
113
|
-
height:
|
|
128
|
+
height: number;
|
|
114
129
|
outline: string;
|
|
115
130
|
};
|
|
116
131
|
tagsWrapper: (theme: Theme) => {
|
|
@@ -133,3 +148,4 @@ export declare const getSelectDefaultStyle: (status: SelectStatus, disabled: boo
|
|
|
133
148
|
export declare const getSelectSearchInputWidthStyle: (isMultiple: boolean, isEmpty: boolean, lettersNumber: number) => {
|
|
134
149
|
width: number;
|
|
135
150
|
} | undefined;
|
|
151
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSelectTokens } from "./
|
|
1
|
+
import { getSelectTokens } from "./BaseSelect.tokens.js";
|
|
2
2
|
const cleanButtonSelector = ".clean-button";
|
|
3
3
|
const lettersWidthOfSearchInput = 7;
|
|
4
4
|
const iconStyles = (theme, disabled) => {
|
|
@@ -50,10 +50,11 @@ const getLabelColor = (selectTokens, isError, variant, disabled) => {
|
|
|
50
50
|
}
|
|
51
51
|
return selectTokens.selectText;
|
|
52
52
|
};
|
|
53
|
-
const getBodyPadding = (selectTokens, isMultipleAndNotResponsive, multiple) => {
|
|
53
|
+
const getBodyPadding = (selectTokens, isMultipleAndNotResponsive, multiple, isEmpty) => {
|
|
54
54
|
const verticalPadding = isMultipleAndNotResponsive ? selectTokens.selectPaddingVertical - 1 : selectTokens.selectPaddingVertical;
|
|
55
55
|
if (multiple) {
|
|
56
|
-
|
|
56
|
+
const leftPadding = isEmpty ? selectTokens.selectPaddingHorizontal : selectTokens.selectPaddingVertical;
|
|
57
|
+
return `${verticalPadding}px ${selectTokens.selectPaddingHorizontal}px ${verticalPadding}px ${leftPadding}px`;
|
|
57
58
|
}
|
|
58
59
|
return `${verticalPadding}px ${selectTokens.selectPaddingHorizontal}px`;
|
|
59
60
|
};
|
|
@@ -67,7 +68,16 @@ const getIconStyles = (theme) => {
|
|
|
67
68
|
}
|
|
68
69
|
};
|
|
69
70
|
};
|
|
70
|
-
const getSelectDefaultStyle = (
|
|
71
|
+
const getSelectDefaultStyle = ({
|
|
72
|
+
status,
|
|
73
|
+
disabled,
|
|
74
|
+
variant,
|
|
75
|
+
multiple,
|
|
76
|
+
isHover,
|
|
77
|
+
maxTagCount,
|
|
78
|
+
withPrefix,
|
|
79
|
+
isEmpty
|
|
80
|
+
}) => {
|
|
71
81
|
const isError = status === "error";
|
|
72
82
|
const isResponsive = maxTagCount === "responsive";
|
|
73
83
|
const isOutlined = variant === "outlined";
|
|
@@ -83,15 +93,17 @@ const getSelectDefaultStyle = (status, disabled, variant, multiple, isHover, max
|
|
|
83
93
|
border: getBorder(selectTokens, isError, variant),
|
|
84
94
|
outline: "none",
|
|
85
95
|
height: isMultipleAndNotResponsive ? "fit-content" : theme.controlHeightM,
|
|
96
|
+
minHeight: theme.controlHeightM,
|
|
86
97
|
boxSizing: "border-box",
|
|
87
98
|
overflow: "hidden",
|
|
88
99
|
justifyContent: "center",
|
|
100
|
+
transition: "border-color .3s, box-shadow .3s",
|
|
89
101
|
":hover": {
|
|
90
102
|
border: isOutlined ? `1px solid ${getHoveredBorder(selectTokens, disabled, isError)}` : "none"
|
|
91
103
|
},
|
|
92
104
|
":active, :focus, :focus-within, :focus-visible": {
|
|
93
105
|
border: isOutlined ? `1px solid ${getActiveBorder(selectTokens, disabled, isError)}` : "none",
|
|
94
|
-
boxShadow: disabled ? "none" : `0px 0px 4px 0px ${theme.fieldFocused}`
|
|
106
|
+
boxShadow: disabled || !isOutlined ? "none" : `0px 0px 4px 0px ${isError ? theme.fieldFocusedDanger : theme.fieldFocused}`
|
|
95
107
|
}
|
|
96
108
|
};
|
|
97
109
|
},
|
|
@@ -102,7 +114,7 @@ const getSelectDefaultStyle = (status, disabled, variant, multiple, isHover, max
|
|
|
102
114
|
alignItems: "center",
|
|
103
115
|
gap: theme.marginM,
|
|
104
116
|
height: isResponsive ? theme.controlHeightM : "fit-content",
|
|
105
|
-
padding: getBodyPadding(selectTokens, isMultipleAndNotResponsive, multiple),
|
|
117
|
+
padding: getBodyPadding(selectTokens, isMultipleAndNotResponsive, multiple, isEmpty),
|
|
106
118
|
borderRadius: theme.borderRadiusM,
|
|
107
119
|
background: disabled && isOutlined ? selectTokens.selectBgDisabled : selectTokens.selectBg,
|
|
108
120
|
boxSizing: "border-box",
|
|
@@ -124,7 +136,7 @@ const getSelectDefaultStyle = (status, disabled, variant, multiple, isHover, max
|
|
|
124
136
|
alignItems: "center",
|
|
125
137
|
gap: theme.marginXS,
|
|
126
138
|
flex: "1 1 auto",
|
|
127
|
-
paddingLeft: multiple ? theme.x2 : 0
|
|
139
|
+
paddingLeft: multiple && withPrefix ? theme.x2 : 0
|
|
128
140
|
}),
|
|
129
141
|
content: (theme) => {
|
|
130
142
|
const selectTokens = getSelectTokens(theme);
|
|
@@ -166,15 +178,16 @@ const getSelectDefaultStyle = (status, disabled, variant, multiple, isHover, max
|
|
|
166
178
|
const selectTokens = getSelectTokens(theme);
|
|
167
179
|
return {
|
|
168
180
|
border: "none",
|
|
169
|
-
height:
|
|
181
|
+
height: 20,
|
|
170
182
|
outline: "none",
|
|
171
183
|
...theme.typography.body2,
|
|
172
184
|
color: disabled ? selectTokens.selectTextDisabled : selectTokens.selectText,
|
|
173
185
|
maxWidth: "80%",
|
|
174
|
-
|
|
186
|
+
padding: 0,
|
|
175
187
|
background: "inherit",
|
|
176
188
|
"::placeholder": {
|
|
177
|
-
color: disabled ? selectTokens.selectTextDisabled : selectTokens.selectPlaceholder
|
|
189
|
+
color: disabled ? selectTokens.selectTextDisabled : selectTokens.selectPlaceholder,
|
|
190
|
+
...theme.typography.body2
|
|
178
191
|
}
|
|
179
192
|
};
|
|
180
193
|
},
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { FocusEvent, KeyboardEvent, ReactNode } from 'react';
|
|
2
|
+
import { Theme } from 'themes';
|
|
3
|
+
import { Interpolation } from '@emotion/react';
|
|
4
|
+
import { DropdownMatchSelectWidthType, DropdownStyles } from './components/BaseSelectOptionList/BaseSelectOptionList.types';
|
|
5
|
+
export type SelectStatus = "default" | "error";
|
|
6
|
+
export type VariantType = "outlined" | "borderless";
|
|
7
|
+
export type ModeType = "single" | "multiple";
|
|
8
|
+
export type maxTagCountType = number | "responsive";
|
|
9
|
+
export type BaseOptionValue = string;
|
|
10
|
+
export interface BaseSelectStyles {
|
|
11
|
+
dropdownStyle?: DropdownStyles;
|
|
12
|
+
wrapper?: (theme: Theme) => Interpolation;
|
|
13
|
+
body?: (theme: Theme) => Interpolation;
|
|
14
|
+
prefixAndContent?: (theme: Theme) => Interpolation;
|
|
15
|
+
content?: (theme: Theme) => Interpolation;
|
|
16
|
+
placeholder?: (theme: Theme) => Interpolation;
|
|
17
|
+
prefix?: (theme: Theme) => Interpolation;
|
|
18
|
+
suffixIcon?: (theme: Theme) => Interpolation;
|
|
19
|
+
cleanIcon?: (theme: Theme) => Interpolation;
|
|
20
|
+
drawerIcon?: (theme: Theme) => Interpolation;
|
|
21
|
+
}
|
|
22
|
+
export interface BaseSelectProps<Option extends BaseSelectOptionInterface<OptionValue>, OptionValue> {
|
|
23
|
+
options?: Option[];
|
|
24
|
+
mode?: ModeType;
|
|
25
|
+
variant?: VariantType;
|
|
26
|
+
defaultValue?: OptionValue | OptionValue[];
|
|
27
|
+
defaultOpen?: boolean;
|
|
28
|
+
value?: OptionValue | OptionValue[];
|
|
29
|
+
open?: boolean;
|
|
30
|
+
defaultActiveFirstOption?: boolean;
|
|
31
|
+
placeholder?: string;
|
|
32
|
+
dropdownMaxHeight?: number;
|
|
33
|
+
dropdownMinWidth?: number;
|
|
34
|
+
allowClear?: boolean;
|
|
35
|
+
autoFocus?: boolean;
|
|
36
|
+
prefix?: ReactNode;
|
|
37
|
+
suffixIcon?: ReactNode;
|
|
38
|
+
status?: SelectStatus;
|
|
39
|
+
disabled?: boolean;
|
|
40
|
+
dropdownPrompt?: string;
|
|
41
|
+
loading?: boolean;
|
|
42
|
+
dropdownClassName?: string;
|
|
43
|
+
dropdownMatchSelectWidth?: DropdownMatchSelectWidthType;
|
|
44
|
+
placement?: PlacementType;
|
|
45
|
+
virtual?: boolean;
|
|
46
|
+
emptyContent?: ReactNode;
|
|
47
|
+
showSearch?: boolean;
|
|
48
|
+
optionFilterProp?: string;
|
|
49
|
+
optionLabelProp?: string;
|
|
50
|
+
filterOption?: boolean | ((inputValue: string, option: Option) => boolean);
|
|
51
|
+
searchValue?: string;
|
|
52
|
+
notFoundContent?: ReactNode;
|
|
53
|
+
drawer?: boolean;
|
|
54
|
+
filterSort?: (optionA: Option, optionB: Option, searchValue: string) => number;
|
|
55
|
+
styles?: BaseSelectStyles;
|
|
56
|
+
autoClearSearchValue?: boolean;
|
|
57
|
+
maxTagCount?: maxTagCountType;
|
|
58
|
+
maxTagPlaceholder?: ((omittedValues: Option[]) => ReactNode) | ReactNode;
|
|
59
|
+
maxTagTextLength?: number;
|
|
60
|
+
currentSelectingIndex: number;
|
|
61
|
+
getCurrentSelectingValue: () => OptionValue | null;
|
|
62
|
+
onKeyControl: (e: KeyboardEvent<Element>) => void;
|
|
63
|
+
getOptionByValue: (value: OptionValue) => Option | undefined;
|
|
64
|
+
virtualizerEstimateSize: (index: number) => number;
|
|
65
|
+
renderDropdownItem: (option: Option, index: number) => ReactNode;
|
|
66
|
+
filterOptions: (options: Option[], filterValue: string) => Option[];
|
|
67
|
+
valuesFilter?: (options: OptionValue[]) => OptionValue[];
|
|
68
|
+
dropdownRender?: (originNode: ReactNode) => ReactNode;
|
|
69
|
+
optionRender?: (option: BaseSelectOptionProps<Option, OptionValue>) => ReactNode;
|
|
70
|
+
labelRender?: (props: LabelInValueType<OptionValue>) => ReactNode;
|
|
71
|
+
tagRender?: (label: string) => ReactNode;
|
|
72
|
+
onFocus?: (event: FocusEvent) => void;
|
|
73
|
+
onBlur?: (event: FocusEvent) => void;
|
|
74
|
+
onChange?: (value: OptionValue[], option: Option[]) => void;
|
|
75
|
+
onClear?: () => void;
|
|
76
|
+
onDropdownVisibleChange?: () => void;
|
|
77
|
+
onInputKeyDown?: (event: KeyboardEvent) => void;
|
|
78
|
+
onSelect?: (value: OptionValue, option: Option) => void;
|
|
79
|
+
getPopupContainer?: () => HTMLElement;
|
|
80
|
+
onSearch?: (searchValue: string) => void;
|
|
81
|
+
onDeselect?: (value: OptionValue) => void;
|
|
82
|
+
onTagClose?: (value: OptionValue) => void;
|
|
83
|
+
}
|
|
84
|
+
export interface LabelInValueType<OptionValue> {
|
|
85
|
+
label: ReactNode;
|
|
86
|
+
value: OptionValue;
|
|
87
|
+
}
|
|
88
|
+
export type PlacementType = "bottomLeft" | "bottomRight" | "topLeft" | "topRight";
|
|
89
|
+
export type UseSearchProps<Option extends BaseSelectOptionInterface<OptionValue>, OptionValue> = Required<Pick<BaseSelectProps<Option, OptionValue>, "options" | "filterOptions">> & Pick<BaseSelectProps<Option, OptionValue>, "onSearch" | "searchValue" | "filterSort">;
|
|
90
|
+
export interface BaseSelectOptionInterface<OptionValue> {
|
|
91
|
+
value: OptionValue;
|
|
92
|
+
title: ReactNode;
|
|
93
|
+
icon?: ReactNode;
|
|
94
|
+
disabled?: boolean;
|
|
95
|
+
}
|
|
96
|
+
export interface BaseSelectOptionProps<Option extends BaseSelectOptionInterface<OptionValue>, OptionValue> {
|
|
97
|
+
option: Option;
|
|
98
|
+
index: number;
|
|
99
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { Placement } from '@floating-ui/react';
|
|
2
|
+
import { maxTagCountType, PlacementType, BaseSelectOptionInterface } from './BaseSelect.types';
|
|
3
|
+
export declare const additionalElements: string[];
|
|
4
|
+
export declare const convertSelectPlacement: (placement: PlacementType) => Placement;
|
|
5
|
+
export declare const isKeyOfObject: <T extends object>(obj: T, key: string | number | symbol) => key is keyof T;
|
|
6
|
+
export declare const getLabelByValue: <SelectOption extends BaseSelectOptionInterface<OptionValue>, OptionValue>(value: OptionValue, getOptionByValue: (value: OptionValue) => SelectOption | undefined, optionLabelProp: string) => string | undefined;
|
|
7
|
+
export declare const getLabel: <SelectOption extends BaseSelectOptionInterface<OptionValue>, OptionValue = string>(values: OptionValue[], getOptionByValue: (value: OptionValue) => SelectOption | undefined, optionLabelProp: string) => string[];
|
|
8
|
+
export declare const getVisibleLabels: (labels: string[], maxTagCount: maxTagCountType | undefined) => string[];
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { isUndefined, isNumber } from "lodash-es";
|
|
2
|
+
const additionalElements = ["search-input", "clean-button"];
|
|
3
|
+
const placementDictionary = {
|
|
4
|
+
bottomLeft: "bottom-start",
|
|
5
|
+
bottomRight: "bottom-end",
|
|
6
|
+
topLeft: "top-start",
|
|
7
|
+
topRight: "top-end"
|
|
8
|
+
};
|
|
9
|
+
const convertSelectPlacement = (placement) => {
|
|
10
|
+
return placementDictionary[placement];
|
|
11
|
+
};
|
|
12
|
+
const isKeyOfObject = (obj, key) => {
|
|
13
|
+
return key in obj;
|
|
14
|
+
};
|
|
15
|
+
const getLabelByValue = (value, getOptionByValue, optionLabelProp) => {
|
|
16
|
+
var _a;
|
|
17
|
+
const option = getOptionByValue(value);
|
|
18
|
+
if (isUndefined(option)) {
|
|
19
|
+
return void 0;
|
|
20
|
+
}
|
|
21
|
+
return isKeyOfObject(option, optionLabelProp) ? (_a = option[optionLabelProp]) == null ? void 0 : _a.toString() : void 0;
|
|
22
|
+
};
|
|
23
|
+
const getLabel = (values, getOptionByValue, optionLabelProp) => {
|
|
24
|
+
return values.map((value) => getLabelByValue(value, getOptionByValue, optionLabelProp) ?? String(value));
|
|
25
|
+
};
|
|
26
|
+
const getVisibleLabels = (labels, maxTagCount) => {
|
|
27
|
+
if (isNumber(maxTagCount)) {
|
|
28
|
+
return labels.slice(0, maxTagCount);
|
|
29
|
+
}
|
|
30
|
+
return labels;
|
|
31
|
+
};
|
|
32
|
+
export {
|
|
33
|
+
additionalElements,
|
|
34
|
+
convertSelectPlacement,
|
|
35
|
+
getLabel,
|
|
36
|
+
getLabelByValue,
|
|
37
|
+
getVisibleLabels,
|
|
38
|
+
isKeyOfObject
|
|
39
|
+
};
|
package/dist/components/BaseSelect/components/BaseSelectOptionList/BaseSelectOptionList.types.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Interpolation } from '@emotion/react';
|
|
2
|
+
import { Theme } from 'themes';
|
|
3
|
+
export type DropdownMatchSelectWidthType = boolean | number;
|
|
4
|
+
export interface DropdownStyles {
|
|
5
|
+
wrapper?: (theme: Theme) => Interpolation;
|
|
6
|
+
container?: (virtual: boolean) => Interpolation;
|
|
7
|
+
prompt?: (theme: Theme) => Interpolation;
|
|
8
|
+
wrapperOfLoading?: (theme: Theme) => Interpolation;
|
|
9
|
+
wrapperOfEmptyContent?: (theme: Theme) => Interpolation;
|
|
10
|
+
virtualizedOptionWrapper?: (theme: Theme) => Interpolation;
|
|
11
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SelectOptionListProps } from './SelectOptionList.types';
|
|
2
|
+
import { BaseSelectOptionInterface } from 'components/BaseSelect/BaseSelect.types';
|
|
3
|
+
export declare const SelectOptionListComponent: <Option extends BaseSelectOptionInterface<OptionValue>, OptionValue>({ options, styles, renderDropdownItem, virtualizerEstimateSize, }: SelectOptionListProps<Option, OptionValue>) => import('react').ReactPortal | null;
|
|
4
|
+
export declare const SelectOptionList: typeof SelectOptionListComponent;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { jsx, jsxs, Fragment } from "@emotion/react/jsx-runtime";
|
|
2
|
+
import { memo, useEffect, useMemo } from "react";
|
|
3
|
+
import { getSelectOptionListStyle } from "./SelectOptionList.styles.js";
|
|
4
|
+
import { isFunction } from "lodash-es";
|
|
5
|
+
import { createPortal } from "react-dom";
|
|
6
|
+
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
7
|
+
import { useBaseSelectContext } from "../../contexts/BaseSelectContext.js";
|
|
8
|
+
import { useTheme } from "../../../../hooks/useTheme/useTheme.js";
|
|
9
|
+
import { LoadingOutlined } from "../../../../icons/icons/LoadingOutlined.js";
|
|
10
|
+
const SelectOptionListComponent = ({
|
|
11
|
+
options,
|
|
12
|
+
styles,
|
|
13
|
+
renderDropdownItem,
|
|
14
|
+
virtualizerEstimateSize
|
|
15
|
+
}) => {
|
|
16
|
+
const theme = useTheme();
|
|
17
|
+
const {
|
|
18
|
+
showOptionList,
|
|
19
|
+
dropdownMinWidth,
|
|
20
|
+
dropdownMaxHeight,
|
|
21
|
+
dropdownPrompt,
|
|
22
|
+
loading,
|
|
23
|
+
dropdownClassName,
|
|
24
|
+
dropdownMatchSelectWidth,
|
|
25
|
+
floatingStyles,
|
|
26
|
+
referenceOffsetWidth,
|
|
27
|
+
floatingRef,
|
|
28
|
+
virtual,
|
|
29
|
+
currentSelectingIndex,
|
|
30
|
+
emptyContent,
|
|
31
|
+
notFoundContent,
|
|
32
|
+
searchValue,
|
|
33
|
+
showSearch,
|
|
34
|
+
setFloating,
|
|
35
|
+
dropdownRender,
|
|
36
|
+
getPopupContainer
|
|
37
|
+
} = useBaseSelectContext();
|
|
38
|
+
const {
|
|
39
|
+
getTotalSize,
|
|
40
|
+
getVirtualItems,
|
|
41
|
+
scrollToIndex,
|
|
42
|
+
scrollToOffset,
|
|
43
|
+
measure
|
|
44
|
+
} = useVirtualizer({
|
|
45
|
+
count: virtual && dropdownPrompt ? options.length + 1 : options.length,
|
|
46
|
+
getScrollElement: () => floatingRef.current,
|
|
47
|
+
estimateSize: (index) => virtualizerEstimateSize(index)
|
|
48
|
+
});
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
measure();
|
|
51
|
+
}, [virtualizerEstimateSize]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!showOptionList) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
scrollToIndex(currentSelectingIndex || 0);
|
|
57
|
+
}, [showOptionList, currentSelectingIndex, scrollToIndex, scrollToOffset]);
|
|
58
|
+
const selectOptionListStyle = getSelectOptionListStyle({
|
|
59
|
+
dropdownMinWidth,
|
|
60
|
+
dropdownMaxHeight,
|
|
61
|
+
showOptionList,
|
|
62
|
+
dropdownMatchSelectWidth,
|
|
63
|
+
referenceOffsetWidth,
|
|
64
|
+
isMaxSize: getTotalSize() >= dropdownMaxHeight,
|
|
65
|
+
getTotalSize
|
|
66
|
+
});
|
|
67
|
+
const hasPlaceholder = loading || options.length === 0;
|
|
68
|
+
const prompt = useMemo(() => {
|
|
69
|
+
var _a;
|
|
70
|
+
if (!dropdownPrompt) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return /* @__PURE__ */ jsx("div", { css: [selectOptionListStyle.prompt(theme), (_a = styles == null ? void 0 : styles.prompt) == null ? void 0 : _a.call(styles, theme), process.env.NODE_ENV === "production" ? "" : ";label:prompt;", process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9idWlsZHMvZnJvbnRlbmQvbGlicy91aS1raXQvc3JjL2NvbXBvbmVudHMvQmFzZVNlbGVjdC9jb21wb25lbnRzL1NlbGVjdE9wdGlvbkxpc3QvU2VsZWN0T3B0aW9uTGlzdC50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBK0VXIiwiZmlsZSI6Ii9idWlsZHMvZnJvbnRlbmQvbGlicy91aS1raXQvc3JjL2NvbXBvbmVudHMvQmFzZVNlbGVjdC9jb21wb25lbnRzL1NlbGVjdE9wdGlvbkxpc3QvU2VsZWN0T3B0aW9uTGlzdC50c3giLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBtZW1vLCB1c2VFZmZlY3QsIHVzZU1lbW8gfSBmcm9tIFwicmVhY3RcIjtcbmltcG9ydCB0eXBlIHsgU2VsZWN0T3B0aW9uTGlzdFByb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H07XG5cbiAgY29uc3QgcmVuZGVyU2VsZWN0T3B0aW9uTGlzdCA9ICgpID0+IChcbiAgICA8ZGl2XG4gICAgICByZWY9e3NldEZsb2F0aW5nfVxuICAgICAgc3R5bGU9e2Zsb2F0aW5nU3R5bGVzfVxuICAgICAgY3NzPXtbc2VsZWN0T3B0aW9uTGlzdFN0eWxlLndyYXBwZXIodGhlbWUpLCBzdHlsZXM/LndyYXBwZXI/Lih0aGVtZSldfVxuICAgICAgY2xhc3NOYW1lPXtkcm9wZG93bkNsYXNzTmFtZX1cbiAgICAgIHRhYkluZGV4PXsyfVxuICAgID5cbiAgICAgIHtoYXNQbGFjZWhvbGRlciA/IChcbiAgICAgICAgcmVuZGVyUGxhY2Vob2xkZXIoKVxuICAgICAgKSA6IChcbiAgICAgICAgPGRpdiBjc3M9e3NlbGVjdE9wdGlvbkxpc3RTdHlsZS5jb250YWluZXIodmlydHVhbCl9PlxuICAgICAgICAgIHtpc0Z1bmN0aW9uKGRyb3Bkb3duUmVuZGVyKVxuICAgICAgICAgICAgPyBkcm9wZG93blJlbmRlcihyZW5kZXJPcHRpb25MaXN0Q29udGVudCgpKVxuICAgICAgICAgICAgOiByZW5kZXJPcHRpb25MaXN0Q29udGVudCgpfVxuICAgICAgICA8L2Rpdj5cbiAgICAgICl9XG4gICAgPC9kaXY+XG4gICk7XG5cbiAgaWYgKCFzaG93T3B0aW9uTGlzdCAmJiAhdmlydHVhbCkge1xuICAgIHJldHVybiBudWxsO1xuICB9XG5cbiAgcmV0dXJuIGNyZWF0ZVBvcnRhbChyZW5kZXJTZWxlY3RPcHRpb25MaXN0KCksIGdldFBvcHVwQ29udGFpbmVyKCkpO1xufTtcblxuZXhwb3J0IGNvbnN0IFNlbGVjdE9wdGlvbkxpc3QgPSBtZW1vKFNlbGVjdE9wdGlvbkxpc3RDb21wb25lbnQpIGFzIHR5cGVvZiBTZWxlY3RPcHRpb25MaXN0Q29tcG9uZW50O1xuIl19 */"], children: dropdownPrompt }, "prompt");
|
|
74
|
+
}, [dropdownPrompt, selectOptionListStyle, styles, theme]);
|
|
75
|
+
const virtualizedOptions = useMemo(() => {
|
|
76
|
+
return getVirtualItems().map(({
|
|
77
|
+
index,
|
|
78
|
+
size,
|
|
79
|
+
start
|
|
80
|
+
}) => {
|
|
81
|
+
var _a;
|
|
82
|
+
if (index < options.length) {
|
|
83
|
+
const option = options[index];
|
|
84
|
+
return /* @__PURE__ */ jsx("div", { css: selectOptionListStyle.virtualizedOptionWrapper(size, start), children: renderDropdownItem(option, index) }, (_a = option.value) == null ? void 0 : _a.toString());
|
|
85
|
+
}
|
|
86
|
+
if (!dropdownPrompt) {
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
return /* @__PURE__ */ jsx("div", { css: selectOptionListStyle.virtualizedOptionWrapper(size, start), children: prompt }, "prompt");
|
|
90
|
+
});
|
|
91
|
+
}, [dropdownPrompt, getVirtualItems, options, prompt, renderDropdownItem, selectOptionListStyle]);
|
|
92
|
+
const optionsList = useMemo(() => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
93
|
+
options.map((option, index) => renderDropdownItem(option, index)),
|
|
94
|
+
prompt
|
|
95
|
+
] }), [options, prompt, renderDropdownItem]);
|
|
96
|
+
const renderOptionListContent = () => virtual ? virtualizedOptions : optionsList;
|
|
97
|
+
const renderPlaceholder = () => {
|
|
98
|
+
if (loading) {
|
|
99
|
+
return /* @__PURE__ */ jsx("span", { css: selectOptionListStyle.wrapperOfLoading(theme), children: /* @__PURE__ */ jsx(LoadingOutlined, {}) });
|
|
100
|
+
}
|
|
101
|
+
const isActiveSearch = searchValue && showSearch;
|
|
102
|
+
if (options.length === 0) {
|
|
103
|
+
return /* @__PURE__ */ jsx("div", { css: selectOptionListStyle.wrapperOfEmptyContent(theme), children: isActiveSearch ? notFoundContent : emptyContent });
|
|
104
|
+
}
|
|
105
|
+
return null;
|
|
106
|
+
};
|
|
107
|
+
const renderSelectOptionList = () => {
|
|
108
|
+
var _a;
|
|
109
|
+
return /* @__PURE__ */ jsx("div", { ref: setFloating, style: floatingStyles, css: [selectOptionListStyle.wrapper(theme), (_a = styles == null ? void 0 : styles.wrapper) == null ? void 0 : _a.call(styles, theme), process.env.NODE_ENV === "production" ? "" : ";label:renderSelectOptionList;", process.env.NODE_ENV === "production" ? "" : "/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi9idWlsZHMvZnJvbnRlbmQvbGlicy91aS1raXQvc3JjL2NvbXBvbmVudHMvQmFzZVNlbGVjdC9jb21wb25lbnRzL1NlbGVjdE9wdGlvbkxpc3QvU2VsZWN0T3B0aW9uTGlzdC50c3giXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBc0pNIiwiZmlsZSI6Ii9idWlsZHMvZnJvbnRlbmQvbGlicy91aS1raXQvc3JjL2NvbXBvbmVudHMvQmFzZVNlbGVjdC9jb21wb25lbnRzL1NlbGVjdE9wdGlvbkxpc3QvU2VsZWN0T3B0aW9uTGlzdC50c3giLCJzb3VyY2VzQ29udGVudCI6WyJpbXBvcnQgeyBtZW1vLCB1c2VFZmZlY3QsIHVzZU1lbW8gfSBmcm9tIFwicmVhY3RcIjtcbmltcG9ydCB0eXBlIHsgU2VsZWN0T3B0aW9uTGlzdFByb3BzIH0gZnJvbSBcIi4vU2VsZWN0T3B0aW9uTGlzdC50eXBlc1wiO1xuaW1wb3J0IHsgZ2V0U2VsZWN0T3B0aW9uTGlzdFN0eWxlIH0gZnJvbSBcIi4vU2VsZWN0T3B0aW9uTGlzdC5zdHlsZXNcIjtcbmltcG9ydCB7IHVzZVRoZW1lIH0gZnJvbSBcImhvb2tzL3VzZVRoZW1lXCI7XG5pbXBvcnQgeyBMb2FkaW5nT3V0bGluZWQgfSBmcm9tIFwiaWNvbnMvaWNvbnNcIjtcbmltcG9ydCB7IGlzRnVuY3Rpb24gfSBmcm9tIFwibG9kYXNoLWVzXCI7XG5pbXBvcnQgeyBjcmVh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biAgICAgICAgcmVuZGVyUGxhY2Vob2xkZXIoKVxuICAgICAgKSA6IChcbiAgICAgICAgPGRpdiBjc3M9e3NlbGVjdE9wdGlvbkxpc3RTdHlsZS5jb250YWluZXIodmlydHVhbCl9PlxuICAgICAgICAgIHtpc0Z1bmN0aW9uKGRyb3Bkb3duUmVuZGVyKVxuICAgICAgICAgICAgPyBkcm9wZG93blJlbmRlcihyZW5kZXJPcHRpb25MaXN0Q29udGVudCgpKVxuICAgICAgICAgICAgOiByZW5kZXJPcHRpb25MaXN0Q29udGVudCgpfVxuICAgICAgICA8L2Rpdj5cbiAgICAgICl9XG4gICAgPC9kaXY+XG4gICk7XG5cbiAgaWYgKCFzaG93T3B0aW9uTGlzdCAmJiAhdmlydHVhbCkge1xuICAgIHJldHVybiBudWxsO1xuICB9XG5cbiAgcmV0dXJuIGNyZWF0ZVBvcnRhbChyZW5kZXJTZWxlY3RPcHRpb25MaXN0KCksIGdldFBvcHVwQ29udGFpbmVyKCkpO1xufTtcblxuZXhwb3J0IGNvbnN0IFNlbGVjdE9wdGlvbkxpc3QgPSBtZW1vKFNlbGVjdE9wdGlvbkxpc3RDb21wb25lbnQpIGFzIHR5cGVvZiBTZWxlY3RPcHRpb25MaXN0Q29tcG9uZW50O1xuIl19 */"], className: dropdownClassName, tabIndex: 2, children: hasPlaceholder ? renderPlaceholder() : /* @__PURE__ */ jsx("div", { css: selectOptionListStyle.container(virtual), children: isFunction(dropdownRender) ? dropdownRender(renderOptionListContent()) : renderOptionListContent() }) });
|
|
110
|
+
};
|
|
111
|
+
if (!showOptionList && !virtual) {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
return createPortal(renderSelectOptionList(), getPopupContainer());
|
|
115
|
+
};
|
|
116
|
+
const SelectOptionList = memo(SelectOptionListComponent);
|
|
117
|
+
export {
|
|
118
|
+
SelectOptionList,
|
|
119
|
+
SelectOptionListComponent
|
|
120
|
+
};
|
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { Theme } from 'themes';
|
|
2
|
-
|
|
2
|
+
interface selectOptionListStyleProps {
|
|
3
|
+
dropdownMinWidth: number;
|
|
4
|
+
dropdownMaxHeight: number;
|
|
5
|
+
showOptionList: boolean;
|
|
6
|
+
dropdownMatchSelectWidth: boolean | number;
|
|
7
|
+
referenceOffsetWidth: number | undefined;
|
|
8
|
+
isMaxSize: boolean;
|
|
9
|
+
getTotalSize: () => number;
|
|
10
|
+
}
|
|
11
|
+
export declare const getSelectOptionListStyle: ({ dropdownMinWidth, dropdownMaxHeight, showOptionList, dropdownMatchSelectWidth, referenceOffsetWidth, isMaxSize, getTotalSize, }: selectOptionListStyleProps) => {
|
|
3
12
|
wrapper: (theme: Theme) => {
|
|
4
13
|
readonly display: "block";
|
|
5
14
|
readonly position: "absolute";
|
|
@@ -8,13 +17,12 @@ export declare const getSelectOptionListStyle: (dropdownMinWidth: number, dropdo
|
|
|
8
17
|
readonly justifyContent: "center";
|
|
9
18
|
readonly padding: 4;
|
|
10
19
|
readonly overflowX: "hidden";
|
|
11
|
-
readonly overflowY: "auto";
|
|
20
|
+
readonly overflowY: "hidden" | "auto";
|
|
12
21
|
readonly minWidth: number;
|
|
13
22
|
readonly width: number | "fit-content";
|
|
14
23
|
readonly maxHeight: number;
|
|
15
24
|
readonly height: "fit-content";
|
|
16
|
-
readonly
|
|
17
|
-
readonly transition: "max-height 200ms, opacity 200ms";
|
|
25
|
+
readonly visibility: "hidden" | "visible";
|
|
18
26
|
readonly boxSizing: "border-box";
|
|
19
27
|
readonly borderRadius: 8;
|
|
20
28
|
readonly background: "#FFFFFF";
|
|
@@ -64,3 +72,4 @@ export declare const getSelectOptionListStyle: (dropdownMinWidth: number, dropdo
|
|
|
64
72
|
readonly transform: `translateY(${number}px)`;
|
|
65
73
|
};
|
|
66
74
|
};
|
|
75
|
+
export {};
|
package/dist/components/{Select → BaseSelect}/components/SelectOptionList/SelectOptionList.styles.js
RENAMED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getSelectTokens } from "../../Select.tokens.js";
|
|
1
|
+
import { getSelectTokens } from "../../BaseSelect.tokens.js";
|
|
3
2
|
import { isNumber } from "lodash-es";
|
|
4
3
|
const getWidth = (dropdownMatchSelectWidth, referenceOffsetWidth) => {
|
|
5
4
|
if (isNumber(dropdownMatchSelectWidth)) {
|
|
@@ -10,7 +9,15 @@ const getWidth = (dropdownMatchSelectWidth, referenceOffsetWidth) => {
|
|
|
10
9
|
}
|
|
11
10
|
return referenceOffsetWidth ?? "fit-content";
|
|
12
11
|
};
|
|
13
|
-
const getSelectOptionListStyle = (
|
|
12
|
+
const getSelectOptionListStyle = ({
|
|
13
|
+
dropdownMinWidth,
|
|
14
|
+
dropdownMaxHeight,
|
|
15
|
+
showOptionList,
|
|
16
|
+
dropdownMatchSelectWidth,
|
|
17
|
+
referenceOffsetWidth,
|
|
18
|
+
isMaxSize,
|
|
19
|
+
getTotalSize
|
|
20
|
+
}) => ({
|
|
14
21
|
wrapper: (theme) => ({
|
|
15
22
|
display: "block",
|
|
16
23
|
position: "absolute",
|
|
@@ -19,13 +26,12 @@ const getSelectOptionListStyle = (dropdownMinWidth, dropdownMaxHeight, showOptio
|
|
|
19
26
|
justifyContent: "center",
|
|
20
27
|
padding: theme.paddingXS,
|
|
21
28
|
overflowX: "hidden",
|
|
22
|
-
overflowY: "auto",
|
|
29
|
+
overflowY: isMaxSize ? "auto" : "hidden",
|
|
23
30
|
minWidth: dropdownMinWidth,
|
|
24
31
|
width: getWidth(dropdownMatchSelectWidth, referenceOffsetWidth),
|
|
25
|
-
maxHeight:
|
|
32
|
+
maxHeight: dropdownMaxHeight,
|
|
26
33
|
height: "fit-content",
|
|
27
|
-
|
|
28
|
-
transition: `max-height ${ANIMATION_DURATION}ms, opacity ${ANIMATION_DURATION}ms`,
|
|
34
|
+
visibility: showOptionList ? "visible" : "hidden",
|
|
29
35
|
boxSizing: "border-box",
|
|
30
36
|
borderRadius: theme.borderRadiusL,
|
|
31
37
|
background: theme.bgFloat,
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Theme } from 'themes';
|
|
2
|
+
import { Interpolation } from '@emotion/react';
|
|
3
|
+
import { ReactNode } from 'react';
|
|
4
|
+
import { BaseSelectOptionInterface, BaseSelectOptionProps } from 'components/BaseSelect/BaseSelect.types';
|
|
5
|
+
export type DropdownMatchSelectWidthType = boolean | number;
|
|
6
|
+
export interface DropdownStyles {
|
|
7
|
+
wrapper?: (theme: Theme) => Interpolation;
|
|
8
|
+
container?: (virtual: boolean) => Interpolation;
|
|
9
|
+
prompt?: (theme: Theme) => Interpolation;
|
|
10
|
+
wrapperOfLoading?: (theme: Theme) => Interpolation;
|
|
11
|
+
wrapperOfEmptyContent?: (theme: Theme) => Interpolation;
|
|
12
|
+
virtualizedOptionWrapper?: (theme: Theme) => Interpolation;
|
|
13
|
+
}
|
|
14
|
+
export interface SelectOptionListProps<Option extends BaseSelectOptionInterface<OptionValue>, OptionValue> {
|
|
15
|
+
options: Option[];
|
|
16
|
+
styles?: DropdownStyles;
|
|
17
|
+
virtualizerEstimateSize: (index: number) => number;
|
|
18
|
+
renderDropdownItem: (option: Option, index: number) => ReactNode;
|
|
19
|
+
optionRender?: (option: BaseSelectOptionProps<Option, OptionValue>) => React.ReactNode;
|
|
20
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { SelectTagProps } from './SelectTag.types';
|
|
2
|
+
declare const SelectTagComponent: <OptionValue>({ value, label, maxTagTextLength, isError, isBorderless, disabled, isHidden, removeValue, onTagClose, }: SelectTagProps<OptionValue>) => import("@emotion/react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare const SelectTag: typeof SelectTagComponent;
|
|
4
|
+
export {};
|
|
@@ -2,23 +2,27 @@ import { jsx } from "@emotion/react/jsx-runtime";
|
|
|
2
2
|
import { memo, useCallback } from "react";
|
|
3
3
|
import { getSelectTagDefaultStyle } from "./SelectTag.styles.js";
|
|
4
4
|
import { Tag } from "../../../Tag/Tag.js";
|
|
5
|
-
const
|
|
5
|
+
const SelectTagComponent = ({
|
|
6
6
|
value,
|
|
7
7
|
label,
|
|
8
8
|
maxTagTextLength,
|
|
9
9
|
isError,
|
|
10
10
|
isBorderless,
|
|
11
11
|
disabled,
|
|
12
|
-
|
|
12
|
+
isHidden,
|
|
13
|
+
removeValue,
|
|
14
|
+
onTagClose
|
|
13
15
|
}) => {
|
|
14
16
|
const closeHandle = useCallback((e) => {
|
|
15
17
|
e.stopPropagation();
|
|
16
18
|
removeValue(value);
|
|
17
|
-
|
|
19
|
+
onTagClose == null ? void 0 : onTagClose(value);
|
|
20
|
+
}, [onTagClose, removeValue, value]);
|
|
18
21
|
const currentLabel = maxTagTextLength && label.length > maxTagTextLength ? label.slice(0, maxTagTextLength) + "…" : label;
|
|
19
|
-
const selectTagDefaultStyle = getSelectTagDefaultStyle(isError, isBorderless, disabled);
|
|
22
|
+
const selectTagDefaultStyle = getSelectTagDefaultStyle(isError, isBorderless, disabled, isHidden);
|
|
20
23
|
return /* @__PURE__ */ jsx(Tag, { closable: disabled ? false : true, onClose: closeHandle, styles: selectTagDefaultStyle, children: currentLabel });
|
|
21
|
-
}
|
|
24
|
+
};
|
|
25
|
+
const SelectTag = memo(SelectTagComponent);
|
|
22
26
|
export {
|
|
23
27
|
SelectTag
|
|
24
28
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Theme } from 'themes';
|
|
2
|
+
export declare const getSelectTagDefaultStyle: (isError: boolean, isBorderless: boolean, disabled: boolean, isHidden: boolean) => {
|
|
3
|
+
wrapper: (theme: Theme) => {
|
|
4
|
+
readonly position: "absolute";
|
|
5
|
+
readonly visibility: "hidden";
|
|
6
|
+
readonly fontSize: 14;
|
|
7
|
+
readonly color: "#262626" | "#8C8C8C" | "#FF4D4F";
|
|
8
|
+
readonly background: "#D9D9D9" | "#F5F5F5";
|
|
9
|
+
} | {
|
|
10
|
+
readonly position?: undefined;
|
|
11
|
+
readonly visibility?: undefined;
|
|
12
|
+
readonly fontSize: 14;
|
|
13
|
+
readonly color: "#262626" | "#8C8C8C" | "#FF4D4F";
|
|
14
|
+
readonly background: "#D9D9D9" | "#F5F5F5";
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { getSelectTokens } from "../../
|
|
1
|
+
import { getSelectTokens } from "../../BaseSelect.tokens.js";
|
|
2
2
|
const getColor = (isError, isBorderless, disabled, selectTokens) => {
|
|
3
3
|
if (disabled) {
|
|
4
4
|
return selectTokens.selectTextDisabled;
|
|
@@ -8,13 +8,23 @@ const getColor = (isError, isBorderless, disabled, selectTokens) => {
|
|
|
8
8
|
}
|
|
9
9
|
return selectTokens.selectText;
|
|
10
10
|
};
|
|
11
|
-
const
|
|
11
|
+
const visibilityStyles = (isHidden) => {
|
|
12
|
+
if (isHidden) {
|
|
13
|
+
return {
|
|
14
|
+
position: "absolute",
|
|
15
|
+
visibility: "hidden"
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return {};
|
|
19
|
+
};
|
|
20
|
+
const getSelectTagDefaultStyle = (isError, isBorderless, disabled, isHidden) => ({
|
|
12
21
|
wrapper: (theme) => {
|
|
13
22
|
const selectTokens = getSelectTokens(theme);
|
|
14
23
|
return {
|
|
15
24
|
fontSize: 14,
|
|
16
25
|
color: getColor(isError, isBorderless, disabled, selectTokens),
|
|
17
|
-
background: disabled ? selectTokens.selectMultipleItemBgDisabled : selectTokens.selectMultipleItemBg
|
|
26
|
+
background: disabled ? selectTokens.selectMultipleItemBgDisabled : selectTokens.selectMultipleItemBg,
|
|
27
|
+
...visibilityStyles(isHidden)
|
|
18
28
|
};
|
|
19
29
|
}
|
|
20
30
|
});
|