@rescui/select 0.18.4 → 0.19.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/lib/_virtual/check-outline.js +294 -63
- package/lib/_virtual/close-outline.js +294 -63
- package/lib/_virtual/down-outline.js +294 -63
- package/lib/_virtual/index.css.js +12 -12
- package/lib/_virtual/loading-outline.js +310 -79
- package/lib/hooks/use-a11y.d.ts +2 -2
- package/lib/hooks/use-a11y.js +124 -36
- package/lib/hooks/use-actual-size-from-css.d.ts +3 -4
- package/lib/hooks/use-actual-size-from-css.js +47 -18
- package/lib/hooks/use-focus.js +54 -10
- package/lib/hooks/use-hover.js +54 -10
- package/lib/hooks/use-label-focus.js +45 -15
- package/lib/hooks/use-multi-handlers.js +113 -38
- package/lib/hooks/use-options.d.ts +2 -1
- package/lib/hooks/use-options.js +92 -56
- package/lib/hooks/use-primary-contrast-css-var-transfer.d.ts +2 -3
- package/lib/hooks/use-primary-contrast-css-var-transfer.js +45 -15
- package/lib/index.css +194 -194
- package/lib/multiselect.js +527 -174
- package/lib/native-select.js +416 -118
- package/lib/parts/form-trigger-wrapper.js +159 -39
- package/lib/parts/hidden-select.js +105 -29
- package/lib/parts/icons.js +191 -49
- package/lib/parts/list-box.js +277 -74
- package/lib/parts/multi-trigger.d.ts +2 -2
- package/lib/parts/multi-trigger.js +125 -48
- package/lib/parts/native-select-options-with-groups.js +154 -52
- package/lib/parts/popup-content.d.ts +3 -3
- package/lib/parts/popup-content.js +146 -46
- package/lib/select-basic.js +456 -147
- package/lib/select-searchable.js +448 -155
- package/lib/select.js +228 -56
- package/lib/styles/common.p.module.css.js +29 -29
- package/lib/styles/form-trigger.p.module.css.js +12 -12
- package/lib/styles/list-box.p.module.css.js +13 -13
- package/lib/utils/get-text-from-nodes.js +1 -1
- package/package.json +12 -11
|
@@ -1,27 +1,56 @@
|
|
|
1
|
-
import _includesInstanceProperty from
|
|
1
|
+
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
2
|
+
import { c } from 'react-compiler-runtime';
|
|
2
3
|
import { useRef, useState } from 'react';
|
|
3
4
|
import { useResizeObserver } from '@rescui/use-resize-observer';
|
|
4
5
|
|
|
5
|
-
const useActualSizeFromCss =
|
|
6
|
-
|
|
6
|
+
const useActualSizeFromCss = t0 => {
|
|
7
|
+
const $ = c(5);
|
|
8
|
+
const {
|
|
7
9
|
sizeFromProps,
|
|
8
|
-
|
|
9
|
-
} =
|
|
10
|
-
// We use invisible and "untouchable" dummy element to observe `size` changes from css to fetch the actual size
|
|
10
|
+
triggerEl
|
|
11
|
+
} = t0;
|
|
11
12
|
const observableRef = useRef(null);
|
|
12
13
|
const [size, setSize] = useState(sizeFromProps);
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
let t1;
|
|
15
|
+
|
|
16
|
+
if ($[0] !== sizeFromProps || $[1] !== triggerEl) {
|
|
17
|
+
t1 = () => {
|
|
18
|
+
var _context;
|
|
19
|
+
|
|
20
|
+
const ownerWindow = triggerEl?.ownerDocument.defaultView;
|
|
21
|
+
|
|
22
|
+
if (!ownerWindow) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const triggerFormWrapperStyles = ownerWindow.getComputedStyle(triggerEl);
|
|
27
|
+
const rawSizeFromCss = triggerFormWrapperStyles.getPropertyValue("--_rs-select-size");
|
|
28
|
+
const sizeFromCss = _includesInstanceProperty(_context = ["s", "m", "l"]).call(_context, rawSizeFromCss) ? rawSizeFromCss : null;
|
|
29
|
+
setSize(sizeFromCss || sizeFromProps);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
$[0] = sizeFromProps;
|
|
33
|
+
$[1] = triggerEl;
|
|
34
|
+
$[2] = t1;
|
|
35
|
+
} else {
|
|
36
|
+
t1 = $[2];
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
useResizeObserver(observableRef, t1);
|
|
40
|
+
let t2;
|
|
41
|
+
|
|
42
|
+
if ($[3] !== size) {
|
|
43
|
+
t2 = {
|
|
44
|
+
observableRef,
|
|
45
|
+
size
|
|
46
|
+
};
|
|
47
|
+
$[3] = size;
|
|
48
|
+
$[4] = t2;
|
|
49
|
+
} else {
|
|
50
|
+
t2 = $[4];
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return t2;
|
|
25
54
|
};
|
|
26
55
|
|
|
27
56
|
export { useActualSizeFromCss };
|
package/lib/hooks/use-focus.js
CHANGED
|
@@ -1,17 +1,61 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
1
2
|
import { useState } from 'react';
|
|
2
3
|
|
|
3
|
-
const useFocus =
|
|
4
|
-
|
|
4
|
+
const useFocus = t0 => {
|
|
5
|
+
const $ = c(8);
|
|
6
|
+
const {
|
|
5
7
|
isDisabled
|
|
6
|
-
} =
|
|
8
|
+
} = t0;
|
|
7
9
|
const [isFocused, setIsFocused] = useState(false);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
let t1;
|
|
11
|
+
|
|
12
|
+
if ($[0] !== isDisabled) {
|
|
13
|
+
t1 = () => setIsFocused(!isDisabled);
|
|
14
|
+
|
|
15
|
+
$[0] = isDisabled;
|
|
16
|
+
$[1] = t1;
|
|
17
|
+
} else {
|
|
18
|
+
t1 = $[1];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let t2;
|
|
22
|
+
|
|
23
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
24
|
+
t2 = () => setIsFocused(false);
|
|
25
|
+
|
|
26
|
+
$[2] = t2;
|
|
27
|
+
} else {
|
|
28
|
+
t2 = $[2];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let t3;
|
|
32
|
+
|
|
33
|
+
if ($[3] !== t1) {
|
|
34
|
+
t3 = {
|
|
35
|
+
onFocus: t1,
|
|
36
|
+
onBlur: t2
|
|
37
|
+
};
|
|
38
|
+
$[3] = t1;
|
|
39
|
+
$[4] = t3;
|
|
40
|
+
} else {
|
|
41
|
+
t3 = $[4];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let t4;
|
|
45
|
+
|
|
46
|
+
if ($[5] !== isFocused || $[6] !== t3) {
|
|
47
|
+
t4 = {
|
|
48
|
+
isFocused,
|
|
49
|
+
focusProps: t3
|
|
50
|
+
};
|
|
51
|
+
$[5] = isFocused;
|
|
52
|
+
$[6] = t3;
|
|
53
|
+
$[7] = t4;
|
|
54
|
+
} else {
|
|
55
|
+
t4 = $[7];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return t4;
|
|
15
59
|
};
|
|
16
60
|
|
|
17
61
|
export { useFocus };
|
package/lib/hooks/use-hover.js
CHANGED
|
@@ -1,17 +1,61 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
1
2
|
import { useState } from 'react';
|
|
2
3
|
|
|
3
|
-
const useHover =
|
|
4
|
-
|
|
4
|
+
const useHover = t0 => {
|
|
5
|
+
const $ = c(8);
|
|
6
|
+
const {
|
|
5
7
|
isDisabled
|
|
6
|
-
} =
|
|
8
|
+
} = t0;
|
|
7
9
|
const [isHovered, setIsHovered] = useState(false);
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
let t1;
|
|
11
|
+
|
|
12
|
+
if ($[0] !== isDisabled) {
|
|
13
|
+
t1 = () => setIsHovered(!isDisabled);
|
|
14
|
+
|
|
15
|
+
$[0] = isDisabled;
|
|
16
|
+
$[1] = t1;
|
|
17
|
+
} else {
|
|
18
|
+
t1 = $[1];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let t2;
|
|
22
|
+
|
|
23
|
+
if ($[2] === Symbol.for("react.memo_cache_sentinel")) {
|
|
24
|
+
t2 = () => setIsHovered(false);
|
|
25
|
+
|
|
26
|
+
$[2] = t2;
|
|
27
|
+
} else {
|
|
28
|
+
t2 = $[2];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
let t3;
|
|
32
|
+
|
|
33
|
+
if ($[3] !== t1) {
|
|
34
|
+
t3 = {
|
|
35
|
+
onMouseEnter: t1,
|
|
36
|
+
onMouseLeave: t2
|
|
37
|
+
};
|
|
38
|
+
$[3] = t1;
|
|
39
|
+
$[4] = t3;
|
|
40
|
+
} else {
|
|
41
|
+
t3 = $[4];
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
let t4;
|
|
45
|
+
|
|
46
|
+
if ($[5] !== isHovered || $[6] !== t3) {
|
|
47
|
+
t4 = {
|
|
48
|
+
isHovered,
|
|
49
|
+
hoverProps: t3
|
|
50
|
+
};
|
|
51
|
+
$[5] = isHovered;
|
|
52
|
+
$[6] = t3;
|
|
53
|
+
$[7] = t4;
|
|
54
|
+
} else {
|
|
55
|
+
t4 = $[7];
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return t4;
|
|
15
59
|
};
|
|
16
60
|
|
|
17
61
|
export { useHover };
|
|
@@ -1,22 +1,52 @@
|
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
1
2
|
import { useState } from 'react';
|
|
2
3
|
|
|
3
4
|
const useLabelFocus = () => {
|
|
5
|
+
const $ = c(4);
|
|
4
6
|
const [isFocusedByLabel, setIsFocusedByLabel] = useState(false);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
let t0;
|
|
8
|
+
|
|
9
|
+
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
|
10
|
+
t0 = {
|
|
11
|
+
onBlur: () => {
|
|
12
|
+
setIsFocusedByLabel(false);
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
$[0] = t0;
|
|
16
|
+
} else {
|
|
17
|
+
t0 = $[0];
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const triggerFocusProps = t0;
|
|
21
|
+
let t1;
|
|
22
|
+
|
|
23
|
+
if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
|
|
24
|
+
t1 = {
|
|
25
|
+
onClick: () => {
|
|
26
|
+
setIsFocusedByLabel(true);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
$[1] = t1;
|
|
30
|
+
} else {
|
|
31
|
+
t1 = $[1];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const labelClickProps = t1;
|
|
35
|
+
let t2;
|
|
36
|
+
|
|
37
|
+
if ($[2] !== isFocusedByLabel) {
|
|
38
|
+
t2 = {
|
|
39
|
+
isFocusedByLabel,
|
|
40
|
+
triggerFocusProps,
|
|
41
|
+
labelClickProps
|
|
42
|
+
};
|
|
43
|
+
$[2] = isFocusedByLabel;
|
|
44
|
+
$[3] = t2;
|
|
45
|
+
} else {
|
|
46
|
+
t2 = $[3];
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return t2;
|
|
20
50
|
};
|
|
21
51
|
|
|
22
52
|
export { useLabelFocus };
|
|
@@ -1,47 +1,122 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c } from 'react-compiler-runtime';
|
|
2
|
+
import { useRef, useEffect, useLayoutEffect } from 'react';
|
|
2
3
|
import { getOptionValue } from '../utils/get-option-value.js';
|
|
3
4
|
const useIsomorphicLayoutEffect = typeof window === 'undefined' ? useEffect : useLayoutEffect;
|
|
4
5
|
|
|
5
|
-
const useMultiHandlers =
|
|
6
|
-
|
|
6
|
+
const useMultiHandlers = t0 => {
|
|
7
|
+
const $ = c(14);
|
|
8
|
+
const {
|
|
7
9
|
selectedItems,
|
|
8
10
|
onChange
|
|
9
|
-
} =
|
|
11
|
+
} = t0;
|
|
10
12
|
const onChangeRef = useRef(null);
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
13
|
+
let t1;
|
|
14
|
+
let t2;
|
|
15
|
+
|
|
16
|
+
if ($[0] !== onChange) {
|
|
17
|
+
t1 = () => {
|
|
18
|
+
onChangeRef.current = onChange;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
t2 = [onChange];
|
|
22
|
+
$[0] = onChange;
|
|
23
|
+
$[1] = t1;
|
|
24
|
+
$[2] = t2;
|
|
25
|
+
} else {
|
|
26
|
+
t1 = $[1];
|
|
27
|
+
t2 = $[2];
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
useIsomorphicLayoutEffect(t1, t2);
|
|
31
|
+
let t3;
|
|
32
|
+
|
|
33
|
+
if ($[3] !== selectedItems) {
|
|
34
|
+
t3 = new Map(selectedItems.map(_temp));
|
|
35
|
+
$[3] = selectedItems;
|
|
36
|
+
$[4] = t3;
|
|
37
|
+
} else {
|
|
38
|
+
t3 = $[4];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const selectedMap = t3;
|
|
42
|
+
let t4;
|
|
43
|
+
|
|
44
|
+
if ($[5] !== selectedMap) {
|
|
45
|
+
t4 = item_0 => {
|
|
46
|
+
if (selectedMap.has(getOptionValue(item_0))) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const newValues = [...selectedMap.values(), item_0];
|
|
51
|
+
onChangeRef.current?.(newValues);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
$[5] = selectedMap;
|
|
55
|
+
$[6] = t4;
|
|
56
|
+
} else {
|
|
57
|
+
t4 = $[6];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const addItem = t4;
|
|
61
|
+
let t5;
|
|
62
|
+
|
|
63
|
+
if ($[7] !== selectedMap) {
|
|
64
|
+
t5 = item_1 => {
|
|
65
|
+
const key = getOptionValue(item_1);
|
|
66
|
+
const newValues_0 = [...selectedMap.entries()].filter(t6 => {
|
|
67
|
+
const [k] = t6;
|
|
68
|
+
return k !== key;
|
|
69
|
+
}).map(_temp2);
|
|
70
|
+
onChangeRef.current?.(newValues_0);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
$[7] = selectedMap;
|
|
74
|
+
$[8] = t5;
|
|
75
|
+
} else {
|
|
76
|
+
t5 = $[8];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const removeItem = t5;
|
|
80
|
+
let t6;
|
|
81
|
+
|
|
82
|
+
if ($[9] === Symbol.for("react.memo_cache_sentinel")) {
|
|
83
|
+
t6 = () => {
|
|
84
|
+
onChangeRef.current?.([]);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
$[9] = t6;
|
|
88
|
+
} else {
|
|
89
|
+
t6 = $[9];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const removeAllItems = t6;
|
|
93
|
+
let t7;
|
|
94
|
+
|
|
95
|
+
if ($[10] !== addItem || $[11] !== removeItem || $[12] !== selectedMap) {
|
|
96
|
+
t7 = {
|
|
97
|
+
selectedMap,
|
|
98
|
+
addItem,
|
|
99
|
+
removeItem,
|
|
100
|
+
removeAllItems
|
|
101
|
+
};
|
|
102
|
+
$[10] = addItem;
|
|
103
|
+
$[11] = removeItem;
|
|
104
|
+
$[12] = selectedMap;
|
|
105
|
+
$[13] = t7;
|
|
106
|
+
} else {
|
|
107
|
+
t7 = $[13];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return t7;
|
|
45
111
|
};
|
|
46
112
|
|
|
113
|
+
function _temp(item) {
|
|
114
|
+
return [getOptionValue(item), item];
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function _temp2(t0) {
|
|
118
|
+
const [, v] = t0;
|
|
119
|
+
return v;
|
|
120
|
+
}
|
|
121
|
+
|
|
47
122
|
export { useMultiHandlers };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
import type { SelectOptionOrGroup, SelectOption, ListBoxItem } from '../types';
|
|
2
3
|
/**
|
|
3
4
|
* Convert an array of options with possible groups to the flat array of options, stripping them of the groups.
|
|
@@ -6,7 +7,7 @@ import type { SelectOptionOrGroup, SelectOption, ListBoxItem } from '../types';
|
|
|
6
7
|
* @param options
|
|
7
8
|
*/
|
|
8
9
|
export declare const useOptions: (options: SelectOptionOrGroup[]) => {
|
|
9
|
-
setFilterString:
|
|
10
|
+
setFilterString: React.Dispatch<React.SetStateAction<string>>;
|
|
10
11
|
filterString: string;
|
|
11
12
|
flattenedOptions: SelectOption[];
|
|
12
13
|
listBoxItems: ListBoxItem[];
|
package/lib/hooks/use-options.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import _includesInstanceProperty from
|
|
2
|
-
import {
|
|
1
|
+
import _includesInstanceProperty from '@babel/runtime-corejs3/core-js-stable/instance/includes';
|
|
2
|
+
import { c } from 'react-compiler-runtime';
|
|
3
|
+
import { useState } from 'react';
|
|
3
4
|
import { isOptionAGroup } from '../utils/is-option-a-group.js';
|
|
4
5
|
import { getTextFromNodes } from '../utils/get-text-from-nodes.js';
|
|
5
6
|
import { getOptionValue } from '../utils/get-option-value.js';
|
|
@@ -16,6 +17,61 @@ const createFilter = substring => {
|
|
|
16
17
|
return _includesInstanceProperty(_context = string.toLowerCase()).call(_context, lowerSubstring);
|
|
17
18
|
};
|
|
18
19
|
};
|
|
20
|
+
|
|
21
|
+
const processOptions = (options, filterFn) => {
|
|
22
|
+
const flattenedOptions = [];
|
|
23
|
+
const listBoxItems = [];
|
|
24
|
+
let index = 0;
|
|
25
|
+
|
|
26
|
+
const createOptionItem = option => {
|
|
27
|
+
return { ...option,
|
|
28
|
+
index: index++,
|
|
29
|
+
type: 'option',
|
|
30
|
+
key: getOptionValue(option)
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
options.forEach((optionOrGroup, arrayIndex) => {
|
|
35
|
+
if (isOptionAGroup(optionOrGroup)) {
|
|
36
|
+
const group = optionOrGroup;
|
|
37
|
+
|
|
38
|
+
if (!group.options || group.options.length === 0) {
|
|
39
|
+
return;
|
|
40
|
+
} // Render as Group (with or without label)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
const groupLabelText = group.label ? getTextFromNodes(group.label) : ''; // Use a special prefix that's unlikely to collide with user values
|
|
44
|
+
|
|
45
|
+
const groupKey = `\0__rs_select_group_${arrayIndex}_${groupLabelText}`;
|
|
46
|
+
const listBoxGroupItem = { ...group,
|
|
47
|
+
type: 'group',
|
|
48
|
+
options: [],
|
|
49
|
+
key: groupKey
|
|
50
|
+
};
|
|
51
|
+
group.options.forEach(option => {
|
|
52
|
+
if (filterFn(getTextFromNodes(option.label))) {
|
|
53
|
+
flattenedOptions.push(option);
|
|
54
|
+
listBoxGroupItem.options.push(createOptionItem(option));
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
if (listBoxGroupItem.options.length > 0) {
|
|
59
|
+
listBoxItems.push(listBoxGroupItem);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (filterFn(getTextFromNodes(optionOrGroup.label))) {
|
|
66
|
+
flattenedOptions.push(optionOrGroup);
|
|
67
|
+
listBoxItems.push(createOptionItem(optionOrGroup));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
return {
|
|
71
|
+
flattenedOptions,
|
|
72
|
+
listBoxItems
|
|
73
|
+
};
|
|
74
|
+
};
|
|
19
75
|
/**
|
|
20
76
|
* Convert an array of options with possible groups to the flat array of options, stripping them of the groups.
|
|
21
77
|
* Also creating a list for ListBox component with indexes and keys.
|
|
@@ -25,66 +81,46 @@ const createFilter = substring => {
|
|
|
25
81
|
|
|
26
82
|
|
|
27
83
|
const useOptions = options => {
|
|
28
|
-
const
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const flattenedOptions = [];
|
|
32
|
-
const listBoxItems = [];
|
|
33
|
-
let index = 0;
|
|
34
|
-
|
|
35
|
-
const createOptionItem = option => {
|
|
36
|
-
return { ...option,
|
|
37
|
-
index: index++,
|
|
38
|
-
type: 'option',
|
|
39
|
-
key: getOptionValue(option)
|
|
40
|
-
};
|
|
41
|
-
};
|
|
84
|
+
const $ = c(8);
|
|
85
|
+
const [filterString, setFilterString] = useState("");
|
|
86
|
+
let t0;
|
|
42
87
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
const groupLabelText = group.label ? getTextFromNodes(group.label) : ''; // Use a special prefix that's unlikely to collide with user values
|
|
88
|
+
if ($[0] !== filterString) {
|
|
89
|
+
t0 = createFilter(filterString);
|
|
90
|
+
$[0] = filterString;
|
|
91
|
+
$[1] = t0;
|
|
92
|
+
} else {
|
|
93
|
+
t0 = $[1];
|
|
94
|
+
}
|
|
53
95
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
type: 'group',
|
|
57
|
-
options: [],
|
|
58
|
-
key: groupKey
|
|
59
|
-
};
|
|
60
|
-
group.options.forEach(option => {
|
|
61
|
-
if (filterFn(getTextFromNodes(option.label))) {
|
|
62
|
-
flattenedOptions.push(option);
|
|
63
|
-
listBoxGroupItem.options.push(createOptionItem(option));
|
|
64
|
-
}
|
|
65
|
-
});
|
|
96
|
+
const filterFn = t0;
|
|
97
|
+
let t1;
|
|
66
98
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
99
|
+
if ($[2] !== filterFn || $[3] !== options) {
|
|
100
|
+
t1 = processOptions(options, filterFn);
|
|
101
|
+
$[2] = filterFn;
|
|
102
|
+
$[3] = options;
|
|
103
|
+
$[4] = t1;
|
|
104
|
+
} else {
|
|
105
|
+
t1 = $[4];
|
|
106
|
+
}
|
|
70
107
|
|
|
71
|
-
|
|
72
|
-
|
|
108
|
+
const processedOptions = t1;
|
|
109
|
+
let t2;
|
|
73
110
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
});
|
|
79
|
-
return {
|
|
80
|
-
flattenedOptions,
|
|
81
|
-
listBoxItems
|
|
111
|
+
if ($[5] !== filterString || $[6] !== processedOptions) {
|
|
112
|
+
t2 = { ...processedOptions,
|
|
113
|
+
setFilterString,
|
|
114
|
+
filterString
|
|
82
115
|
};
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
116
|
+
$[5] = filterString;
|
|
117
|
+
$[6] = processedOptions;
|
|
118
|
+
$[7] = t2;
|
|
119
|
+
} else {
|
|
120
|
+
t2 = $[7];
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return t2;
|
|
88
124
|
};
|
|
89
125
|
|
|
90
126
|
export { useOptions };
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
1
|
export type UsePrimaryContrastCssVarTransferParams = {
|
|
3
|
-
|
|
2
|
+
triggerEl: HTMLElement | null;
|
|
4
3
|
isOpen: boolean;
|
|
5
4
|
};
|
|
6
5
|
/**
|
|
7
6
|
* Transfer primary contrast css var to the dropdown, but only when the dropdown opens
|
|
8
7
|
*/
|
|
9
|
-
export declare const usePrimaryContrastCssVarTransfer: ({
|
|
8
|
+
export declare const usePrimaryContrastCssVarTransfer: ({ triggerEl, isOpen }: UsePrimaryContrastCssVarTransferParams) => {
|
|
10
9
|
isPrimaryContrast: boolean;
|
|
11
10
|
};
|