@salutejs/plasma-core 1.226.1-next-sbcom.0 → 1.227.0-dev.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/__helpers/IconPlaceholder.js +6 -9
- package/__helpers/index.js +1 -1
- package/collectPackageInfo.js +4 -4
- package/components/Badge/Badge.js +30 -103
- package/components/Badge/index.js +1 -1
- package/components/Basebox/Basebox.js +33 -42
- package/components/Basebox/index.js +1 -1
- package/components/Button/Button.js +28 -67
- package/components/Button/Button.mixins.js +22 -76
- package/components/Button/Button.props.js +5 -5
- package/components/Button/createButton.js +14 -145
- package/components/Button/index.js +4 -4
- package/components/Card/Card.js +34 -162
- package/components/Card/CardBody.js +4 -4
- package/components/Card/CardContent.js +14 -23
- package/components/Card/CardMedia.js +20 -91
- package/components/Card/CardPrice.js +18 -60
- package/components/Card/CardTypography.js +43 -52
- package/components/Card/index.js +5 -5
- package/components/Carousel/Carousel.js +46 -64
- package/components/Carousel/CarouselItem.js +21 -93
- package/components/Carousel/hooks.js +62 -121
- package/components/Carousel/index.js +3 -3
- package/components/Carousel/utils.js +59 -73
- package/components/Fade/Fade.js +6 -9
- package/components/Fade/index.js +1 -1
- package/components/Field/Field.js +48 -63
- package/components/Field/Field.statuses.js +3 -3
- package/components/Field/index.js +2 -2
- package/components/Image/Image.js +34 -115
- package/components/Image/index.js +1 -1
- package/components/Input/Input.js +7 -7
- package/components/Input/Input.mixins.js +9 -12
- package/components/Input/index.js +1 -1
- package/components/ModalBase/ModalBase.js +22 -100
- package/components/ModalBase/ModalBaseContext.js +6 -9
- package/components/ModalBase/ModalOverlay.js +28 -111
- package/components/ModalBase/hooks.js +15 -43
- package/components/ModalBase/index.js +2 -2
- package/components/PaginationDots/PaginationDot.js +11 -17
- package/components/PaginationDots/PaginationDots.js +4 -7
- package/components/PaginationDots/index.js +3 -3
- package/components/PaginationDots/usePaginationDots.js +10 -11
- package/components/Popup/Popup.js +52 -205
- package/components/Popup/index.js +1 -1
- package/components/PopupBase/PopupBase.js +35 -169
- package/components/PopupBase/PopupBaseContext.js +26 -86
- package/components/PopupBase/PopupBaseRoot.js +31 -169
- package/components/PopupBase/hooks.js +23 -97
- package/components/PopupBase/index.js +3 -3
- package/components/PopupBase/utils.js +32 -78
- package/components/Price/Price.js +15 -90
- package/components/Price/index.js +1 -1
- package/components/RadioGroup/RadioGroup.js +6 -127
- package/components/RadioGroup/index.js +1 -1
- package/components/SSRProvider/SSRProvider.js +4 -5
- package/components/SSRProvider/index.js +1 -1
- package/components/Skeleton/LineSkeleton.js +23 -95
- package/components/Skeleton/RectSkeleton.js +20 -93
- package/components/Skeleton/Skeleton.js +2 -2
- package/components/Skeleton/TextSkeleton.js +11 -55
- package/components/Skeleton/index.js +3 -3
- package/components/Slider/Double.js +52 -203
- package/components/Slider/Handle.js +28 -158
- package/components/Slider/Single.js +29 -177
- package/components/Slider/Slider.js +5 -7
- package/components/Slider/SliderBase.js +39 -48
- package/components/Slider/ThumbBase.js +19 -95
- package/components/Slider/index.js +3 -3
- package/components/Slider/utils.js +2 -2
- package/components/Spinner/Spinner.js +28 -100
- package/components/Spinner/SpinnerSvg.js +9 -78
- package/components/Spinner/index.js +1 -1
- package/components/Switch/Switch.js +49 -220
- package/components/Switch/index.js +1 -1
- package/components/Tabs/TabItem.js +33 -168
- package/components/Tabs/Tabs.js +32 -170
- package/components/Tabs/TabsContext.js +12 -42
- package/components/Tabs/createTabsController.js +33 -168
- package/components/Tabs/index.js +4 -4
- package/components/TextArea/TextArea.js +20 -30
- package/components/TextArea/index.js +1 -1
- package/components/TextField/index.js +3 -3
- package/components/Toast/Toast.js +15 -16
- package/components/Toast/ToastContext.js +4 -8
- package/components/Toast/ToastController.js +44 -101
- package/components/Toast/ToastProvider.js +37 -142
- package/components/Toast/index.js +3 -3
- package/components/Toast/useToast.js +6 -6
- package/components/Typography/Body.js +18 -18
- package/components/Typography/Button.js +13 -13
- package/components/Typography/Caption.js +8 -8
- package/components/Typography/Display.js +18 -18
- package/components/Typography/Footnote.js +13 -13
- package/components/Typography/Headline.js +43 -43
- package/components/Typography/Paragraph.js +24 -24
- package/components/Typography/Underline.js +8 -8
- package/es/__helpers/IconPlaceholder.js +5 -8
- package/es/collectPackageInfo.js +3 -3
- package/es/components/Badge/Badge.js +27 -100
- package/es/components/Basebox/Basebox.js +28 -37
- package/es/components/Button/Button.js +24 -63
- package/es/components/Button/Button.mixins.js +19 -73
- package/es/components/Button/Button.props.js +3 -3
- package/es/components/Button/createButton.js +12 -143
- package/es/components/Card/Card.js +29 -157
- package/es/components/Card/CardBody.js +2 -2
- package/es/components/Card/CardContent.js +12 -21
- package/es/components/Card/CardMedia.js +17 -88
- package/es/components/Card/CardPrice.js +13 -55
- package/es/components/Card/CardTypography.js +43 -52
- package/es/components/Carousel/Carousel.js +45 -63
- package/es/components/Carousel/CarouselItem.js +18 -90
- package/es/components/Carousel/hooks.js +58 -117
- package/es/components/Carousel/utils.js +58 -72
- package/es/components/Fade/Fade.js +5 -8
- package/es/components/Field/Field.js +44 -59
- package/es/components/Field/Field.statuses.js +4 -4
- package/es/components/Image/Image.js +31 -112
- package/es/components/Input/Input.js +4 -4
- package/es/components/Input/Input.mixins.js +6 -9
- package/es/components/ModalBase/ModalBase.js +16 -94
- package/es/components/ModalBase/ModalBaseContext.js +6 -9
- package/es/components/ModalBase/ModalOverlay.js +23 -106
- package/es/components/ModalBase/hooks.js +12 -40
- package/es/components/PaginationDots/PaginationDot.js +9 -15
- package/es/components/PaginationDots/PaginationDots.js +3 -6
- package/es/components/PaginationDots/usePaginationDots.js +9 -10
- package/es/components/Popup/Popup.js +48 -201
- package/es/components/PopupBase/PopupBase.js +27 -161
- package/es/components/PopupBase/PopupBaseContext.js +25 -85
- package/es/components/PopupBase/PopupBaseRoot.js +26 -164
- package/es/components/PopupBase/hooks.js +21 -95
- package/es/components/PopupBase/utils.js +31 -77
- package/es/components/Price/Price.js +12 -87
- package/es/components/RadioGroup/RadioGroup.js +5 -126
- package/es/components/SSRProvider/SSRProvider.js +3 -4
- package/es/components/Skeleton/LineSkeleton.js +18 -90
- package/es/components/Skeleton/RectSkeleton.js +16 -89
- package/es/components/Skeleton/Skeleton.js +2 -2
- package/es/components/Skeleton/TextSkeleton.js +7 -51
- package/es/components/Slider/Double.js +49 -200
- package/es/components/Slider/Handle.js +23 -153
- package/es/components/Slider/Single.js +26 -174
- package/es/components/Slider/Slider.js +2 -4
- package/es/components/Slider/SliderBase.js +36 -45
- package/es/components/Slider/ThumbBase.js +16 -92
- package/es/components/Slider/index.js +1 -1
- package/es/components/Slider/utils.js +2 -2
- package/es/components/Spinner/Spinner.js +23 -95
- package/es/components/Spinner/SpinnerSvg.js +8 -77
- package/es/components/Switch/Switch.js +45 -216
- package/es/components/Tabs/TabItem.js +28 -163
- package/es/components/Tabs/Tabs.js +28 -166
- package/es/components/Tabs/TabsContext.js +11 -41
- package/es/components/Tabs/createTabsController.js +28 -163
- package/es/components/TextArea/TextArea.js +18 -28
- package/es/components/Toast/Toast.js +10 -11
- package/es/components/Toast/ToastContext.js +3 -7
- package/es/components/Toast/ToastController.js +38 -95
- package/es/components/Toast/ToastProvider.js +34 -139
- package/es/components/Toast/useToast.js +4 -4
- package/es/components/Typography/Body.js +15 -15
- package/es/components/Typography/Button.js +10 -10
- package/es/components/Typography/Caption.js +5 -5
- package/es/components/Typography/Display.js +15 -15
- package/es/components/Typography/Footnote.js +10 -10
- package/es/components/Typography/Headline.js +40 -40
- package/es/components/Typography/Paragraph.js +21 -21
- package/es/components/Typography/Underline.js +5 -5
- package/es/hocs/withAutoFocus.js +8 -78
- package/es/hocs/withSkeleton.js +5 -10
- package/es/hooks/useDebouncedFunction.js +4 -36
- package/es/hooks/useFocusTrap.js +18 -21
- package/es/hooks/useForkRef.js +3 -3
- package/es/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/es/hooks/useResizeObserver.js +8 -8
- package/es/hooks/useUniqId.js +6 -52
- package/es/mixins/addFocus.js +17 -22
- package/es/mixins/applyDisabled.js +6 -9
- package/es/mixins/applyEllipsis.js +2 -4
- package/es/mixins/applyMaxLines.js +3 -6
- package/es/mixins/applyNoSelect.js +2 -4
- package/es/mixins/applyOutline.js +2 -4
- package/es/mixins/applyRoundness.js +4 -7
- package/es/mixins/applyScrollSnap.js +4 -7
- package/es/mixins/applySkeletonGradient.js +6 -9
- package/es/mixins/applyView.js +2 -5
- package/es/mixins/blur.js +2 -5
- package/es/mixins/shadows.js +1 -1
- package/es/tokens/colors.js +48 -48
- package/es/tokens/typography.js +18 -18
- package/es/utils/__tests__/formatters.test.js +2 -2
- package/es/utils/animatedScrollTo.js +24 -34
- package/es/utils/canUseDOM.js +1 -1
- package/es/utils/extractTextFrom.js +3 -7
- package/es/utils/focusManager.js +40 -47
- package/es/utils/formatCurrency.js +4 -4
- package/es/utils/formatters.js +6 -14
- package/es/utils/react.js +4 -4
- package/es/utils/roundness.js +2 -4
- package/es/utils/scopeTab.js +5 -5
- package/es/utils/setRef.js +1 -1
- package/es/utils/tabbable.js +16 -25
- package/es/utils/toCssSize.js +1 -3
- package/es/utils/transformStyles.js +5 -60
- package/hocs/index.js +2 -2
- package/hocs/withAutoFocus.js +9 -79
- package/hocs/withSkeleton.js +8 -13
- package/hooks/index.js +6 -6
- package/hooks/useDebouncedFunction.js +5 -37
- package/hooks/useFocusTrap.js +22 -25
- package/hooks/useForkRef.js +5 -5
- package/hooks/useIsomorphicLayoutEffect.js +3 -3
- package/hooks/useResizeObserver.js +9 -9
- package/hooks/useUniqId.js +8 -54
- package/mixins/addFocus.js +19 -24
- package/mixins/applyDisabled.js +7 -10
- package/mixins/applyEllipsis.js +3 -5
- package/mixins/applyMaxLines.js +4 -7
- package/mixins/applyNoSelect.js +3 -5
- package/mixins/applyOutline.js +3 -5
- package/mixins/applyRoundness.js +5 -8
- package/mixins/applyScrollSnap.js +5 -8
- package/mixins/applySkeletonGradient.js +8 -11
- package/mixins/applyView.js +3 -6
- package/mixins/blur.js +2 -5
- package/mixins/index.js +11 -11
- package/mixins/shadows.js +1 -1
- package/package.json +13 -18
- package/tokens/colors.js +48 -48
- package/tokens/typography.js +18 -18
- package/utils/__tests__/formatters.test.js +3 -3
- package/utils/animatedScrollTo.js +24 -34
- package/utils/canUseDOM.js +1 -1
- package/utils/extractTextFrom.js +4 -8
- package/utils/focusManager.js +41 -48
- package/utils/formatCurrency.js +4 -4
- package/utils/formatters.js +6 -14
- package/utils/index.js +10 -10
- package/utils/react.js +7 -7
- package/utils/roundness.js +2 -4
- package/utils/scopeTab.js +6 -6
- package/utils/setRef.js +1 -1
- package/utils/tabbable.js +16 -25
- package/utils/toCssSize.js +1 -3
- package/utils/transformStyles.js +5 -60
|
@@ -1,109 +1,59 @@
|
|
|
1
|
-
function _array_like_to_array(arr, len) {
|
|
2
|
-
if (len == null || len > arr.length) len = arr.length;
|
|
3
|
-
for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
|
|
4
|
-
return arr2;
|
|
5
|
-
}
|
|
6
|
-
function _array_with_holes(arr) {
|
|
7
|
-
if (Array.isArray(arr)) return arr;
|
|
8
|
-
}
|
|
9
|
-
function _iterable_to_array_limit(arr, i) {
|
|
10
|
-
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
11
|
-
if (_i == null) return;
|
|
12
|
-
var _arr = [];
|
|
13
|
-
var _n = true;
|
|
14
|
-
var _d = false;
|
|
15
|
-
var _s, _e;
|
|
16
|
-
try {
|
|
17
|
-
for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
|
|
18
|
-
_arr.push(_s.value);
|
|
19
|
-
if (i && _arr.length === i) break;
|
|
20
|
-
}
|
|
21
|
-
} catch (err) {
|
|
22
|
-
_d = true;
|
|
23
|
-
_e = err;
|
|
24
|
-
} finally{
|
|
25
|
-
try {
|
|
26
|
-
if (!_n && _i["return"] != null) _i["return"]();
|
|
27
|
-
} finally{
|
|
28
|
-
if (_d) throw _e;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return _arr;
|
|
32
|
-
}
|
|
33
|
-
function _non_iterable_rest() {
|
|
34
|
-
throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
35
|
-
}
|
|
36
|
-
function _sliced_to_array(arr, i) {
|
|
37
|
-
return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
|
|
38
|
-
}
|
|
39
|
-
function _unsupported_iterable_to_array(o, minLen) {
|
|
40
|
-
if (!o) return;
|
|
41
|
-
if (typeof o === "string") return _array_like_to_array(o, minLen);
|
|
42
|
-
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
43
|
-
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
44
|
-
if (n === "Map" || n === "Set") return Array.from(n);
|
|
45
|
-
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
|
|
46
|
-
}
|
|
47
1
|
/* eslint-disable no-continue */ import throttle from 'lodash.throttle';
|
|
48
2
|
import { useRef, useEffect, useCallback, useMemo, useLayoutEffect, useState } from 'react';
|
|
49
3
|
import { useDebouncedFunction } from '../../hooks';
|
|
50
4
|
import { scrollToPos, getCalculatedPos, getCalculatedOffset, getItemSlot, getCarouselItems, translateToIndex } from './utils';
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
export
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
var trackRef = useRef(null);
|
|
5
|
+
const THROTTLE_DEFAULT_MS = 100;
|
|
6
|
+
const DEBOUNCE_DEFAULT_MS = 150;
|
|
7
|
+
export const useCarousel = ({ index, axis, detectActive = false, detectThreshold = 0.5, scrollAlign = 'center', scaleCallback, scaleResetCallback, onIndexChange, onDetectActiveItem, animatedScrollByIndex = false, throttleMs = THROTTLE_DEFAULT_MS, debounceMs = DEBOUNCE_DEFAULT_MS })=>{
|
|
8
|
+
const prevIndex = useRef(null);
|
|
9
|
+
const direction = useRef(null);
|
|
10
|
+
const offset = useRef(0);
|
|
11
|
+
const scrollRef = useRef(null);
|
|
12
|
+
const trackRef = useRef(null);
|
|
60
13
|
/**
|
|
61
14
|
* Для того, чтобы не спамить изменениями индекса.
|
|
62
15
|
* Задержка дебаунса слегка больше, чем у тротлинга.
|
|
63
16
|
* Таким образом, событие срабатывает при завершении скролла.
|
|
64
|
-
*/
|
|
65
|
-
return onIndexChange === null || onIndexChange === void 0 ? void 0 : onIndexChange(i);
|
|
66
|
-
}, debounceMs);
|
|
17
|
+
*/ const debouncedOnIndexChange = useDebouncedFunction((i)=>onIndexChange?.(i), debounceMs);
|
|
67
18
|
/**
|
|
68
19
|
* Вычисление центрального элемента.
|
|
69
20
|
* Подсчет: от 0 до 1, какое количество ширины/высоты
|
|
70
21
|
* каждого элемента находится по центру скролла.
|
|
71
|
-
*/
|
|
72
|
-
return throttle(
|
|
22
|
+
*/ const throttledDetectActiveItem = useMemo(()=>{
|
|
23
|
+
return throttle(()=>{
|
|
73
24
|
if (!detectActive || scrollRef.current === null || trackRef.current === null) {
|
|
74
25
|
return;
|
|
75
26
|
}
|
|
76
27
|
/**
|
|
77
28
|
* Правая (или нижняя для Оу) граница элемента.
|
|
78
|
-
*/
|
|
29
|
+
*/ let itemEdge = offset.current;
|
|
79
30
|
/**
|
|
80
31
|
* Смещение (отрицательный или положительный отступ)
|
|
81
32
|
* и размер карусели (для Ox - ширина, для Oy - высота).
|
|
82
|
-
*/
|
|
83
|
-
|
|
33
|
+
*/ const scrollPos = scrollRef.current[axis === 'x' ? 'scrollLeft' : 'scrollTop'];
|
|
34
|
+
const scrollSize = scrollRef.current[axis === 'x' ? 'offsetWidth' : 'offsetHeight'];
|
|
84
35
|
/**
|
|
85
36
|
* Граница скролла (видимой части).
|
|
86
37
|
* Смещение + размер.
|
|
87
|
-
*/
|
|
38
|
+
*/ const scrollEdge = scrollPos + scrollSize;
|
|
88
39
|
/**
|
|
89
40
|
* Элементы перед, после и в видимой части.
|
|
90
41
|
* перед [ ВИДИМЫЕ ] после
|
|
91
|
-
*/
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
42
|
+
*/ const prevItems = [];
|
|
43
|
+
const nextItems = [];
|
|
44
|
+
let count = 0;
|
|
45
|
+
const items = getCarouselItems(trackRef.current);
|
|
95
46
|
/**
|
|
96
47
|
* Проходим по всему списку, суммируя ширины элементов,
|
|
97
48
|
* пока не найдем один элемент, чей центр будет в центре карусели.
|
|
98
|
-
*/ for(
|
|
99
|
-
|
|
100
|
-
var item = items.item(itemIndex);
|
|
49
|
+
*/ for(let itemIndex = 0; itemIndex < items.length; itemIndex++){
|
|
50
|
+
const item = items.item(itemIndex);
|
|
101
51
|
if (item === null) {
|
|
102
52
|
continue;
|
|
103
53
|
}
|
|
104
54
|
/**
|
|
105
55
|
* Для Ox - ширина, для Oy - высота.
|
|
106
|
-
*/
|
|
56
|
+
*/ const itemSize = item[axis === 'x' ? 'offsetWidth' : 'offsetHeight'];
|
|
107
57
|
/**
|
|
108
58
|
* Все элементы правее вьюпорта выпадают из процедуры.
|
|
109
59
|
* Сравниваем по предыдущему элементу.
|
|
@@ -125,11 +75,11 @@ export var useCarousel = function useCarousel(param) {
|
|
|
125
75
|
}
|
|
126
76
|
continue;
|
|
127
77
|
}
|
|
128
|
-
|
|
78
|
+
const itemSlot = getItemSlot(itemIndex, itemEdge, itemSize, scrollPos, scrollSize, scrollAlign, prevIndex.current ?? 0, offset.current);
|
|
129
79
|
if (itemSlot !== null) {
|
|
130
80
|
if (detectThreshold && Math.abs(itemSlot) <= detectThreshold) {
|
|
131
|
-
onDetectActiveItem
|
|
132
|
-
debouncedOnIndexChange
|
|
81
|
+
onDetectActiveItem?.(itemIndex);
|
|
82
|
+
debouncedOnIndexChange?.(itemIndex);
|
|
133
83
|
}
|
|
134
84
|
if (scaleCallback) {
|
|
135
85
|
scaleCallback(item, itemSlot);
|
|
@@ -140,27 +90,19 @@ export var useCarousel = function useCarousel(param) {
|
|
|
140
90
|
}
|
|
141
91
|
}
|
|
142
92
|
if (scaleCallback && scaleResetCallback) {
|
|
143
|
-
window.requestAnimationFrame(
|
|
93
|
+
window.requestAnimationFrame(()=>{
|
|
144
94
|
if (direction.current) {
|
|
145
95
|
if (nextItems.length) {
|
|
146
|
-
nextItems.splice(0, count).forEach(
|
|
147
|
-
return scaleCallback(elem, count);
|
|
148
|
-
});
|
|
96
|
+
nextItems.splice(0, count).forEach((elem)=>scaleCallback(elem, count));
|
|
149
97
|
if (nextItems.length) {
|
|
150
|
-
nextItems.splice(0, count).forEach(
|
|
151
|
-
return scaleResetCallback(elem);
|
|
152
|
-
});
|
|
98
|
+
nextItems.splice(0, count).forEach((elem)=>scaleResetCallback(elem));
|
|
153
99
|
}
|
|
154
100
|
}
|
|
155
101
|
} else if (prevItems.length) {
|
|
156
|
-
|
|
157
|
-
prItemsRev.splice(0, count).forEach(
|
|
158
|
-
return scaleCallback(elem, count * -1);
|
|
159
|
-
});
|
|
102
|
+
const prItemsRev = prevItems.reverse();
|
|
103
|
+
prItemsRev.splice(0, count).forEach((elem)=>scaleCallback(elem, count * -1));
|
|
160
104
|
if (prItemsRev.length) {
|
|
161
|
-
prItemsRev.splice(0, count).forEach(
|
|
162
|
-
return scaleResetCallback(elem);
|
|
163
|
-
});
|
|
105
|
+
prItemsRev.splice(0, count).forEach((elem)=>scaleResetCallback(elem));
|
|
164
106
|
}
|
|
165
107
|
}
|
|
166
108
|
});
|
|
@@ -179,21 +121,21 @@ export var useCarousel = function useCarousel(param) {
|
|
|
179
121
|
]);
|
|
180
122
|
/**
|
|
181
123
|
* Прокрутка до нужной позиции индекса.
|
|
182
|
-
*/
|
|
183
|
-
|
|
184
|
-
|
|
124
|
+
*/ const toIndex = useCallback((i)=>{
|
|
125
|
+
const scrollEl = scrollRef.current;
|
|
126
|
+
const items = trackRef.current ? getCarouselItems(trackRef.current) : null;
|
|
185
127
|
if (scrollEl && items && items.length > 0 && i >= 0) {
|
|
186
128
|
scrollToPos({
|
|
187
|
-
scrollEl
|
|
129
|
+
scrollEl,
|
|
188
130
|
pos: getCalculatedPos({
|
|
189
|
-
scrollEl
|
|
190
|
-
items
|
|
191
|
-
axis
|
|
131
|
+
scrollEl,
|
|
132
|
+
items,
|
|
133
|
+
axis,
|
|
192
134
|
index: i,
|
|
193
135
|
offset: offset.current,
|
|
194
|
-
scrollAlign
|
|
136
|
+
scrollAlign
|
|
195
137
|
}),
|
|
196
|
-
axis
|
|
138
|
+
axis,
|
|
197
139
|
/**
|
|
198
140
|
* Без анимации при переходе на другой конец списка
|
|
199
141
|
*/ animated: animatedScrollByIndex && (prevIndex.current === null || Math.abs(i - prevIndex.current) !== items.length - 1)
|
|
@@ -205,7 +147,7 @@ export var useCarousel = function useCarousel(param) {
|
|
|
205
147
|
axis,
|
|
206
148
|
scrollAlign
|
|
207
149
|
]);
|
|
208
|
-
useEffect(
|
|
150
|
+
useEffect(()=>{
|
|
209
151
|
if (scrollRef.current && trackRef.current) {
|
|
210
152
|
offset.current = getCalculatedOffset(scrollRef.current, trackRef.current, axis);
|
|
211
153
|
}
|
|
@@ -215,12 +157,12 @@ export var useCarousel = function useCarousel(param) {
|
|
|
215
157
|
/**
|
|
216
158
|
* Операции на маунте/анмаунте компонента.
|
|
217
159
|
* Создать слушатели событи и т.п.
|
|
218
|
-
*/ useEffect(
|
|
219
|
-
|
|
160
|
+
*/ useEffect(()=>{
|
|
161
|
+
const carouselElement = scrollRef.current;
|
|
220
162
|
if (carouselElement) {
|
|
221
163
|
carouselElement.addEventListener('scroll', throttledDetectActiveItem);
|
|
222
164
|
}
|
|
223
|
-
return
|
|
165
|
+
return ()=>{
|
|
224
166
|
if (carouselElement) {
|
|
225
167
|
carouselElement.removeEventListener('scroll', throttledDetectActiveItem);
|
|
226
168
|
}
|
|
@@ -230,8 +172,8 @@ export var useCarousel = function useCarousel(param) {
|
|
|
230
172
|
]);
|
|
231
173
|
/**
|
|
232
174
|
* Нужно вызвать только при первом рендере
|
|
233
|
-
*/ useEffect(
|
|
234
|
-
requestAnimationFrame(
|
|
175
|
+
*/ useEffect(()=>{
|
|
176
|
+
requestAnimationFrame(()=>{
|
|
235
177
|
/**
|
|
236
178
|
* Прокрутка до начального индекса.
|
|
237
179
|
*/ toIndex(index);
|
|
@@ -245,7 +187,7 @@ export var useCarousel = function useCarousel(param) {
|
|
|
245
187
|
}, []);
|
|
246
188
|
/**
|
|
247
189
|
* Прокрутка до нужной позиции индекса, если индекс изменился.
|
|
248
|
-
*/ useEffect(
|
|
190
|
+
*/ useEffect(()=>{
|
|
249
191
|
if (index !== prevIndex.current) {
|
|
250
192
|
toIndex(index);
|
|
251
193
|
}
|
|
@@ -254,29 +196,28 @@ export var useCarousel = function useCarousel(param) {
|
|
|
254
196
|
toIndex
|
|
255
197
|
]);
|
|
256
198
|
return {
|
|
257
|
-
scrollRef
|
|
258
|
-
trackRef
|
|
199
|
+
scrollRef,
|
|
200
|
+
trackRef
|
|
259
201
|
};
|
|
260
202
|
};
|
|
261
|
-
export function useCarouselLite(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
var needTranslateToInitialIndex = useRef(true);
|
|
203
|
+
export function useCarouselLite({ index, axis, scrollAlign = 'center', scrollMode = 'translate' }) {
|
|
204
|
+
const [prevIndex, setPrevIndex] = useState(index);
|
|
205
|
+
const carouselRef = useRef(null);
|
|
206
|
+
const trackRef = useRef(null);
|
|
207
|
+
const needTranslateToInitialIndex = useRef(true);
|
|
267
208
|
// Первый раз нужно проскролить к индексу, после первого рендера
|
|
268
|
-
useLayoutEffect(
|
|
209
|
+
useLayoutEffect(()=>{
|
|
269
210
|
if (needTranslateToInitialIndex.current === false) {
|
|
270
211
|
return;
|
|
271
212
|
}
|
|
272
213
|
/**
|
|
273
214
|
* Вызываем через requestAnimationFrame, так как при использовании динамических CarouselCol
|
|
274
215
|
* ширины элементов высчитываются неверно внутри translateToIndex при синхронном вызове
|
|
275
|
-
*/
|
|
216
|
+
*/ const rafId = requestAnimationFrame(()=>{
|
|
276
217
|
translateToIndex(index, index, axis, scrollAlign, trackRef.current, carouselRef.current, true, scrollMode);
|
|
277
218
|
needTranslateToInitialIndex.current = false;
|
|
278
219
|
});
|
|
279
|
-
return
|
|
220
|
+
return ()=>{
|
|
280
221
|
cancelAnimationFrame(rafId);
|
|
281
222
|
};
|
|
282
223
|
}, [
|
|
@@ -293,6 +234,6 @@ export function useCarouselLite(param) {
|
|
|
293
234
|
}
|
|
294
235
|
return {
|
|
295
236
|
scrollRef: carouselRef,
|
|
296
|
-
trackRef
|
|
237
|
+
trackRef
|
|
297
238
|
};
|
|
298
239
|
}
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { animatedScrollToX, animatedScrollToY } from '../../utils';
|
|
2
|
-
|
|
3
|
-
var scrollAlign = param.scrollAlign, position = param.position, carouselSize = param.carouselSize, itemSize = param.itemSize, offset = param.offset, scrollStart = param.scrollStart, axis = param.axis;
|
|
2
|
+
const positionModByScrollAlign = ({ scrollAlign, position, carouselSize, itemSize, offset, scrollStart, axis })=>{
|
|
4
3
|
if (scrollAlign === 'start') {
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
const inaccuracy = 1;
|
|
5
|
+
const paddingOffset = axis === 'y' ? offset - itemSize / 2 + inaccuracy : 0;
|
|
7
6
|
return position + paddingOffset;
|
|
8
7
|
}
|
|
9
8
|
if (scrollAlign === 'center') {
|
|
@@ -24,59 +23,49 @@ var positionModByScrollAlign = function positionModByScrollAlign(param) {
|
|
|
24
23
|
};
|
|
25
24
|
/**
|
|
26
25
|
* Подсчет скролла до переданного индекса.
|
|
27
|
-
*/ export
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
var scrollStart;
|
|
26
|
+
*/ export const getCalculatedPos = ({ scrollEl, items, axis, index, offset, scrollAlign })=>{
|
|
27
|
+
let position = scrollAlign === 'center' ? offset : 0;
|
|
28
|
+
let carouselSize;
|
|
29
|
+
let itemSize;
|
|
30
|
+
let scrollStart;
|
|
33
31
|
if (items.item(index) === null) {
|
|
34
32
|
return position;
|
|
35
33
|
}
|
|
36
|
-
for(
|
|
34
|
+
for(let i = 0; i < index; i++){
|
|
37
35
|
if (axis === 'x') {
|
|
38
|
-
|
|
39
|
-
var _items_item;
|
|
40
|
-
position += (_ref = (_items_item = items.item(i)) === null || _items_item === void 0 ? void 0 : _items_item.offsetWidth) !== null && _ref !== void 0 ? _ref : 0;
|
|
36
|
+
position += items.item(i)?.offsetWidth ?? 0;
|
|
41
37
|
} else {
|
|
42
|
-
|
|
43
|
-
var _items_item1;
|
|
44
|
-
position += (_ref1 = (_items_item1 = items.item(i)) === null || _items_item1 === void 0 ? void 0 : _items_item1.offsetHeight) !== null && _ref1 !== void 0 ? _ref1 : 0;
|
|
38
|
+
position += items.item(i)?.offsetHeight ?? 0;
|
|
45
39
|
}
|
|
46
40
|
}
|
|
47
41
|
if (axis === 'x') {
|
|
48
|
-
var _ref2;
|
|
49
|
-
var _items_item2;
|
|
50
42
|
carouselSize = scrollEl.offsetWidth;
|
|
51
|
-
itemSize =
|
|
43
|
+
itemSize = items.item(index)?.offsetWidth ?? 0;
|
|
52
44
|
scrollStart = scrollEl.scrollLeft;
|
|
53
45
|
} else {
|
|
54
|
-
var _ref3;
|
|
55
|
-
var _items_item3;
|
|
56
46
|
carouselSize = scrollEl.offsetHeight;
|
|
57
|
-
itemSize =
|
|
47
|
+
itemSize = items.item(index)?.offsetHeight ?? 0;
|
|
58
48
|
scrollStart = scrollEl.scrollTop;
|
|
59
49
|
}
|
|
60
50
|
return positionModByScrollAlign({
|
|
61
|
-
scrollAlign
|
|
62
|
-
position
|
|
63
|
-
carouselSize
|
|
64
|
-
itemSize
|
|
65
|
-
offset
|
|
66
|
-
scrollStart
|
|
67
|
-
axis
|
|
51
|
+
scrollAlign,
|
|
52
|
+
position,
|
|
53
|
+
carouselSize,
|
|
54
|
+
itemSize,
|
|
55
|
+
offset,
|
|
56
|
+
scrollStart,
|
|
57
|
+
axis
|
|
68
58
|
});
|
|
69
59
|
};
|
|
70
60
|
/**
|
|
71
61
|
* Подсчет смещения из-за паддингов.
|
|
72
|
-
*/ export
|
|
73
|
-
|
|
62
|
+
*/ export const getCalculatedOffset = (scrollEl, trackEl, axis)=>{
|
|
63
|
+
const paddingProp = axis === 'x' ? 'paddingLeft' : 'paddingTop';
|
|
74
64
|
return parseInt(getComputedStyle(scrollEl)[paddingProp], 10) + parseInt(getComputedStyle(trackEl)[paddingProp], 10);
|
|
75
65
|
};
|
|
76
66
|
/**
|
|
77
67
|
* Прокрутка к указанной позиции с анимацией или без.
|
|
78
|
-
*/ export
|
|
79
|
-
var scrollEl = param.scrollEl, pos = param.pos, axis = param.axis, animated = param.animated, duration = param.duration, timingFunction = param.timingFunction;
|
|
68
|
+
*/ export const scrollToPos = ({ scrollEl, pos, axis, animated, duration, timingFunction })=>{
|
|
80
69
|
if (axis === 'x' && Math.abs(pos - scrollEl.scrollLeft) > 1) {
|
|
81
70
|
if (animated) {
|
|
82
71
|
animatedScrollToX(scrollEl, pos, duration, timingFunction);
|
|
@@ -96,20 +85,17 @@ var positionModByScrollAlign = function positionModByScrollAlign(param) {
|
|
|
96
85
|
}
|
|
97
86
|
}
|
|
98
87
|
};
|
|
99
|
-
|
|
100
|
-
return Math.round(n * 100) / 100;
|
|
101
|
-
};
|
|
88
|
+
const round = (n)=>Math.round(n * 100) / 100;
|
|
102
89
|
/**
|
|
103
90
|
* Получить позицию (слот) айтема в каруселе.
|
|
104
91
|
* Каждый айтем имеет свой слот относительно вьюпорта карусели.
|
|
105
|
-
*/ export
|
|
106
|
-
var prevIndex = arguments.length > 6 && arguments[6] !== void 0 ? arguments[6] : 0, offset = arguments.length > 7 && arguments[7] !== void 0 ? arguments[7] : 0;
|
|
92
|
+
*/ export const getItemSlot = (itemIndex, itemEnd, itemSize, scrollStart, scrollSize, scrollAlign, prevIndex = 0, offset = 0)=>{
|
|
107
93
|
/**
|
|
108
94
|
* Граница и центр скролла (видимой части).
|
|
109
95
|
* Смещение + размер.
|
|
110
|
-
*/
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
*/ const scrollEnd = scrollStart + scrollSize;
|
|
97
|
+
const scrollCenter = scrollStart + scrollSize / 2;
|
|
98
|
+
const itemCenter = itemEnd - itemSize / 2;
|
|
113
99
|
if (scrollAlign === 'center') {
|
|
114
100
|
return round((itemCenter - scrollCenter) / itemSize);
|
|
115
101
|
}
|
|
@@ -120,9 +106,9 @@ var round = function round(n) {
|
|
|
120
106
|
return round((itemEnd - (scrollSize + scrollStart)) / itemSize);
|
|
121
107
|
}
|
|
122
108
|
if (scrollAlign === 'activeDirection') {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
109
|
+
const prevStart = offset + itemSize * prevIndex;
|
|
110
|
+
const prevEnd = prevStart + itemSize;
|
|
111
|
+
const prevVisible = prevEnd > scrollStart && prevStart < scrollEnd;
|
|
126
112
|
if (!prevVisible) {
|
|
127
113
|
if (prevIndex < itemIndex) {
|
|
128
114
|
return round((itemEnd - (scrollSize + scrollStart)) / itemSize);
|
|
@@ -135,28 +121,28 @@ var round = function round(n) {
|
|
|
135
121
|
export function getCarouselItems(track) {
|
|
136
122
|
return track.children;
|
|
137
123
|
}
|
|
138
|
-
|
|
139
|
-
x
|
|
140
|
-
return
|
|
124
|
+
const axisToTranslateMap = {
|
|
125
|
+
x (position) {
|
|
126
|
+
return `translateX(${-position}px)`;
|
|
141
127
|
},
|
|
142
|
-
y
|
|
143
|
-
return
|
|
128
|
+
y (position) {
|
|
129
|
+
return `translateY(${-position}px)`;
|
|
144
130
|
}
|
|
145
131
|
};
|
|
146
|
-
|
|
132
|
+
const axisToOffsetKeyMap = {
|
|
147
133
|
x: 'offsetLeft',
|
|
148
134
|
y: 'offsetTop'
|
|
149
135
|
};
|
|
150
|
-
|
|
136
|
+
const axisToSizeKeyMap = {
|
|
151
137
|
x: 'offsetWidth',
|
|
152
138
|
y: 'offsetHeight'
|
|
153
139
|
};
|
|
154
|
-
|
|
140
|
+
const axisToScrollKeyMap = {
|
|
155
141
|
x: 'scrollLeft',
|
|
156
142
|
y: 'scrollTop'
|
|
157
143
|
};
|
|
158
144
|
function getCenterPosition(itemSize, itemStart, carouselSize, trackOffset) {
|
|
159
|
-
|
|
145
|
+
const relativeMiddle = itemStart + trackOffset + itemSize / 2;
|
|
160
146
|
return relativeMiddle - carouselSize / 2;
|
|
161
147
|
}
|
|
162
148
|
function getEndPosition(itemSize, itemStart, carouselSize, trackOffset) {
|
|
@@ -184,12 +170,12 @@ function boundPosition(position, trackSize, carouselSize, trackOffset) {
|
|
|
184
170
|
}
|
|
185
171
|
// если все элементы помещаются в ширину карусели, то считаем trackEnd по-другому
|
|
186
172
|
if (trackSize < carouselSize) {
|
|
187
|
-
|
|
173
|
+
const trackEnd = Math.abs(carouselSize - trackSize - trackOffset);
|
|
188
174
|
return position < trackEnd ? position : trackEnd;
|
|
189
175
|
}
|
|
190
|
-
|
|
191
|
-
if (position >
|
|
192
|
-
return
|
|
176
|
+
const trackEnd = trackSize - carouselSize + trackOffset;
|
|
177
|
+
if (position > trackEnd) {
|
|
178
|
+
return trackEnd;
|
|
193
179
|
}
|
|
194
180
|
return position;
|
|
195
181
|
}
|
|
@@ -217,10 +203,10 @@ function setTimingFunction(element, timingFunction) {
|
|
|
217
203
|
}
|
|
218
204
|
}
|
|
219
205
|
function translateToPosition(element, axis, position) {
|
|
220
|
-
|
|
206
|
+
const translate = axisToTranslateMap[axis];
|
|
221
207
|
element.style.transform = translate(position);
|
|
222
208
|
}
|
|
223
|
-
|
|
209
|
+
const scrollOptions = {
|
|
224
210
|
behavior: 'auto',
|
|
225
211
|
left: 0,
|
|
226
212
|
top: 0
|
|
@@ -244,24 +230,24 @@ var scrollOptions = {
|
|
|
244
230
|
if (track === null || carousel === null) {
|
|
245
231
|
return;
|
|
246
232
|
}
|
|
247
|
-
|
|
233
|
+
const scrollKey = axisToScrollKeyMap[axis];
|
|
248
234
|
if (disableAnimation === false && scrollMode === 'translate' && carousel[scrollKey] !== 0) {
|
|
249
235
|
carousel.scrollTo(scrollOptions);
|
|
250
236
|
}
|
|
251
|
-
|
|
237
|
+
const itemToTranslateTo = track.children.item(index);
|
|
252
238
|
if (itemToTranslateTo === null) {
|
|
253
239
|
return;
|
|
254
240
|
}
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
241
|
+
const numberOfItems = track.children.length;
|
|
242
|
+
const offsetKey = axisToOffsetKeyMap[axis];
|
|
243
|
+
const sizeKey = axisToSizeKeyMap[axis];
|
|
244
|
+
const carouselSize = carousel[sizeKey];
|
|
245
|
+
const trackSize = track[sizeKey];
|
|
246
|
+
const trackOffset = track[offsetKey];
|
|
247
|
+
const itemSize = itemToTranslateTo[sizeKey];
|
|
248
|
+
const itemStart = itemToTranslateTo[offsetKey];
|
|
249
|
+
const translatePosition = getTranslatePosition(itemSize, itemStart, carouselSize, trackOffset, align);
|
|
250
|
+
const position = boundPosition(translatePosition, trackSize, carouselSize, trackOffset);
|
|
265
251
|
if (scrollMode === 'scroll') {
|
|
266
252
|
carousel.scrollTo({
|
|
267
253
|
behavior: disableAnimation ? 'auto' : 'smooth',
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import styled from 'styled-components';
|
|
2
|
-
|
|
2
|
+
const gradients = {
|
|
3
3
|
top: 'radial-gradient(200% 200% at 50% -100%, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%)',
|
|
4
4
|
bottom: 'radial-gradient(200% 200% at 50% 200%, rgba(0, 0, 0, 0.8) 0%, rgba(0, 0, 0, 0) 100%)'
|
|
5
5
|
};
|
|
6
|
-
export
|
|
6
|
+
export const Fade = styled.div.withConfig({
|
|
7
7
|
displayName: "Fade",
|
|
8
8
|
componentId: "sc-1f25e4f8-0"
|
|
9
9
|
})([
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
],
|
|
13
|
-
var _param_placement = param.placement, placement = _param_placement === void 0 ? 'bottom' : _param_placement;
|
|
14
|
-
return gradients[placement];
|
|
15
|
-
});
|
|
10
|
+
`position:fixed;top:0;left:0;right:0;bottom:0;z-index:999;background:`,
|
|
11
|
+
`;`
|
|
12
|
+
], ({ placement = 'bottom' })=>gradients[placement]);
|