@snack-uikit/carousel 0.4.18-preview-790689b4.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -3,6 +3,27 @@
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.5.0 (2025-03-29)
7
+
8
+
9
+ ### Features
10
+
11
+ * **PDS-1119:** carousel autoswipe ([ff064ac](https://github.com/cloud-ru-tech/snack-uikit/commit/ff064acc23974c47acf2e1c3a52638fd482fecdb))
12
+
13
+
14
+
15
+
16
+
17
+ ## 0.4.18 (2025-03-19)
18
+
19
+ ### Only dependencies have been changed
20
+ * [@snack-uikit/icons@0.26.2](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/icons/CHANGELOG.md)
21
+ * [@snack-uikit/pagination@0.10.9](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/pagination/CHANGELOG.md)
22
+
23
+
24
+
25
+
26
+
6
27
  ## 0.4.17 (2025-03-17)
7
28
 
8
29
  ### 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
+ | autoSwipe | `number` | - | Автоматическое переключение слайдов в секундах |
21
22
  | swipeActivateLength | `number` | 48 | Минимальная длина в px для активации свайпа |
22
23
  | arrows | `boolean` | true | Использовать стрелки для переключения страниц |
23
24
  | pagination | `boolean` | true | Использовать пагинацию для переключения страниц |
@@ -13,6 +13,8 @@ export type CarouselProps = WithSupportProps<{
13
13
  transition?: number;
14
14
  /** Переключение страниц свайпом @default true */
15
15
  swipe?: boolean;
16
+ /** Автоматическое переключение слайдов в секундах */
17
+ autoSwipe?: number;
16
18
  /** Минимальная длина в px для активации свайпа @default 48 */
17
19
  swipeActivateLength?: number;
18
20
  /** Использовать стрелки для переключения страниц @default true */
@@ -29,4 +31,4 @@ export type CarouselProps = WithSupportProps<{
29
31
  /** Цикличная прокрутка @default false*/
30
32
  infiniteScroll?: boolean;
31
33
  }>;
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;
34
+ export declare function Carousel({ children: items, showItems, scrollBy: scrollByProp, transition, swipe, arrows, pagination, className, gap, state, infiniteScroll, swipeActivateLength, autoSwipe, ...rest }: CarouselProps): import("react/jsx-runtime").JSX.Element;
@@ -41,9 +41,11 @@ function Carousel(_a) {
41
41
  gap,
42
42
  state,
43
43
  infiniteScroll = false,
44
- swipeActivateLength = 48
44
+ swipeActivateLength = 48,
45
+ autoSwipe
45
46
  } = _a,
46
- rest = __rest(_a, ["children", "showItems", "scrollBy", "transition", "swipe", "arrows", "pagination", "className", "gap", "state", "infiniteScroll", "swipeActivateLength"]);
47
+ rest = __rest(_a, ["children", "showItems", "scrollBy", "transition", "swipe", "arrows", "pagination", "className", "gap", "state", "infiniteScroll", "swipeActivateLength", "autoSwipe"]);
48
+ const timerRef = (0, react_1.useRef)();
47
49
  const scrollBy = (0, react_1.useMemo)(() => scrollByProp !== null && scrollByProp !== void 0 ? scrollByProp : Math.trunc(showItems), [showItems, scrollByProp]);
48
50
  const [page, setPage] = (0, uncontrollable_1.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 => {
49
51
  const result = typeof newPage === 'function' ? newPage(page) : newPage;
@@ -68,6 +70,13 @@ function Carousel(_a) {
68
70
  }
69
71
  onLeftArrowClick();
70
72
  }, [onLeftArrowClick, onRightArrowClick]);
73
+ (0, react_1.useEffect)(() => {
74
+ if (!autoSwipe || !infiniteScroll) {
75
+ return;
76
+ }
77
+ timerRef.current = setTimeout(() => onRightArrowClick(), autoSwipe * 1000);
78
+ return () => clearTimeout(timerRef.current);
79
+ }, [autoSwipe, infiniteScroll, onRightArrowClick]);
71
80
  return (0, jsx_runtime_1.jsxs)("div", Object.assign({
72
81
  className: (0, classnames_1.default)(styles_module_scss_1.default.carousel, className)
73
82
  }, (0, utils_1.extractSupportProps)(rest), {
@@ -13,6 +13,8 @@ export type CarouselProps = WithSupportProps<{
13
13
  transition?: number;
14
14
  /** Переключение страниц свайпом @default true */
15
15
  swipe?: boolean;
16
+ /** Автоматическое переключение слайдов в секундах */
17
+ autoSwipe?: number;
16
18
  /** Минимальная длина в px для активации свайпа @default 48 */
17
19
  swipeActivateLength?: number;
18
20
  /** Использовать стрелки для переключения страниц @default true */
@@ -29,4 +31,4 @@ export type CarouselProps = WithSupportProps<{
29
31
  /** Цикличная прокрутка @default false*/
30
32
  infiniteScroll?: boolean;
31
33
  }>;
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;
34
+ export declare function Carousel({ children: items, showItems, scrollBy: scrollByProp, transition, swipe, arrows, pagination, className, gap, state, infiniteScroll, swipeActivateLength, autoSwipe, ...rest }: CarouselProps): import("react/jsx-runtime").JSX.Element;
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import cn from 'classnames';
14
- import { useCallback, useMemo } from 'react';
14
+ import { useCallback, useEffect, useMemo, useRef } from 'react';
15
15
  import { useUncontrolledProp } from 'uncontrollable';
16
16
  import { PaginationSlider } from '@snack-uikit/pagination';
17
17
  import { extractSupportProps } from '@snack-uikit/utils';
@@ -21,7 +21,8 @@ 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, swipeActivateLength = 48 } = _a, rest = __rest(_a, ["children", "showItems", "scrollBy", "transition", "swipe", "arrows", "pagination", "className", "gap", "state", "infiniteScroll", "swipeActivateLength"]);
24
+ var { children: items, showItems = 1, scrollBy: scrollByProp, transition = 0.4, swipe = true, arrows = true, pagination = true, className, gap, state, infiniteScroll = false, swipeActivateLength = 48, autoSwipe } = _a, rest = __rest(_a, ["children", "showItems", "scrollBy", "transition", "swipe", "arrows", "pagination", "className", "gap", "state", "infiniteScroll", "swipeActivateLength", "autoSwipe"]);
25
+ const timerRef = useRef();
25
26
  const scrollBy = useMemo(() => scrollByProp !== null && scrollByProp !== void 0 ? scrollByProp : Math.trunc(showItems), [showItems, scrollByProp]);
26
27
  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
28
  const result = typeof newPage === 'function' ? newPage(page) : newPage;
@@ -46,6 +47,13 @@ export function Carousel(_a) {
46
47
  }
47
48
  onLeftArrowClick();
48
49
  }, [onLeftArrowClick, onRightArrowClick]);
50
+ useEffect(() => {
51
+ if (!autoSwipe || !infiniteScroll) {
52
+ return;
53
+ }
54
+ timerRef.current = setTimeout(() => onRightArrowClick(), autoSwipe * 1000);
55
+ return () => clearTimeout(timerRef.current);
56
+ }, [autoSwipe, infiniteScroll, onRightArrowClick]);
49
57
  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) => {
50
58
  setPage(page - 1);
51
59
  }, total: total }) }))] })));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.4.18-preview-790689b4.0",
