@alfalab/core-components-select 17.5.0 → 17.6.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/components/arrow/Component.js +1 -1
- package/components/arrow/index.css +3 -3
- package/components/base-checkmark/Component.js +1 -1
- package/components/base-checkmark/index.css +4 -4
- package/components/base-option/Component.js +1 -1
- package/components/base-option/index.css +15 -15
- package/components/base-select/Component.js +24 -12
- package/components/base-select/index.css +11 -11
- package/components/base-select/mobile.css +12 -12
- package/components/checkmark/Component.js +1 -1
- package/components/checkmark/index.css +10 -10
- package/components/checkmark-mobile/Component.js +1 -1
- package/components/checkmark-mobile/index.css +6 -6
- package/components/field/Component.js +1 -1
- package/components/field/index.css +12 -12
- package/components/footer/Component.js +1 -1
- package/components/footer/index.css +5 -5
- package/components/optgroup/Component.js +1 -1
- package/components/optgroup/index.css +6 -6
- package/components/option/Component.js +1 -1
- package/components/option/index.css +19 -19
- package/components/options-list/Component.js +1 -1
- package/components/options-list/index.css +10 -10
- package/components/search/Component.js +1 -1
- package/components/search/index.css +2 -2
- package/components/virtual-options-list/Component.js +1 -1
- package/components/virtual-options-list/index.css +15 -15
- package/cssm/components/base-select/Component.js +22 -10
- package/cssm/components/base-select/mobile.module.css +2 -2
- package/cssm/{hook-546b2479.js → hook-052c1a2e.js} +20 -8
- package/{hook-64a8061f.d.ts → cssm/hook-2f4e96b2.d.ts} +9 -7
- package/cssm/mobile/Component.mobile.js +7 -9
- package/cssm/presets/index.d.ts +1 -1
- package/cssm/presets/index.js +1 -1
- package/cssm/presets/useSelectWithApply/hook.js +1 -1
- package/cssm/presets/useSelectWithApply/options-list-with-apply/Component.js +1 -1
- package/cssm/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +2 -2
- package/cssm/presets/useSelectWithApply/options-list-with-apply/footer/index.module.css +1 -1
- package/cssm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
- package/cssm/presets/useSelectWithApply/options-list-with-apply/index.js +1 -1
- package/cssm/shared/index.js +2 -1
- package/cssm/typings.d.ts +3 -1
- package/cssm/utils.d.ts +3 -2
- package/cssm/utils.js +24 -9
- package/esm/components/arrow/Component.js +1 -1
- package/esm/components/arrow/index.css +3 -3
- package/esm/components/base-checkmark/Component.js +1 -1
- package/esm/components/base-checkmark/index.css +4 -4
- package/esm/components/base-option/Component.js +1 -1
- package/esm/components/base-option/index.css +15 -15
- package/esm/components/base-select/Component.js +25 -13
- package/esm/components/base-select/index.css +11 -11
- package/esm/components/base-select/mobile.css +12 -12
- package/esm/components/checkmark/Component.js +1 -1
- package/esm/components/checkmark/index.css +10 -10
- package/esm/components/checkmark-mobile/Component.js +1 -1
- package/esm/components/checkmark-mobile/index.css +6 -6
- package/esm/components/field/Component.js +1 -1
- package/esm/components/field/index.css +12 -12
- package/esm/components/footer/Component.js +1 -1
- package/esm/components/footer/index.css +5 -5
- package/esm/components/optgroup/Component.js +1 -1
- package/esm/components/optgroup/index.css +6 -6
- package/esm/components/option/Component.js +1 -1
- package/esm/components/option/index.css +19 -19
- package/esm/components/options-list/Component.js +1 -1
- package/esm/components/options-list/index.css +10 -10
- package/esm/components/search/Component.js +1 -1
- package/esm/components/search/index.css +2 -2
- package/esm/components/virtual-options-list/Component.js +1 -1
- package/esm/components/virtual-options-list/index.css +15 -15
- package/{modern/hook-64a8061f.d.ts → esm/hook-2f4e96b2.d.ts} +9 -7
- package/esm/{hook-5906d9e6.js → hook-8bbe812b.js} +21 -9
- package/esm/mobile/Component.mobile.js +7 -9
- package/esm/presets/index.d.ts +1 -1
- package/esm/presets/index.js +1 -1
- package/esm/presets/useSelectWithApply/hook.js +1 -1
- package/esm/presets/useSelectWithApply/options-list-with-apply/Component.js +1 -1
- package/esm/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +3 -3
- package/esm/presets/useSelectWithApply/options-list-with-apply/footer/index.css +3 -3
- package/esm/presets/useSelectWithApply/options-list-with-apply/header/Component.js +1 -1
- package/esm/presets/useSelectWithApply/options-list-with-apply/header/index.css +3 -3
- package/esm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
- package/esm/presets/useSelectWithApply/options-list-with-apply/index.js +1 -1
- package/esm/presets/useSelectWithLoading/hook.js +1 -1
- package/esm/presets/useSelectWithLoading/index.css +2 -2
- package/esm/shared/index.js +2 -2
- package/esm/typings.d.ts +3 -1
- package/esm/utils.d.ts +3 -2
- package/esm/utils.js +24 -10
- package/{cssm/hook-64a8061f.d.ts → hook-2f4e96b2.d.ts} +9 -7
- package/{hook-598322df.js → hook-4d5fa450.js} +20 -8
- package/mobile/Component.mobile.js +7 -9
- package/modern/components/arrow/Component.js +1 -1
- package/modern/components/arrow/index.css +3 -3
- package/modern/components/base-checkmark/Component.js +1 -1
- package/modern/components/base-checkmark/index.css +4 -4
- package/modern/components/base-option/Component.js +1 -1
- package/modern/components/base-option/index.css +15 -15
- package/modern/components/base-select/Component.js +13 -4
- package/modern/components/base-select/index.css +11 -11
- package/modern/components/base-select/mobile.css +12 -12
- package/modern/components/checkmark/Component.js +1 -1
- package/modern/components/checkmark/index.css +10 -10
- package/modern/components/checkmark-mobile/Component.js +1 -1
- package/modern/components/checkmark-mobile/index.css +6 -6
- package/modern/components/field/Component.js +1 -1
- package/modern/components/field/index.css +12 -12
- package/modern/components/footer/Component.js +1 -1
- package/modern/components/footer/index.css +5 -5
- package/modern/components/optgroup/Component.js +1 -1
- package/modern/components/optgroup/index.css +6 -6
- package/modern/components/option/Component.js +1 -1
- package/modern/components/option/index.css +19 -19
- package/modern/components/options-list/Component.js +1 -1
- package/modern/components/options-list/index.css +10 -10
- package/modern/components/search/Component.js +1 -1
- package/modern/components/search/index.css +2 -2
- package/modern/components/virtual-options-list/Component.js +1 -1
- package/modern/components/virtual-options-list/index.css +15 -15
- package/{esm/hook-64a8061f.d.ts → modern/hook-2f4e96b2.d.ts} +9 -7
- package/modern/{hook-241d62bb.js → hook-6a076c91.js} +14 -3
- package/modern/mobile/Component.mobile.js +8 -10
- package/modern/presets/index.d.ts +1 -1
- package/modern/presets/index.js +1 -1
- package/modern/presets/useSelectWithApply/hook.js +1 -1
- package/modern/presets/useSelectWithApply/options-list-with-apply/Component.js +1 -1
- package/modern/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +3 -3
- package/modern/presets/useSelectWithApply/options-list-with-apply/footer/index.css +3 -3
- package/modern/presets/useSelectWithApply/options-list-with-apply/header/Component.js +1 -1
- package/modern/presets/useSelectWithApply/options-list-with-apply/header/index.css +3 -3
- package/modern/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
- package/modern/presets/useSelectWithApply/options-list-with-apply/index.js +1 -1
- package/modern/presets/useSelectWithLoading/hook.js +1 -1
- package/modern/presets/useSelectWithLoading/index.css +2 -2
- package/modern/shared/index.js +2 -2
- package/modern/typings.d.ts +3 -1
- package/modern/utils.d.ts +3 -2
- package/modern/utils.js +23 -10
- package/package.json +1 -1
- package/presets/index.d.ts +1 -1
- package/presets/index.js +1 -1
- package/presets/useSelectWithApply/hook.js +1 -1
- package/presets/useSelectWithApply/options-list-with-apply/Component.js +1 -1
- package/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +3 -3
- package/presets/useSelectWithApply/options-list-with-apply/footer/index.css +3 -3
- package/presets/useSelectWithApply/options-list-with-apply/header/Component.js +1 -1
- package/presets/useSelectWithApply/options-list-with-apply/header/index.css +3 -3
- package/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
- package/presets/useSelectWithApply/options-list-with-apply/index.js +1 -1
- package/presets/useSelectWithLoading/hook.js +1 -1
- package/presets/useSelectWithLoading/index.css +2 -2
- package/shared/index.js +2 -1
- package/src/components/base-select/Component.tsx +28 -3
- package/src/components/base-select/mobile.module.css +1 -1
- package/src/mobile/Component.mobile.tsx +8 -18
- package/src/presets/useSelectWithApply/hook.tsx +26 -4
- package/src/presets/useSelectWithApply/options-list-with-apply/footer/Component.tsx +2 -0
- package/src/presets/useSelectWithApply/options-list-with-apply/footer/index.module.css +1 -1
- package/src/typings.ts +2 -0
- package/src/utils.ts +26 -8
- package/typings.d.ts +3 -1
- package/utils.d.ts +3 -2
- package/utils.js +24 -9
- /package/cssm/{hook-546b2479.d.ts → hook-052c1a2e.d.ts} +0 -0
- /package/esm/{hook-5906d9e6.d.ts → hook-8bbe812b.d.ts} +0 -0
- /package/{hook-598322df.d.ts → hook-4d5fa450.d.ts} +0 -0
- /package/modern/{hook-241d62bb.d.ts → hook-6a076c91.d.ts} +0 -0
|
@@ -10,7 +10,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
10
10
|
|
|
11
11
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
12
12
|
|
|
13
|
-
var styles = {"footer":"
|
|
13
|
+
var styles = {"footer":"select__footer_1i5y0","button":"select__button_1i5y0"};
|
|
14
14
|
require('./index.css')
|
|
15
15
|
|
|
16
16
|
var Footer = function (_a) {
|
|
@@ -18,8 +18,8 @@ var Footer = function (_a) {
|
|
|
18
18
|
return (React__default.default.createElement("div", {
|
|
19
19
|
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
20
20
|
tabIndex: 0, className: styles.footer },
|
|
21
|
-
React__default.default.createElement(desktop.ButtonDesktop, { size: 32, view: 'primary', onClick: handleApply, dataTestId: coreComponentsShared.getDataTestId(dataTestId, 'apply') }, "\u041F\u0440\u0438\u043C\u0435\u043D\u0438\u0442\u044C"),
|
|
22
|
-
showClear && selectedDraft.length > 0 && (React__default.default.createElement(desktop.ButtonDesktop, { size: 32, view: 'secondary', onClick: handleClear, dataTestId: coreComponentsShared.getDataTestId(dataTestId, 'clear') }, "\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C"))));
|
|
21
|
+
React__default.default.createElement(desktop.ButtonDesktop, { size: 32, view: 'primary', onClick: handleApply, dataTestId: coreComponentsShared.getDataTestId(dataTestId, 'apply'), className: styles.button }, "\u041F\u0440\u0438\u043C\u0435\u043D\u0438\u0442\u044C"),
|
|
22
|
+
showClear && selectedDraft.length > 0 && (React__default.default.createElement(desktop.ButtonDesktop, { size: 32, view: 'secondary', onClick: handleClear, dataTestId: coreComponentsShared.getDataTestId(dataTestId, 'clear'), className: styles.button }, "\u0421\u0431\u0440\u043E\u0441\u0438\u0442\u044C"))));
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
exports.Footer = Footer;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: 467s1 */
|
|
2
2
|
:root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
3
3
|
} /* deprecated */ :root {
|
|
4
4
|
--color-light-bg-primary: #fff; /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
@@ -17,10 +17,10 @@
|
|
|
17
17
|
--gap-s: 12px;
|
|
18
18
|
} :root {
|
|
19
19
|
} :root {
|
|
20
|
-
} .
|
|
20
|
+
} .select__footer_1i5y0 {
|
|
21
21
|
background-color: var(--color-light-bg-primary);
|
|
22
22
|
padding: var(--gap-s);
|
|
23
23
|
outline: none
|
|
24
|
-
} .
|
|
24
|
+
} .select__footer_1i5y0 > .select__button_1i5y0 + .select__button_1i5y0 {
|
|
25
25
|
margin-left: var(--gap-xs);
|
|
26
26
|
}
|
|
@@ -11,7 +11,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
12
12
|
var cn__default = /*#__PURE__*/_interopDefaultCompat(cn);
|
|
13
13
|
|
|
14
|
-
var styles = {"desktop":"
|
|
14
|
+
var styles = {"desktop":"select__desktop_14hbg","mobile":"select__mobile_14hbg"};
|
|
15
15
|
require('./index.css')
|
|
16
16
|
|
|
17
17
|
var Header = function (_a) {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* hash:
|
|
1
|
+
/* hash: 7p34l */
|
|
2
2
|
:root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
3
3
|
} /* deprecated */ :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
4
4
|
} :root { /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */ /* deprecated */
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
--gap-s: 12px;
|
|
17
17
|
} :root {
|
|
18
18
|
} :root {
|
|
19
|
-
} .
|
|
19
|
+
} .select__desktop_14hbg {
|
|
20
20
|
padding: var(--gap-s);
|
|
21
|
-
} .
|
|
21
|
+
} .select__mobile_14hbg {
|
|
22
22
|
padding: var(--gap-s) var(--gap-xs);
|
|
23
23
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from "../../../hook-
|
|
1
|
+
export * from "../../../hook-4d5fa450";
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
var presets_useSelectWithApply_optionsListWithApply_Component = require('../../../hook-
|
|
5
|
+
var presets_useSelectWithApply_optionsListWithApply_Component = require('../../../hook-4d5fa450.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
11
11
|
|
|
12
12
|
var React__default = /*#__PURE__*/_interopDefaultCompat(React);
|
|
13
13
|
|
|
14
|
-
var styles = {"skeleton":"
|
|
14
|
+
var styles = {"skeleton":"select__skeleton_170xy"};
|
|
15
15
|
require('./index.css')
|
|
16
16
|
|
|
17
17
|
function useSelectWithLoading(_a) {
|
package/shared/index.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var presets_useSelectWithLoading_hook = require('../presets/useSelectWithLoading/hook.js');
|
|
6
6
|
var presets_useLazyLoading_hook = require('../presets/useLazyLoading/hook.js');
|
|
7
|
-
var presets_useSelectWithApply_optionsListWithApply_Component = require('../hook-
|
|
7
|
+
var presets_useSelectWithApply_optionsListWithApply_Component = require('../hook-4d5fa450.js');
|
|
8
8
|
var utils = require('../utils.js');
|
|
9
9
|
var components_option_Component = require('../components/option/Component.js');
|
|
10
10
|
var components_baseOption_Component = require('../components/base-option/Component.js');
|
|
@@ -25,6 +25,7 @@ exports.SELECT_ALL_KEY = presets_useSelectWithApply_optionsListWithApply_Compone
|
|
|
25
25
|
exports.useSelectWithApply = presets_useSelectWithApply_optionsListWithApply_Component.useSelectWithApply;
|
|
26
26
|
exports.defaultAccessor = utils.defaultAccessor;
|
|
27
27
|
exports.defaultFilterFn = utils.defaultFilterFn;
|
|
28
|
+
exports.defaultGroupAccessor = utils.defaultGroupAccessor;
|
|
28
29
|
exports.getSelectTestIds = utils.getSelectTestIds;
|
|
29
30
|
exports.isGroup = utils.isGroup;
|
|
30
31
|
exports.isOptionShape = utils.isOptionShape;
|
|
@@ -44,7 +44,13 @@ import type {
|
|
|
44
44
|
OptionsListProps,
|
|
45
45
|
SearchProps,
|
|
46
46
|
} from '../../typings';
|
|
47
|
-
import {
|
|
47
|
+
import {
|
|
48
|
+
defaultAccessor,
|
|
49
|
+
defaultFilterFn,
|
|
50
|
+
defaultGroupAccessor,
|
|
51
|
+
isGroup,
|
|
52
|
+
processOptions,
|
|
53
|
+
} from '../../utils';
|
|
48
54
|
import { NativeSelect } from '../native-select';
|
|
49
55
|
|
|
50
56
|
import styles from './index.module.css';
|
|
@@ -162,10 +168,29 @@ export const BaseSelect = forwardRef(
|
|
|
162
168
|
|
|
163
169
|
const accessor = searchProps.accessor || defaultAccessor;
|
|
164
170
|
const filterFn = searchProps.filterFn || defaultFilterFn;
|
|
171
|
+
const filterGroup = searchProps.filterGroup ?? false;
|
|
172
|
+
const groupAccessor = searchProps.groupAccessor ?? defaultGroupAccessor;
|
|
165
173
|
|
|
166
174
|
const { filteredOptions, flatOptions, selectedOptions } = useMemo(
|
|
167
|
-
() =>
|
|
168
|
-
|
|
175
|
+
() =>
|
|
176
|
+
processOptions(
|
|
177
|
+
options,
|
|
178
|
+
selected,
|
|
179
|
+
(option) => {
|
|
180
|
+
if (isGroup(option)) {
|
|
181
|
+
const groupAccessorValue = groupAccessor(option);
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
typeof groupAccessorValue === 'string' &&
|
|
185
|
+
filterFn(groupAccessorValue, search)
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return filterFn(accessor(option), search);
|
|
190
|
+
},
|
|
191
|
+
filterGroup,
|
|
192
|
+
),
|
|
193
|
+
[options, selected, filterFn, accessor, search, filterGroup, groupAccessor],
|
|
169
194
|
);
|
|
170
195
|
|
|
171
196
|
const scrollIntoView = (node: HTMLElement) => {
|
|
@@ -15,12 +15,7 @@ import { Search as DefaultSearch } from '../components/search';
|
|
|
15
15
|
import { VirtualOptionsList as DefaultVirtualOptionsList } from '../components/virtual-options-list';
|
|
16
16
|
import { useSelectWithApply } from '../presets/useSelectWithApply/hook';
|
|
17
17
|
import { Header } from '../presets/useSelectWithApply/options-list-with-apply/header/Component';
|
|
18
|
-
import {
|
|
19
|
-
AnyObject,
|
|
20
|
-
BottomSheetSelectMobileProps,
|
|
21
|
-
ModalSelectMobileProps,
|
|
22
|
-
SelectMobileProps,
|
|
23
|
-
} from '../typings';
|
|
18
|
+
import { AnyObject, SelectMobileProps } from '../typings';
|
|
24
19
|
|
|
25
20
|
const VIRTUAL_OPTIONS_LIST_THRESHOLD = 30;
|
|
26
21
|
|
|
@@ -46,7 +41,6 @@ export const SelectMobile = forwardRef(
|
|
|
46
41
|
Option = DefaultOption,
|
|
47
42
|
Search = DefaultSearch,
|
|
48
43
|
selected,
|
|
49
|
-
isBottomSheet = true,
|
|
50
44
|
options,
|
|
51
45
|
OptionsList = options.length > VIRTUAL_OPTIONS_LIST_THRESHOLD
|
|
52
46
|
? DefaultVirtualOptionsList
|
|
@@ -62,9 +56,6 @@ export const SelectMobile = forwardRef(
|
|
|
62
56
|
}: SelectMobileProps,
|
|
63
57
|
ref,
|
|
64
58
|
) => {
|
|
65
|
-
const typedRestBottomSheetProps = restProps as BottomSheetSelectMobileProps;
|
|
66
|
-
const typedRestModalProps = restProps as ModalSelectMobileProps;
|
|
67
|
-
|
|
68
59
|
const applyProps = useSelectWithApply({
|
|
69
60
|
optionsListProps: {
|
|
70
61
|
...(optionsListProps as AnyObject),
|
|
@@ -108,7 +99,6 @@ export const SelectMobile = forwardRef(
|
|
|
108
99
|
Optgroup={Optgroup}
|
|
109
100
|
Option={Option}
|
|
110
101
|
Search={Search}
|
|
111
|
-
isBottomSheet={isBottomSheet}
|
|
112
102
|
options={options}
|
|
113
103
|
selected={selected}
|
|
114
104
|
onChange={onChange}
|
|
@@ -117,21 +107,21 @@ export const SelectMobile = forwardRef(
|
|
|
117
107
|
searchProps={searchProps}
|
|
118
108
|
BottomSheet={BottomSheet}
|
|
119
109
|
ModalMobile={ModalMobile}
|
|
120
|
-
{
|
|
110
|
+
optionsListProps={optionsListProps}
|
|
111
|
+
{...restProps}
|
|
112
|
+
{...(restProps.isBottomSheet === false
|
|
121
113
|
? {
|
|
122
|
-
|
|
114
|
+
modalHeaderProps: {
|
|
123
115
|
bottomAddons,
|
|
124
|
-
...
|
|
116
|
+
...restProps.modalHeaderProps,
|
|
125
117
|
},
|
|
126
118
|
}
|
|
127
119
|
: {
|
|
128
|
-
|
|
120
|
+
bottomSheetProps: {
|
|
129
121
|
bottomAddons,
|
|
130
|
-
...
|
|
122
|
+
...restProps.bottomSheetProps,
|
|
131
123
|
},
|
|
132
124
|
})}
|
|
133
|
-
optionsListProps={optionsListProps}
|
|
134
|
-
{...restProps}
|
|
135
125
|
{...(useWithApplyHook && applyProps)}
|
|
136
126
|
/>
|
|
137
127
|
);
|
|
@@ -2,7 +2,13 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
|
|
2
2
|
import deepEqual from 'deep-equal';
|
|
3
3
|
|
|
4
4
|
import type { AnyObject, BaseSelectProps, OptionShape } from '../../typings';
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
defaultAccessor,
|
|
7
|
+
defaultFilterFn,
|
|
8
|
+
defaultGroupAccessor,
|
|
9
|
+
isGroup,
|
|
10
|
+
processOptions,
|
|
11
|
+
} from '../../utils';
|
|
6
12
|
|
|
7
13
|
import { OptionsListWithApply } from './options-list-with-apply';
|
|
8
14
|
|
|
@@ -71,7 +77,7 @@ export function useSelectWithApply({
|
|
|
71
77
|
showClear = true,
|
|
72
78
|
showSelectAll = false,
|
|
73
79
|
showHeaderWithSelectAll = false,
|
|
74
|
-
showSearch,
|
|
80
|
+
showSearch = false,
|
|
75
81
|
searchProps = {},
|
|
76
82
|
}: UseSelectWithApplyProps) {
|
|
77
83
|
const [searchState, setSearchState] = useState('');
|
|
@@ -83,15 +89,31 @@ export function useSelectWithApply({
|
|
|
83
89
|
|
|
84
90
|
const accessor = searchProps.accessor || defaultAccessor;
|
|
85
91
|
const filterFn = searchProps.filterFn || defaultFilterFn;
|
|
92
|
+
const groupAccessor = searchProps.groupAccessor ?? defaultGroupAccessor;
|
|
93
|
+
const filterGroup = searchProps.filterGroup ?? false;
|
|
86
94
|
|
|
87
95
|
const { flatOptions, selectedOptions } = useMemo(
|
|
88
96
|
() =>
|
|
89
97
|
processOptions(
|
|
90
98
|
options,
|
|
91
99
|
selected,
|
|
92
|
-
showSearch
|
|
100
|
+
showSearch
|
|
101
|
+
? (option) => {
|
|
102
|
+
if (isGroup(option)) {
|
|
103
|
+
const groupAccessorValue = groupAccessor(option);
|
|
104
|
+
|
|
105
|
+
return (
|
|
106
|
+
typeof groupAccessorValue === 'string' &&
|
|
107
|
+
filterFn(groupAccessorValue, search)
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return filterFn(accessor(option), search);
|
|
112
|
+
}
|
|
113
|
+
: undefined,
|
|
114
|
+
filterGroup,
|
|
93
115
|
),
|
|
94
|
-
[
|
|
116
|
+
[options, selected, showSearch, filterGroup, filterFn, accessor, search, groupAccessor],
|
|
95
117
|
);
|
|
96
118
|
|
|
97
119
|
const [selectedDraft, setSelectedDraft] = useState<OptionShape[]>(selectedOptions);
|
|
@@ -32,6 +32,7 @@ export const Footer = ({
|
|
|
32
32
|
view='primary'
|
|
33
33
|
onClick={handleApply}
|
|
34
34
|
dataTestId={getDataTestId(dataTestId, 'apply')}
|
|
35
|
+
className={styles.button}
|
|
35
36
|
>
|
|
36
37
|
Применить
|
|
37
38
|
</ButtonDesktop>
|
|
@@ -42,6 +43,7 @@ export const Footer = ({
|
|
|
42
43
|
view='secondary'
|
|
43
44
|
onClick={handleClear}
|
|
44
45
|
dataTestId={getDataTestId(dataTestId, 'clear')}
|
|
46
|
+
className={styles.button}
|
|
45
47
|
>
|
|
46
48
|
Сбросить
|
|
47
49
|
</ButtonDesktop>
|
package/src/typings.ts
CHANGED
|
@@ -307,6 +307,8 @@ export type BaseSelectProps = {
|
|
|
307
307
|
filterFn?: (optionText: string, search: string) => boolean;
|
|
308
308
|
value?: string;
|
|
309
309
|
onChange?: (value: string) => void;
|
|
310
|
+
filterGroup?: boolean;
|
|
311
|
+
groupAccessor?: (group: GroupShape) => string | undefined;
|
|
310
312
|
};
|
|
311
313
|
|
|
312
314
|
/**
|
package/src/utils.ts
CHANGED
|
@@ -38,7 +38,8 @@ export const joinOptions = ({
|
|
|
38
38
|
export function processOptions(
|
|
39
39
|
options: BaseSelectProps['options'],
|
|
40
40
|
selected: BaseSelectProps['selected'] = [],
|
|
41
|
-
filterFn: (option: OptionShape) => boolean = () => true,
|
|
41
|
+
filterFn: (option: OptionShape | GroupShape) => boolean = () => true,
|
|
42
|
+
filterGroup = false,
|
|
42
43
|
) {
|
|
43
44
|
const flatOptions: OptionShape[] = [];
|
|
44
45
|
const filteredOptions: BaseSelectProps['options'] = [];
|
|
@@ -51,14 +52,22 @@ export function processOptions(
|
|
|
51
52
|
|
|
52
53
|
const isSelected = (option: OptionShape) => selectedKeys.includes(option.key);
|
|
53
54
|
|
|
54
|
-
const process = (option: OptionShape) => {
|
|
55
|
-
|
|
55
|
+
const process = (option: OptionShape | GroupShape) => {
|
|
56
|
+
const isGroupOption = isGroup(option);
|
|
57
|
+
|
|
58
|
+
if (!isGroupOption && isSelected(option)) {
|
|
56
59
|
selectedOptions.push(option);
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
if (!filterFn(option)) return false;
|
|
60
63
|
|
|
61
|
-
|
|
64
|
+
if (isGroupOption) {
|
|
65
|
+
if (filterGroup) {
|
|
66
|
+
Array.prototype.push.apply(flatOptions, option.options);
|
|
67
|
+
}
|
|
68
|
+
} else {
|
|
69
|
+
flatOptions.push(option);
|
|
70
|
+
}
|
|
62
71
|
|
|
63
72
|
return true;
|
|
64
73
|
};
|
|
@@ -76,12 +85,17 @@ export function processOptions(
|
|
|
76
85
|
if (matched) group.options.push(groupOption);
|
|
77
86
|
});
|
|
78
87
|
|
|
79
|
-
if (group.options.length)
|
|
80
|
-
|
|
81
|
-
const matched = process(option);
|
|
88
|
+
if (group.options.length) {
|
|
89
|
+
filteredOptions.push(group);
|
|
82
90
|
|
|
83
|
-
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (!filterGroup) return;
|
|
84
95
|
}
|
|
96
|
+
const matched = process(option);
|
|
97
|
+
|
|
98
|
+
if (matched) filteredOptions.push(option);
|
|
85
99
|
});
|
|
86
100
|
|
|
87
101
|
return { filteredOptions, flatOptions, selectedOptions };
|
|
@@ -160,6 +174,10 @@ export function defaultFilterFn(optionText: string, search: string) {
|
|
|
160
174
|
return optionText.toLowerCase().includes(search.toLowerCase());
|
|
161
175
|
}
|
|
162
176
|
|
|
177
|
+
export function defaultGroupAccessor(option: GroupShape) {
|
|
178
|
+
return option.label;
|
|
179
|
+
}
|
|
180
|
+
|
|
163
181
|
export function defaultAccessor(option: OptionShape) {
|
|
164
182
|
if (typeof option.content === 'string') return option.content;
|
|
165
183
|
if (typeof option.value === 'string') return option.value;
|
package/typings.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { InputProps } from "@alfalab/core-components-input";
|
|
|
5
5
|
import { ModalProps } from "@alfalab/core-components-modal";
|
|
6
6
|
import { ModalFooterProps, ModalHeaderProps } from "@alfalab/core-components-modal/shared";
|
|
7
7
|
import { PopoverProps } from "@alfalab/core-components-popover";
|
|
8
|
-
import { UseSelectWithApplyProps } from "./hook-
|
|
8
|
+
import { UseSelectWithApplyProps } from "./hook-2f4e96b2";
|
|
9
9
|
type AnyObject = Record<string, any>;
|
|
10
10
|
type OptionShape = {
|
|
11
11
|
/**
|
|
@@ -237,6 +237,8 @@ type BaseSelectProps = {
|
|
|
237
237
|
filterFn?: (optionText: string, search: string) => boolean;
|
|
238
238
|
value?: string;
|
|
239
239
|
onChange?: (value: string) => void;
|
|
240
|
+
filterGroup?: boolean;
|
|
241
|
+
groupAccessor?: (group: GroupShape) => string | undefined;
|
|
240
242
|
};
|
|
241
243
|
/**
|
|
242
244
|
* Обработчик выбора
|
package/utils.d.ts
CHANGED
|
@@ -6,7 +6,7 @@ declare const joinOptions: ({ selected, selectedMultiple, }: {
|
|
|
6
6
|
selected?: OptionShape | undefined;
|
|
7
7
|
selectedMultiple?: OptionShape[] | undefined;
|
|
8
8
|
}) => ReactNode[] | null;
|
|
9
|
-
declare function processOptions(options: BaseSelectProps['options'], selected?: BaseSelectProps['selected'], filterFn?: (option: OptionShape) => boolean): {
|
|
9
|
+
declare function processOptions(options: BaseSelectProps['options'], selected?: BaseSelectProps['selected'], filterFn?: (option: OptionShape | GroupShape) => boolean, filterGroup?: boolean): {
|
|
10
10
|
filteredOptions: (OptionShape | GroupShape)[];
|
|
11
11
|
flatOptions: OptionShape[];
|
|
12
12
|
selectedOptions: OptionShape[];
|
|
@@ -35,6 +35,7 @@ type useVisibleOptionsArgs = {
|
|
|
35
35
|
};
|
|
36
36
|
declare function useVisibleOptions({ visibleOptions, listRef, styleTargetRef, open, invalidate, }: useVisibleOptionsArgs): void;
|
|
37
37
|
declare function defaultFilterFn(optionText: string, search: string): boolean;
|
|
38
|
+
declare function defaultGroupAccessor(option: GroupShape): string | undefined;
|
|
38
39
|
declare function defaultAccessor(option: OptionShape): string;
|
|
39
40
|
declare function usePrevious<T>(value: T): T | undefined;
|
|
40
41
|
declare const lastIndexOf: <T>(array: T[], predicate: (item: T) => boolean) => number;
|
|
@@ -64,4 +65,4 @@ declare function getSelectTestIds(dataTestId: string): {
|
|
|
64
65
|
modalHeader: string;
|
|
65
66
|
modalContent: string;
|
|
66
67
|
};
|
|
67
|
-
export { isGroup, isOptionShape, joinOptions, processOptions, useVisibleOptions, defaultFilterFn, defaultAccessor, usePrevious, lastIndexOf, getSelectTestIds };
|
|
68
|
+
export { isGroup, isOptionShape, joinOptions, processOptions, useVisibleOptions, defaultFilterFn, defaultGroupAccessor, defaultAccessor, usePrevious, lastIndexOf, getSelectTestIds };
|
package/utils.js
CHANGED
|
@@ -30,9 +30,10 @@ var joinOptions = function (_a) {
|
|
|
30
30
|
}, []);
|
|
31
31
|
};
|
|
32
32
|
// За один проход делает список пунктов меню плоским и находит выбранные пункты по ключу
|
|
33
|
-
function processOptions(options, selected, filterFn) {
|
|
33
|
+
function processOptions(options, selected, filterFn, filterGroup) {
|
|
34
34
|
if (selected === void 0) { selected = []; }
|
|
35
35
|
if (filterFn === void 0) { filterFn = function () { return true; }; }
|
|
36
|
+
if (filterGroup === void 0) { filterGroup = false; }
|
|
36
37
|
var flatOptions = [];
|
|
37
38
|
var filteredOptions = [];
|
|
38
39
|
var selectedArray = Array.isArray(selected) ? selected : [selected];
|
|
@@ -40,12 +41,20 @@ function processOptions(options, selected, filterFn) {
|
|
|
40
41
|
var selectedKeys = selectedArray.filter(function (option) { return typeof option === 'string'; });
|
|
41
42
|
var isSelected = function (option) { return selectedKeys.includes(option.key); };
|
|
42
43
|
var process = function (option) {
|
|
43
|
-
|
|
44
|
+
var isGroupOption = isGroup(option);
|
|
45
|
+
if (!isGroupOption && isSelected(option)) {
|
|
44
46
|
selectedOptions.push(option);
|
|
45
47
|
}
|
|
46
48
|
if (!filterFn(option))
|
|
47
49
|
return false;
|
|
48
|
-
|
|
50
|
+
if (isGroupOption) {
|
|
51
|
+
if (filterGroup) {
|
|
52
|
+
Array.prototype.push.apply(flatOptions, option.options);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
flatOptions.push(option);
|
|
57
|
+
}
|
|
49
58
|
return true;
|
|
50
59
|
};
|
|
51
60
|
options.forEach(function (option) {
|
|
@@ -56,14 +65,16 @@ function processOptions(options, selected, filterFn) {
|
|
|
56
65
|
if (matched)
|
|
57
66
|
group_1.options.push(groupOption);
|
|
58
67
|
});
|
|
59
|
-
if (group_1.options.length)
|
|
68
|
+
if (group_1.options.length) {
|
|
60
69
|
filteredOptions.push(group_1);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (!filterGroup)
|
|
73
|
+
return;
|
|
61
74
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
filteredOptions.push(option);
|
|
66
|
-
}
|
|
75
|
+
var matched = process(option);
|
|
76
|
+
if (matched)
|
|
77
|
+
filteredOptions.push(option);
|
|
67
78
|
});
|
|
68
79
|
return { filteredOptions: filteredOptions, flatOptions: flatOptions, selectedOptions: selectedOptions };
|
|
69
80
|
}
|
|
@@ -94,6 +105,9 @@ function defaultFilterFn(optionText, search) {
|
|
|
94
105
|
return true;
|
|
95
106
|
return optionText.toLowerCase().includes(search.toLowerCase());
|
|
96
107
|
}
|
|
108
|
+
function defaultGroupAccessor(option) {
|
|
109
|
+
return option.label;
|
|
110
|
+
}
|
|
97
111
|
function defaultAccessor(option) {
|
|
98
112
|
if (typeof option.content === 'string')
|
|
99
113
|
return option.content;
|
|
@@ -148,6 +162,7 @@ function getSelectTestIds(dataTestId) {
|
|
|
148
162
|
|
|
149
163
|
exports.defaultAccessor = defaultAccessor;
|
|
150
164
|
exports.defaultFilterFn = defaultFilterFn;
|
|
165
|
+
exports.defaultGroupAccessor = defaultGroupAccessor;
|
|
151
166
|
exports.getSelectTestIds = getSelectTestIds;
|
|
152
167
|
exports.isGroup = isGroup;
|
|
153
168
|
exports.isOptionShape = isOptionShape;
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|