@snack-uikit/carousel 0.2.17 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +20 -0
- package/README.md +1 -0
- package/dist/components/Carousel/Carousel.d.ts +3 -1
- package/dist/components/Carousel/Carousel.js +2 -2
- package/dist/components/ItemProvider/ItemProvider.d.ts +2 -1
- package/dist/components/ItemProvider/ItemProvider.js +2 -2
- package/package.json +3 -3
- package/src/components/Carousel/Carousel.tsx +4 -0
- package/src/components/ItemProvider/ItemProvider.tsx +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,26 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## 0.2.19 (2024-09-07)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* **FF-5560:** fix swipe ([12714e8](https://github.com/cloud-ru-tech/snack-uikit/commit/12714e8c0318f7aac976fe327fa830ebd37cb3ed))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
## 0.2.18 (2024-08-15)
|
|
18
|
+
|
|
19
|
+
### Only dependencies have been changed
|
|
20
|
+
* [@snack-uikit/pagination@0.7.0](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/pagination/CHANGELOG.md)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
6
26
|
## 0.2.17 (2024-08-14)
|
|
7
27
|
|
|
8
28
|
### Only dependencies have been changed
|
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
| scrollBy | `number` | Math.trunc(show) | Сдвиг айтемов при смене 1 страницы |
|
|
19
19
|
| transition | `number` | 0.4 | Время переключения 1 страницы (в s) |
|
|
20
20
|
| swipe | `boolean` | true | Переключение страниц свайпом |
|
|
21
|
+
| swipeActivateLength | `number` | 48 | Минимальная длина в px для активации свайпа |
|
|
21
22
|
| arrows | `boolean` | true | Использовать стрелки для переключения страниц |
|
|
22
23
|
| pagination | `boolean` | true | Использовать пагинацию для переключения страниц |
|
|
23
24
|
| gap | `string` | var(--dimension-2m) | Расстояние между айтемами |
|
|
@@ -13,6 +13,8 @@ export type CarouselProps = WithSupportProps<{
|
|
|
13
13
|
transition?: number;
|
|
14
14
|
/** Переключение страниц свайпом @default true */
|
|
15
15
|
swipe?: boolean;
|
|
16
|
+
/** Минимальная длина в px для активации свайпа @default 48 */
|
|
17
|
+
swipeActivateLength?: number;
|
|
16
18
|
/** Использовать стрелки для переключения страниц @default true */
|
|
17
19
|
arrows?: boolean;
|
|
18
20
|
/** Использовать пагинацию для переключения страниц @default true */
|
|
@@ -27,4 +29,4 @@ export type CarouselProps = WithSupportProps<{
|
|
|
27
29
|
/** Цикличная прокрутка @default false*/
|
|
28
30
|
infiniteScroll?: boolean;
|
|
29
31
|
}>;
|
|
30
|
-
export declare function Carousel({ children: items, showItems, scrollBy: scrollByProp, transition, swipe, arrows, pagination, className, gap, state, infiniteScroll, ...rest }: CarouselProps): import("react/jsx-runtime").JSX.Element;
|
|
32
|
+
export declare function Carousel({ children: items, showItems, scrollBy: scrollByProp, transition, swipe, arrows, pagination, className, gap, state, infiniteScroll, swipeActivateLength, ...rest }: CarouselProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -21,7 +21,7 @@ import { ItemProvider } from '../ItemProvider';
|
|
|
21
21
|
import styles from './styles.module.css';
|
|
22
22
|
export function Carousel(_a) {
|
|
23
23
|
var _b;
|
|
24
|
-
var { children: items, showItems = 1, scrollBy: scrollByProp, transition = 0.4, swipe = true, arrows = true, pagination = true, className, gap, state, infiniteScroll = false } = _a, rest = __rest(_a, ["children", "showItems", "scrollBy", "transition", "swipe", "arrows", "pagination", "className", "gap", "state", "infiniteScroll"]);
|
|
24
|
+
var { children: items, showItems = 1, scrollBy: scrollByProp, transition = 0.4, swipe = true, arrows = true, pagination = true, className, gap, state, infiniteScroll = false, swipeActivateLength = 48 } = _a, rest = __rest(_a, ["children", "showItems", "scrollBy", "transition", "swipe", "arrows", "pagination", "className", "gap", "state", "infiniteScroll", "swipeActivateLength"]);
|
|
25
25
|
const scrollBy = useMemo(() => scrollByProp !== null && scrollByProp !== void 0 ? scrollByProp : Math.trunc(showItems), [showItems, scrollByProp]);
|
|
26
26
|
const [page, setPage] = useUncontrolledProp(state === null || state === void 0 ? void 0 : state.page, (_b = state === null || state === void 0 ? void 0 : state.page) !== null && _b !== void 0 ? _b : 0, newPage => {
|
|
27
27
|
const result = typeof newPage === 'function' ? newPage(page) : newPage;
|
|
@@ -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 }), 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) => {
|
|
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
|
}
|
|
@@ -6,7 +6,8 @@ export type ItemProviderProps = {
|
|
|
6
6
|
slideCallback(direction: number): void;
|
|
7
7
|
transition: number;
|
|
8
8
|
swipe: boolean;
|
|
9
|
+
swipeActivateLength: number;
|
|
9
10
|
page: number;
|
|
10
11
|
gap?: string;
|
|
11
12
|
};
|
|
12
|
-
export declare function ItemProvider({ items, showItems, scrollBy, slideCallback, transition, swipe, page, gap, }: ItemProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
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, transition, swipe, page, gap, }) {
|
|
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,
|
|
@@ -83,7 +83,7 @@ export function ItemProvider({ items, showItems, scrollBy, slideCallback, transi
|
|
|
83
83
|
if (drag.finished) {
|
|
84
84
|
return;
|
|
85
85
|
}
|
|
86
|
-
if (Math.abs(drag.drag) <
|
|
86
|
+
if (Math.abs(drag.drag) < swipeActivateLength) {
|
|
87
87
|
return setDrag({
|
|
88
88
|
initial: transform,
|
|
89
89
|
start: 0,
|
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.2.
|
|
7
|
+
"version": "0.2.19",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"scripts": {},
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@snack-uikit/icons": "0.22.0",
|
|
36
|
-
"@snack-uikit/pagination": "0.
|
|
36
|
+
"@snack-uikit/pagination": "0.7.0",
|
|
37
37
|
"@snack-uikit/utils": "3.3.0",
|
|
38
38
|
"classnames": "2.3.2",
|
|
39
39
|
"lodash.debounce": "4.0.8",
|
|
40
40
|
"uncontrollable": "8.0.4"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "1fbc35f6653e2f9f4fb38fc455d217c9fb23d1cd"
|
|
43
43
|
}
|
|
@@ -23,6 +23,8 @@ export type CarouselProps = WithSupportProps<{
|
|
|
23
23
|
transition?: number;
|
|
24
24
|
/** Переключение страниц свайпом @default true */
|
|
25
25
|
swipe?: boolean;
|
|
26
|
+
/** Минимальная длина в px для активации свайпа @default 48 */
|
|
27
|
+
swipeActivateLength?: number;
|
|
26
28
|
/** Использовать стрелки для переключения страниц @default true */
|
|
27
29
|
arrows?: boolean;
|
|
28
30
|
/** Использовать пагинацию для переключения страниц @default true */
|
|
@@ -50,6 +52,7 @@ export function Carousel({
|
|
|
50
52
|
gap,
|
|
51
53
|
state,
|
|
52
54
|
infiniteScroll = false,
|
|
55
|
+
swipeActivateLength = 48,
|
|
53
56
|
...rest
|
|
54
57
|
}: CarouselProps) {
|
|
55
58
|
const scrollBy = useMemo(() => scrollByProp ?? Math.trunc(showItems), [showItems, scrollByProp]);
|
|
@@ -96,6 +99,7 @@ export function Carousel({
|
|
|
96
99
|
slideCallback={slideCallback}
|
|
97
100
|
page={page}
|
|
98
101
|
gap={gap}
|
|
102
|
+
swipeActivateLength={swipeActivateLength}
|
|
99
103
|
/>
|
|
100
104
|
|
|
101
105
|
{arrows && (
|
|
@@ -12,6 +12,7 @@ export type ItemProviderProps = {
|
|
|
12
12
|
slideCallback(direction: number): void;
|
|
13
13
|
transition: number;
|
|
14
14
|
swipe: boolean;
|
|
15
|
+
swipeActivateLength: number;
|
|
15
16
|
page: number;
|
|
16
17
|
gap?: string;
|
|
17
18
|
};
|
|
@@ -23,6 +24,7 @@ export function ItemProvider({
|
|
|
23
24
|
slideCallback,
|
|
24
25
|
transition,
|
|
25
26
|
swipe,
|
|
27
|
+
swipeActivateLength,
|
|
26
28
|
page,
|
|
27
29
|
gap,
|
|
28
30
|
}: ItemProviderProps) {
|
|
@@ -131,7 +133,7 @@ export function ItemProvider({
|
|
|
131
133
|
if (drag.finished) {
|
|
132
134
|
return;
|
|
133
135
|
}
|
|
134
|
-
if (Math.abs(drag.drag) <
|
|
136
|
+
if (Math.abs(drag.drag) < swipeActivateLength) {
|
|
135
137
|
return setDrag({
|
|
136
138
|
initial: transform,
|
|
137
139
|
start: 0,
|