7
+ "version": "0.5.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -36,13 +36,13 @@
36
36
  "license": "Apache-2.0",
37
37
  "scripts": {},
38
38
  "dependencies": {
39
- "@snack-uikit/icons": "0.26.2-preview-790689b4.0",
40
- "@snack-uikit/pagination": "0.10.9-preview-790689b4.0",
39
+ "@snack-uikit/icons": "0.26.2",
40
+ "@snack-uikit/pagination": "0.10.9",
41
41
  "@snack-uikit/utils": "3.8.1",
42
42
  "classnames": "2.5.1",
43
43
  "lodash.debounce": "4.0.8",
44
44
  "merge-refs": "1.3.0",
45
45
  "uncontrollable": "8.0.4"
46
46
  },
47
- "gitHead": "ea32d3ce80ab87290636f1ff7eadf56392651524"
47
+ "gitHead": "614c4dc0de37ef72d1b1c66f2b393933321d73db"
48
48
  }
@@ -1,5 +1,5 @@
1
1
  import cn from 'classnames';
2
- import { ReactElement, useCallback, useMemo } from 'react';
2
+ import { ReactElement, useCallback, useEffect, useMemo, useRef } from 'react';
3
3
  import { useUncontrolledProp } from 'uncontrollable';
4
4
 
5
5
  import { PaginationSlider } from '@snack-uikit/pagination';
@@ -23,6 +23,8 @@ export type CarouselProps = WithSupportProps<{
23
23
  transition?: number;
24
24
  /** Переключение страниц свайпом @default true */
25
25
  swipe?: boolean;
26
+ /** Автоматическое переключение слайдов в секундах */
27
+ autoSwipe?: number;
26
28
  /** Минимальная длина в px для активации свайпа @default 48 */
27
29
  swipeActivateLength?: number;
28
30
  /** Использовать стрелки для переключения страниц @default true */
@@ -53,8 +55,11 @@ export function Carousel({
53
55
  state,
54
56
  infiniteScroll = false,
55
57
  swipeActivateLength = 48,
58
+ autoSwipe,
56
59
  ...rest
57
60
  }: CarouselProps) {
61
+ const timerRef = useRef<NodeJS.Timeout>();
62
+
58
63
  const scrollBy = useMemo(() => scrollByProp ?? Math.trunc(showItems), [showItems, scrollByProp]);
59
64
 
60
65
  const [page, setPage] = useUncontrolledProp<number>(state?.page, state?.page ?? 0, newPage => {
@@ -89,6 +94,16 @@ export function Carousel({
89
94
  [onLeftArrowClick, onRightArrowClick],
90
95
  );
91
96
 
97
+ useEffect(() => {
98
+ if (!autoSwipe || !infiniteScroll) {
99
+ return;
100
+ }
101
+
102
+ timerRef.current = setTimeout(() => onRightArrowClick(), autoSwipe * 1000);
103
+
104
+ return () => clearTimeout(timerRef.current);
105
+ }, [autoSwipe, infiniteScroll, onRightArrowClick]);
106
+
92
107
  return (
93
108
  <div className={cn(styles.carousel, className)} {...extractSupportProps(rest)}>
94
109
  <div className={styles.carouselBase}>