@rescui/select 0.15.1-RUI-280-Update-select-component-downshift-2f40ef205.67 → 0.15.2
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/common-prop-types.d.ts +14 -9
- package/lib/common-prop-types.js +3 -4
- package/lib/index.css +432 -808
- package/lib/index.d.ts +6 -4
- package/lib/index.js +3 -3
- package/lib/key-codes.d.ts +7 -0
- package/lib/key-codes.js +8 -0
- package/lib/parts/common-select.p.module.css.js +15 -0
- package/lib/parts/foldable.js +2 -1
- package/lib/parts/form-trigger-wrapper.d.ts +7 -7
- package/lib/parts/form-trigger-wrapper.js +34 -16
- package/lib/parts/form-trigger.p.module.css.js +15 -0
- package/lib/parts/multiselect.d.ts +86 -0
- package/lib/parts/multiselect.js +455 -0
- package/lib/parts/native-select.d.ts +36 -0
- package/lib/parts/native-select.js +255 -0
- package/lib/parts/native-select.p.module.css.js +9 -0
- package/lib/parts/throttle.d.ts +1 -0
- package/lib/parts/trigger.d.ts +37 -0
- package/lib/parts/trigger.js +255 -0
- package/lib/parts/trigger.p.module.css.js +31 -0
- package/lib/parts/use-observable-force-rerender.d.ts +2 -0
- package/lib/parts/use-observable-force-rerender.js +16 -0
- package/lib/public-api.p.css +309 -545
- package/lib/public-api.pcss +309 -545
- package/lib/select.d.ts +91 -27
- package/lib/select.js +351 -51
- package/lib/types.d.ts +4 -167
- package/lib/utils.d.ts +22 -0
- package/lib/utils.js +199 -0
- package/package.json +12 -12
- package/lib/constants.d.ts +0 -6
- package/lib/constants.js +0 -7
- package/lib/hooks/use-a11y.d.ts +0 -29
- package/lib/hooks/use-a11y.js +0 -53
- package/lib/hooks/use-focus.d.ts +0 -10
- package/lib/hooks/use-focus.js +0 -17
- package/lib/hooks/use-hover.d.ts +0 -10
- package/lib/hooks/use-hover.js +0 -17
- package/lib/hooks/use-label-focus.d.ts +0 -9
- package/lib/hooks/use-label-focus.js +0 -22
- package/lib/hooks/use-multi-handlers.d.ts +0 -11
- package/lib/hooks/use-multi-handlers.js +0 -48
- package/lib/hooks/use-options.d.ts +0 -13
- package/lib/hooks/use-options.js +0 -89
- package/lib/multiselect.d.ts +0 -3
- package/lib/multiselect.js +0 -312
- package/lib/native-select.d.ts +0 -4
- package/lib/native-select.js +0 -211
- package/lib/parts/hidden-select.d.ts +0 -13
- package/lib/parts/hidden-select.js +0 -45
- package/lib/parts/icons.d.ts +0 -17
- package/lib/parts/icons.js +0 -69
- package/lib/parts/list-box.d.ts +0 -11
- package/lib/parts/list-box.js +0 -116
- package/lib/parts/multi-trigger.d.ts +0 -12
- package/lib/parts/multi-trigger.js +0 -74
- package/lib/parts/native-select-options-with-groups.d.ts +0 -8
- package/lib/parts/native-select-options-with-groups.js +0 -76
- package/lib/select-basic.d.ts +0 -3
- package/lib/select-basic.js +0 -203
- package/lib/select-searchable.d.ts +0 -3
- package/lib/select-searchable.js +0 -250
- package/lib/styles/common.p.module.css.js +0 -31
- package/lib/styles/form-trigger.p.module.css.js +0 -15
- package/lib/styles/list-box.p.module.css.js +0 -14
- package/lib/utils/calculate-max-height-by-items.d.ts +0 -13
- package/lib/utils/calculate-max-height-by-items.js +0 -22
- package/lib/utils/get-empty-message.d.ts +0 -6
- package/lib/utils/get-empty-message.js +0 -32
- package/lib/utils/get-option-value.d.ts +0 -2
- package/lib/utils/get-option-value.js +0 -11
- package/lib/utils/get-real-items-cnt.d.ts +0 -2
- package/lib/utils/get-real-items-cnt.js +0 -19
- package/lib/utils/get-text-from-nodes.d.ts +0 -2
- package/lib/utils/get-text-from-nodes.js +0 -28
- package/lib/utils/is-option-a-group.d.ts +0 -2
- package/lib/utils/is-option-a-group.js +0 -5
- package/lib/utils/item-to-string.d.ts +0 -2
- package/lib/utils/item-to-string.js +0 -7
- package/lib/utils/merge-props.d.ts +0 -29
- package/lib/utils/merge-props.js +0 -106
- package/lib/utils/throttle.d.ts +0 -1
- /package/lib/{utils → parts}/throttle.js +0 -0
- /package/lib/{hooks → parts}/use-backward-compatible-id.d.ts +0 -0
- /package/lib/{hooks → parts}/use-backward-compatible-id.js +0 -0
|
@@ -1,45 +0,0 @@
|
|
|
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.visuallyHidden
|
|
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
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
declare type ClearOrLoadingProps = {
|
|
3
|
-
isLoading: boolean;
|
|
4
|
-
canHaveClearIcon: boolean;
|
|
5
|
-
onClearClick: () => void;
|
|
6
|
-
triggerId?: string;
|
|
7
|
-
className?: string;
|
|
8
|
-
};
|
|
9
|
-
export declare const ClearOrLoading: React.FC<ClearOrLoadingProps>;
|
|
10
|
-
export declare type IconsProps = {
|
|
11
|
-
isLoading?: boolean;
|
|
12
|
-
canHaveClearIcon?: boolean;
|
|
13
|
-
onClear?: () => void;
|
|
14
|
-
triggerId?: string;
|
|
15
|
-
};
|
|
16
|
-
export declare const Icons: ({ isLoading, canHaveClearIcon, onClear, triggerId }: IconsProps) => JSX.Element;
|
|
17
|
-
export {};
|
package/lib/parts/icons.js
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import cn from 'classnames';
|
|
3
|
-
import CloseOutlineIcon from '../_virtual/close-outline.js';
|
|
4
|
-
import LoadingOutlineIcon from '../_virtual/loading-outline.js';
|
|
5
|
-
import DownOutlineIcon from '../_virtual/down-outline.js';
|
|
6
|
-
import styles from '../styles/common.p.module.css.js';
|
|
7
|
-
|
|
8
|
-
const ClearOrLoading = _ref => {
|
|
9
|
-
let {
|
|
10
|
-
isLoading,
|
|
11
|
-
canHaveClearIcon,
|
|
12
|
-
onClearClick,
|
|
13
|
-
triggerId,
|
|
14
|
-
className
|
|
15
|
-
} = _ref;
|
|
16
|
-
|
|
17
|
-
if (isLoading) {
|
|
18
|
-
return /*#__PURE__*/React.createElement(LoadingOutlineIcon, {
|
|
19
|
-
style: {
|
|
20
|
-
pointerEvents: 'none'
|
|
21
|
-
},
|
|
22
|
-
className: cn(className, styles.icon),
|
|
23
|
-
"data-test": "loading-icon",
|
|
24
|
-
"data-render-all-sizes": true
|
|
25
|
-
});
|
|
26
|
-
} else if (canHaveClearIcon) {
|
|
27
|
-
return /*#__PURE__*/React.createElement("button", {
|
|
28
|
-
type: "button",
|
|
29
|
-
className: cn(className, styles.icon, styles.clearIcon),
|
|
30
|
-
"data-test": "clear-icon",
|
|
31
|
-
onClick: e => {
|
|
32
|
-
e.stopPropagation();
|
|
33
|
-
onClearClick();
|
|
34
|
-
},
|
|
35
|
-
onPointerDown: e => e.stopPropagation(),
|
|
36
|
-
onMouseDown: e => e.stopPropagation(),
|
|
37
|
-
onKeyDown: e => e.stopPropagation(),
|
|
38
|
-
"aria-label": "Clear",
|
|
39
|
-
"aria-controls": triggerId
|
|
40
|
-
}, /*#__PURE__*/React.createElement(CloseOutlineIcon, {
|
|
41
|
-
"data-render-all-sizes": true
|
|
42
|
-
}));
|
|
43
|
-
} else {
|
|
44
|
-
return null;
|
|
45
|
-
}
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
const Icons = _ref2 => {
|
|
49
|
-
let {
|
|
50
|
-
isLoading,
|
|
51
|
-
canHaveClearIcon,
|
|
52
|
-
onClear,
|
|
53
|
-
triggerId
|
|
54
|
-
} = _ref2;
|
|
55
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
56
|
-
className: styles.iconsWrapper
|
|
57
|
-
}, /*#__PURE__*/React.createElement(ClearOrLoading, {
|
|
58
|
-
isLoading: isLoading,
|
|
59
|
-
canHaveClearIcon: canHaveClearIcon,
|
|
60
|
-
onClearClick: onClear,
|
|
61
|
-
triggerId: triggerId
|
|
62
|
-
}), /*#__PURE__*/React.createElement(DownOutlineIcon, {
|
|
63
|
-
className: styles.toggle,
|
|
64
|
-
"data-test": "toggle-icon",
|
|
65
|
-
"data-render-all-sizes": true
|
|
66
|
-
}));
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export { ClearOrLoading, Icons };
|
package/lib/parts/list-box.d.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { SelectSize, ListBoxItem, ListBoxState } from '../types';
|
|
3
|
-
export declare type ListBoxProps = {
|
|
4
|
-
state: ListBoxState;
|
|
5
|
-
items: ListBoxItem[];
|
|
6
|
-
size?: SelectSize;
|
|
7
|
-
className?: string;
|
|
8
|
-
maxVisibleItems?: number;
|
|
9
|
-
emptyListMessage: string;
|
|
10
|
-
};
|
|
11
|
-
export declare function ListBox({ state, items, size, maxVisibleItems, emptyListMessage }: ListBoxProps): JSX.Element;
|
package/lib/parts/list-box.js
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import React, { useRef } from 'react';
|
|
2
|
-
import cn from 'classnames';
|
|
3
|
-
import styles from '../styles/list-box.p.module.css.js';
|
|
4
|
-
import { calculateMaxHeightByItems } from '../utils/calculate-max-height-by-items.js';
|
|
5
|
-
import { getRealItemsCnt } from '../utils/get-real-items-cnt.js';
|
|
6
|
-
import { getTextFromNodes } from '../utils/get-text-from-nodes.js';
|
|
7
|
-
import CheckOutlineIcon from '../_virtual/check-outline.js';
|
|
8
|
-
const SIZE_STYLES = {
|
|
9
|
-
s: styles.sizeS,
|
|
10
|
-
m: styles.sizeM,
|
|
11
|
-
l: styles.sizeL
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
function Option(_ref) {
|
|
15
|
-
let {
|
|
16
|
-
item,
|
|
17
|
-
state
|
|
18
|
-
} = _ref;
|
|
19
|
-
// Get props for the option element
|
|
20
|
-
const ref = useRef(null);
|
|
21
|
-
const {
|
|
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
|
-
className: cn(styles.item, isSelected && styles.selected, isDisabled && styles.disabled),
|
|
39
|
-
"data-rs-internal": "select-list-box__item",
|
|
40
|
-
"data-focused": isHighlighted,
|
|
41
|
-
"data-test": `select-options-list__item_${item.key}`
|
|
42
|
-
}, /*#__PURE__*/React.createElement("span", null, item.label), selectionMode === 'multiple' && /*#__PURE__*/React.createElement(CheckOutlineIcon, {
|
|
43
|
-
"data-rs-internal": "select-list-box__check-icon",
|
|
44
|
-
className: cn(styles.checkIcon, isSelected && styles.visible)
|
|
45
|
-
}));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function ListBoxGroup(_ref2) {
|
|
49
|
-
let {
|
|
50
|
-
item,
|
|
51
|
-
isFirst,
|
|
52
|
-
state
|
|
53
|
-
} = _ref2;
|
|
54
|
-
const hasHeading = item.label !== null && item.label !== undefined;
|
|
55
|
-
const hasDivider = !isFirst && !hasHeading; // If the section is not the first, add a divider for visual separation
|
|
56
|
-
|
|
57
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, hasDivider && /*#__PURE__*/React.createElement("hr", {
|
|
58
|
-
className: styles.divider
|
|
59
|
-
}), /*#__PURE__*/React.createElement("li", {
|
|
60
|
-
role: "presentation"
|
|
61
|
-
}, hasHeading && /*#__PURE__*/React.createElement("span", {
|
|
62
|
-
className: styles.groupHeader,
|
|
63
|
-
role: "presentation",
|
|
64
|
-
"data-rs-internal": "select-list-box__group-header"
|
|
65
|
-
}, item.label), /*#__PURE__*/React.createElement("ul", {
|
|
66
|
-
role: "group",
|
|
67
|
-
"aria-label": hasHeading ? getTextFromNodes(item.label) : undefined,
|
|
68
|
-
style: {
|
|
69
|
-
padding: 0,
|
|
70
|
-
listStyle: 'none'
|
|
71
|
-
}
|
|
72
|
-
}, item.options.map(option => /*#__PURE__*/React.createElement(Option, {
|
|
73
|
-
key: option.key,
|
|
74
|
-
item: option,
|
|
75
|
-
state: state
|
|
76
|
-
})))));
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function ListBox(_ref3) {
|
|
80
|
-
var _items$find;
|
|
81
|
-
|
|
82
|
-
let {
|
|
83
|
-
state,
|
|
84
|
-
items,
|
|
85
|
-
size,
|
|
86
|
-
maxVisibleItems = 5,
|
|
87
|
-
emptyListMessage
|
|
88
|
-
} = _ref3;
|
|
89
|
-
const {
|
|
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]),
|
|
96
|
-
style: {
|
|
97
|
-
'--_rs-select-list-box-max-height-by-items': calculateMaxHeightByItems(itemsCount, maxVisibleItems)
|
|
98
|
-
},
|
|
99
|
-
"data-rs-internal": "select-list-box",
|
|
100
|
-
"data-test": "select-options-list"
|
|
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, {
|
|
105
|
-
key: item.key,
|
|
106
|
-
item: item,
|
|
107
|
-
state: state,
|
|
108
|
-
isFirst: item.key === firstGroupKey
|
|
109
|
-
}) : /*#__PURE__*/React.createElement(Option, {
|
|
110
|
-
key: item.key,
|
|
111
|
-
item: item,
|
|
112
|
-
state: state
|
|
113
|
-
})));
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export { ListBox };
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { SelectOption } from '../types';
|
|
3
|
-
export interface MultiTriggerProps {
|
|
4
|
-
selectedItems: SelectOption[];
|
|
5
|
-
removeSelectedItem: (item: SelectOption) => void;
|
|
6
|
-
valueProps: object;
|
|
7
|
-
isSingleLine: boolean;
|
|
8
|
-
isDisabled: boolean;
|
|
9
|
-
placeholder?: string;
|
|
10
|
-
triggerRef?: React.RefObject<HTMLDivElement>;
|
|
11
|
-
}
|
|
12
|
-
export declare function MultiTrigger({ selectedItems, valueProps, isSingleLine, isDisabled, placeholder, triggerRef, removeSelectedItem }: MultiTriggerProps): JSX.Element;
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import cn from 'classnames';
|
|
3
|
-
import { RemovableTag, Tag } from '@rescui/tag';
|
|
4
|
-
import styles from '../styles/common.p.module.css.js';
|
|
5
|
-
import { getTextFromNodes } from '../utils/get-text-from-nodes.js';
|
|
6
|
-
import { getOptionValue } from '../utils/get-option-value.js';
|
|
7
|
-
import Foldable from './foldable.js';
|
|
8
|
-
|
|
9
|
-
function MultiTrigger(_ref) {
|
|
10
|
-
let {
|
|
11
|
-
selectedItems,
|
|
12
|
-
valueProps,
|
|
13
|
-
isSingleLine,
|
|
14
|
-
isDisabled,
|
|
15
|
-
placeholder,
|
|
16
|
-
triggerRef,
|
|
17
|
-
removeSelectedItem
|
|
18
|
-
} = _ref;
|
|
19
|
-
const hasValue = selectedItems.length > 0;
|
|
20
|
-
|
|
21
|
-
if (!hasValue) {
|
|
22
|
-
return /*#__PURE__*/React.createElement("div", { ...valueProps,
|
|
23
|
-
className: cn(styles.triggerText, styles.labelNotSelected),
|
|
24
|
-
"data-test": 'multiselect__trigger_content'
|
|
25
|
-
}, placeholder);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const tags = selectedItems.map(option => {
|
|
29
|
-
const key = getOptionValue(option);
|
|
30
|
-
return /*#__PURE__*/React.createElement(RemovableTag, {
|
|
31
|
-
key: key,
|
|
32
|
-
tabIndex: -1,
|
|
33
|
-
"data-test": `selected-tag-${key}`,
|
|
34
|
-
className: styles.tag,
|
|
35
|
-
disabled: isDisabled,
|
|
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
|
-
},
|
|
44
|
-
"data-rs-internal": "select-trigger__removable-tag",
|
|
45
|
-
wrap: !isSingleLine,
|
|
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);
|
|
57
|
-
});
|
|
58
|
-
return /*#__PURE__*/React.createElement("div", { ...valueProps,
|
|
59
|
-
className: styles.multi,
|
|
60
|
-
"data-test": "multiselect__trigger_content"
|
|
61
|
-
}, isSingleLine ? /*#__PURE__*/React.createElement(Foldable, {
|
|
62
|
-
className: styles.tagsContainer,
|
|
63
|
-
renderHiddenCounter: (n, ref) => /*#__PURE__*/React.createElement(Tag, {
|
|
64
|
-
className: cn(styles.tag, styles.filledTag),
|
|
65
|
-
key: "+",
|
|
66
|
-
ref: ref,
|
|
67
|
-
"data-rs-internal": "select-trigger__tag"
|
|
68
|
-
}, "+", n)
|
|
69
|
-
}, tags) : /*#__PURE__*/React.createElement("div", {
|
|
70
|
-
className: styles.tagsContainer
|
|
71
|
-
}, tags));
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
export { MultiTrigger };
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import type { NativeSelectOptionOrGroup } from '../types';
|
|
3
|
-
export declare type NativeSelectOptionsWithGroupsProps = {
|
|
4
|
-
optionsWithGroups: NativeSelectOptionOrGroup[];
|
|
5
|
-
placeholder?: string;
|
|
6
|
-
emptyListMessage?: string;
|
|
7
|
-
};
|
|
8
|
-
export declare const NativeSelectOptionsWithGroups: React.FC<NativeSelectOptionsWithGroupsProps>;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { NO_OPTIONS_VALUE } from '../constants.js';
|
|
3
|
-
import { isOptionAGroup } from '../utils/is-option-a-group.js';
|
|
4
|
-
|
|
5
|
-
const collectOptionGroupValues = options => options.map(_ref => {
|
|
6
|
-
let {
|
|
7
|
-
value
|
|
8
|
-
} = _ref;
|
|
9
|
-
return value;
|
|
10
|
-
}).join('-');
|
|
11
|
-
|
|
12
|
-
const Option = _ref2 => {
|
|
13
|
-
let {
|
|
14
|
-
value,
|
|
15
|
-
label,
|
|
16
|
-
disabled = false
|
|
17
|
-
} = _ref2;
|
|
18
|
-
return /*#__PURE__*/React.createElement("option", {
|
|
19
|
-
value: value,
|
|
20
|
-
disabled: disabled
|
|
21
|
-
}, label);
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const OptionGroup = _ref3 => {
|
|
25
|
-
let {
|
|
26
|
-
options = [],
|
|
27
|
-
label = '',
|
|
28
|
-
disabled = false
|
|
29
|
-
} = _ref3;
|
|
30
|
-
return /*#__PURE__*/React.createElement("optgroup", {
|
|
31
|
-
label: label,
|
|
32
|
-
disabled: disabled
|
|
33
|
-
}, options.map(option => /*#__PURE__*/React.createElement(Option, {
|
|
34
|
-
key: option.value,
|
|
35
|
-
value: option.value,
|
|
36
|
-
label: option.label,
|
|
37
|
-
disabled: option.disabled
|
|
38
|
-
})));
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const NativeSelectOptionsWithGroups = _ref4 => {
|
|
42
|
-
let {
|
|
43
|
-
optionsWithGroups,
|
|
44
|
-
placeholder,
|
|
45
|
-
emptyListMessage
|
|
46
|
-
} = _ref4;
|
|
47
|
-
const hasOptions = optionsWithGroups.length > 0;
|
|
48
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("option", {
|
|
49
|
-
value: '',
|
|
50
|
-
disabled: true,
|
|
51
|
-
hidden: true
|
|
52
|
-
}, hasOptions ? placeholder : emptyListMessage), !hasOptions && /*#__PURE__*/React.createElement("option", {
|
|
53
|
-
value: NO_OPTIONS_VALUE,
|
|
54
|
-
disabled: true
|
|
55
|
-
}, emptyListMessage), optionsWithGroups.map(optionOrGroup => {
|
|
56
|
-
if (isOptionAGroup(optionOrGroup)) {
|
|
57
|
-
const group = optionOrGroup;
|
|
58
|
-
return /*#__PURE__*/React.createElement(OptionGroup, {
|
|
59
|
-
key: `group--${group.label}--${collectOptionGroupValues(group.options)}`,
|
|
60
|
-
options: group.options,
|
|
61
|
-
disabled: group.disabled,
|
|
62
|
-
label: group.label
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const option = optionOrGroup;
|
|
67
|
-
return /*#__PURE__*/React.createElement(Option, {
|
|
68
|
-
key: option.value,
|
|
69
|
-
value: option.value,
|
|
70
|
-
label: option.label,
|
|
71
|
-
disabled: option.disabled
|
|
72
|
-
});
|
|
73
|
-
}));
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
export { NativeSelectOptionsWithGroups };
|
package/lib/select-basic.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
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;
|
package/lib/select-basic.js
DELETED
|
@@ -1,203 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import cn from 'classnames';
|
|
3
|
-
import { Dropdown } from '@rescui/dropdown';
|
|
4
|
-
import { useSelect } from 'downshift';
|
|
5
|
-
import scrollIntoView from 'scroll-into-view-if-needed';
|
|
6
|
-
import { useLabelFocus } from './hooks/use-label-focus.js';
|
|
7
|
-
import { useOptions } from './hooks/use-options.js';
|
|
8
|
-
import { useA11y } from './hooks/use-a11y.js';
|
|
9
|
-
import { ListBox } from './parts/list-box.js';
|
|
10
|
-
import { Icons } from './parts/icons.js';
|
|
11
|
-
import { HiddenSelect } from './parts/hidden-select.js';
|
|
12
|
-
import { FormTriggerWrapper } from './parts/form-trigger-wrapper.js';
|
|
13
|
-
import { getEmptyMessage } from './utils/get-empty-message.js';
|
|
14
|
-
import { mergeProps } from './utils/merge-props.js';
|
|
15
|
-
import { itemToString } from './utils/item-to-string.js';
|
|
16
|
-
import { getOptionValue } from './utils/get-option-value.js';
|
|
17
|
-
import { getRealItemsCnt } from './utils/get-real-items-cnt.js';
|
|
18
|
-
import styles from './styles/common.p.module.css.js'; // eslint-disable-next-line complexity
|
|
19
|
-
|
|
20
|
-
function SelectBasic(_ref) {
|
|
21
|
-
let {
|
|
22
|
-
options,
|
|
23
|
-
value: selectedItem,
|
|
24
|
-
onChange,
|
|
25
|
-
error,
|
|
26
|
-
label,
|
|
27
|
-
note,
|
|
28
|
-
size,
|
|
29
|
-
mode,
|
|
30
|
-
theme,
|
|
31
|
-
placement,
|
|
32
|
-
boldLabel,
|
|
33
|
-
reserveErrorLine,
|
|
34
|
-
maxVisibleItems,
|
|
35
|
-
isClearable,
|
|
36
|
-
isLoading,
|
|
37
|
-
isDisabled,
|
|
38
|
-
name,
|
|
39
|
-
noOptionsMessage,
|
|
40
|
-
className,
|
|
41
|
-
id,
|
|
42
|
-
style,
|
|
43
|
-
placeholder,
|
|
44
|
-
...rest
|
|
45
|
-
} = _ref;
|
|
46
|
-
const triggerRef = React.useRef(null);
|
|
47
|
-
const dropdownRef = React.useRef(null);
|
|
48
|
-
const menuRef = React.useRef(null);
|
|
49
|
-
const {
|
|
50
|
-
flattenedOptions,
|
|
51
|
-
listBoxItems
|
|
52
|
-
} = useOptions(options);
|
|
53
|
-
const isListBoxEmpty = getRealItemsCnt(listBoxItems) === 0;
|
|
54
|
-
const hasValue = Boolean(selectedItem);
|
|
55
|
-
const selectedMap = selectedItem ? new Map([[getOptionValue(selectedItem), selectedItem]]) : new Map();
|
|
56
|
-
const {
|
|
57
|
-
fieldProps,
|
|
58
|
-
errorMessageProps,
|
|
59
|
-
descriptionProps,
|
|
60
|
-
baseId
|
|
61
|
-
} = useA11y({
|
|
62
|
-
prefix: 'select',
|
|
63
|
-
error,
|
|
64
|
-
description: note
|
|
65
|
-
});
|
|
66
|
-
const {
|
|
67
|
-
isOpen,
|
|
68
|
-
getToggleButtonProps,
|
|
69
|
-
getLabelProps,
|
|
70
|
-
getMenuProps,
|
|
71
|
-
highlightedIndex,
|
|
72
|
-
getItemProps,
|
|
73
|
-
reset
|
|
74
|
-
} = useSelect({
|
|
75
|
-
items: flattenedOptions,
|
|
76
|
-
itemToString,
|
|
77
|
-
id: baseId,
|
|
78
|
-
selectedItem,
|
|
79
|
-
// defining our scroll behavior because on the first menu render the hook
|
|
80
|
-
// doesn't know menuRef and use page as the scroll boundary
|
|
81
|
-
scrollIntoView: (listItemEl, listEl) => {
|
|
82
|
-
scrollIntoView(listItemEl, {
|
|
83
|
-
scrollMode: 'if-needed',
|
|
84
|
-
block: 'nearest',
|
|
85
|
-
boundary: listEl ?? menuRef.current
|
|
86
|
-
});
|
|
87
|
-
},
|
|
88
|
-
onSelectedItemChange: _ref2 => {
|
|
89
|
-
let {
|
|
90
|
-
selectedItem: newSelectedItem
|
|
91
|
-
} = _ref2;
|
|
92
|
-
onChange === null || onChange === void 0 || onChange(newSelectedItem);
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
isItemDisabled(item) {
|
|
96
|
-
return item && item.disabled;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
});
|
|
100
|
-
const menuProps = getMenuProps({
|
|
101
|
-
ref: menuRef
|
|
102
|
-
}, {
|
|
103
|
-
suppressRefError: true
|
|
104
|
-
});
|
|
105
|
-
const triggerProps = getToggleButtonProps({
|
|
106
|
-
ref: triggerRef,
|
|
107
|
-
onKeyDown: event => {
|
|
108
|
-
// backspace and backspace removing the last selected item (when popup is closed)
|
|
109
|
-
if (isClearable && !isOpen && (event.key === 'Backspace' || event.key === 'Delete')) {
|
|
110
|
-
reset();
|
|
111
|
-
}
|
|
112
|
-
},
|
|
113
|
-
// fix screen-reader focus on an opened popup with an empty list
|
|
114
|
-
...(isOpen && isListBoxEmpty ? {
|
|
115
|
-
'aria-activedescendant': menuProps.id
|
|
116
|
-
} : {})
|
|
117
|
-
});
|
|
118
|
-
const {
|
|
119
|
-
isFocusedByLabel,
|
|
120
|
-
labelClickProps,
|
|
121
|
-
triggerFocusProps: labelFocusForTriggerProps
|
|
122
|
-
} = useLabelFocus();
|
|
123
|
-
const emptyListMessage = getEmptyMessage({
|
|
124
|
-
isLoading,
|
|
125
|
-
isNothingFound: false,
|
|
126
|
-
noOptionsMessage
|
|
127
|
-
});
|
|
128
|
-
const listBoxState = {
|
|
129
|
-
selectedMap,
|
|
130
|
-
selectionMode: 'single',
|
|
131
|
-
highlightedIndex,
|
|
132
|
-
getItemProps,
|
|
133
|
-
menuProps
|
|
134
|
-
};
|
|
135
|
-
return /*#__PURE__*/React.createElement(FormTriggerWrapper, {
|
|
136
|
-
theme: theme,
|
|
137
|
-
size: size,
|
|
138
|
-
disabled: isDisabled,
|
|
139
|
-
label: label,
|
|
140
|
-
labelProps: mergeProps(getLabelProps(), labelClickProps),
|
|
141
|
-
boldLabel: boldLabel,
|
|
142
|
-
error: error,
|
|
143
|
-
reserveErrorLine: reserveErrorLine,
|
|
144
|
-
errorMessageProps: errorMessageProps,
|
|
145
|
-
note: note,
|
|
146
|
-
descriptionProps: descriptionProps
|
|
147
|
-
}, /*#__PURE__*/React.createElement(HiddenSelect, {
|
|
148
|
-
name: name,
|
|
149
|
-
value: selectedItem,
|
|
150
|
-
isMultiple: false,
|
|
151
|
-
options: flattenedOptions
|
|
152
|
-
}), /*#__PURE__*/React.createElement(Dropdown, {
|
|
153
|
-
mode: mode,
|
|
154
|
-
theme: theme,
|
|
155
|
-
ref: dropdownRef,
|
|
156
|
-
placement: placement,
|
|
157
|
-
maxWidth: "trigger",
|
|
158
|
-
minWidth: "trigger",
|
|
159
|
-
isOpen: isOpen,
|
|
160
|
-
cancelCloseAnimation: true,
|
|
161
|
-
disableFocusLock: true,
|
|
162
|
-
trigger: _ref3 => {
|
|
163
|
-
let {
|
|
164
|
-
ref: triggerRefForDropdown
|
|
165
|
-
} = _ref3;
|
|
166
|
-
return /*#__PURE__*/React.createElement("div", {
|
|
167
|
-
className: styles.triggerContainer,
|
|
168
|
-
"data-open": isOpen,
|
|
169
|
-
"data-label-focused": isFocusedByLabel
|
|
170
|
-
}, /*#__PURE__*/React.createElement("div", { ...rest,
|
|
171
|
-
...mergeProps(fieldProps, // aria-invalid & aria-describedby, rest are overridden by triggerProps
|
|
172
|
-
triggerProps, labelFocusForTriggerProps, {
|
|
173
|
-
ref: triggerRefForDropdown
|
|
174
|
-
}),
|
|
175
|
-
className: styles.trigger,
|
|
176
|
-
"data-test": "select__trigger"
|
|
177
|
-
}, /*#__PURE__*/React.createElement("span", {
|
|
178
|
-
className: cn(styles.triggerText, !hasValue && styles.labelNotSelected),
|
|
179
|
-
"data-test": "select__trigger_content"
|
|
180
|
-
}, (selectedItem === null || selectedItem === void 0 ? void 0 : selectedItem.label) ?? placeholder), /*#__PURE__*/React.createElement(Icons, {
|
|
181
|
-
isLoading: isLoading,
|
|
182
|
-
canHaveClearIcon: isClearable && !isDisabled && hasValue,
|
|
183
|
-
onClear: () => {
|
|
184
|
-
var _triggerRef$current;
|
|
185
|
-
|
|
186
|
-
reset();
|
|
187
|
-
(_triggerRef$current = triggerRef.current) === null || _triggerRef$current === void 0 || _triggerRef$current.focus({
|
|
188
|
-
focusVisible: false
|
|
189
|
-
});
|
|
190
|
-
},
|
|
191
|
-
triggerId: triggerProps.id
|
|
192
|
-
})));
|
|
193
|
-
}
|
|
194
|
-
}, /*#__PURE__*/React.createElement(ListBox, {
|
|
195
|
-
state: listBoxState,
|
|
196
|
-
size: size,
|
|
197
|
-
maxVisibleItems: maxVisibleItems,
|
|
198
|
-
emptyListMessage: emptyListMessage,
|
|
199
|
-
items: listBoxItems
|
|
200
|
-
})));
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
export { SelectBasic };
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
|
-
import { InnerSingleComponentProps } from './types';
|
|
3
|
-
export declare function SelectSearchable({ 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;
|