@snack-uikit/carousel 0.2.21-preview-d46fe148.0 → 0.2.21-preview-e6983aad.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/dist/components/Carousel/Carousel.js +1 -1
- package/dist/components/ItemProvider/ItemProvider.d.ts +1 -2
- package/dist/components/ItemProvider/ItemProvider.js +10 -5
- package/package.json +2 -2
- package/src/components/Carousel/Carousel.tsx +0 -1
- package/src/components/ItemProvider/ItemProvider.tsx +9 -7
|
@@ -41,7 +41,7 @@ export function Carousel(_a) {
|
|
|
41
41
|
}
|
|
42
42
|
onLeftArrowClick();
|
|
43
43
|
}, [onLeftArrowClick, onRightArrowClick]);
|
|
44
|
-
return (_jsxs("div", Object.assign({ className: cn(styles.carousel, className) }, extractSupportProps(rest), { children: [_jsxs("div", { className: styles.carouselBase, children: [_jsx(ItemProvider, { showItems: showItems, scrollBy: scrollBy, swipe: swipe, transition: transition, items: items, slideCallback: slideCallback, page: page, gap: gap, swipeActivateLength: swipeActivateLength
|
|
44
|
+
return (_jsxs("div", Object.assign({ className: cn(styles.carousel, className) }, extractSupportProps(rest), { children: [_jsxs("div", { className: styles.carouselBase, children: [_jsx(ItemProvider, { showItems: showItems, scrollBy: scrollBy, swipe: swipe, transition: transition, items: items, slideCallback: slideCallback, page: page, gap: gap, swipeActivateLength: swipeActivateLength }), arrows && (_jsxs(_Fragment, { children: [(infiniteScroll || page > 0) && (_jsx(Control, { onClick: onLeftArrowClick, variant: 'prev', "data-test-id": TEST_IDS.arrowPrev })), (infiniteScroll || page + 1 < total) && (_jsx(Control, { onClick: onRightArrowClick, variant: 'next', "data-test-id": TEST_IDS.arrowNext }))] }))] }), pagination && (_jsx("div", { className: styles.pagination, children: _jsx(PaginationSlider, { "data-test-id": TEST_IDS.pagination, page: page + 1, onChange: (page) => {
|
|
45
45
|
setPage(page - 1);
|
|
46
46
|
}, total: total }) }))] })));
|
|
47
47
|
}
|
|
@@ -4,11 +4,10 @@ export type ItemProviderProps = {
|
|
|
4
4
|
showItems: number;
|
|
5
5
|
scrollBy: number;
|
|
6
6
|
slideCallback(direction: number): void;
|
|
7
|
-
scrollToNextPage(): void;
|
|
8
7
|
transition: number;
|
|
9
8
|
swipe: boolean;
|
|
10
9
|
swipeActivateLength: number;
|
|
11
10
|
page: number;
|
|
12
11
|
gap?: string;
|
|
13
12
|
};
|
|
14
|
-
export declare function ItemProvider({ items, showItems, scrollBy, slideCallback,
|
|
13
|
+
export declare function ItemProvider({ items, showItems, scrollBy, slideCallback, transition, swipe, swipeActivateLength, page, gap, }: ItemProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
|
|
|
4
4
|
import { TEST_IDS } from '../../testIds';
|
|
5
5
|
import { getPageX } from './helpers';
|
|
6
6
|
import styles from './styles.module.css';
|
|
7
|
-
export function ItemProvider({ items, showItems, scrollBy, slideCallback,
|
|
7
|
+
export function ItemProvider({ items, showItems, scrollBy, slideCallback, transition, swipe, swipeActivateLength, page, gap, }) {
|
|
8
8
|
const containerRef = useRef(null);
|
|
9
9
|
const [computedValues, setComputedValues] = useState({
|
|
10
10
|
itemWidth: 200,
|
|
@@ -116,11 +116,16 @@ export function ItemProvider({ items, showItems, scrollBy, slideCallback, scroll
|
|
|
116
116
|
}
|
|
117
117
|
: {};
|
|
118
118
|
const handleSlideClick = useCallback(e => {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
119
|
+
var _a, _b;
|
|
120
|
+
const slideRect = e.currentTarget.getBoundingClientRect();
|
|
121
|
+
const containerRect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
122
|
+
const containerViewport = (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _b !== void 0 ? _b : 0;
|
|
123
|
+
const slidePositionDelta = containerViewport - slideRect.right;
|
|
124
|
+
const minPos = Math.min(slidePositionDelta, slideRect.x);
|
|
125
|
+
if (minPos < 0) {
|
|
126
|
+
slideCallback(slidePositionDelta);
|
|
122
127
|
}
|
|
123
|
-
}, [
|
|
128
|
+
}, [slideCallback]);
|
|
124
129
|
return (_jsx("div", { ref: containerRef, className: styles.itemProvider, "data-pointers": !drag.pointers || undefined, "data-swipe": swipe || undefined, "data-gap": gap, style: Object.assign({}, (Boolean(gap) ? { '--gap': gap } : {})), children: _jsx("div", Object.assign({}, swipeProps, { className: styles.itemTracker, "data-test-id": TEST_IDS.trackLine, style: {
|
|
125
130
|
transform: `translateX(${transform - drag.drag}px)`,
|
|
126
131
|
transition: `transform ${transition}s ease 0s`,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.2.21-preview-
|
|
7
|
+
"version": "0.2.21-preview-e6983aad.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"lodash.debounce": "4.0.8",
|
|
40
40
|
"uncontrollable": "8.0.4"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "b0f78be1b5a0b02fcd7c8fed0c0f39f912bf0f30"
|
|
43
43
|
}
|
|
@@ -20,7 +20,6 @@ export type ItemProviderProps = {
|
|
|
20
20
|
showItems: number;
|
|
21
21
|
scrollBy: number;
|
|
22
22
|
slideCallback(direction: number): void;
|
|
23
|
-
scrollToNextPage(): void;
|
|
24
23
|
transition: number;
|
|
25
24
|
swipe: boolean;
|
|
26
25
|
swipeActivateLength: number;
|
|
@@ -33,7 +32,6 @@ export function ItemProvider({
|
|
|
33
32
|
showItems,
|
|
34
33
|
scrollBy,
|
|
35
34
|
slideCallback,
|
|
36
|
-
scrollToNextPage,
|
|
37
35
|
transition,
|
|
38
36
|
swipe,
|
|
39
37
|
swipeActivateLength,
|
|
@@ -192,13 +190,17 @@ export function ItemProvider({
|
|
|
192
190
|
|
|
193
191
|
const handleSlideClick: MouseEventHandler = useCallback(
|
|
194
192
|
e => {
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
193
|
+
const slideRect = e.currentTarget.getBoundingClientRect();
|
|
194
|
+
const containerRect = containerRef.current?.getBoundingClientRect();
|
|
195
|
+
const containerViewport = containerRect?.right ?? 0;
|
|
196
|
+
const slidePositionDelta = containerViewport - slideRect.right;
|
|
197
|
+
const minPos = Math.min(slidePositionDelta, slideRect.x);
|
|
198
|
+
|
|
199
|
+
if (minPos < 0) {
|
|
200
|
+
slideCallback(slidePositionDelta);
|
|
199
201
|
}
|
|
200
202
|
},
|
|
201
|
-
[
|
|
203
|
+
[slideCallback],
|
|
202
204
|
);
|
|
203
205
|
|
|
204
206
|
return (
|