@rescui/select 0.15.1-RUI-280-Update-select-component-e516591ed.54 → 0.15.1-RUI-280-Update-select-component-downshift-cd2a98813.66
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-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 +323 -371
- package/lib/multiselect.d.ts +3 -29
- package/lib/multiselect.js +249 -171
- package/lib/native-select.js +67 -44
- package/lib/parts/hidden-select.d.ts +13 -0
- package/lib/parts/hidden-select.js +45 -0
- package/lib/parts/icons.d.ts +3 -1
- package/lib/parts/icons.js +11 -14
- package/lib/parts/list-box.d.ts +7 -15
- package/lib/parts/list-box.js +50 -80
- package/lib/parts/multi-trigger.d.ts +5 -4
- package/lib/parts/multi-trigger.js +27 -15
- package/lib/parts/native-select-trigger.d.ts +6 -8
- package/lib/parts/native-select-trigger.js +14 -23
- package/lib/select-basic.d.ts +2 -2
- package/lib/select-basic.js +162 -95
- package/lib/select-searchable.d.ts +2 -2
- package/lib/select-searchable.js +209 -119
- package/lib/select.d.ts +1 -1
- package/lib/select.js +38 -31
- package/lib/styles/common.p.module.css.js +25 -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/styles/native-select-trigger.p.module.css.js +15 -14
- package/lib/styles/native-select.p.module.css.js +6 -6
- package/lib/types.d.ts +26 -26
- 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 +12 -8
- 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/popover.d.ts +0 -12
- package/lib/parts/popover.js +0 -62
- package/lib/parts/popup-content.d.ts +0 -19
- package/lib/parts/popup-content.js +0 -76
- 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
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { SelectOption } from '../types';
|
|
3
|
+
export declare type HiddenSelectProps = {
|
|
4
|
+
name?: string;
|
|
5
|
+
options: SelectOption[];
|
|
6
|
+
} & ({
|
|
7
|
+
value: SelectOption[];
|
|
8
|
+
isMultiple: true;
|
|
9
|
+
} | {
|
|
10
|
+
value: SelectOption;
|
|
11
|
+
isMultiple: false;
|
|
12
|
+
});
|
|
13
|
+
export declare const HiddenSelect: ({ name, options, value, isMultiple }: HiddenSelectProps) => JSX.Element;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import styles from '../styles/common.p.module.css.js';
|
|
3
|
+
|
|
4
|
+
const HiddenSelect = _ref => {
|
|
5
|
+
let {
|
|
6
|
+
name,
|
|
7
|
+
options,
|
|
8
|
+
value,
|
|
9
|
+
isMultiple
|
|
10
|
+
} = _ref;
|
|
11
|
+
const selectProps = {
|
|
12
|
+
name,
|
|
13
|
+
'aria-hidden': true,
|
|
14
|
+
readOnly: true,
|
|
15
|
+
tabIndex: -1
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
if (isMultiple) {
|
|
19
|
+
selectProps.multiple = true;
|
|
20
|
+
|
|
21
|
+
if (value && value.length !== 0) {
|
|
22
|
+
selectProps.value = value.map(v => String(v.value));
|
|
23
|
+
}
|
|
24
|
+
} else if (value) {
|
|
25
|
+
const singleValue = value;
|
|
26
|
+
selectProps.value = singleValue.value;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const arrayValue = isMultiple ? value : [value]; // merge options with value in case the provided value is not included in options
|
|
30
|
+
|
|
31
|
+
const allItems = Array.from( // map will deduplicate options by values
|
|
32
|
+
new Map((!value ? options : [...options, ...arrayValue]).map(item => [item.value, item])).values());
|
|
33
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
34
|
+
className: styles.hiddenSelect
|
|
35
|
+
}, /*#__PURE__*/React.createElement("select", { ...selectProps
|
|
36
|
+
}, /*#__PURE__*/React.createElement("option", {
|
|
37
|
+
value: "",
|
|
38
|
+
label: '\u00A0'
|
|
39
|
+
}, '\u00A0'), allItems.map(option => /*#__PURE__*/React.createElement("option", {
|
|
40
|
+
key: option.value,
|
|
41
|
+
value: option.value
|
|
42
|
+
}, option.label))));
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export { HiddenSelect };
|
package/lib/parts/icons.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ declare type ClearOrLoadingProps = {
|
|
|
5
5
|
onClearClick: () => void;
|
|
6
6
|
triggerId?: string;
|
|
7
7
|
className?: string;
|
|
8
|
+
customStylesMap?: Record<string, string>;
|
|
8
9
|
};
|
|
9
10
|
export declare const ClearOrLoading: React.FC<ClearOrLoadingProps>;
|
|
10
11
|
export declare type IconsProps = {
|
|
@@ -12,6 +13,7 @@ export declare type IconsProps = {
|
|
|
12
13
|
canHaveClearIcon?: boolean;
|
|
13
14
|
onClear?: () => void;
|
|
14
15
|
triggerId?: string;
|
|
16
|
+
customStylesMap?: Record<string, string>;
|
|
15
17
|
};
|
|
16
|
-
export declare const Icons: ({ isLoading, canHaveClearIcon, onClear, triggerId }: IconsProps) => JSX.Element;
|
|
18
|
+
export declare const Icons: ({ isLoading, canHaveClearIcon, onClear, triggerId, customStylesMap: styles }: IconsProps) => JSX.Element;
|
|
17
19
|
export {};
|
package/lib/parts/icons.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
-
import { useFocusRing } from 'react-aria';
|
|
4
3
|
import CloseOutlineIcon from '../_virtual/close-outline.js';
|
|
5
4
|
import LoadingOutlineIcon from '../_virtual/loading-outline.js';
|
|
6
5
|
import DownOutlineIcon from '../_virtual/down-outline.js';
|
|
@@ -12,26 +11,23 @@ const ClearOrLoading = _ref => {
|
|
|
12
11
|
canHaveClearIcon,
|
|
13
12
|
onClearClick,
|
|
14
13
|
triggerId,
|
|
15
|
-
className
|
|
14
|
+
className,
|
|
15
|
+
customStylesMap: styles$1 = styles
|
|
16
16
|
} = _ref;
|
|
17
|
-
const {
|
|
18
|
-
isFocusVisible,
|
|
19
|
-
focusProps
|
|
20
|
-
} = useFocusRing();
|
|
21
17
|
|
|
22
18
|
if (isLoading) {
|
|
23
19
|
return /*#__PURE__*/React.createElement(LoadingOutlineIcon, {
|
|
24
20
|
style: {
|
|
25
21
|
pointerEvents: 'none'
|
|
26
22
|
},
|
|
27
|
-
className: cn(className, styles.icon),
|
|
23
|
+
className: cn(className, styles$1.icon),
|
|
28
24
|
"data-test": "loading-icon",
|
|
29
25
|
"data-render-all-sizes": true
|
|
30
26
|
});
|
|
31
27
|
} else if (canHaveClearIcon) {
|
|
32
28
|
return /*#__PURE__*/React.createElement("button", {
|
|
33
29
|
type: "button",
|
|
34
|
-
className: cn(className, styles.icon, styles.clearIcon
|
|
30
|
+
className: cn(className, styles$1.icon, styles$1.clearIcon),
|
|
35
31
|
"data-test": "clear-icon",
|
|
36
32
|
onClick: e => {
|
|
37
33
|
e.stopPropagation();
|
|
@@ -41,8 +37,7 @@ const ClearOrLoading = _ref => {
|
|
|
41
37
|
onMouseDown: e => e.stopPropagation(),
|
|
42
38
|
onKeyDown: e => e.stopPropagation(),
|
|
43
39
|
"aria-label": "Clear",
|
|
44
|
-
"aria-controls": triggerId
|
|
45
|
-
...focusProps
|
|
40
|
+
"aria-controls": triggerId
|
|
46
41
|
}, /*#__PURE__*/React.createElement(CloseOutlineIcon, {
|
|
47
42
|
"data-render-all-sizes": true
|
|
48
43
|
}));
|
|
@@ -56,17 +51,19 @@ const Icons = _ref2 => {
|
|
|
56
51
|
isLoading,
|
|
57
52
|
canHaveClearIcon,
|
|
58
53
|
onClear,
|
|
59
|
-
triggerId
|
|
54
|
+
triggerId,
|
|
55
|
+
customStylesMap: styles$1 = styles
|
|
60
56
|
} = _ref2;
|
|
61
57
|
return /*#__PURE__*/React.createElement("div", {
|
|
62
|
-
className: styles.iconsWrapper
|
|
58
|
+
className: styles$1.iconsWrapper
|
|
63
59
|
}, /*#__PURE__*/React.createElement(ClearOrLoading, {
|
|
64
60
|
isLoading: isLoading,
|
|
65
61
|
canHaveClearIcon: canHaveClearIcon,
|
|
66
62
|
onClearClick: onClear,
|
|
67
|
-
triggerId: triggerId
|
|
63
|
+
triggerId: triggerId,
|
|
64
|
+
customStylesMap: styles$1
|
|
68
65
|
}), /*#__PURE__*/React.createElement(DownOutlineIcon, {
|
|
69
|
-
className: styles.toggle,
|
|
66
|
+
className: styles$1.toggle,
|
|
70
67
|
"data-test": "toggle-icon",
|
|
71
68
|
"data-render-all-sizes": true
|
|
72
69
|
}));
|
package/lib/parts/list-box.d.ts
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
listBoxRef?: React.RefObject<HTMLUListElement>;
|
|
7
|
-
state: ListState<T>;
|
|
8
|
-
ariaListBoxProps?: AriaListBoxOptions<T>;
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SelectSize, ListBoxItem, ListBoxState } from '../types';
|
|
3
|
+
export declare type ListBoxProps = {
|
|
4
|
+
state: ListBoxState;
|
|
5
|
+
items: ListBoxItem[];
|
|
9
6
|
size?: SelectSize;
|
|
10
|
-
mode?: SelectMode;
|
|
11
7
|
className?: string;
|
|
12
8
|
maxVisibleItems?: number;
|
|
13
|
-
selectionMode?: 'single' | 'multiple';
|
|
14
|
-
};
|
|
15
|
-
export declare function ListBox<T extends object>({ listBoxRef: listBoxRefFromProps, state, ariaListBoxProps, size, mode, maxVisibleItems, selectionMode }: ListBoxProps<T>): JSX.Element;
|
|
16
|
-
export declare type EmptyListBoxProps<T extends object> = {
|
|
17
9
|
emptyListMessage: string;
|
|
18
|
-
}
|
|
19
|
-
export declare
|
|
10
|
+
};
|
|
11
|
+
export declare function ListBox({ state, items, size, maxVisibleItems, emptyListMessage }: ListBoxProps): JSX.Element;
|
package/lib/parts/list-box.js
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import React, { useRef } from 'react';
|
|
2
2
|
import cn from 'classnames';
|
|
3
|
-
import { useListState, Item } from 'react-stately';
|
|
4
|
-
import { useListBox, useOption, mergeProps, useListBoxSection } from 'react-aria';
|
|
5
3
|
import styles from '../styles/list-box.p.module.css.js';
|
|
6
4
|
import { calculateMaxHeightByItems } from '../utils/calculate-max-height-by-items.js';
|
|
7
5
|
import { getRealItemsCnt } from '../utils/get-real-items-cnt.js';
|
|
8
|
-
import {
|
|
6
|
+
import { getTextFromNodes } from '../utils/get-text-from-nodes.js';
|
|
9
7
|
import CheckOutlineIcon from '../_virtual/check-outline.js';
|
|
10
|
-
const MODE_STYLES = {
|
|
11
|
-
classic: styles.modeClassic,
|
|
12
|
-
rock: styles.modeRock
|
|
13
|
-
};
|
|
14
8
|
const SIZE_STYLES = {
|
|
15
9
|
s: styles.sizeS,
|
|
16
10
|
m: styles.sizeM,
|
|
@@ -20,66 +14,65 @@ const SIZE_STYLES = {
|
|
|
20
14
|
function Option(_ref) {
|
|
21
15
|
let {
|
|
22
16
|
item,
|
|
23
|
-
state
|
|
24
|
-
selectionMode
|
|
17
|
+
state
|
|
25
18
|
} = _ref;
|
|
26
19
|
// Get props for the option element
|
|
27
20
|
const ref = useRef(null);
|
|
28
21
|
const {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
} =
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
selectedMap,
|
|
23
|
+
selectionMode,
|
|
24
|
+
getItemProps,
|
|
25
|
+
highlightedIndex
|
|
26
|
+
} = state;
|
|
27
|
+
const index = item.index;
|
|
28
|
+
const isSelected = selectedMap.has(item.key);
|
|
29
|
+
const isHighlighted = highlightedIndex === item.index;
|
|
30
|
+
const isDisabled = item.disabled;
|
|
31
|
+
return /*#__PURE__*/React.createElement("li", { ...getItemProps({
|
|
32
|
+
item,
|
|
33
|
+
index,
|
|
34
|
+
'aria-selected': isSelected,
|
|
35
|
+
'tab-index': isHighlighted ? 0 : -1,
|
|
36
|
+
ref
|
|
37
|
+
}),
|
|
38
38
|
className: cn(styles.item, isSelected && styles.selected, isDisabled && styles.disabled),
|
|
39
39
|
"data-rs-internal": "select-list-box__item",
|
|
40
|
-
"data-focused":
|
|
40
|
+
"data-focused": isHighlighted,
|
|
41
41
|
"data-test": `select-options-list__item_${item.key}`
|
|
42
|
-
}, /*#__PURE__*/React.createElement("span", null, item.
|
|
42
|
+
}, /*#__PURE__*/React.createElement("span", null, item.label), selectionMode === 'multiple' && /*#__PURE__*/React.createElement(CheckOutlineIcon, {
|
|
43
43
|
"data-rs-internal": "select-list-box__check-icon",
|
|
44
44
|
className: cn(styles.checkIcon, isSelected && styles.visible)
|
|
45
45
|
}));
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
function
|
|
48
|
+
function ListBoxGroup(_ref2) {
|
|
49
49
|
let {
|
|
50
|
-
|
|
51
|
-
state,
|
|
50
|
+
item,
|
|
52
51
|
isFirst,
|
|
53
|
-
|
|
52
|
+
state
|
|
54
53
|
} = _ref2;
|
|
55
|
-
const
|
|
56
|
-
itemProps,
|
|
57
|
-
headingProps,
|
|
58
|
-
groupProps
|
|
59
|
-
} = useListBoxSection({
|
|
60
|
-
heading: section.rendered,
|
|
61
|
-
'aria-label': section['aria-label']
|
|
62
|
-
});
|
|
63
|
-
const hasHeading = section.rendered !== null && section.rendered !== undefined;
|
|
54
|
+
const hasHeading = item.label !== null && item.label !== undefined;
|
|
64
55
|
const hasDivider = !isFirst && !hasHeading; // If the section is not the first, add a divider for visual separation
|
|
65
56
|
|
|
66
57
|
return /*#__PURE__*/React.createElement(React.Fragment, null, hasDivider && /*#__PURE__*/React.createElement("hr", {
|
|
67
58
|
className: styles.divider
|
|
68
|
-
}), /*#__PURE__*/React.createElement("li", {
|
|
59
|
+
}), /*#__PURE__*/React.createElement("li", {
|
|
60
|
+
role: "presentation"
|
|
69
61
|
}, hasHeading && /*#__PURE__*/React.createElement("span", {
|
|
70
62
|
className: styles.groupHeader,
|
|
71
|
-
|
|
63
|
+
role: "presentation",
|
|
72
64
|
"data-rs-internal": "select-list-box__group-header"
|
|
73
|
-
},
|
|
65
|
+
}, item.label), /*#__PURE__*/React.createElement("ul", {
|
|
66
|
+
role: "group",
|
|
67
|
+
"aria-label": hasHeading ? getTextFromNodes(item.label) : undefined,
|
|
74
68
|
style: {
|
|
75
69
|
padding: 0,
|
|
76
70
|
listStyle: 'none'
|
|
77
71
|
}
|
|
78
|
-
},
|
|
79
|
-
key:
|
|
80
|
-
item:
|
|
81
|
-
state: state
|
|
82
|
-
selectionMode: selectionMode
|
|
72
|
+
}, item.options.map(option => /*#__PURE__*/React.createElement(Option, {
|
|
73
|
+
key: option.key,
|
|
74
|
+
item: option,
|
|
75
|
+
state: state
|
|
83
76
|
})))));
|
|
84
77
|
}
|
|
85
78
|
|
|
@@ -87,60 +80,37 @@ function ListBox(_ref3) {
|
|
|
87
80
|
var _items$find;
|
|
88
81
|
|
|
89
82
|
let {
|
|
90
|
-
listBoxRef: listBoxRefFromProps,
|
|
91
83
|
state,
|
|
92
|
-
|
|
84
|
+
items,
|
|
93
85
|
size,
|
|
94
|
-
mode,
|
|
95
86
|
maxVisibleItems = 5,
|
|
96
|
-
|
|
87
|
+
emptyListMessage
|
|
97
88
|
} = _ref3;
|
|
98
|
-
const ref = useRef(null);
|
|
99
|
-
const listBoxRef = listBoxRefFromProps ?? ref;
|
|
100
89
|
const {
|
|
101
|
-
|
|
102
|
-
} =
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
className: cn(styles.listBox, MODE_STYLES[mode], SIZE_STYLES[size]),
|
|
108
|
-
ref: listBoxRef,
|
|
90
|
+
menuProps
|
|
91
|
+
} = state;
|
|
92
|
+
const firstGroupKey = (_items$find = items.find(item => item.type === 'group')) === null || _items$find === void 0 ? void 0 : _items$find.key;
|
|
93
|
+
const itemsCount = getRealItemsCnt(items);
|
|
94
|
+
return /*#__PURE__*/React.createElement("ul", { ...menuProps,
|
|
95
|
+
className: cn(styles.listBox, SIZE_STYLES[size]),
|
|
109
96
|
style: {
|
|
110
97
|
'--_rs-select-list-box-max-height-by-items': calculateMaxHeightByItems(itemsCount, maxVisibleItems)
|
|
111
98
|
},
|
|
112
99
|
"data-rs-internal": "select-list-box",
|
|
113
100
|
"data-test": "select-options-list"
|
|
114
|
-
},
|
|
101
|
+
}, itemsCount === 0 ? /*#__PURE__*/React.createElement("li", {
|
|
102
|
+
className: cn(styles.item, styles.disabled),
|
|
103
|
+
"data-rs-internal": "select-list-box__item"
|
|
104
|
+
}, /*#__PURE__*/React.createElement("span", null, emptyListMessage)) : items.map(item => item.type === 'group' ? /*#__PURE__*/React.createElement(ListBoxGroup, {
|
|
115
105
|
key: item.key,
|
|
116
|
-
|
|
106
|
+
item: item,
|
|
117
107
|
state: state,
|
|
118
|
-
isFirst: item.key ===
|
|
119
|
-
selectionMode: selectionMode
|
|
108
|
+
isFirst: item.key === firstGroupKey
|
|
120
109
|
}) : /*#__PURE__*/React.createElement(Option, {
|
|
121
110
|
key: item.key,
|
|
122
111
|
item: item,
|
|
123
|
-
state: state
|
|
124
|
-
selectionMode: selectionMode
|
|
112
|
+
state: state
|
|
125
113
|
})));
|
|
126
114
|
}
|
|
127
115
|
|
|
128
|
-
|
|
129
|
-
let {
|
|
130
|
-
emptyListMessage,
|
|
131
|
-
...props
|
|
132
|
-
} = _ref4;
|
|
133
|
-
const emptyListState = useListState({
|
|
134
|
-
children: [/*#__PURE__*/React.createElement(Item, {
|
|
135
|
-
key: "no-results",
|
|
136
|
-
textValue: emptyListMessage
|
|
137
|
-
}, emptyListMessage)],
|
|
138
|
-
disabledKeys: ['no-results'],
|
|
139
|
-
selectionMode: 'none'
|
|
140
|
-
});
|
|
141
|
-
return /*#__PURE__*/React.createElement(ListBox, { ...props,
|
|
142
|
-
state: emptyListState
|
|
143
|
-
});
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
export { EmptyListBox, ListBox };
|
|
116
|
+
export { ListBox };
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import type {
|
|
3
|
-
export interface MultiTriggerProps
|
|
4
|
-
|
|
2
|
+
import type { SelectOption } from '../types';
|
|
3
|
+
export interface MultiTriggerProps {
|
|
4
|
+
selectedItems: SelectOption[];
|
|
5
|
+
removeSelectedItem: (item: SelectOption) => void;
|
|
5
6
|
valueProps: object;
|
|
6
7
|
isSingleLine: boolean;
|
|
7
8
|
isDisabled: boolean;
|
|
8
9
|
placeholder?: string;
|
|
9
10
|
triggerRef?: React.RefObject<HTMLDivElement>;
|
|
10
11
|
}
|
|
11
|
-
export declare function MultiTrigger
|
|
12
|
+
export declare function MultiTrigger({ selectedItems, valueProps, isSingleLine, isDisabled, placeholder, triggerRef, removeSelectedItem }: MultiTriggerProps): JSX.Element;
|
|
@@ -3,18 +3,20 @@ import cn from 'classnames';
|
|
|
3
3
|
import { RemovableTag, Tag } from '@rescui/tag';
|
|
4
4
|
import styles from '../styles/common.p.module.css.js';
|
|
5
5
|
import { getTextFromNodes } from '../utils/get-text-from-nodes.js';
|
|
6
|
+
import { getOptionValue } from '../utils/get-option-value.js';
|
|
6
7
|
import Foldable from './foldable.js';
|
|
7
8
|
|
|
8
9
|
function MultiTrigger(_ref) {
|
|
9
10
|
let {
|
|
10
|
-
|
|
11
|
+
selectedItems,
|
|
11
12
|
valueProps,
|
|
12
13
|
isSingleLine,
|
|
13
14
|
isDisabled,
|
|
14
15
|
placeholder,
|
|
15
|
-
triggerRef
|
|
16
|
+
triggerRef,
|
|
17
|
+
removeSelectedItem
|
|
16
18
|
} = _ref;
|
|
17
|
-
const hasValue =
|
|
19
|
+
const hasValue = selectedItems.length > 0;
|
|
18
20
|
|
|
19
21
|
if (!hasValue) {
|
|
20
22
|
return /*#__PURE__*/React.createElement("div", { ...valueProps,
|
|
@@ -23,25 +25,35 @@ function MultiTrigger(_ref) {
|
|
|
23
25
|
}, placeholder);
|
|
24
26
|
}
|
|
25
27
|
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
state.setValue([...state.selectedItems].map(item => item.key).filter(itemKey => itemKey !== key));
|
|
30
|
-
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus();
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
const tags = [...state.selectedItems].map(item => {
|
|
34
|
-
const key = item.key;
|
|
28
|
+
const tags = selectedItems.map(option => {
|
|
29
|
+
const key = getOptionValue(option);
|
|
35
30
|
return /*#__PURE__*/React.createElement(RemovableTag, {
|
|
36
31
|
key: key,
|
|
32
|
+
tabIndex: -1,
|
|
37
33
|
"data-test": `selected-tag-${key}`,
|
|
38
34
|
className: styles.tag,
|
|
39
35
|
disabled: isDisabled,
|
|
40
|
-
onRemoveClick: () =>
|
|
36
|
+
onRemoveClick: () => {
|
|
37
|
+
var _triggerRef$current;
|
|
38
|
+
|
|
39
|
+
removeSelectedItem(option);
|
|
40
|
+
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus({
|
|
41
|
+
focusVisible: false
|
|
42
|
+
});
|
|
43
|
+
},
|
|
41
44
|
"data-rs-internal": "select-trigger__removable-tag",
|
|
42
45
|
wrap: !isSingleLine,
|
|
43
|
-
"aria-label": getTextFromNodes(
|
|
44
|
-
|
|
46
|
+
"aria-label": getTextFromNodes(option.label),
|
|
47
|
+
onFocus: e => {
|
|
48
|
+
if (e.target.getAttribute('tabindex') === '-1') {
|
|
49
|
+
var _triggerRef$current2;
|
|
50
|
+
|
|
51
|
+
(_triggerRef$current2 = triggerRef.current) === null || _triggerRef$current2 === void 0 || _triggerRef$current2.focus({
|
|
52
|
+
focusVisible: false
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}, option.label);
|
|
45
57
|
});
|
|
46
58
|
return /*#__PURE__*/React.createElement("div", { ...valueProps,
|
|
47
59
|
className: styles.multi,
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import type { Theme } from '@rescui/ui-contexts';
|
|
3
|
-
import {
|
|
3
|
+
import { NativeSelectOption, SelectSize } from '../types';
|
|
4
4
|
export declare type NativeSelectDefaultTriggerProps = {
|
|
5
|
-
isFocused: boolean;
|
|
6
|
-
isHovered: boolean;
|
|
7
5
|
isLoading: boolean;
|
|
8
6
|
isDisabled: boolean;
|
|
7
|
+
isClearable: boolean;
|
|
9
8
|
size: SelectSize;
|
|
10
9
|
theme?: Theme;
|
|
11
10
|
hasError: boolean;
|
|
12
11
|
placeholder?: string;
|
|
13
|
-
value:
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
12
|
+
value: NativeSelectOption;
|
|
13
|
+
onClear?: () => void;
|
|
14
|
+
triggerId?: string;
|
|
17
15
|
};
|
|
18
|
-
export declare const NativeSelectTrigger: ({
|
|
16
|
+
export declare const NativeSelectTrigger: ({ isLoading, isDisabled, isClearable, hasError, size, theme, placeholder, value, onClear, triggerId }: NativeSelectDefaultTriggerProps) => JSX.Element;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import cn from 'classnames';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import LoadingOutlineIcon from '../_virtual/loading-outline.js';
|
|
4
|
-
import DownOutlineIcon from '../_virtual/down-outline.js';
|
|
5
3
|
import styles from '../styles/native-select-trigger.p.module.css.js';
|
|
4
|
+
import { Icons } from './icons.js';
|
|
6
5
|
const SIZE_STYLES = {
|
|
7
6
|
s: styles.sizeS,
|
|
8
7
|
m: styles.sizeM,
|
|
@@ -15,40 +14,32 @@ const THEME_STYLES = {
|
|
|
15
14
|
|
|
16
15
|
const NativeSelectTrigger = _ref => {
|
|
17
16
|
let {
|
|
18
|
-
isFocused,
|
|
19
|
-
isHovered,
|
|
20
17
|
isLoading,
|
|
21
18
|
isDisabled,
|
|
19
|
+
isClearable,
|
|
22
20
|
hasError,
|
|
23
21
|
size,
|
|
24
22
|
theme,
|
|
25
23
|
placeholder,
|
|
26
|
-
value
|
|
24
|
+
value,
|
|
25
|
+
onClear,
|
|
26
|
+
triggerId
|
|
27
27
|
} = _ref;
|
|
28
28
|
return /*#__PURE__*/React.createElement("div", {
|
|
29
|
-
"aria-hidden": "true",
|
|
30
29
|
className: cn(styles.trigger, SIZE_STYLES[size], THEME_STYLES[theme], isDisabled ? styles.disabled : styles.enabled, hasError && styles.error),
|
|
31
|
-
"data-focused": isFocused,
|
|
32
|
-
"data-hovered": isHovered,
|
|
33
30
|
"data-test": 'native-select_trigger',
|
|
34
31
|
"data-rs-internal": 'select-native-trigger'
|
|
35
32
|
}, /*#__PURE__*/React.createElement("span", {
|
|
36
33
|
className: cn(styles.triggerText, !(value !== null && value !== void 0 && value.value) && styles.labelNotSelected),
|
|
37
|
-
"data-test": 'native-select_trigger_text'
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"data-render-all-sizes": true
|
|
47
|
-
}), /*#__PURE__*/React.createElement(DownOutlineIcon, {
|
|
48
|
-
className: styles.toggle,
|
|
49
|
-
"data-test": "down-icon",
|
|
50
|
-
"data-render-all-sizes": true
|
|
51
|
-
})));
|
|
34
|
+
"data-test": 'native-select_trigger_text',
|
|
35
|
+
"aria-hidden": "true"
|
|
36
|
+
}, (value === null || value === void 0 ? void 0 : value.label) ?? placeholder), /*#__PURE__*/React.createElement(Icons, {
|
|
37
|
+
isLoading: isLoading,
|
|
38
|
+
triggerId: triggerId,
|
|
39
|
+
onClear: onClear,
|
|
40
|
+
canHaveClearIcon: isClearable && !isDisabled && Boolean(value === null || value === void 0 ? void 0 : value.value),
|
|
41
|
+
customStylesMap: styles
|
|
42
|
+
}));
|
|
52
43
|
};
|
|
53
44
|
|
|
54
45
|
export { NativeSelectTrigger };
|
package/lib/select-basic.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import
|
|
3
|
-
export declare function SelectBasic
|
|
2
|
+
import { InnerSingleComponentProps } from './types';
|
|
3
|
+
export declare function SelectBasic({ options, value: selectedItem, onChange, error, label, note, size, mode, theme, placement, boldLabel, reserveErrorLine, maxVisibleItems, isClearable, isLoading, isDisabled, name, noOptionsMessage, className, id, style, placeholder, ...rest }: InnerSingleComponentProps): JSX.Element;
|