@snack-uikit/carousel 0.2.8 → 0.2.9-preview-ed180305.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.
@@ -27,4 +27,4 @@ export type CarouselProps = WithSupportProps<{
27
27
  /** Цикличная прокрутка @default false*/
28
28
  infiniteScroll?: boolean;
29
29
  }>;
30
- export declare function Carousel({ children, showItems, scrollBy: scrollByProp, transition, swipe, arrows, pagination, className, gap, state, infiniteScroll, ...rest }: CarouselProps): import("react/jsx-runtime").JSX.Element;
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;
@@ -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, useEffect, useMemo, useRef } from 'react';
14
+ import { useCallback, useMemo } 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,19 +21,13 @@ 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, 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"]);
25
- const initialItems = children;
26
- const itemsRef = useRef(children);
27
- useEffect(() => {
28
- itemsRef.current = initialItems;
29
- // eslint-disable-next-line react-hooks/exhaustive-deps
30
- }, [initialItems.length]);
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"]);
31
25
  const scrollBy = useMemo(() => scrollByProp !== null && scrollByProp !== void 0 ? scrollByProp : Math.trunc(showItems), [showItems, scrollByProp]);
32
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 => {
33
27
  const result = typeof newPage === 'function' ? newPage(page) : newPage;
34
28
  state === null || state === void 0 ? void 0 : state.onChange(result);
35
29
  });
36
- const total = useMemo(() => Math.trunc(initialItems.length / scrollBy) + (initialItems.length % scrollBy ? 1 : 0), [initialItems.length, scrollBy]);
30
+ const total = useMemo(() => Math.trunc(items.length / scrollBy) + (items.length % scrollBy ? 1 : 0), [items.length, scrollBy]);
37
31
  const onLeftArrowClick = useCallback(() => {
38
32
  setPage((page) => (infiniteScroll ? (total + page - 1) % total : Math.max(0, page - 1)));
39
33
  }, [infiniteScroll, setPage, total]);
@@ -47,7 +41,7 @@ export function Carousel(_a) {
47
41
  }
48
42
  onLeftArrowClick();
49
43
  }, [onLeftArrowClick, onRightArrowClick]);
50
- 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: itemsRef.current, 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 }), 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) => {
51
45
  setPage(page - 1);
52
46
  }, total: total }) }))] })));
53
47
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.2.8",
7
+ "version": "0.2.9-preview-ed180305.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -38,5 +38,5 @@
38
38
  "classnames": "2.3.2",
39
39
  "uncontrollable": "8.0.4"
40
40
  },
41
- "gitHead": "0054db0a5550fb69d388335d844017bca31fffe7"
41
+ "gitHead": "4d064fd7b52925063c068f94739fb2a9a34b7b13"
42
42
  }
@@ -1,5 +1,5 @@
1
1
  import cn from 'classnames';
2
- import { ReactElement, useCallback, useEffect, useMemo, useRef } from 'react';
2
+ import { ReactElement, useCallback, useMemo } from 'react';
3
3
  import { useUncontrolledProp } from 'uncontrollable';
4
4
 
5
5
  import { PaginationSlider } from '@snack-uikit/pagination';
@@ -39,7 +39,7 @@ export type CarouselProps = WithSupportProps<{
39
39
  }>;
40
40
 
41
41
  export function Carousel({
42
- children,
42
+ children: items,
43
43
  showItems = 1,
44
44
  scrollBy: scrollByProp,
45
45
  transition = 0.4,
@@ -52,14 +52,6 @@ export function Carousel({
52
52
  infiniteScroll = false,
53
53
  ...rest
54
54
  }: CarouselProps) {
55
- const initialItems = children;
56
- const itemsRef = useRef(children);
57
-
58
- useEffect(() => {
59
- itemsRef.current = initialItems;
60
- // eslint-disable-next-line react-hooks/exhaustive-deps
61
- }, [initialItems.length]);
62
-
63
55
  const scrollBy = useMemo(() => scrollByProp ?? Math.trunc(showItems), [showItems, scrollByProp]);
64
56
 
65
57
  const [page, setPage] = useUncontrolledProp<number>(state?.page, state?.page ?? 0, newPage => {
@@ -68,8 +60,8 @@ export function Carousel({
68
60
  });
69
61
 
70
62
  const total = useMemo(
71
- () => Math.trunc(initialItems.length / scrollBy) + (initialItems.length % scrollBy ? 1 : 0),
72
- [initialItems.length, scrollBy],
63
+ () => Math.trunc(items.length / scrollBy) + (items.length % scrollBy ? 1 : 0),
64
+ [items.length, scrollBy],
73
65
  );
74
66
 
75
67
  const onLeftArrowClick = useCallback(() => {
@@ -100,7 +92,7 @@ export function Carousel({
100
92
  scrollBy={scrollBy}
101
93
  swipe={swipe}
102
94
  transition={transition}
103
- items={itemsRef.current}
95
+ items={items}
104
96
  slideCallback={slideCallback}
105
97
  page={page}
106
98
  gap={gap}