@alfalab/core-components-select 10.2.2 → 10.4.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/CHANGELOG.md +42 -0
- package/dist/Component.d.ts +1 -1
- package/dist/Component.js +2 -1
- package/dist/components/arrow/Component.js +1 -1
- package/dist/components/arrow/index.css +3 -3
- package/dist/components/base-select/Component.js +25 -22
- package/dist/components/base-select/index.css +7 -7
- package/dist/components/base-select/index.js +1 -1
- package/dist/components/checkmark/Component.d.ts +1 -1
- package/dist/components/checkmark/Component.js +11 -5
- package/dist/components/checkmark/index.css +21 -9
- package/dist/components/checkmark/index.js +1 -0
- package/dist/components/field/Component.d.ts +1 -1
- package/dist/components/field/Component.js +3 -3
- package/dist/components/field/index.css +9 -9
- package/dist/components/field/index.js +1 -1
- package/dist/components/index.js +2 -1
- package/dist/components/native-select/Component.js +1 -1
- package/dist/components/native-select/index.js +1 -1
- package/dist/components/optgroup/Component.js +1 -1
- package/dist/components/optgroup/index.css +6 -6
- package/dist/components/option/Component.js +7 -5
- package/dist/components/option/index.css +20 -20
- package/dist/components/option/index.js +2 -1
- package/dist/components/options-list/Component.js +13 -8
- package/dist/components/options-list/index.css +9 -5
- package/dist/components/options-list/index.js +1 -0
- package/dist/components/virtual-options-list/Component.d.ts +1 -1
- package/dist/components/virtual-options-list/Component.js +22 -18
- package/dist/components/virtual-options-list/index.css +15 -12
- package/dist/components/virtual-options-list/index.js +1 -0
- package/dist/cssm/Component.d.ts +1 -1
- package/dist/cssm/Component.js +1 -0
- package/dist/cssm/components/base-select/Component.js +23 -20
- package/dist/cssm/components/checkmark/Component.d.ts +1 -1
- package/dist/cssm/components/checkmark/Component.js +10 -4
- package/dist/cssm/components/checkmark/index.js +1 -0
- package/dist/cssm/components/checkmark/index.module.css +19 -7
- package/dist/cssm/components/field/Component.d.ts +1 -1
- package/dist/cssm/components/field/Component.js +1 -1
- package/dist/cssm/components/index.js +1 -0
- package/dist/cssm/components/option/Component.js +5 -3
- package/dist/cssm/components/option/index.js +1 -0
- package/dist/cssm/components/options-list/Component.js +12 -7
- package/dist/cssm/components/options-list/index.js +1 -0
- package/dist/cssm/components/options-list/index.module.css +4 -0
- package/dist/cssm/components/virtual-options-list/Component.d.ts +1 -1
- package/dist/cssm/components/virtual-options-list/Component.js +21 -17
- package/dist/cssm/components/virtual-options-list/index.js +1 -0
- package/dist/cssm/components/virtual-options-list/index.module.css +4 -1
- package/dist/cssm/hook-45e5f3a8.d.ts +12 -0
- package/dist/cssm/hook-45e5f3a8.js +147 -0
- package/dist/cssm/hook-f5b8fe4f.d.ts +61 -0
- package/dist/cssm/index.js +8 -1
- package/dist/cssm/intersection-observer-8c55e13a.d.ts +1 -0
- package/dist/cssm/intersection-observer-8c55e13a.js +893 -0
- package/dist/cssm/presets/index.d.ts +1 -0
- package/dist/cssm/presets/index.js +30 -1
- package/dist/cssm/presets/useLazyLoading/hook.js +2 -892
- package/dist/cssm/presets/useSelectWithApply/hook.d.ts +0 -0
- package/dist/cssm/presets/useSelectWithApply/hook.js +46 -0
- package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
- package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/Component.js +45 -0
- package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
- package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.js +45 -0
- package/dist/cssm/presets/useSelectWithApply/options-list-with-apply/index.module.css +38 -0
- package/dist/cssm/presets/useSelectWithLoading/hook.js +1 -0
- package/dist/cssm/typings.d.ts +55 -6
- package/dist/esm/Component.d.ts +1 -1
- package/dist/esm/Component.js +2 -1
- package/dist/esm/components/arrow/Component.js +1 -1
- package/dist/esm/components/arrow/index.css +3 -3
- package/dist/esm/components/base-select/Component.js +25 -22
- package/dist/esm/components/base-select/index.css +7 -7
- package/dist/esm/components/base-select/index.js +1 -1
- package/dist/esm/components/checkmark/Component.d.ts +1 -1
- package/dist/esm/components/checkmark/Component.js +12 -6
- package/dist/esm/components/checkmark/index.css +21 -9
- package/dist/esm/components/checkmark/index.js +1 -0
- package/dist/esm/components/field/Component.d.ts +1 -1
- package/dist/esm/components/field/Component.js +3 -3
- package/dist/esm/components/field/index.css +9 -9
- package/dist/esm/components/field/index.js +1 -1
- package/dist/esm/components/index.js +2 -1
- package/dist/esm/components/native-select/Component.js +1 -1
- package/dist/esm/components/native-select/index.js +1 -1
- package/dist/esm/components/optgroup/Component.js +1 -1
- package/dist/esm/components/optgroup/index.css +6 -6
- package/dist/esm/components/option/Component.js +7 -5
- package/dist/esm/components/option/index.css +20 -20
- package/dist/esm/components/option/index.js +2 -1
- package/dist/esm/components/options-list/Component.js +14 -9
- package/dist/esm/components/options-list/index.css +9 -5
- package/dist/esm/components/options-list/index.js +1 -0
- package/dist/esm/components/virtual-options-list/Component.d.ts +1 -1
- package/dist/esm/components/virtual-options-list/Component.js +22 -18
- package/dist/esm/components/virtual-options-list/index.css +15 -12
- package/dist/esm/components/virtual-options-list/index.js +1 -0
- package/dist/esm/hook-a01ac265.d.ts +12 -0
- package/dist/esm/hook-a01ac265.js +131 -0
- package/dist/esm/hook-f5b8fe4f.d.ts +61 -0
- package/dist/esm/index.js +5 -1
- package/dist/esm/intersection-observer-2080f60e.d.ts +1 -0
- package/dist/esm/intersection-observer-2080f60e.js +891 -0
- package/dist/esm/presets/index.d.ts +1 -0
- package/dist/esm/presets/index.js +21 -1
- package/dist/esm/presets/useLazyLoading/hook.js +4 -894
- package/dist/esm/presets/useLazyLoading/index.css +2 -2
- package/dist/esm/presets/useSelectWithApply/hook.d.ts +0 -0
- package/dist/esm/presets/useSelectWithApply/hook.js +26 -0
- package/dist/esm/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
- package/dist/esm/presets/useSelectWithApply/options-list-with-apply/Component.js +26 -0
- package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
- package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
- package/dist/esm/presets/useSelectWithApply/options-list-with-apply/index.js +26 -0
- package/dist/esm/presets/useSelectWithLoading/hook.js +3 -2
- package/dist/esm/presets/useSelectWithLoading/index.css +2 -2
- package/dist/esm/{tslib.es6-e134354f.d.ts → tslib.es6-11a0bbd3.d.ts} +0 -0
- package/dist/esm/{tslib.es6-e134354f.js → tslib.es6-11a0bbd3.js} +0 -0
- package/dist/esm/typings.d.ts +55 -6
- package/dist/hook-4f9a90b8.d.ts +12 -0
- package/dist/hook-4f9a90b8.js +140 -0
- package/dist/hook-f5b8fe4f.d.ts +61 -0
- package/dist/index.js +7 -1
- package/dist/intersection-observer-c983b2d1.d.ts +1 -0
- package/dist/intersection-observer-c983b2d1.js +893 -0
- package/dist/modern/Component.d.ts +1 -1
- package/dist/modern/Component.js +1 -0
- package/dist/modern/components/arrow/Component.js +1 -1
- package/dist/modern/components/arrow/index.css +3 -3
- package/dist/modern/components/base-select/Component.js +19 -14
- package/dist/modern/components/base-select/index.css +7 -7
- package/dist/modern/components/checkmark/Component.d.ts +1 -1
- package/dist/modern/components/checkmark/Component.js +12 -4
- package/dist/modern/components/checkmark/index.css +21 -9
- package/dist/modern/components/checkmark/index.js +1 -0
- package/dist/modern/components/field/Component.d.ts +1 -1
- package/dist/modern/components/field/Component.js +2 -2
- package/dist/modern/components/field/index.css +9 -9
- package/dist/modern/components/index.js +1 -0
- package/dist/modern/components/optgroup/Component.js +1 -1
- package/dist/modern/components/optgroup/index.css +6 -6
- package/dist/modern/components/option/Component.js +6 -4
- package/dist/modern/components/option/index.css +20 -20
- package/dist/modern/components/option/index.js +1 -0
- package/dist/modern/components/options-list/Component.js +11 -7
- package/dist/modern/components/options-list/index.css +9 -5
- package/dist/modern/components/virtual-options-list/Component.d.ts +1 -1
- package/dist/modern/components/virtual-options-list/Component.js +20 -17
- package/dist/modern/components/virtual-options-list/index.css +15 -12
- package/dist/modern/hook-cdda7a62.d.ts +12 -0
- package/dist/modern/hook-cdda7a62.js +132 -0
- package/dist/modern/hook-f5b8fe4f.d.ts +61 -0
- package/dist/modern/index.js +4 -0
- package/dist/modern/intersection-observer-2080f60e.d.ts +1 -0
- package/dist/modern/intersection-observer-2080f60e.js +891 -0
- package/dist/modern/presets/index.d.ts +1 -0
- package/dist/modern/presets/index.js +20 -0
- package/dist/modern/presets/useLazyLoading/hook.js +3 -893
- package/dist/modern/presets/useLazyLoading/index.css +2 -2
- package/dist/modern/presets/useSelectWithApply/hook.d.ts +0 -0
- package/dist/modern/presets/useSelectWithApply/hook.js +25 -0
- package/dist/modern/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
- package/dist/modern/presets/useSelectWithApply/options-list-with-apply/Component.js +25 -0
- package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
- package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
- package/dist/modern/presets/useSelectWithApply/options-list-with-apply/index.js +25 -0
- package/dist/modern/presets/useSelectWithLoading/hook.js +2 -1
- package/dist/modern/presets/useSelectWithLoading/index.css +2 -2
- package/dist/modern/typings.d.ts +55 -6
- package/dist/presets/index.d.ts +1 -0
- package/dist/presets/index.js +23 -1
- package/dist/presets/useLazyLoading/hook.js +4 -894
- package/dist/presets/useLazyLoading/index.css +2 -2
- package/dist/presets/useSelectWithApply/hook.d.ts +0 -0
- package/dist/presets/useSelectWithApply/hook.js +35 -0
- package/dist/presets/useSelectWithApply/options-list-with-apply/Component.d.ts +0 -0
- package/dist/presets/useSelectWithApply/options-list-with-apply/Component.js +34 -0
- package/dist/presets/useSelectWithApply/options-list-with-apply/index.css +39 -0
- package/dist/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -0
- package/dist/presets/useSelectWithApply/options-list-with-apply/index.js +34 -0
- package/dist/presets/useSelectWithLoading/hook.js +3 -2
- package/dist/presets/useSelectWithLoading/index.css +2 -2
- package/dist/{tslib.es6-b50d38c9.d.ts → tslib.es6-edfcd771.d.ts} +0 -0
- package/dist/{tslib.es6-b50d38c9.js → tslib.es6-edfcd771.js} +0 -0
- package/dist/typings.d.ts +55 -6
- package/package.json +5 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: llpjm */
|
|
2
2
|
:root {
|
|
3
3
|
--color-light-text-secondary: #546272;
|
|
4
4
|
}
|
|
@@ -26,17 +26,21 @@
|
|
|
26
26
|
|
|
27
27
|
/* optgroup */
|
|
28
28
|
}
|
|
29
|
-
.
|
|
29
|
+
.select__optionsList_6utg9 {
|
|
30
30
|
overflow: auto;
|
|
31
31
|
width: 100%;
|
|
32
32
|
outline: none;
|
|
33
33
|
box-sizing: border-box;
|
|
34
34
|
}
|
|
35
|
-
.
|
|
35
|
+
.select__scrollable_6utg9 {
|
|
36
|
+
overflow: auto;
|
|
37
|
+
width: 100%;
|
|
38
|
+
}
|
|
39
|
+
.select__emptyPlaceholder_6utg9 {
|
|
36
40
|
padding: var(--gap-m) var(--gap-s);
|
|
37
41
|
color: var(--select-options-list-empty-placeholder-color);
|
|
38
42
|
}
|
|
39
|
-
.
|
|
40
|
-
.
|
|
43
|
+
.select__l_6utg9 .select__emptyPlaceholder_6utg9,
|
|
44
|
+
.select__xl_6utg9 .select__emptyPlaceholder_6utg9 {
|
|
41
45
|
padding: var(--gap-xl) var(--gap-m);
|
|
42
46
|
}
|
|
@@ -6,5 +6,5 @@ type VirtualOptionsList = OptionsListProps & {
|
|
|
6
6
|
*/
|
|
7
7
|
overscan?: number;
|
|
8
8
|
};
|
|
9
|
-
declare const VirtualOptionsList: ({ size, flatOptions, highlightedIndex, className, Option, open, options, overscan, Optgroup, dataTestId, emptyPlaceholder, visibleOptions, onScroll, }: VirtualOptionsList) => JSX.Element;
|
|
9
|
+
declare const VirtualOptionsList: ({ size, flatOptions, highlightedIndex, className, getOptionProps, Option, open, options, overscan, Optgroup, dataTestId, emptyPlaceholder, visibleOptions, onScroll, header, footer, }: VirtualOptionsList) => JSX.Element;
|
|
10
10
|
export { VirtualOptionsList };
|
|
@@ -4,11 +4,11 @@ import { usePrevious, lastIndexOf, useVisibleOptions, isGroup } from '../../util
|
|
|
4
4
|
import { Optgroup } from '../optgroup/Component.js';
|
|
5
5
|
import { useVirtual } from 'react-virtual';
|
|
6
6
|
|
|
7
|
-
var styles = {"virtualOptionsList":"
|
|
7
|
+
var styles = {"virtualOptionsList":"select__virtualOptionsList_1ryi1","scrollable":"select__scrollable_1ryi1","inner":"select__inner_1ryi1","virtualRow":"select__virtualRow_1ryi1","highlighted":"select__highlighted_1ryi1","emptyPlaceholder":"select__emptyPlaceholder_1ryi1","l":"select__l_1ryi1","xl":"select__xl_1ryi1"};
|
|
8
8
|
require('./index.css')
|
|
9
9
|
|
|
10
10
|
/* eslint-disable react-hooks/exhaustive-deps */
|
|
11
|
-
const VirtualOptionsList = ({ size = 's', flatOptions = [], highlightedIndex = -1, className, Option, open, options = [], overscan = 10, Optgroup: Optgroup$1 = Optgroup, dataTestId, emptyPlaceholder, visibleOptions = 5, onScroll, }) => {
|
|
11
|
+
const VirtualOptionsList = ({ size = 's', flatOptions = [], highlightedIndex = -1, className, getOptionProps, Option, open, options = [], overscan = 10, Optgroup: Optgroup$1 = Optgroup, dataTestId, emptyPlaceholder, visibleOptions = 5, onScroll, header, footer, }) => {
|
|
12
12
|
const listRef = useRef(null);
|
|
13
13
|
const parentRef = useRef(null);
|
|
14
14
|
const [visibleOptionsInvalidateKey, setVisibleOptionsInvalidateKey] = useState(0);
|
|
@@ -75,21 +75,24 @@ const VirtualOptionsList = ({ size = 's', flatOptions = [], highlightedIndex = -
|
|
|
75
75
|
return acc;
|
|
76
76
|
}, {});
|
|
77
77
|
}, [options]);
|
|
78
|
-
return (React.createElement("div", { className: cn(styles.virtualOptionsList, styles[size], className),
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
78
|
+
return (React.createElement("div", { className: cn(styles.virtualOptionsList, styles[size], className), "data-test-id": dataTestId },
|
|
79
|
+
header,
|
|
80
|
+
React.createElement("div", { className: styles.scrollable, ref: parentRef, onScroll: onScroll },
|
|
81
|
+
React.createElement("div", { className: styles.inner, style: {
|
|
82
|
+
height: `${rowVirtualizer.totalSize}px`,
|
|
83
|
+
}, ref: listRef }, rowVirtualizer.virtualItems.map(virtualRow => {
|
|
84
|
+
const option = flatOptions[virtualRow.index];
|
|
85
|
+
const group = options[groupStartIndexes[virtualRow.index]];
|
|
86
|
+
return (React.createElement("div", { key: virtualRow.index, ref: virtualRow.measureRef, className: cn(styles.virtualRow, {
|
|
87
|
+
[styles.highlighted]: highlightedIndex === virtualRow.index,
|
|
88
|
+
}), style: {
|
|
89
|
+
transform: `translateY(${virtualRow.start}px)`,
|
|
90
|
+
} },
|
|
91
|
+
group && React.createElement(Optgroup$1, { label: group.label }),
|
|
92
|
+
!isGroup(option) && (React.createElement(Option, Object.assign({}, getOptionProps(option, virtualRow.index))))));
|
|
93
|
+
}))),
|
|
94
|
+
emptyPlaceholder && options.length === 0 && (React.createElement("div", { className: styles.emptyPlaceholder }, emptyPlaceholder)),
|
|
95
|
+
footer));
|
|
93
96
|
};
|
|
94
97
|
|
|
95
98
|
export { VirtualOptionsList };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: 1cdpu */
|
|
2
2
|
:root {
|
|
3
3
|
--color-light-border-primary: #dbdee1;
|
|
4
4
|
--color-light-text-secondary: #546272;
|
|
@@ -32,24 +32,27 @@
|
|
|
32
32
|
|
|
33
33
|
/* optgroup */
|
|
34
34
|
}
|
|
35
|
-
.
|
|
36
|
-
overflow: auto;
|
|
35
|
+
.select__virtualOptionsList_1ryi1 {
|
|
37
36
|
width: 100%;
|
|
38
37
|
outline: none;
|
|
39
38
|
box-sizing: border-box;
|
|
40
39
|
position: relative;
|
|
41
40
|
}
|
|
42
|
-
.
|
|
41
|
+
.select__scrollable_1ryi1 {
|
|
42
|
+
overflow: auto;
|
|
43
|
+
width: 100%;
|
|
44
|
+
}
|
|
45
|
+
.select__inner_1ryi1 {
|
|
43
46
|
position: relative;
|
|
44
47
|
width: 100%;
|
|
45
48
|
}
|
|
46
|
-
.
|
|
49
|
+
.select__virtualRow_1ryi1 {
|
|
47
50
|
position: absolute;
|
|
48
51
|
top: 0;
|
|
49
52
|
left: 0;
|
|
50
53
|
width: 100%
|
|
51
54
|
}
|
|
52
|
-
.
|
|
55
|
+
.select__virtualRow_1ryi1:before {
|
|
53
56
|
content: '';
|
|
54
57
|
position: absolute;
|
|
55
58
|
z-index: 1;
|
|
@@ -60,18 +63,18 @@
|
|
|
60
63
|
background: var(--select-option-divider-background);
|
|
61
64
|
display: var(--select-option-divider-display);
|
|
62
65
|
}
|
|
63
|
-
.
|
|
66
|
+
.select__virtualRow_1ryi1:first-child:before {
|
|
64
67
|
display: none;
|
|
65
68
|
}
|
|
66
|
-
.
|
|
67
|
-
.
|
|
69
|
+
.select__highlighted_1ryi1:before,
|
|
70
|
+
.select__highlighted_1ryi1 + .select__virtualRow_1ryi1:before {
|
|
68
71
|
display: none;
|
|
69
72
|
}
|
|
70
|
-
.
|
|
73
|
+
.select__emptyPlaceholder_1ryi1 {
|
|
71
74
|
padding: var(--gap-m) var(--gap-s);
|
|
72
75
|
color: var(--select-options-list-empty-placeholder-color);
|
|
73
76
|
}
|
|
74
|
-
.
|
|
75
|
-
.
|
|
77
|
+
.select__l_1ryi1 .select__emptyPlaceholder_1ryi1,
|
|
78
|
+
.select__xl_1ryi1 .select__emptyPlaceholder_1ryi1 {
|
|
76
79
|
padding: var(--gap-xl) var(--gap-m);
|
|
77
80
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { OptionShape, OptionsListProps } from "./typings";
|
|
4
|
+
declare const OptionsListWithApply: React.ForwardRefExoticComponent<OptionsListProps & {
|
|
5
|
+
showClear?: boolean | undefined;
|
|
6
|
+
onApply?: (() => void) | undefined;
|
|
7
|
+
onClear?: (() => void) | undefined;
|
|
8
|
+
onClose?: (() => void) | undefined;
|
|
9
|
+
selectedDraft?: OptionShape[] | undefined;
|
|
10
|
+
OptionsList?: React.FC<OptionsListProps & React.RefAttributes<unknown>> | undefined;
|
|
11
|
+
} & React.RefAttributes<unknown>>;
|
|
12
|
+
export { OptionsListWithApply };
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React, { forwardRef, useRef, useCallback, useEffect, useMemo, useState } from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
import '@alfalab/hooks';
|
|
4
|
+
import '@alfalab/core-components-form-control/dist/modern';
|
|
5
|
+
import { processOptions } from './utils.js';
|
|
6
|
+
import '@alfalab/icons-glyph/ChevronDownMIcon';
|
|
7
|
+
import { OptionsList } from './components/options-list/Component.js';
|
|
8
|
+
import '@alfalab/core-components-checkbox/dist/modern';
|
|
9
|
+
import './components/base-select/Component.js';
|
|
10
|
+
import './Component.js';
|
|
11
|
+
import 'react-virtual';
|
|
12
|
+
import '@alfalab/core-components-skeleton/dist/modern';
|
|
13
|
+
import './intersection-observer-2080f60e.js';
|
|
14
|
+
import { Button } from '@alfalab/core-components-button/dist/modern';
|
|
15
|
+
|
|
16
|
+
var styles = {"footer":"select__footer_1lf9t","withBorder":"select__withBorder_1lf9t"};
|
|
17
|
+
require('./presets/useSelectWithApply/options-list-with-apply/index.css')
|
|
18
|
+
|
|
19
|
+
const OptionsListWithApply = forwardRef(({ toggleMenu, OptionsList: OptionsList$1 = OptionsList, getOptionProps: defaultGetOptionProps, showClear = true, selectedDraft = [], flatOptions = [], onApply = () => null, onClear = () => null, onClose = () => null, visibleOptions = 5, ...restProps }, ref) => {
|
|
20
|
+
const footerRef = useRef(null);
|
|
21
|
+
const getOptionProps = useCallback((option, index) => {
|
|
22
|
+
const optionProps = defaultGetOptionProps(option, index);
|
|
23
|
+
const selected = option.key === SELECT_ALL_KEY
|
|
24
|
+
? selectedDraft.length === flatOptions.length - 1
|
|
25
|
+
: selectedDraft.includes(option);
|
|
26
|
+
return {
|
|
27
|
+
...optionProps,
|
|
28
|
+
selected,
|
|
29
|
+
};
|
|
30
|
+
}, [defaultGetOptionProps, flatOptions.length, selectedDraft]);
|
|
31
|
+
const handleApply = useCallback(() => {
|
|
32
|
+
onApply();
|
|
33
|
+
toggleMenu();
|
|
34
|
+
}, [onApply, toggleMenu]);
|
|
35
|
+
const handleClear = useCallback(() => {
|
|
36
|
+
onClear();
|
|
37
|
+
toggleMenu();
|
|
38
|
+
}, [onClear, toggleMenu]);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const activeElement = document.activeElement;
|
|
41
|
+
setTimeout(() => {
|
|
42
|
+
if (footerRef.current) {
|
|
43
|
+
footerRef.current.focus();
|
|
44
|
+
}
|
|
45
|
+
}, 0);
|
|
46
|
+
return () => {
|
|
47
|
+
onClose();
|
|
48
|
+
if (activeElement) {
|
|
49
|
+
activeElement.focus();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
53
|
+
}, []);
|
|
54
|
+
return (React.createElement(OptionsList$1, Object.assign({}, restProps, { ref: ref, visibleOptions: visibleOptions, toggleMenu: toggleMenu, flatOptions: flatOptions, getOptionProps: getOptionProps, footer: React.createElement("div", {
|
|
55
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
56
|
+
tabIndex: 0, className: cn(styles.footer, {
|
|
57
|
+
[styles.withBorder]: visibleOptions && flatOptions.length > visibleOptions,
|
|
58
|
+
}), ref: footerRef },
|
|
59
|
+
React.createElement(Button, { size: 'xxs', view: 'primary', onClick: handleApply }, "\u041F\u0440\u0438\u043C\u0435\u043D\u0438\u0442\u044C"),
|
|
60
|
+
showClear && (React.createElement(Button, { size: 'xxs', view: 'secondary', onClick: handleClear }, "\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C"))) })));
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const SELECT_ALL_KEY = 'select_all';
|
|
64
|
+
const selectAllOption = { key: SELECT_ALL_KEY, content: 'Выбрать все' };
|
|
65
|
+
function useSelectWithApply({ options, selected, onChange = () => null, OptionsList, showClear = true, showSelectAll = false, }) {
|
|
66
|
+
const { flatOptions, selectedOptions } = useMemo(() => processOptions(options, selected), [
|
|
67
|
+
options,
|
|
68
|
+
selected,
|
|
69
|
+
]);
|
|
70
|
+
const [selectedDraft, setSelectedDraft] = useState(selectedOptions);
|
|
71
|
+
const selectedOptionsRef = useRef(selectedOptions);
|
|
72
|
+
const handleApply = useCallback(() => {
|
|
73
|
+
onChange({
|
|
74
|
+
selected: selectedDraft[0],
|
|
75
|
+
selectedMultiple: selectedDraft,
|
|
76
|
+
initiator: null,
|
|
77
|
+
});
|
|
78
|
+
}, [onChange, selectedDraft]);
|
|
79
|
+
const handleClear = useCallback(() => {
|
|
80
|
+
setSelectedDraft([]);
|
|
81
|
+
onChange({
|
|
82
|
+
selected: null,
|
|
83
|
+
selectedMultiple: [],
|
|
84
|
+
initiator: null,
|
|
85
|
+
});
|
|
86
|
+
}, [onChange]);
|
|
87
|
+
const handleChange = useCallback(({ initiator, ...restArgs }) => {
|
|
88
|
+
if (!initiator) {
|
|
89
|
+
onChange({
|
|
90
|
+
initiator: null,
|
|
91
|
+
...restArgs,
|
|
92
|
+
});
|
|
93
|
+
return;
|
|
94
|
+
}
|
|
95
|
+
const initiatorSelected = selectedDraft.includes(initiator) ||
|
|
96
|
+
(initiator.key === SELECT_ALL_KEY && selectedDraft.length === flatOptions.length);
|
|
97
|
+
if (initiator.key === SELECT_ALL_KEY) {
|
|
98
|
+
setSelectedDraft(initiatorSelected ? [] : flatOptions);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
setSelectedDraft(initiatorSelected
|
|
102
|
+
? selectedDraft.filter(o => o !== initiator)
|
|
103
|
+
: selectedDraft.concat(initiator));
|
|
104
|
+
}
|
|
105
|
+
}, [flatOptions, onChange, selectedDraft]);
|
|
106
|
+
const handleClose = useCallback(() => {
|
|
107
|
+
setSelectedDraft(selectedOptionsRef.current);
|
|
108
|
+
}, []);
|
|
109
|
+
useEffect(() => {
|
|
110
|
+
setSelectedDraft(selectedOptions);
|
|
111
|
+
selectedOptionsRef.current = selectedOptions;
|
|
112
|
+
}, [selectedOptions]);
|
|
113
|
+
const memoizedOptions = useMemo(() => (showSelectAll ? [selectAllOption, ...options] : options), [options, showSelectAll]);
|
|
114
|
+
return {
|
|
115
|
+
OptionsList: OptionsListWithApply,
|
|
116
|
+
optionsListProps: {
|
|
117
|
+
OptionsList,
|
|
118
|
+
showClear: showClear && (selectedDraft.length > 0 || selectedOptions.length > 0),
|
|
119
|
+
onClear: handleClear,
|
|
120
|
+
onApply: handleApply,
|
|
121
|
+
onClose: handleClose,
|
|
122
|
+
selectedDraft,
|
|
123
|
+
},
|
|
124
|
+
allowUnselect: true,
|
|
125
|
+
multiple: true,
|
|
126
|
+
options: memoizedOptions,
|
|
127
|
+
onChange: handleChange,
|
|
128
|
+
selected,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export { OptionsListWithApply as O, SELECT_ALL_KEY as S, useSelectWithApply as u };
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { OptionShape, BaseSelectProps } from "./index";
|
|
3
|
+
type useSelectWithApplyProps = {
|
|
4
|
+
/**
|
|
5
|
+
* Список выбранных пунктов
|
|
6
|
+
*/
|
|
7
|
+
selected: BaseSelectProps['selected'];
|
|
8
|
+
/**
|
|
9
|
+
* Список вариантов выбора
|
|
10
|
+
*/
|
|
11
|
+
options: BaseSelectProps['options'];
|
|
12
|
+
/**
|
|
13
|
+
* Обработчик выбора
|
|
14
|
+
*/
|
|
15
|
+
onChange: BaseSelectProps['onChange'];
|
|
16
|
+
/**
|
|
17
|
+
* Компонент выпадающего меню
|
|
18
|
+
*/
|
|
19
|
+
OptionsList?: BaseSelectProps['OptionsList'];
|
|
20
|
+
/**
|
|
21
|
+
* Показывать кнопку очистки
|
|
22
|
+
*/
|
|
23
|
+
showClear?: boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Показывать пункт "Выбрать все"
|
|
26
|
+
*/
|
|
27
|
+
showSelectAll?: boolean;
|
|
28
|
+
};
|
|
29
|
+
declare const SELECT_ALL_KEY = "select_all";
|
|
30
|
+
declare function useSelectWithApply({ options, selected, onChange, OptionsList, showClear, showSelectAll, }: useSelectWithApplyProps): {
|
|
31
|
+
OptionsList: import("react").ForwardRefExoticComponent<import("./index").OptionsListProps & {
|
|
32
|
+
showClear?: boolean | undefined;
|
|
33
|
+
onApply?: (() => void) | undefined;
|
|
34
|
+
onClear?: (() => void) | undefined;
|
|
35
|
+
onClose?: (() => void) | undefined;
|
|
36
|
+
selectedDraft?: OptionShape[] | undefined;
|
|
37
|
+
OptionsList?: import("react").FC<import("./index").OptionsListProps & import("react").RefAttributes<unknown>> | undefined;
|
|
38
|
+
} & import("react").RefAttributes<unknown>>;
|
|
39
|
+
optionsListProps: {
|
|
40
|
+
OptionsList: import("react").FC<import("./index").OptionsListProps> | undefined;
|
|
41
|
+
showClear: boolean;
|
|
42
|
+
onClear: () => void;
|
|
43
|
+
onApply: () => void;
|
|
44
|
+
onClose: () => void;
|
|
45
|
+
selectedDraft: OptionShape[];
|
|
46
|
+
};
|
|
47
|
+
allowUnselect: boolean;
|
|
48
|
+
multiple: boolean;
|
|
49
|
+
options: (OptionShape | import("./index").GroupShape | {
|
|
50
|
+
key: string;
|
|
51
|
+
content: string;
|
|
52
|
+
})[];
|
|
53
|
+
onChange: (payload: {
|
|
54
|
+
selected: OptionShape | null;
|
|
55
|
+
selectedMultiple: OptionShape[];
|
|
56
|
+
initiator: OptionShape | null;
|
|
57
|
+
name?: string | undefined;
|
|
58
|
+
}) => void;
|
|
59
|
+
selected: string | OptionShape | (string | OptionShape)[] | null | undefined;
|
|
60
|
+
};
|
|
61
|
+
export { SELECT_ALL_KEY, useSelectWithApply };
|
package/dist/modern/index.js
CHANGED
|
@@ -9,6 +9,7 @@ export { Arrow } from './components/arrow/Component.js';
|
|
|
9
9
|
import 'react-merge-refs';
|
|
10
10
|
export { Optgroup } from './components/optgroup/Component.js';
|
|
11
11
|
export { OptionsList } from './components/options-list/Component.js';
|
|
12
|
+
import '@alfalab/core-components-checkbox/dist/modern';
|
|
12
13
|
import './components/checkmark/Component.js';
|
|
13
14
|
export { Option } from './components/option/Component.js';
|
|
14
15
|
import 'resize-observer';
|
|
@@ -21,4 +22,7 @@ import 'react-virtual';
|
|
|
21
22
|
export { VirtualOptionsList } from './components/virtual-options-list/Component.js';
|
|
22
23
|
import '@alfalab/core-components-skeleton/dist/modern';
|
|
23
24
|
export { useSelectWithLoading } from './presets/useSelectWithLoading/hook.js';
|
|
25
|
+
import './intersection-observer-2080f60e.js';
|
|
24
26
|
export { useLazyLoading } from './presets/useLazyLoading/hook.js';
|
|
27
|
+
import '@alfalab/core-components-button/dist/modern';
|
|
28
|
+
export { S as SELECT_ALL_KEY, u as useSelectWithApply } from './hook-cdda7a62.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|