@rescui/select 0.15.1-RUI-280-Update-select-component-separate-components-e772abaa1.56 → 0.15.1-RUI-280-Update-select-component-downshift-2f40ef205.67
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/lib/_virtual/index.css.js +12 -12
- package/lib/constants.d.ts +0 -1
- package/lib/constants.js +1 -2
- package/lib/hooks/use-a11y.d.ts +29 -0
- package/lib/hooks/use-a11y.js +53 -0
- package/lib/hooks/use-backward-compatible-id.d.ts +4 -0
- package/lib/hooks/use-backward-compatible-id.js +14 -0
- package/lib/hooks/use-focus.d.ts +10 -0
- package/lib/hooks/use-focus.js +17 -0
- package/lib/hooks/use-hover.d.ts +10 -0
- package/lib/hooks/use-hover.js +17 -0
- package/lib/hooks/use-label-focus.d.ts +1 -3
- package/lib/hooks/use-label-focus.js +3 -9
- package/lib/hooks/use-multi-handlers.d.ts +11 -0
- package/lib/hooks/use-multi-handlers.js +48 -0
- package/lib/hooks/use-options.d.ts +13 -0
- package/lib/hooks/use-options.js +89 -0
- package/lib/index.css +423 -1195
- package/lib/multiselect.d.ts +3 -29
- package/lib/multiselect.js +250 -180
- package/lib/native-select.js +75 -48
- package/lib/parts/hidden-select.d.ts +13 -0
- package/lib/parts/hidden-select.js +45 -0
- package/lib/parts/icons.js +2 -8
- package/lib/parts/list-box.d.ts +7 -15
- package/lib/parts/list-box.js +50 -82
- package/lib/parts/multi-trigger.d.ts +5 -4
- package/lib/parts/multi-trigger.js +27 -15
- package/lib/public-api.p.css +368 -126
- package/lib/public-api.pcss +368 -126
- package/lib/select-basic.d.ts +2 -2
- package/lib/select-basic.js +160 -103
- package/lib/select-searchable.d.ts +2 -2
- package/lib/select-searchable.js +205 -127
- package/lib/select.d.ts +1 -1
- package/lib/select.js +38 -31
- package/lib/styles/common.p.module.css.js +28 -24
- package/lib/styles/form-trigger.p.module.css.js +12 -12
- package/lib/styles/list-box.p.module.css.js +11 -13
- package/lib/types.d.ts +26 -27
- package/lib/utils/get-real-items-cnt.d.ts +2 -2
- package/lib/utils/get-real-items-cnt.js +8 -10
- package/lib/utils/item-to-string.d.ts +2 -0
- package/lib/utils/item-to-string.js +7 -0
- package/lib/utils/merge-props.d.ts +29 -0
- package/lib/utils/merge-props.js +106 -0
- package/package.json +11 -23
- package/lib/hooks/use-css-context-transfer.d.ts +0 -14
- package/lib/hooks/use-css-context-transfer.js +0 -40
- package/lib/hooks/use-multi-option-serialization.d.ts +0 -10
- package/lib/hooks/use-multi-option-serialization.js +0 -82
- package/lib/hooks/use-observable-force-rerender.d.ts +0 -2
- package/lib/hooks/use-observable-force-rerender.js +0 -16
- package/lib/hooks/use-option-serialization.d.ts +0 -10
- package/lib/hooks/use-option-serialization.js +0 -59
- package/lib/parts/native-select-trigger.d.ts +0 -18
- package/lib/parts/native-select-trigger.js +0 -54
- package/lib/parts/popover.d.ts +0 -12
- package/lib/parts/popover.js +0 -64
- package/lib/parts/popup-content.d.ts +0 -19
- package/lib/parts/popup-content.js +0 -76
- package/lib/styles/native-select-trigger.p.module.css.js +0 -17
- package/lib/styles/native-select.p.module.css.js +0 -9
- package/lib/styles/popover.p.module.css.js +0 -10
- package/lib/utils/convert-options.d.ts +0 -3
- package/lib/utils/convert-options.js +0 -52
- package/lib/utils/convert-placement.d.ts +0 -3
- package/lib/utils/convert-placement.js +0 -22
- package/lib/utils/css-vars-utils.d.ts +0 -3
- package/lib/utils/css-vars-utils.js +0 -20
package/lib/select.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import PropTypes from 'prop-types';
|
|
3
3
|
import type { SelectProps, SelectOption, SelectOptionOrGroup } from './types';
|
|
4
4
|
export declare const Select: {
|
|
5
|
-
({ options, size, mode, theme: themeFromProps, className, style, value, onChange, placeholder, isClearable, isLoading, isDisabled, isSearchable, noOptionsMessage, error, placement, boldLabel, reserveErrorLine, note, maxVisibleItems, ...restProps }: SelectProps): JSX.Element;
|
|
5
|
+
({ options, size, mode, theme: themeFromProps, className, style, value, onChange, placeholder, isClearable, isLoading, isDisabled, isSearchable, noOptionsMessage, error, placement, boldLabel, reserveErrorLine, note, maxVisibleItems, id, ...restProps }: SelectProps): JSX.Element;
|
|
6
6
|
propTypes: {
|
|
7
7
|
className: PropTypes.Requireable<string>;
|
|
8
8
|
style: PropTypes.Requireable<object>;
|
package/lib/select.js
CHANGED
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
4
3
|
import PropTypes from 'prop-types';
|
|
5
4
|
import { ErrorMessage } from '@rescui/form-field';
|
|
5
|
+
import cn from 'classnames';
|
|
6
|
+
import { useThemeWithUndefined } from '@rescui/ui-contexts';
|
|
6
7
|
import { optionType, optionsGroupType, noOptionsMessageType } from './common-prop-types.js';
|
|
7
|
-
import { useOptionSerialization } from './hooks/use-option-serialization.js';
|
|
8
|
-
import { convertOptions } from './utils/convert-options.js';
|
|
9
|
-
import { convertPlacement } from './utils/convert-placement.js';
|
|
10
|
-
import { getOptionValue } from './utils/get-option-value.js';
|
|
11
8
|
import { SelectBasic } from './select-basic.js';
|
|
12
9
|
import { SelectSearchable } from './select-searchable.js';
|
|
10
|
+
import styles from './styles/common.p.module.css.js';
|
|
11
|
+
const THEME_STYLES = {
|
|
12
|
+
light: styles.themeLight,
|
|
13
|
+
dark: styles.themeDark
|
|
14
|
+
};
|
|
15
|
+
const SIZE_STYLES = {
|
|
16
|
+
s: styles.sizeS,
|
|
17
|
+
m: styles.sizeM,
|
|
18
|
+
l: styles.sizeL
|
|
19
|
+
};
|
|
20
|
+
const MODE_STYLES = {
|
|
21
|
+
classic: styles.classic,
|
|
22
|
+
rock: styles.rock
|
|
23
|
+
};
|
|
13
24
|
|
|
14
25
|
const Select = _ref => {
|
|
15
26
|
let {
|
|
@@ -33,42 +44,38 @@ const Select = _ref => {
|
|
|
33
44
|
reserveErrorLine = false,
|
|
34
45
|
note,
|
|
35
46
|
maxVisibleItems = 5,
|
|
47
|
+
id,
|
|
36
48
|
...restProps
|
|
37
49
|
} = _ref;
|
|
38
50
|
const theme = useThemeWithUndefined(themeFromProps);
|
|
39
|
-
const {
|
|
40
|
-
selectedKey,
|
|
41
|
-
findOptionByKey,
|
|
42
|
-
virtualOption
|
|
43
|
-
} = useOptionSerialization(options, value);
|
|
44
|
-
|
|
45
|
-
const handleSelectionChange = key => {
|
|
46
|
-
const option = findOptionByKey(key);
|
|
47
|
-
onChange === null || onChange === void 0 || onChange(option);
|
|
48
|
-
};
|
|
49
|
-
|
|
50
51
|
const InnerSingleComponent = isSearchable ? SelectSearchable : SelectBasic;
|
|
51
|
-
return /*#__PURE__*/React.createElement(
|
|
52
|
-
isDisabled:
|
|
53
|
-
|
|
54
|
-
onChange: handleSelectionChange,
|
|
55
|
-
placeholder: placeholder,
|
|
56
|
-
isClearable: isClearable,
|
|
57
|
-
isLoading: isLoading,
|
|
58
|
-
className: className,
|
|
52
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
53
|
+
className: cn(className, styles.root, THEME_STYLES[theme], SIZE_STYLES[size], MODE_STYLES[mode], isDisabled ? styles.disabled : styles.enabled, Boolean(error) && styles.error, isSearchable && styles.searchable),
|
|
54
|
+
id: id,
|
|
59
55
|
style: style,
|
|
56
|
+
"data-test": "select"
|
|
57
|
+
}, /*#__PURE__*/React.createElement(InnerSingleComponent, { ...restProps,
|
|
58
|
+
options: options,
|
|
60
59
|
size: size,
|
|
61
60
|
mode: mode,
|
|
62
61
|
theme: theme,
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
className: className,
|
|
63
|
+
id: id,
|
|
64
|
+
style: style,
|
|
65
|
+
value: value,
|
|
66
|
+
onChange: onChange,
|
|
67
|
+
placeholder: placeholder,
|
|
68
|
+
isClearable: isClearable,
|
|
69
|
+
isLoading: isLoading,
|
|
70
|
+
isDisabled: isDisabled,
|
|
71
|
+
noOptionsMessage: noOptionsMessage,
|
|
72
|
+
error: error,
|
|
73
|
+
placement: placement,
|
|
65
74
|
boldLabel: boldLabel,
|
|
66
75
|
reserveErrorLine: reserveErrorLine,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
disabledKeys: virtualOption ? [getOptionValue(virtualOption)] : []
|
|
71
|
-
}, convertOptions(options, [virtualOption].filter(Boolean)));
|
|
76
|
+
note: note,
|
|
77
|
+
maxVisibleItems: maxVisibleItems
|
|
78
|
+
}));
|
|
72
79
|
};
|
|
73
80
|
|
|
74
81
|
Select.propTypes = {
|
|
@@ -1,27 +1,31 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"themeLight": "
|
|
3
|
-
"themeDark": "
|
|
4
|
-
"sizeS": "
|
|
5
|
-
"sizeM": "
|
|
6
|
-
"sizeL": "
|
|
7
|
-
"classic": "
|
|
8
|
-
"rock": "
|
|
9
|
-
"root": "
|
|
10
|
-
"trigger": "
|
|
11
|
-
"error": "
|
|
12
|
-
"enabled": "
|
|
13
|
-
"disabled": "
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
2
|
+
"themeLight": "_themeLight_buyj66_6",
|
|
3
|
+
"themeDark": "_themeDark_buyj66_9",
|
|
4
|
+
"sizeS": "_sizeS_buyj66_13",
|
|
5
|
+
"sizeM": "_sizeM_buyj66_16",
|
|
6
|
+
"sizeL": "_sizeL_buyj66_19",
|
|
7
|
+
"classic": "_classic_buyj66_23",
|
|
8
|
+
"rock": "_rock_buyj66_26",
|
|
9
|
+
"root": "_root_buyj66_30",
|
|
10
|
+
"trigger": "_trigger_buyj66_36",
|
|
11
|
+
"error": "_error_buyj66_70",
|
|
12
|
+
"enabled": "_enabled_buyj66_75",
|
|
13
|
+
"disabled": "_disabled_buyj66_79",
|
|
14
|
+
"searchable": "_searchable_buyj66_92",
|
|
15
|
+
"canBeMultiline": "_canBeMultiline_buyj66_119",
|
|
16
|
+
"triggerContainer": "_triggerContainer_buyj66_123",
|
|
17
|
+
"triggerText": "_triggerText_buyj66_127",
|
|
18
|
+
"searchInput": "_searchInput_buyj66_128",
|
|
19
|
+
"labelNotSelected": "_labelNotSelected_buyj66_159",
|
|
20
|
+
"multi": "_multi_buyj66_213",
|
|
21
|
+
"tagsContainer": "_tagsContainer_buyj66_230",
|
|
22
|
+
"tag": "_tag_buyj66_230",
|
|
23
|
+
"filledTag": "_filledTag_buyj66_252",
|
|
24
|
+
"iconsWrapper": "_iconsWrapper_buyj66_260",
|
|
25
|
+
"toggle": "_toggle_buyj66_278",
|
|
26
|
+
"icon": "_icon_buyj66_260",
|
|
27
|
+
"clearIcon": "_clearIcon_buyj66_352",
|
|
28
|
+
"visuallyHidden": "_visuallyHidden_buyj66_412",
|
|
29
|
+
"select": "_select_buyj66_429"
|
|
26
30
|
};
|
|
27
31
|
export { styles as default };
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"themeLight": "
|
|
3
|
-
"themeDark": "
|
|
4
|
-
"sizeS": "
|
|
5
|
-
"sizeM": "
|
|
6
|
-
"sizeL": "
|
|
7
|
-
"main": "
|
|
8
|
-
"label": "
|
|
9
|
-
"disabled": "
|
|
10
|
-
"footer": "
|
|
11
|
-
"errorMessage": "
|
|
12
|
-
"error": "
|
|
13
|
-
"note": "
|
|
2
|
+
"themeLight": "_themeLight_lyv0k_6",
|
|
3
|
+
"themeDark": "_themeDark_lyv0k_9",
|
|
4
|
+
"sizeS": "_sizeS_lyv0k_13",
|
|
5
|
+
"sizeM": "_sizeM_lyv0k_16",
|
|
6
|
+
"sizeL": "_sizeL_lyv0k_19",
|
|
7
|
+
"main": "_main_lyv0k_23",
|
|
8
|
+
"label": "_label_lyv0k_27",
|
|
9
|
+
"disabled": "_disabled_lyv0k_33",
|
|
10
|
+
"footer": "_footer_lyv0k_38",
|
|
11
|
+
"errorMessage": "_errorMessage_lyv0k_45",
|
|
12
|
+
"error": "_error_lyv0k_45",
|
|
13
|
+
"note": "_note_lyv0k_54"
|
|
14
14
|
};
|
|
15
15
|
export { styles as default };
|
|
@@ -1,16 +1,14 @@
|
|
|
1
1
|
var styles = {
|
|
2
|
-
"sizeS": "
|
|
3
|
-
"sizeM": "
|
|
4
|
-
"sizeL": "
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"divider": "_divider_xturi0_114",
|
|
14
|
-
"groupHeader": "_groupHeader_xturi0_128"
|
|
2
|
+
"sizeS": "_sizeS_tuv1by_6",
|
|
3
|
+
"sizeM": "_sizeM_tuv1by_9",
|
|
4
|
+
"sizeL": "_sizeL_tuv1by_12",
|
|
5
|
+
"listBox": "_listBox_tuv1by_16",
|
|
6
|
+
"item": "_item_tuv1by_30",
|
|
7
|
+
"selected": "_selected_tuv1by_76",
|
|
8
|
+
"disabled": "_disabled_tuv1by_87",
|
|
9
|
+
"checkIcon": "_checkIcon_tuv1by_94",
|
|
10
|
+
"visible": "_visible_tuv1by_101",
|
|
11
|
+
"divider": "_divider_tuv1by_108",
|
|
12
|
+
"groupHeader": "_groupHeader_tuv1by_122"
|
|
15
13
|
};
|
|
16
14
|
export { styles as default };
|
package/lib/types.d.ts
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import type { Theme } from '@rescui/ui-contexts';
|
|
3
|
-
import type {
|
|
4
|
-
|
|
5
|
-
import type { AriaPositionProps } from '@react-aria/overlays';
|
|
6
|
-
import type { AriaFieldProps } from '@react-aria/label';
|
|
7
|
-
import type { SelectState } from '@react-stately/select';
|
|
8
|
-
import type { ComboBoxState } from '@react-stately/combobox';
|
|
9
|
-
import type { Key } from '@react-types/shared';
|
|
10
|
-
export type { Key } from '@react-types/shared';
|
|
3
|
+
import type { UseSelectPropGetters } from 'downshift';
|
|
4
|
+
export declare type Key = string | number;
|
|
11
5
|
export declare type Placement = 'auto-start' | 'auto' | 'auto-end' | 'top-start' | 'top' | 'top-end' | 'right-start' | 'right' | 'right-end' | 'bottom-end' | 'bottom' | 'bottom-start' | 'left-end' | 'left' | 'left-start';
|
|
12
|
-
export declare type AriaPlacement = AriaPositionProps['placement'];
|
|
13
6
|
export declare type SelectSize = 'l' | 'm' | 's';
|
|
14
7
|
export declare type SelectMode = 'classic' | 'rock';
|
|
15
8
|
export declare type SelectOption = {
|
|
@@ -22,6 +15,27 @@ export declare type SelectOptionsGroup = {
|
|
|
22
15
|
};
|
|
23
16
|
export declare type SelectOptionOrGroup = SelectOption | SelectOptionsGroup;
|
|
24
17
|
export declare type SelectOptions = SelectOptionOrGroup[];
|
|
18
|
+
export declare type ListBoxOptionItem = SelectOption & {
|
|
19
|
+
index: number;
|
|
20
|
+
type: 'option';
|
|
21
|
+
key: Key;
|
|
22
|
+
disabled?: boolean;
|
|
23
|
+
};
|
|
24
|
+
export declare type ListBoxGroupItem = Omit<SelectOptionsGroup, 'options'> & {
|
|
25
|
+
options: ListBoxOptionItem[];
|
|
26
|
+
type: 'group';
|
|
27
|
+
key: Key;
|
|
28
|
+
};
|
|
29
|
+
export declare type ListBoxItem = ListBoxOptionItem | ListBoxGroupItem;
|
|
30
|
+
export declare type ListBoxItems = ListBoxItem[];
|
|
31
|
+
export declare type ListBoxState = {
|
|
32
|
+
menuProps: ReturnType<UseSelectPropGetters<SelectOption>['getMenuProps']>;
|
|
33
|
+
getItemProps: UseSelectPropGetters<SelectOption>['getItemProps'];
|
|
34
|
+
selectionMode: 'single' | 'multiple';
|
|
35
|
+
highlightedIndex: number;
|
|
36
|
+
selectedMap: Map<Key, SelectOption>;
|
|
37
|
+
menuRef?: React.RefObject<HTMLUListElement>;
|
|
38
|
+
};
|
|
25
39
|
export declare type NativeSelectOption = {
|
|
26
40
|
label: string;
|
|
27
41
|
value?: Key;
|
|
@@ -166,6 +180,7 @@ export declare type NativeSelectProps = {
|
|
|
166
180
|
placeholder?: string;
|
|
167
181
|
isLoading?: boolean;
|
|
168
182
|
isDisabled?: boolean;
|
|
183
|
+
isClearable?: boolean;
|
|
169
184
|
trigger?: (props: TriggerFuncProps) => React.ReactNode;
|
|
170
185
|
label?: React.ReactNode;
|
|
171
186
|
note?: React.ReactNode;
|
|
@@ -178,21 +193,5 @@ export declare type NativeSelectProps = {
|
|
|
178
193
|
noOptionsMessage?: NoOptionsMessage;
|
|
179
194
|
name?: string;
|
|
180
195
|
boldLabel?: boolean;
|
|
181
|
-
}
|
|
182
|
-
export declare type InnerSingleComponentProps
|
|
183
|
-
size?: SelectSize;
|
|
184
|
-
mode?: SelectMode;
|
|
185
|
-
theme?: Theme;
|
|
186
|
-
style?: React.CSSProperties;
|
|
187
|
-
className?: string;
|
|
188
|
-
isClearable?: boolean;
|
|
189
|
-
isLoading?: boolean;
|
|
190
|
-
errorMessage?: React.ReactNode;
|
|
191
|
-
placement?: AriaPlacement;
|
|
192
|
-
boldLabel?: boolean;
|
|
193
|
-
reserveErrorLine?: boolean;
|
|
194
|
-
placeholder?: string;
|
|
195
|
-
noOptionsMessage?: NoOptionsMessage;
|
|
196
|
-
maxVisibleItems?: number;
|
|
197
|
-
} & Omit<AriaSelectProps<T, 'single'> | AriaComboBoxProps<T, 'single'>, 'errorMessage' | 'validate'>;
|
|
198
|
-
export declare type CommonState<T extends object> = SelectState<T, 'single'> | SelectState<T, 'multiple'> | ComboBoxState<T>;
|
|
196
|
+
};
|
|
197
|
+
export declare type InnerSingleComponentProps = Omit<SelectProps, 'isSearchable'>;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
2
|
-
export declare const getRealItemsCnt:
|
|
1
|
+
import { ListBoxItem } from '../types';
|
|
2
|
+
export declare const getRealItemsCnt: (items: ListBoxItem[]) => number;
|
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
|
|
1
|
+
const getRealItemsCnt = items => {
|
|
2
|
+
// Count total number of items
|
|
3
|
+
return items.reduce((count, item) => {
|
|
4
|
+
if (item.type === 'group') {
|
|
5
|
+
const groupOptions = item.options;
|
|
6
|
+
const hasHeading = item.label !== null && item.label !== undefined; // Count heading (if present) + all options in the section
|
|
2
7
|
|
|
3
|
-
|
|
4
|
-
// Count total number of items, ignoring virtual items
|
|
5
|
-
return [...state.collection].reduce((count, item) => {
|
|
6
|
-
if (item.type === 'section' && item.key !== VIRTUAL_ITEMS_SECTION_KEY) {
|
|
7
|
-
const sectionChildren = [...state.collection.getChildren(item.key)];
|
|
8
|
-
const hasHeading = item.rendered !== null && item.rendered !== undefined; // Count heading (if present) + all options in the section
|
|
9
|
-
|
|
10
|
-
return count + (hasHeading ? 1 : 0) + sectionChildren.length;
|
|
8
|
+
return count + (hasHeading ? 1 : 0) + groupOptions.length;
|
|
11
9
|
}
|
|
12
10
|
|
|
13
|
-
if (item.type === '
|
|
11
|
+
if (item.type === 'option') {
|
|
14
12
|
return count + 1;
|
|
15
13
|
}
|
|
16
14
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copied from react-aria repo
|
|
3
|
+
* @see https://github.com/adobe/react-spectrum/blob/main/packages/react-aria/src/utils/mergeProps.ts
|
|
4
|
+
*/
|
|
5
|
+
import type { MutableRefObject, RefCallback } from 'react';
|
|
6
|
+
/**
|
|
7
|
+
* Merges multiple refs into one. Works with either callback or object refs.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeRefs<T>(...refs: Array<RefCallback<T> | MutableRefObject<T> | null | undefined>): RefCallback<T> | MutableRefObject<T>;
|
|
10
|
+
export declare function chain(...callbacks: any[]): (...args: any[]) => void;
|
|
11
|
+
interface Props {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
declare type PropsArg = Props | null | undefined;
|
|
15
|
+
declare type TupleTypes<T> = {
|
|
16
|
+
[P in keyof T]: T[P];
|
|
17
|
+
} extends {
|
|
18
|
+
[key: number]: infer V;
|
|
19
|
+
} ? NullToObject<V> : never;
|
|
20
|
+
declare type NullToObject<T> = T extends null | undefined ? object : T;
|
|
21
|
+
declare type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
|
|
22
|
+
/**
|
|
23
|
+
* Merges multiple props objects together. Event handlers are chained,
|
|
24
|
+
* classNames are combined, ids are deduplicated, and refs are merged.
|
|
25
|
+
* For all other props, the last prop object overrides all previous ones.
|
|
26
|
+
* @param args - Multiple sets of props to merge together.
|
|
27
|
+
*/
|
|
28
|
+
export declare function mergeProps<T extends PropsArg[]>(...args: T): UnionToIntersection<TupleTypes<T>>;
|
|
29
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import cn from 'classnames';
|
|
2
|
+
/* eslint-disable @typescript-eslint/no-explicit-any,consistent-return */
|
|
3
|
+
|
|
4
|
+
function setRef(ref, value) {
|
|
5
|
+
if (typeof ref === 'function') {
|
|
6
|
+
return ref(value);
|
|
7
|
+
} else if (ref !== null) {
|
|
8
|
+
ref.current = value;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Merges multiple refs into one. Works with either callback or object refs.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
function mergeRefs() {
|
|
17
|
+
for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
18
|
+
refs[_key] = arguments[_key];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (refs.length === 1 && refs[0]) {
|
|
22
|
+
return refs[0];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return value => {
|
|
26
|
+
let hasCleanup = false;
|
|
27
|
+
const cleanups = refs.map(ref => {
|
|
28
|
+
const cleanup = setRef(ref, value);
|
|
29
|
+
hasCleanup = hasCleanup || typeof cleanup === 'function';
|
|
30
|
+
return cleanup;
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
if (hasCleanup) {
|
|
34
|
+
return () => {
|
|
35
|
+
cleanups.forEach((cleanup, i) => {
|
|
36
|
+
if (typeof cleanup === 'function') {
|
|
37
|
+
cleanup();
|
|
38
|
+
} else {
|
|
39
|
+
setRef(refs[i], null);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function chain() {
|
|
48
|
+
for (var _len2 = arguments.length, callbacks = new Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
|
|
49
|
+
callbacks[_key2] = arguments[_key2];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return function () {
|
|
53
|
+
for (const callback of callbacks) {
|
|
54
|
+
if (typeof callback === 'function') {
|
|
55
|
+
callback(...arguments);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Merges multiple props objects together. Event handlers are chained,
|
|
62
|
+
* classNames are combined, ids are deduplicated, and refs are merged.
|
|
63
|
+
* For all other props, the last prop object overrides all previous ones.
|
|
64
|
+
* @param args - Multiple sets of props to merge together.
|
|
65
|
+
*/
|
|
66
|
+
// eslint-disable-next-line complexity
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
function mergeProps() {
|
|
70
|
+
// Start with a base clone of the first argument. This is a lot faster than starting
|
|
71
|
+
// with an empty object and adding properties as we go.
|
|
72
|
+
const result = { ...(arguments.length <= 0 ? undefined : arguments[0])
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
for (let i = 1; i < arguments.length; i++) {
|
|
76
|
+
const props = i < 0 || arguments.length <= i ? undefined : arguments[i];
|
|
77
|
+
|
|
78
|
+
for (const key in props) {
|
|
79
|
+
if (!props.hasOwnProperty(key)) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const a = result[key];
|
|
84
|
+
const b = props[key]; // Chain events
|
|
85
|
+
|
|
86
|
+
if (typeof a === 'function' && typeof b === 'function' && // This is a lot faster than a regex.
|
|
87
|
+
key[0] === 'o' && key[1] === 'n' && key.charCodeAt(2) >=
|
|
88
|
+
/* 'A' */
|
|
89
|
+
65 && key.charCodeAt(2) <=
|
|
90
|
+
/* 'Z' */
|
|
91
|
+
90) {
|
|
92
|
+
result[key] = chain(a, b); // Merge classnames, sometimes classNames are empty string which eval to false, so we just need to do a type check
|
|
93
|
+
} else if (key === 'className' && typeof a === 'string' && typeof b === 'string') {
|
|
94
|
+
result[key] = cn(a, b);
|
|
95
|
+
} else if (key === 'ref' && a && b) {
|
|
96
|
+
result.ref = mergeRefs(a, b); // Override others
|
|
97
|
+
} else {
|
|
98
|
+
result[key] = b !== undefined ? b : a;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return result;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export { chain, mergeProps, mergeRefs };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rescui/select",
|
|
3
|
-
"version": "0.15.1-RUI-280-Update-select-component-
|
|
3
|
+
"version": "0.15.1-RUI-280-Update-select-component-downshift-2f40ef205.67+2f40ef205",
|
|
4
4
|
"description": "",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "JetBrains",
|
|
@@ -16,25 +16,13 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime-corejs3": "^7.26.0",
|
|
19
|
-
"@
|
|
20
|
-
"@
|
|
21
|
-
"@
|
|
22
|
-
"@
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"@react-aria/select": "^3.18.0",
|
|
27
|
-
"@react-aria/utils": "^3.34.0",
|
|
28
|
-
"@react-stately/collections": "^3.13.0",
|
|
29
|
-
"@react-stately/combobox": "^3.14.0",
|
|
30
|
-
"@react-stately/list": "^3.14.0",
|
|
31
|
-
"@react-stately/overlays": "^3.7.0",
|
|
32
|
-
"@react-stately/select": "^3.10.0",
|
|
33
|
-
"@react-types/shared": "^3.34.0",
|
|
34
|
-
"@rescui/form-field": "0.1.1-RUI-280-Update-select-component-separate-components-e772abaa1.56+e772abaa1",
|
|
35
|
-
"@rescui/tag": "0.13.5-RUI-280-Update-select-component-separate-components-e772abaa1.56+e772abaa1",
|
|
36
|
-
"@rescui/use-resize-observer": "0.3.1-RUI-280-Update-select-component-separate-components-e772abaa1.168+e772abaa1",
|
|
37
|
-
"classnames": "^2.2.6"
|
|
19
|
+
"@rescui/dropdown": "0.9.5-RUI-280-Update-select-component-downshift-2f40ef205.67+2f40ef205",
|
|
20
|
+
"@rescui/form-field": "0.1.1-RUI-280-Update-select-component-downshift-2f40ef205.67+2f40ef205",
|
|
21
|
+
"@rescui/tag": "0.13.5-RUI-280-Update-select-component-downshift-2f40ef205.67+2f40ef205",
|
|
22
|
+
"@rescui/use-resize-observer": "0.3.1-RUI-280-Update-select-component-downshift-2f40ef205.179+2f40ef205",
|
|
23
|
+
"classnames": "^2.2.6",
|
|
24
|
+
"downshift": "^9.3.2",
|
|
25
|
+
"scroll-into-view-if-needed": "3.1.0"
|
|
38
26
|
},
|
|
39
27
|
"peerDependencies": {
|
|
40
28
|
"@rescui/ui-contexts": "^0.6.0",
|
|
@@ -42,9 +30,9 @@
|
|
|
42
30
|
"react": ">=16.8.0 <20"
|
|
43
31
|
},
|
|
44
32
|
"devDependencies": {
|
|
45
|
-
"@rescui/colors": "0.3.1-RUI-280-Update-select-component-
|
|
33
|
+
"@rescui/colors": "0.3.1-RUI-280-Update-select-component-downshift-2f40ef205.67+2f40ef205",
|
|
46
34
|
"@rescui/scripts": "0.5.1",
|
|
47
|
-
"@rescui/typography": "0.24.5-RUI-280-Update-select-component-
|
|
35
|
+
"@rescui/typography": "0.24.5-RUI-280-Update-select-component-downshift-2f40ef205.67+2f40ef205",
|
|
48
36
|
"@rescui/visual-regression": "0.1.4",
|
|
49
37
|
"sniffr": "^1.2.0"
|
|
50
38
|
},
|
|
@@ -53,5 +41,5 @@
|
|
|
53
41
|
"build-pcss-api": "rescui-scripts build-pcss-api --file public-api.p.css"
|
|
54
42
|
},
|
|
55
43
|
"nx": {},
|
|
56
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "2f40ef205f94c200019ec963e3fd0ca47fe1cdcb"
|
|
57
45
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { type Theme } from '@rescui/ui-contexts';
|
|
3
|
-
import type { SelectSize } from '../types';
|
|
4
|
-
export declare type useCssContextTransferArgs = {
|
|
5
|
-
triggerRef: React.RefObject<HTMLElement>;
|
|
6
|
-
isOpen: boolean;
|
|
7
|
-
themeFromProps: Theme;
|
|
8
|
-
sizeFromProps: SelectSize;
|
|
9
|
-
};
|
|
10
|
-
export declare const useCssContextTransfer: ({ triggerRef, isOpen, themeFromProps, sizeFromProps }: useCssContextTransferArgs) => {
|
|
11
|
-
size: SelectSize;
|
|
12
|
-
theme: Theme;
|
|
13
|
-
primaryColors: Record<string, string>;
|
|
14
|
-
};
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import _includesInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/includes";
|
|
2
|
-
import { useContext } from 'react';
|
|
3
|
-
import { ThemeContext } from '@rescui/ui-contexts';
|
|
4
|
-
import { extractThemeFromCss, extractPrimaryColors } from '../utils/css-vars-utils.js';
|
|
5
|
-
|
|
6
|
-
const useCssContextTransfer = _ref => {
|
|
7
|
-
let {
|
|
8
|
-
triggerRef,
|
|
9
|
-
isOpen,
|
|
10
|
-
themeFromProps,
|
|
11
|
-
sizeFromProps
|
|
12
|
-
} = _ref;
|
|
13
|
-
let sizeFromCss = null;
|
|
14
|
-
let themeFromCss = 'light';
|
|
15
|
-
let primaryColors = {};
|
|
16
|
-
|
|
17
|
-
if (triggerRef.current && isOpen) {
|
|
18
|
-
var _context;
|
|
19
|
-
|
|
20
|
-
const triggerFormWrapperStyles = getComputedStyle(triggerRef.current);
|
|
21
|
-
const rawSizeFromCss = triggerFormWrapperStyles.getPropertyValue('--_rs-select-size');
|
|
22
|
-
sizeFromCss = _includesInstanceProperty(_context = ['s', 'm', 'l']).call(_context, rawSizeFromCss) ? rawSizeFromCss : null;
|
|
23
|
-
themeFromCss = extractThemeFromCss(triggerFormWrapperStyles);
|
|
24
|
-
primaryColors = extractPrimaryColors(triggerFormWrapperStyles);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
const size = sizeFromCss || sizeFromProps;
|
|
28
|
-
const {
|
|
29
|
-
theme: themeFromContext,
|
|
30
|
-
noProvider
|
|
31
|
-
} = useContext(ThemeContext);
|
|
32
|
-
const theme = themeFromProps || (noProvider ? themeFromCss : themeFromContext);
|
|
33
|
-
return {
|
|
34
|
-
size,
|
|
35
|
-
theme,
|
|
36
|
-
primaryColors
|
|
37
|
-
};
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export { useCssContextTransfer };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { SelectOption, SelectOptionOrGroup, Key } from '../types';
|
|
2
|
-
export declare function useMultiOptionSerialization(options: SelectOptionOrGroup[], value?: SelectOption[] | null): {
|
|
3
|
-
optionsMap: Map<Key, {
|
|
4
|
-
option: SelectOption;
|
|
5
|
-
isVirtual: boolean;
|
|
6
|
-
}>;
|
|
7
|
-
selectedKeys: Key[];
|
|
8
|
-
findOptionsByKeys: (keys: Key[]) => SelectOption[];
|
|
9
|
-
virtualOptions: SelectOption[];
|
|
10
|
-
};
|