@alfalab/core-components-select 14.3.5 → 15.0.1
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/Component.desktop.d.ts +19 -0
- package/{Component.js → Component.desktop.js} +6 -6
- package/Component.mobile-ebda875c.d.ts +6 -0
- package/Component.mobile-f1f15074.d.ts +387 -0
- package/Component.mobile.d.ts +41 -0
- package/Component.mobile.js +62 -0
- package/Component.modal.mobile.d.ts +60 -0
- package/Component.modal.mobile.js +62 -0
- package/Component.responsive.d.ts +1 -1
- package/Component.responsive.js +26 -25
- 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 +13 -13
- package/components/base-select/Component.js +6 -6
- package/components/base-select/index.css +8 -8
- package/components/base-select/index.js +1 -1
- package/components/base-select-mobile/Component.d.ts +3 -3
- package/components/base-select-mobile/Component.js +13 -9
- package/components/base-select-mobile/footer/Component.js +4 -4
- package/components/base-select-mobile/footer/index.css +5 -5
- package/components/base-select-mobile/footer/index.js +1 -1
- package/components/base-select-mobile/index.css +13 -11
- package/components/base-select-mobile/index.js +1 -2
- 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.d.ts +8 -1
- package/components/field/Component.js +19 -16
- package/components/field/index.css +38 -11
- package/components/field/index.js +0 -1
- package/components/index.d.ts +0 -2
- package/components/index.js +4 -19
- 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 +20 -20
- package/components/options-list/Component.js +1 -1
- package/components/options-list/index.css +9 -9
- package/components/virtual-options-list/Component.js +1 -1
- package/components/virtual-options-list/index.css +15 -15
- package/cssm/Component.desktop.d.ts +19 -0
- package/cssm/{Component.js → Component.desktop.js} +6 -6
- package/cssm/Component.mobile-ebda875c.d.ts +6 -0
- package/cssm/Component.mobile-f1f15074.d.ts +387 -0
- package/cssm/Component.mobile.d.ts +41 -0
- package/cssm/Component.mobile.js +74 -0
- package/cssm/Component.modal.mobile.d.ts +60 -0
- package/cssm/Component.modal.mobile.js +74 -0
- package/cssm/Component.responsive.d.ts +1 -1
- package/cssm/Component.responsive.js +30 -33
- package/cssm/components/base-select/Component.js +5 -5
- package/cssm/components/base-select/index.js +1 -1
- package/cssm/components/base-select-mobile/Component.d.ts +3 -3
- package/cssm/components/base-select-mobile/Component.js +12 -8
- package/cssm/components/base-select-mobile/footer/Component.js +3 -3
- package/cssm/components/base-select-mobile/footer/index.js +1 -1
- package/cssm/components/base-select-mobile/index.js +1 -2
- package/cssm/components/base-select-mobile/index.module.css +4 -2
- package/cssm/components/field/Component.d.ts +8 -1
- package/cssm/components/field/Component.js +18 -15
- package/cssm/components/field/index.js +0 -1
- package/cssm/components/field/index.module.css +31 -4
- package/cssm/components/index.d.ts +0 -2
- package/cssm/components/index.js +7 -28
- package/cssm/desktop-63dec22f.d.ts +6 -0
- package/cssm/desktop.d.ts +2 -0
- package/cssm/desktop.js +44 -0
- package/cssm/hook-97e6e688.d.ts +16 -0
- package/cssm/hook-97e6e688.js +110 -0
- package/{esm/hook-b4e70cb0.d.ts → cssm/hook-9ea9e32c.d.ts} +9 -7
- package/cssm/index-ebda875c.d.ts +20 -60
- package/cssm/index.d.ts +2 -5
- package/cssm/index.js +34 -61
- package/cssm/mobile-96988a65.d.ts +2 -0
- package/cssm/mobile.d.ts +5 -4
- package/cssm/mobile.js +15 -24
- package/cssm/presets/index.d.ts +1 -1
- package/cssm/presets/index.js +9 -36
- package/cssm/presets/useLazyLoading/hook.js +9 -4
- package/cssm/presets/useSelectWithApply/hook.js +9 -48
- package/cssm/presets/useSelectWithApply/options-list-with-apply/Component.js +3 -42
- package/cssm/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +3 -3
- package/cssm/presets/useSelectWithApply/options-list-with-apply/index.d.ts +1 -1
- package/cssm/presets/useSelectWithApply/options-list-with-apply/index.js +10 -49
- package/cssm/shared.d.ts +5 -0
- package/cssm/shared.js +78 -0
- package/cssm/typings-9211a437.d.ts +95 -0
- package/cssm/typings-baf4875b.d.ts +52 -0
- package/desktop-63dec22f.d.ts +6 -0
- package/desktop.d.ts +2 -0
- package/{responsive.js → desktop.js} +5 -19
- package/esm/Component.desktop.d.ts +19 -0
- package/esm/{Component.js → Component.desktop.js} +6 -6
- package/esm/Component.mobile-ebda875c.d.ts +6 -0
- package/esm/Component.mobile-f1f15074.d.ts +387 -0
- package/esm/Component.mobile.d.ts +41 -0
- package/esm/Component.mobile.js +54 -0
- package/esm/Component.modal.mobile.d.ts +60 -0
- package/esm/Component.modal.mobile.js +54 -0
- package/esm/Component.responsive.d.ts +1 -1
- package/esm/Component.responsive.js +26 -25
- 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 +13 -13
- package/esm/components/base-select/Component.js +2 -2
- package/esm/components/base-select/index.css +8 -8
- package/esm/components/base-select/index.js +1 -1
- package/esm/components/base-select-mobile/Component.d.ts +3 -3
- package/esm/components/base-select-mobile/Component.js +9 -5
- package/esm/components/base-select-mobile/footer/Component.js +4 -4
- package/esm/components/base-select-mobile/footer/index.css +5 -5
- package/esm/components/base-select-mobile/footer/index.js +1 -1
- package/esm/components/base-select-mobile/index.css +13 -11
- package/esm/components/base-select-mobile/index.js +1 -2
- 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.d.ts +8 -1
- package/esm/components/field/Component.js +19 -16
- package/esm/components/field/index.css +38 -11
- package/esm/components/field/index.js +0 -1
- package/esm/components/index.d.ts +0 -2
- package/esm/components/index.js +4 -17
- 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 +20 -20
- package/esm/components/options-list/Component.js +1 -1
- package/esm/components/options-list/index.css +9 -9
- package/esm/components/virtual-options-list/Component.js +1 -1
- package/esm/components/virtual-options-list/index.css +15 -15
- package/esm/desktop-63dec22f.d.ts +6 -0
- package/esm/desktop.d.ts +2 -0
- package/esm/{responsive.js → desktop.js} +4 -18
- package/{cssm/hook-b4e70cb0.d.ts → esm/hook-9ea9e32c.d.ts} +9 -7
- package/esm/hook-cb30fc23.d.ts +16 -0
- package/esm/hook-cb30fc23.js +102 -0
- package/esm/index-ebda875c.d.ts +20 -60
- package/esm/index.d.ts +2 -5
- package/esm/index.js +27 -29
- package/esm/mobile-96988a65.d.ts +2 -0
- package/esm/mobile.d.ts +5 -4
- package/esm/mobile.js +12 -16
- package/esm/presets/index.d.ts +1 -1
- package/esm/presets/index.js +7 -25
- package/esm/presets/useLazyLoading/hook.js +9 -5
- package/esm/presets/useSelectWithApply/hook.js +7 -33
- package/esm/presets/useSelectWithApply/options-list-with-apply/Component.js +2 -28
- package/esm/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +4 -4
- 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 +8 -34
- package/esm/presets/useSelectWithLoading/hook.js +1 -1
- package/esm/presets/useSelectWithLoading/index.css +2 -2
- package/esm/shared.d.ts +5 -0
- package/esm/shared.js +38 -0
- package/esm/typings-9211a437.d.ts +95 -0
- package/esm/typings-baf4875b.d.ts +52 -0
- package/hook-3e654f56.d.ts +16 -0
- package/hook-3e654f56.js +110 -0
- package/{hook-b4e70cb0.d.ts → hook-9ea9e32c.d.ts} +9 -7
- package/index-ebda875c.d.ts +20 -60
- package/index.d.ts +2 -5
- package/index.js +28 -51
- package/mobile-96988a65.d.ts +2 -0
- package/mobile.d.ts +5 -4
- package/mobile.js +14 -18
- package/modern/Component.desktop.d.ts +19 -0
- package/modern/{Component.js → Component.desktop.js} +7 -4
- package/modern/Component.mobile-ebda875c.d.ts +6 -0
- package/modern/Component.mobile-f1f15074.d.ts +387 -0
- package/modern/Component.mobile.d.ts +41 -0
- package/modern/Component.mobile.js +61 -0
- package/modern/Component.modal.mobile.d.ts +60 -0
- package/modern/Component.modal.mobile.js +61 -0
- package/modern/Component.responsive.d.ts +1 -1
- package/modern/Component.responsive.js +26 -25
- 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 +13 -13
- package/modern/components/base-select/Component.js +2 -2
- package/modern/components/base-select/index.css +8 -8
- package/modern/components/base-select/index.js +1 -1
- package/modern/components/base-select-mobile/Component.d.ts +3 -3
- package/modern/components/base-select-mobile/Component.js +9 -5
- package/modern/components/base-select-mobile/footer/Component.js +4 -4
- package/modern/components/base-select-mobile/footer/index.css +5 -5
- package/modern/components/base-select-mobile/footer/index.js +1 -1
- package/modern/components/base-select-mobile/index.css +13 -11
- package/modern/components/base-select-mobile/index.js +1 -2
- 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.d.ts +8 -1
- package/modern/components/field/Component.js +17 -14
- package/modern/components/field/index.css +38 -11
- package/modern/components/field/index.js +0 -1
- package/modern/components/index.d.ts +0 -2
- package/modern/components/index.js +4 -17
- 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 +20 -20
- package/modern/components/options-list/Component.js +1 -1
- package/modern/components/options-list/index.css +9 -9
- package/modern/components/virtual-options-list/Component.js +1 -1
- package/modern/components/virtual-options-list/index.css +15 -15
- package/modern/desktop-63dec22f.d.ts +6 -0
- package/modern/desktop.d.ts +2 -0
- package/modern/{responsive.js → desktop.js} +4 -18
- package/modern/hook-467b4d42.d.ts +16 -0
- package/modern/{Component-5c16a908.js → hook-467b4d42.js} +3 -66
- package/modern/{hook-b4e70cb0.d.ts → hook-9ea9e32c.d.ts} +9 -7
- package/modern/index-ebda875c.d.ts +20 -60
- package/modern/index.d.ts +2 -5
- package/modern/index.js +27 -29
- package/modern/mobile-96988a65.d.ts +2 -0
- package/modern/mobile.d.ts +5 -4
- package/modern/mobile.js +12 -16
- package/modern/presets/index.d.ts +1 -1
- package/modern/presets/index.js +7 -25
- package/modern/presets/useLazyLoading/hook.js +9 -5
- package/modern/presets/useSelectWithApply/hook.js +7 -33
- package/modern/presets/useSelectWithApply/options-list-with-apply/Component.js +2 -28
- package/modern/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +4 -4
- 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 +8 -34
- package/modern/presets/useSelectWithLoading/hook.js +1 -1
- package/modern/presets/useSelectWithLoading/index.css +2 -2
- package/modern/shared.d.ts +5 -0
- package/modern/shared.js +37 -0
- package/modern/typings-9211a437.d.ts +95 -0
- package/modern/typings-baf4875b.d.ts +52 -0
- package/package.json +38 -12
- package/presets/index.d.ts +1 -1
- package/presets/index.js +7 -25
- package/presets/useLazyLoading/hook.js +9 -5
- package/presets/useSelectWithApply/hook.js +7 -33
- package/presets/useSelectWithApply/options-list-with-apply/Component.js +2 -28
- package/presets/useSelectWithApply/options-list-with-apply/footer/Component.js +4 -4
- 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 +8 -34
- package/presets/useSelectWithLoading/hook.js +1 -1
- package/presets/useSelectWithLoading/index.css +2 -2
- package/shared.d.ts +5 -0
- package/shared.js +64 -0
- package/src/Component.desktop.tsx +52 -0
- package/src/Component.mobile.tsx +149 -0
- package/src/Component.modal.mobile.tsx +144 -0
- package/src/Component.responsive.tsx +59 -0
- package/src/components/arrow/Component.tsx +12 -0
- package/src/components/arrow/index.module.css +15 -0
- package/src/components/arrow/index.ts +1 -0
- package/src/components/base-checkmark/Component.tsx +33 -0
- package/src/components/base-checkmark/index.module.css +18 -0
- package/src/components/base-checkmark/index.ts +1 -0
- package/src/components/base-option/Component.tsx +57 -0
- package/src/components/base-option/index.module.css +67 -0
- package/src/components/base-option/index.ts +1 -0
- package/src/components/base-select/Component.tsx +478 -0
- package/src/components/base-select/index.module.css +68 -0
- package/src/components/base-select/index.ts +1 -0
- package/src/components/base-select-mobile/Component.tsx +486 -0
- package/src/components/base-select-mobile/footer/Component.tsx +46 -0
- package/src/components/base-select-mobile/footer/index.module.css +23 -0
- package/src/components/base-select-mobile/footer/index.ts +1 -0
- package/src/components/base-select-mobile/index.module.css +48 -0
- package/src/components/base-select-mobile/index.ts +1 -0
- package/src/components/checkmark/Component.tsx +56 -0
- package/src/components/checkmark/index.module.css +48 -0
- package/src/components/checkmark/index.ts +1 -0
- package/src/components/checkmark-mobile/Component.tsx +18 -0
- package/src/components/checkmark-mobile/index.module.css +28 -0
- package/src/components/checkmark-mobile/index.ts +1 -0
- package/src/components/field/Component.tsx +110 -0
- package/src/components/field/index.module.css +60 -0
- package/src/components/field/index.ts +1 -0
- package/src/components/index.ts +8 -0
- package/src/components/native-select/Component.tsx +60 -0
- package/src/components/native-select/index.ts +1 -0
- package/src/components/optgroup/Component.tsx +15 -0
- package/src/components/optgroup/index.module.css +30 -0
- package/src/components/optgroup/index.ts +1 -0
- package/src/components/option/Component.tsx +65 -0
- package/src/components/option/index.module.css +108 -0
- package/src/components/option/index.ts +1 -0
- package/src/components/options-list/Component.tsx +140 -0
- package/src/components/options-list/index.module.css +40 -0
- package/src/components/options-list/index.ts +1 -0
- package/src/components/virtual-options-list/Component.tsx +217 -0
- package/src/components/virtual-options-list/index.module.css +76 -0
- package/src/components/virtual-options-list/index.ts +1 -0
- package/src/consts.ts +1 -0
- package/src/desktop.ts +1 -0
- package/src/index.ts +4 -0
- package/src/mobile.ts +5 -0
- package/src/presets/index.ts +3 -0
- package/src/presets/useLazyLoading/hook.tsx +309 -0
- package/src/presets/useSelectWithApply/hook.tsx +154 -0
- package/src/presets/useSelectWithApply/options-list-with-apply/Component.tsx +106 -0
- package/src/presets/useSelectWithApply/options-list-with-apply/footer/Component.tsx +37 -0
- package/src/presets/useSelectWithApply/options-list-with-apply/footer/index.module.css +11 -0
- package/src/presets/useSelectWithApply/options-list-with-apply/header/Component.tsx +26 -0
- package/src/presets/useSelectWithApply/options-list-with-apply/header/index.module.css +9 -0
- package/src/presets/useSelectWithApply/options-list-with-apply/index.ts +1 -0
- package/src/presets/useSelectWithLoading/hook.tsx +40 -0
- package/src/shared.ts +5 -0
- package/src/typings.ts +691 -0
- package/src/utils.ts +154 -0
- package/src/vars.css +57 -0
- package/typings-9211a437.d.ts +95 -0
- package/typings-baf4875b.d.ts +52 -0
- package/Component-1e06de61.d.ts +0 -108
- package/Component-1e06de61.js +0 -165
- package/Component-3885b0d7.d.ts +0 -169
- package/Component.d.ts +0 -104
- package/Component.mobile-b2c0420d.d.ts +0 -93
- package/components/select-mobile/Component.d.ts +0 -0
- package/components/select-mobile/Component.js +0 -49
- package/components/select-mobile/index.d.ts +0 -1
- package/components/select-mobile/index.js +0 -49
- package/components/select-modal-mobile/Component.d.ts +0 -0
- package/components/select-modal-mobile/Component.js +0 -49
- package/components/select-modal-mobile/index.d.ts +0 -1
- package/components/select-modal-mobile/index.js +0 -49
- package/cssm/Component-3885b0d7.d.ts +0 -169
- package/cssm/Component-4727d474.d.ts +0 -108
- package/cssm/Component-4727d474.js +0 -175
- package/cssm/Component.d.ts +0 -104
- package/cssm/Component.mobile-b2c0420d.d.ts +0 -93
- package/cssm/components/select-mobile/Component.d.ts +0 -0
- package/cssm/components/select-mobile/Component.js +0 -66
- package/cssm/components/select-mobile/index.d.ts +0 -1
- package/cssm/components/select-mobile/index.js +0 -66
- package/cssm/components/select-modal-mobile/Component.d.ts +0 -0
- package/cssm/components/select-modal-mobile/Component.js +0 -66
- package/cssm/components/select-modal-mobile/index.d.ts +0 -1
- package/cssm/components/select-modal-mobile/index.js +0 -66
- package/cssm/getDataTestId-5c876d98.d.ts +0 -2
- package/cssm/getDataTestId-5c876d98.js +0 -8
- package/cssm/index-3885b0d7.d.ts +0 -3
- package/cssm/intersection-observer-9ec5cf59.d.ts +0 -1
- package/cssm/intersection-observer-9ec5cf59.js +0 -893
- package/cssm/responsive.d.ts +0 -2
- package/cssm/responsive.js +0 -67
- package/cssm/types-ebda875c.d.ts +0 -113
- package/esm/Component-16af9d1e.d.ts +0 -108
- package/esm/Component-16af9d1e.js +0 -155
- package/esm/Component-3885b0d7.d.ts +0 -169
- package/esm/Component.d.ts +0 -104
- package/esm/Component.mobile-b2c0420d.d.ts +0 -93
- package/esm/components/select-mobile/Component.d.ts +0 -0
- package/esm/components/select-mobile/Component.js +0 -41
- package/esm/components/select-mobile/index.d.ts +0 -1
- package/esm/components/select-mobile/index.js +0 -41
- package/esm/components/select-modal-mobile/Component.d.ts +0 -0
- package/esm/components/select-modal-mobile/Component.js +0 -41
- package/esm/components/select-modal-mobile/index.d.ts +0 -1
- package/esm/components/select-modal-mobile/index.js +0 -41
- package/esm/getDataTestId-1a678b16.d.ts +0 -2
- package/esm/getDataTestId-1a678b16.js +0 -6
- package/esm/index-3885b0d7.d.ts +0 -3
- package/esm/intersection-observer-4e5bb99c.d.ts +0 -1
- package/esm/intersection-observer-4e5bb99c.js +0 -891
- package/esm/presets/useLazyLoading/index.css +0 -8
- package/esm/responsive.d.ts +0 -2
- package/esm/types-ebda875c.d.ts +0 -113
- package/getDataTestId-3f974970.d.ts +0 -2
- package/getDataTestId-3f974970.js +0 -8
- package/index-3885b0d7.d.ts +0 -3
- package/intersection-observer-411362a8.d.ts +0 -1
- package/intersection-observer-411362a8.js +0 -893
- package/modern/Component-3885b0d7.d.ts +0 -169
- package/modern/Component-5c16a908.d.ts +0 -108
- package/modern/Component.d.ts +0 -104
- package/modern/Component.mobile-b2c0420d.d.ts +0 -93
- package/modern/components/select-mobile/Component.d.ts +0 -0
- package/modern/components/select-mobile/Component.js +0 -40
- package/modern/components/select-mobile/index.d.ts +0 -1
- package/modern/components/select-mobile/index.js +0 -40
- package/modern/components/select-modal-mobile/Component.d.ts +0 -0
- package/modern/components/select-modal-mobile/Component.js +0 -40
- package/modern/components/select-modal-mobile/index.d.ts +0 -1
- package/modern/components/select-modal-mobile/index.js +0 -40
- package/modern/getDataTestId-c17bfb0c.d.ts +0 -2
- package/modern/getDataTestId-c17bfb0c.js +0 -6
- package/modern/index-3885b0d7.d.ts +0 -3
- package/modern/intersection-observer-4e5bb99c.d.ts +0 -1
- package/modern/intersection-observer-4e5bb99c.js +0 -891
- package/modern/presets/useLazyLoading/index.css +0 -8
- package/modern/responsive.d.ts +0 -2
- package/modern/types-ebda875c.d.ts +0 -113
- package/presets/useLazyLoading/index.css +0 -8
- package/responsive.d.ts +0 -2
- package/types-ebda875c.d.ts +0 -113
- /package/{cssm/presets/useLazyLoading → src/presets/useSelectWithLoading}/index.module.css +0 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import React, { Reducer, useCallback, useEffect, useMemo, useReducer, useRef } from 'react';
|
|
2
|
+
|
|
3
|
+
import { InputProps } from '@alfalab/core-components-input';
|
|
4
|
+
import { Skeleton } from '@alfalab/core-components-skeleton';
|
|
5
|
+
|
|
6
|
+
import { Option as DefaultOption } from '../../components/option';
|
|
7
|
+
import { OptionProps, OptionShape } from '../../typings';
|
|
8
|
+
|
|
9
|
+
import 'intersection-observer';
|
|
10
|
+
|
|
11
|
+
const DEBOUNCE_TIMEOUT = 300;
|
|
12
|
+
|
|
13
|
+
type OptionsFetcherResponse = {
|
|
14
|
+
options: OptionShape[];
|
|
15
|
+
hasMore: boolean;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
19
|
+
type useLazyLoadingProps = {
|
|
20
|
+
/** Количество элементов на "странице" */
|
|
21
|
+
limit?: number;
|
|
22
|
+
|
|
23
|
+
/** Начальный номер "страницы" */
|
|
24
|
+
initialOffset?: number;
|
|
25
|
+
|
|
26
|
+
/** Скелетон загружаемых элементов */
|
|
27
|
+
skeleton?: React.ReactNode;
|
|
28
|
+
|
|
29
|
+
/** Компонент пункта меню */
|
|
30
|
+
Option?: React.FC<OptionProps>;
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Функция-загрузчик опций.
|
|
34
|
+
* @param offset - текущая страница
|
|
35
|
+
* @param limit - количество элементов на странице
|
|
36
|
+
* @param queryString - строчные данные, пробрасываемые для поиска из кастомного инпута, расположенного в заголовке OptionsList
|
|
37
|
+
* @returns Promise<{
|
|
38
|
+
* options - список опций следующей "страницы". Они аппендятся к предыдущим
|
|
39
|
+
* hasMore - указывает, есть ли еще незагруженные элементы (в случае false перестает загружать "следующую страницу")
|
|
40
|
+
* }>
|
|
41
|
+
*/
|
|
42
|
+
optionsFetcher(
|
|
43
|
+
offset: number,
|
|
44
|
+
limit: number,
|
|
45
|
+
queryString?: string,
|
|
46
|
+
): Promise<OptionsFetcherResponse>;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const actions = {
|
|
50
|
+
fetchOptionsStart() {
|
|
51
|
+
return { type: 'FETCH_OPTIONS_START' } as const;
|
|
52
|
+
},
|
|
53
|
+
fetchOptionsBreak() {
|
|
54
|
+
return { type: 'FETCH_OPTIONS_BREAK' } as const;
|
|
55
|
+
},
|
|
56
|
+
fetchOptionsSuccess(payload: { options: OptionShape[]; hasMore: boolean }) {
|
|
57
|
+
return { type: 'FETCH_OPTIONS_SUCCESS', payload } as const;
|
|
58
|
+
},
|
|
59
|
+
setIsOpened(opened: boolean) {
|
|
60
|
+
return { type: 'SET_IS_OPENED', payload: opened } as const;
|
|
61
|
+
},
|
|
62
|
+
setQueryString(qs: string) {
|
|
63
|
+
return { type: 'SET_QUERY_STRING', payload: qs } as const;
|
|
64
|
+
},
|
|
65
|
+
reset() {
|
|
66
|
+
return { type: 'RESET' } as const;
|
|
67
|
+
},
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
type Actions = typeof actions extends { [key: string]: (...args: any) => infer U } ? U : never;
|
|
72
|
+
|
|
73
|
+
const skeletonStyle: React.CSSProperties = {
|
|
74
|
+
position: 'absolute',
|
|
75
|
+
top: '50%',
|
|
76
|
+
transform: 'translateY(-50%)',
|
|
77
|
+
height: '16px',
|
|
78
|
+
width: '50%',
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
export function useLazyLoading({
|
|
82
|
+
limit = 10,
|
|
83
|
+
initialOffset = 0,
|
|
84
|
+
optionsFetcher,
|
|
85
|
+
skeleton = <Skeleton style={skeletonStyle} visible={true} />,
|
|
86
|
+
Option = DefaultOption,
|
|
87
|
+
}: useLazyLoadingProps) {
|
|
88
|
+
const initialOptions: OptionShape[] = [];
|
|
89
|
+
const initialLoading = false;
|
|
90
|
+
|
|
91
|
+
const lazyLoadingInitialState = {
|
|
92
|
+
opened: false,
|
|
93
|
+
offset: initialOffset,
|
|
94
|
+
options: initialOptions,
|
|
95
|
+
loading: initialLoading,
|
|
96
|
+
allOptionsLoaded: false,
|
|
97
|
+
queryString: '',
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const lazyLoadingReducer: Reducer<typeof lazyLoadingInitialState, Actions> = (
|
|
101
|
+
state,
|
|
102
|
+
action,
|
|
103
|
+
) => {
|
|
104
|
+
switch (action.type) {
|
|
105
|
+
case 'FETCH_OPTIONS_START': {
|
|
106
|
+
return {
|
|
107
|
+
...state,
|
|
108
|
+
loading: true,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
case 'FETCH_OPTIONS_BREAK': {
|
|
112
|
+
return {
|
|
113
|
+
...state,
|
|
114
|
+
loading: false,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
case 'FETCH_OPTIONS_SUCCESS': {
|
|
118
|
+
return {
|
|
119
|
+
...state,
|
|
120
|
+
options: [...state.options, ...action.payload.options],
|
|
121
|
+
offset: state.offset + (action.payload.options.length ? 1 : 0),
|
|
122
|
+
allOptionsLoaded: !action.payload.hasMore,
|
|
123
|
+
loading: false,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
case 'SET_IS_OPENED': {
|
|
127
|
+
return {
|
|
128
|
+
...state,
|
|
129
|
+
opened: action.payload,
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
case 'SET_QUERY_STRING': {
|
|
133
|
+
return {
|
|
134
|
+
// Изменение queryString подразумевает сброс текущих опций.
|
|
135
|
+
...lazyLoadingInitialState,
|
|
136
|
+
opened: state.opened,
|
|
137
|
+
loading: true,
|
|
138
|
+
queryString: action.payload,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
case 'RESET': {
|
|
142
|
+
return {
|
|
143
|
+
...lazyLoadingInitialState,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
default: {
|
|
147
|
+
return state;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const [{ opened, offset, options, loading, allOptionsLoaded, queryString }, dispatch] =
|
|
153
|
+
useReducer(lazyLoadingReducer, lazyLoadingInitialState);
|
|
154
|
+
|
|
155
|
+
const abortFetchingOptionsRef = useRef<() => void>();
|
|
156
|
+
|
|
157
|
+
const fetchNextOffsetOptions = useCallback(() => {
|
|
158
|
+
dispatch(actions.fetchOptionsStart());
|
|
159
|
+
|
|
160
|
+
new Promise<OptionsFetcherResponse>((resolve, reject) => {
|
|
161
|
+
// eslint-disable-next-line no-unused-expressions
|
|
162
|
+
abortFetchingOptionsRef.current?.();
|
|
163
|
+
abortFetchingOptionsRef.current = reject;
|
|
164
|
+
optionsFetcher(offset, limit, queryString).then((res) => {
|
|
165
|
+
resolve(res);
|
|
166
|
+
});
|
|
167
|
+
})
|
|
168
|
+
.then((res) => {
|
|
169
|
+
dispatch(actions.fetchOptionsSuccess(res));
|
|
170
|
+
abortFetchingOptionsRef.current = undefined;
|
|
171
|
+
})
|
|
172
|
+
.catch(
|
|
173
|
+
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
174
|
+
() => {},
|
|
175
|
+
);
|
|
176
|
+
}, [optionsFetcher, offset, limit, queryString]);
|
|
177
|
+
|
|
178
|
+
const listRef = useRef<HTMLDivElement>(null);
|
|
179
|
+
|
|
180
|
+
useEffect(() => {
|
|
181
|
+
let observer: IntersectionObserver;
|
|
182
|
+
|
|
183
|
+
if (opened && !loading && !allOptionsLoaded) {
|
|
184
|
+
observer = new IntersectionObserver(
|
|
185
|
+
([entry]) => {
|
|
186
|
+
if (entry.isIntersecting) {
|
|
187
|
+
if (observer) {
|
|
188
|
+
observer.disconnect();
|
|
189
|
+
}
|
|
190
|
+
fetchNextOffsetOptions();
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
root: listRef.current,
|
|
195
|
+
},
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
/*
|
|
199
|
+
* Обсервим пересечение последней опции с контейнером.
|
|
200
|
+
* Таким образом, загрузка следующей "страницы" начнется когда юзер доскроллит список
|
|
201
|
+
* до верхнего края последней опции, что обеспечивает плавность
|
|
202
|
+
*/
|
|
203
|
+
const optionList = listRef.current?.querySelectorAll('[role="option"]');
|
|
204
|
+
const lastOption = optionList?.[optionList.length - 1];
|
|
205
|
+
|
|
206
|
+
if (lastOption) {
|
|
207
|
+
observer.observe(lastOption);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
return () => {
|
|
212
|
+
if (observer) {
|
|
213
|
+
observer.disconnect();
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
}, [offset, fetchNextOffsetOptions, opened, allOptionsLoaded, initialOffset, loading]);
|
|
217
|
+
|
|
218
|
+
const onOpen = useCallback(
|
|
219
|
+
(payload: { open?: boolean }) => {
|
|
220
|
+
if (payload.open) {
|
|
221
|
+
if (options.length === initialOptions.length) {
|
|
222
|
+
fetchNextOffsetOptions();
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
// eslint-disable-next-line no-unused-expressions
|
|
226
|
+
abortFetchingOptionsRef.current?.();
|
|
227
|
+
dispatch(actions.fetchOptionsBreak());
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
dispatch(actions.setIsOpened(payload.open ?? false));
|
|
231
|
+
},
|
|
232
|
+
[initialOptions.length, fetchNextOffsetOptions, options.length],
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
const fetchNextOptionsRef = useRef<() => void>();
|
|
236
|
+
const fetchNextOptionsTimerRef = useRef<ReturnType<typeof setTimeout>>();
|
|
237
|
+
|
|
238
|
+
useEffect(() => {
|
|
239
|
+
fetchNextOptionsRef.current = fetchNextOffsetOptions;
|
|
240
|
+
}, [fetchNextOffsetOptions]);
|
|
241
|
+
|
|
242
|
+
const onQueryStringChange = useCallback<Exclude<InputProps['onChange'], undefined>>(
|
|
243
|
+
(_, payload) => {
|
|
244
|
+
dispatch(actions.setQueryString(payload.value));
|
|
245
|
+
/* eslint-disable no-unused-expressions */
|
|
246
|
+
|
|
247
|
+
/*
|
|
248
|
+
* Если во время загрузки опций юзер ввел новый текст в инпут,
|
|
249
|
+
* нужно прервать текущую загрузку, чтобы неактуальные опции не попали в выдачу
|
|
250
|
+
*/
|
|
251
|
+
abortFetchingOptionsRef.current?.();
|
|
252
|
+
|
|
253
|
+
listRef.current?.scrollTo({ top: 0 });
|
|
254
|
+
|
|
255
|
+
/* Дебаунсим ввод текста, чтобы не отправлять запрос к новым опциям на каждый чих */
|
|
256
|
+
if (fetchNextOptionsTimerRef.current) {
|
|
257
|
+
clearTimeout(fetchNextOptionsTimerRef.current);
|
|
258
|
+
}
|
|
259
|
+
fetchNextOptionsTimerRef.current = setTimeout(() => {
|
|
260
|
+
/*
|
|
261
|
+
* После дебаунса необходимо вызвать функцию-загрузчик,
|
|
262
|
+
* содержащую актуальные на данный момент данные оффсета и queryString.
|
|
263
|
+
* Поэтому мы не можем обратиться напрямую к функции fetchNextOptions,
|
|
264
|
+
* так как она будет замкнута на старые значения, актуальные на момент вызова хэндлера,
|
|
265
|
+
* так что берем ее из обновляемого рефа
|
|
266
|
+
*/
|
|
267
|
+
fetchNextOptionsRef.current?.();
|
|
268
|
+
}, DEBOUNCE_TIMEOUT);
|
|
269
|
+
/* eslint-enable */
|
|
270
|
+
},
|
|
271
|
+
[],
|
|
272
|
+
);
|
|
273
|
+
|
|
274
|
+
const renderOption = (props: OptionProps) => (
|
|
275
|
+
<Option {...props} highlighted={loading ? false : props.highlighted} />
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
const skeletonOptions: OptionShape[] = useMemo(
|
|
279
|
+
() =>
|
|
280
|
+
Array(loading ? limit : 0)
|
|
281
|
+
.fill(0)
|
|
282
|
+
.map((_, key) => ({
|
|
283
|
+
key: `loading-${key}`,
|
|
284
|
+
disabled: true,
|
|
285
|
+
content: skeleton,
|
|
286
|
+
})),
|
|
287
|
+
[loading, limit, skeleton],
|
|
288
|
+
);
|
|
289
|
+
|
|
290
|
+
const reset = useCallback(() => {
|
|
291
|
+
dispatch(actions.reset());
|
|
292
|
+
}, []);
|
|
293
|
+
|
|
294
|
+
return {
|
|
295
|
+
optionsProps: {
|
|
296
|
+
Option: renderOption,
|
|
297
|
+
options: [...options, ...skeletonOptions],
|
|
298
|
+
optionsListProps: {
|
|
299
|
+
ref: listRef,
|
|
300
|
+
inputProps: {
|
|
301
|
+
onChange: onQueryStringChange,
|
|
302
|
+
value: queryString,
|
|
303
|
+
},
|
|
304
|
+
},
|
|
305
|
+
onOpen,
|
|
306
|
+
},
|
|
307
|
+
reset,
|
|
308
|
+
};
|
|
309
|
+
}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
2
|
+
|
|
3
|
+
import type { AnyObject, BaseSelectProps, OptionShape } from '../../typings';
|
|
4
|
+
import { processOptions } from '../../utils';
|
|
5
|
+
|
|
6
|
+
import { OptionsListWithApply } from './options-list-with-apply';
|
|
7
|
+
|
|
8
|
+
export type UseSelectWithApplyProps = {
|
|
9
|
+
/**
|
|
10
|
+
* Список выбранных пунктов
|
|
11
|
+
*/
|
|
12
|
+
selected: BaseSelectProps['selected'];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Список вариантов выбора
|
|
16
|
+
*/
|
|
17
|
+
options: BaseSelectProps['options'];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Обработчик выбора
|
|
21
|
+
*/
|
|
22
|
+
onChange: BaseSelectProps['onChange'];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Компонент выпадающего меню
|
|
26
|
+
*/
|
|
27
|
+
OptionsList?: BaseSelectProps['OptionsList'];
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Пропсы, которые будут прокинуты в компонент списка
|
|
31
|
+
*/
|
|
32
|
+
optionsListProps?: BaseSelectProps['optionsListProps'];
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Показывать кнопку очистки
|
|
36
|
+
*/
|
|
37
|
+
showClear?: boolean;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Показывать пункт "Выбрать все"
|
|
41
|
+
*/
|
|
42
|
+
showSelectAll?: boolean;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Показывать пункт "Выбрать все" в заголовке списка
|
|
46
|
+
*/
|
|
47
|
+
showHeaderWithSelectAll?: boolean;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export const SELECT_ALL_KEY = 'select_all';
|
|
51
|
+
|
|
52
|
+
const selectAllOption = { key: SELECT_ALL_KEY, content: 'Выбрать все' };
|
|
53
|
+
|
|
54
|
+
export function useSelectWithApply({
|
|
55
|
+
options,
|
|
56
|
+
selected,
|
|
57
|
+
onChange = () => null,
|
|
58
|
+
OptionsList,
|
|
59
|
+
optionsListProps = {},
|
|
60
|
+
showClear = true,
|
|
61
|
+
showSelectAll = false,
|
|
62
|
+
showHeaderWithSelectAll = false,
|
|
63
|
+
}: UseSelectWithApplyProps) {
|
|
64
|
+
const { flatOptions, selectedOptions } = useMemo(
|
|
65
|
+
() => processOptions(options, selected),
|
|
66
|
+
[options, selected],
|
|
67
|
+
);
|
|
68
|
+
|
|
69
|
+
const [selectedDraft, setSelectedDraft] = useState<OptionShape[]>(selectedOptions);
|
|
70
|
+
|
|
71
|
+
const selectedOptionsRef = useRef<OptionShape[]>(selectedOptions);
|
|
72
|
+
|
|
73
|
+
const handleApply = () => {
|
|
74
|
+
onChange({
|
|
75
|
+
selected: selectedDraft[0],
|
|
76
|
+
selectedMultiple: selectedDraft,
|
|
77
|
+
initiator: null,
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const handleClear = () => {
|
|
82
|
+
setSelectedDraft([]);
|
|
83
|
+
onChange({
|
|
84
|
+
selected: null,
|
|
85
|
+
selectedMultiple: [],
|
|
86
|
+
initiator: null,
|
|
87
|
+
});
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
const handleToggleAll = () => {
|
|
91
|
+
setSelectedDraft(flatOptions.length === selectedDraft.length ? [] : flatOptions);
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const handleChange: Required<BaseSelectProps>['onChange'] = ({ initiator, ...restArgs }) => {
|
|
95
|
+
if (!initiator) {
|
|
96
|
+
onChange({
|
|
97
|
+
initiator: null,
|
|
98
|
+
...restArgs,
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const initiatorSelected =
|
|
105
|
+
selectedDraft.includes(initiator) ||
|
|
106
|
+
(initiator.key === SELECT_ALL_KEY && selectedDraft.length === flatOptions.length);
|
|
107
|
+
|
|
108
|
+
if (initiator.key === SELECT_ALL_KEY) {
|
|
109
|
+
setSelectedDraft(initiatorSelected ? [] : flatOptions);
|
|
110
|
+
} else {
|
|
111
|
+
setSelectedDraft(
|
|
112
|
+
initiatorSelected
|
|
113
|
+
? selectedDraft.filter((o) => o !== initiator)
|
|
114
|
+
: selectedDraft.concat(initiator),
|
|
115
|
+
);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const handleClose = () => setSelectedDraft(selectedOptionsRef.current);
|
|
120
|
+
|
|
121
|
+
useEffect(() => {
|
|
122
|
+
setSelectedDraft(selectedOptions);
|
|
123
|
+
selectedOptionsRef.current = selectedOptions;
|
|
124
|
+
}, [selectedOptions]);
|
|
125
|
+
|
|
126
|
+
const memoizedOptions = useMemo(
|
|
127
|
+
() => (showSelectAll ? [selectAllOption, ...options] : options),
|
|
128
|
+
[options, showSelectAll],
|
|
129
|
+
);
|
|
130
|
+
|
|
131
|
+
return {
|
|
132
|
+
OptionsList: OptionsListWithApply,
|
|
133
|
+
optionsListProps: {
|
|
134
|
+
...(optionsListProps as AnyObject),
|
|
135
|
+
OptionsList,
|
|
136
|
+
showClear,
|
|
137
|
+
onClear: handleClear,
|
|
138
|
+
onApply: handleApply,
|
|
139
|
+
onClose: handleClose,
|
|
140
|
+
selectedDraft,
|
|
141
|
+
showHeaderWithSelectAll,
|
|
142
|
+
headerProps: {
|
|
143
|
+
indeterminate: !!selectedDraft.length && selectedDraft.length < flatOptions.length,
|
|
144
|
+
checked: selectedDraft.length === flatOptions.length,
|
|
145
|
+
onChange: handleToggleAll,
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
allowUnselect: true,
|
|
149
|
+
multiple: true,
|
|
150
|
+
options: memoizedOptions,
|
|
151
|
+
onChange: handleChange,
|
|
152
|
+
selected,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import React, { FC, forwardRef, RefAttributes, useCallback, useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
import { OptionsList as DefaultOptionsList } from '../../../components/options-list';
|
|
4
|
+
import { DEFAULT_VISIBLE_OPTIONS } from '../../../consts';
|
|
5
|
+
import { OptionShape, OptionsListProps } from '../../../typings';
|
|
6
|
+
import { SELECT_ALL_KEY } from '../hook';
|
|
7
|
+
|
|
8
|
+
import { Footer as DefaultFooter, FooterProps } from './footer/Component';
|
|
9
|
+
import { Header as DefaultHeader, HeaderProps } from './header/Component';
|
|
10
|
+
|
|
11
|
+
type OptionsListWithApplyProps = OptionsListProps & {
|
|
12
|
+
showClear?: boolean;
|
|
13
|
+
onClose?: () => void;
|
|
14
|
+
selectedDraft?: OptionShape[];
|
|
15
|
+
OptionsList?: React.FC<OptionsListProps & RefAttributes<HTMLDivElement>>;
|
|
16
|
+
Footer?: FC<FooterProps>;
|
|
17
|
+
Header?: FC<HeaderProps>;
|
|
18
|
+
headerProps?: HeaderProps;
|
|
19
|
+
showHeaderWithSelectAll?: boolean;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const OptionsListWithApply = forwardRef<HTMLDivElement, OptionsListWithApplyProps>(
|
|
23
|
+
(
|
|
24
|
+
{
|
|
25
|
+
toggleMenu,
|
|
26
|
+
getOptionProps: defaultGetOptionProps,
|
|
27
|
+
showClear = true,
|
|
28
|
+
showHeaderWithSelectAll,
|
|
29
|
+
selectedDraft = [],
|
|
30
|
+
flatOptions = [],
|
|
31
|
+
OptionsList = DefaultOptionsList,
|
|
32
|
+
onApply = () => null,
|
|
33
|
+
onClear = () => null,
|
|
34
|
+
onClose = () => null,
|
|
35
|
+
visibleOptions = DEFAULT_VISIBLE_OPTIONS,
|
|
36
|
+
Footer = DefaultFooter,
|
|
37
|
+
Header = DefaultHeader,
|
|
38
|
+
headerProps,
|
|
39
|
+
...restProps
|
|
40
|
+
}: OptionsListWithApplyProps,
|
|
41
|
+
ref,
|
|
42
|
+
) => {
|
|
43
|
+
const getOptionProps = useCallback(
|
|
44
|
+
(option: OptionShape, index: number) => {
|
|
45
|
+
const optionProps = defaultGetOptionProps(option, index);
|
|
46
|
+
|
|
47
|
+
const selected =
|
|
48
|
+
option.key === SELECT_ALL_KEY
|
|
49
|
+
? selectedDraft.length === flatOptions.length - 1
|
|
50
|
+
: selectedDraft.includes(option);
|
|
51
|
+
|
|
52
|
+
return {
|
|
53
|
+
...optionProps,
|
|
54
|
+
selected,
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
[defaultGetOptionProps, flatOptions.length, selectedDraft],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const handleApply = useCallback(() => {
|
|
61
|
+
onApply();
|
|
62
|
+
|
|
63
|
+
toggleMenu();
|
|
64
|
+
}, [onApply, toggleMenu]);
|
|
65
|
+
|
|
66
|
+
const handleClear = useCallback(() => {
|
|
67
|
+
onClear();
|
|
68
|
+
|
|
69
|
+
toggleMenu();
|
|
70
|
+
}, [onClear, toggleMenu]);
|
|
71
|
+
|
|
72
|
+
useEffect(() => {
|
|
73
|
+
const activeElement = document.activeElement as HTMLElement;
|
|
74
|
+
|
|
75
|
+
return () => {
|
|
76
|
+
onClose();
|
|
77
|
+
if (activeElement) {
|
|
78
|
+
activeElement.focus();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
82
|
+
}, []);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<OptionsList
|
|
86
|
+
{...restProps}
|
|
87
|
+
ref={ref}
|
|
88
|
+
visibleOptions={visibleOptions}
|
|
89
|
+
toggleMenu={toggleMenu}
|
|
90
|
+
flatOptions={flatOptions}
|
|
91
|
+
getOptionProps={getOptionProps}
|
|
92
|
+
onApply={handleApply}
|
|
93
|
+
onClear={handleClear}
|
|
94
|
+
header={showHeaderWithSelectAll ? <Header {...headerProps} /> : undefined}
|
|
95
|
+
footer={
|
|
96
|
+
<Footer
|
|
97
|
+
handleApply={handleApply}
|
|
98
|
+
handleClear={handleClear}
|
|
99
|
+
showClear={showClear}
|
|
100
|
+
selectedDraft={selectedDraft}
|
|
101
|
+
/>
|
|
102
|
+
}
|
|
103
|
+
/>
|
|
104
|
+
);
|
|
105
|
+
},
|
|
106
|
+
);
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { ButtonDesktop } from '@alfalab/core-components-button/desktop';
|
|
4
|
+
|
|
5
|
+
import { OptionShape } from '../../../../typings';
|
|
6
|
+
|
|
7
|
+
import styles from './index.module.css';
|
|
8
|
+
|
|
9
|
+
export type FooterProps = {
|
|
10
|
+
handleClear?: () => void;
|
|
11
|
+
handleApply?: () => void;
|
|
12
|
+
showClear?: boolean;
|
|
13
|
+
selectedDraft?: OptionShape[];
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const Footer = ({
|
|
17
|
+
handleApply,
|
|
18
|
+
handleClear,
|
|
19
|
+
showClear,
|
|
20
|
+
selectedDraft = [],
|
|
21
|
+
}: FooterProps) => (
|
|
22
|
+
<div
|
|
23
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex
|
|
24
|
+
tabIndex={0}
|
|
25
|
+
className={styles.footer}
|
|
26
|
+
>
|
|
27
|
+
<ButtonDesktop size='xxs' view='primary' onClick={handleApply}>
|
|
28
|
+
Применить
|
|
29
|
+
</ButtonDesktop>
|
|
30
|
+
|
|
31
|
+
{showClear && selectedDraft.length > 0 && (
|
|
32
|
+
<ButtonDesktop size='xxs' view='secondary' onClick={handleClear}>
|
|
33
|
+
Сбросить
|
|
34
|
+
</ButtonDesktop>
|
|
35
|
+
)}
|
|
36
|
+
</div>
|
|
37
|
+
);
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import cn from 'classnames';
|
|
3
|
+
|
|
4
|
+
import { Checkbox, CheckboxProps } from '@alfalab/core-components-checkbox';
|
|
5
|
+
|
|
6
|
+
import styles from './index.module.css';
|
|
7
|
+
|
|
8
|
+
export type HeaderProps = {
|
|
9
|
+
checked?: boolean;
|
|
10
|
+
indeterminate?: boolean;
|
|
11
|
+
onChange?: CheckboxProps['onChange'];
|
|
12
|
+
mobile?: boolean;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const Header: React.FC<HeaderProps> = ({ onChange, checked, indeterminate, mobile }) => (
|
|
16
|
+
<div className={cn({ [styles.desktop]: !mobile, [styles.mobile]: mobile })}>
|
|
17
|
+
<Checkbox
|
|
18
|
+
block={true}
|
|
19
|
+
indeterminate={indeterminate}
|
|
20
|
+
size='m'
|
|
21
|
+
onChange={onChange}
|
|
22
|
+
checked={checked}
|
|
23
|
+
label='Выбрать все'
|
|
24
|
+
/>
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Component';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
import { Skeleton } from '@alfalab/core-components-skeleton';
|
|
4
|
+
|
|
5
|
+
import { Option as DefaultOption } from '../../components/option';
|
|
6
|
+
import { BaseSelectProps, OptionProps, OptionShape } from '../../typings';
|
|
7
|
+
|
|
8
|
+
import styles from './index.module.css';
|
|
9
|
+
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
11
|
+
type useSelectWithLoadingProps = {
|
|
12
|
+
loading?: boolean;
|
|
13
|
+
visibleOptions?: BaseSelectProps['visibleOptions'];
|
|
14
|
+
Option?: React.FC<OptionProps>;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export function useSelectWithLoading({
|
|
18
|
+
loading = false,
|
|
19
|
+
visibleOptions = 6,
|
|
20
|
+
Option = DefaultOption,
|
|
21
|
+
}: useSelectWithLoadingProps) {
|
|
22
|
+
const renderOption = (props: OptionProps) => (
|
|
23
|
+
<Option {...props} Checkmark={null} highlighted={loading ? false : props.highlighted} />
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const options: OptionShape[] = Array(visibleOptions)
|
|
27
|
+
.fill(0)
|
|
28
|
+
.map((_, key) => ({
|
|
29
|
+
key: `loading-${key}`,
|
|
30
|
+
disabled: true,
|
|
31
|
+
content: <Skeleton className={styles.skeleton} visible={true} />,
|
|
32
|
+
}));
|
|
33
|
+
|
|
34
|
+
if (!loading) return null;
|
|
35
|
+
|
|
36
|
+
return {
|
|
37
|
+
Option: renderOption,
|
|
38
|
+
options,
|
|
39
|
+
};
|
|
40
|
+
}
|