@snack-uikit/carousel 0.2.12 → 0.2.14-preview-95fbee92.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,15 @@
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.13 (2024-06-11)
7
+
8
+ ### Only dependencies have been changed
9
+ * [@snack-uikit/pagination@0.6.9](https://github.com/cloud-ru-tech/snack-uikit/blob/master/packages/pagination/CHANGELOG.md)
10
+
11
+
12
+
13
+
14
+
6
15
  ## 0.2.12 (2024-05-08)
7
16
 
8
17
  ### Only dependencies have been changed
@@ -1,27 +1,31 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { useEffect, useMemo, useRef, useState } from 'react';
3
3
  import { TEST_IDS } from '../../testIds';
4
4
  import { getPageX } from './helpers';
5
5
  import { useWindowWidthChange } from './hooks';
6
6
  import styles from './styles.module.css';
7
7
  export function ItemProvider({ items, showItems, scrollBy, slideCallback, transition, swipe, page, gap, }) {
8
+ const containerRef = useRef(null);
8
9
  const [computedValues, setComputedValues] = useState({
9
10
  itemWidth: 200,
10
11
  gap: 0,
11
12
  });
12
- const ref = useCallback((node) => {
13
- if (node !== null) {
14
- const styles = getComputedStyle(node);
15
- const gap = Number.parseFloat(styles.getPropertyValue('--gap'));
16
- const paddingLeft = Number.parseFloat(styles.getPropertyValue('padding-left'));
17
- const paddingRight = Number.parseFloat(styles.getPropertyValue('padding-right'));
18
- const itemWidth = (node.getBoundingClientRect().width - (Math.trunc(showItems) - 1) * gap - paddingLeft - paddingRight) /
19
- showItems;
20
- setComputedValues({ itemWidth, gap });
13
+ const containerElement = containerRef.current;
14
+ useEffect(() => {
15
+ if (!containerElement) {
16
+ return;
21
17
  }
22
- },
23
- // eslint-disable-next-line react-hooks/exhaustive-deps
24
- [computedValues.itemWidth, showItems]);
18
+ const styles = getComputedStyle(containerElement);
19
+ const gap = Number.parseFloat(styles.getPropertyValue('--gap'));
20
+ const paddingLeft = Number.parseFloat(styles.getPropertyValue('padding-left'));
21
+ const paddingRight = Number.parseFloat(styles.getPropertyValue('padding-right'));
22
+ const itemWidth = (containerElement.getBoundingClientRect().width -
23
+ (Math.trunc(showItems) - 1) * gap -
24
+ paddingLeft -
25
+ paddingRight) /
26
+ showItems;
27
+ setComputedValues({ itemWidth, gap });
28
+ }, [showItems, containerElement]);
25
29
  const itemsTrackerRef = useRef(null);
26
30
  function hideNonVisibleItems() {
27
31
  var _a;
@@ -106,7 +110,7 @@ export function ItemProvider({ items, showItems, scrollBy, slideCallback, transi
106
110
  onMouseMove: handleDragMove,
107
111
  }
108
112
  : {};
109
- return (_jsx("div", { ref: ref, className: styles.itemProvider, "data-pointers": !drag.pointers || undefined, "data-swipe": swipe || undefined, style: Object.assign({}, (Boolean(gap) ? { '--gap': gap } : {})), children: _jsx("div", Object.assign({}, swipeProps, { className: styles.itemTracker, "data-test-id": TEST_IDS.trackLine, style: {
113
+ return (_jsx("div", { ref: containerRef, className: styles.itemProvider, "data-pointers": !drag.pointers || undefined, "data-swipe": swipe || undefined, style: Object.assign({}, (Boolean(gap) ? { '--gap': gap } : {})), children: _jsx("div", Object.assign({}, swipeProps, { className: styles.itemTracker, "data-test-id": TEST_IDS.trackLine, style: {
110
114
  transform: `translateX(${transform - drag.drag}px)`,
111
115
  transition: `transform ${transition}s ease 0s`,
112
116
  }, ref: itemsTrackerRef, children: items.map((item, i) => (_jsx("div", { style: { width: computedValues.itemWidth }, className: styles.itemContainer, role: 'group', "data-test-id": TEST_IDS.trackItem, children: item }, i))) })) }));
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.2.12",
7
+ "version": "0.2.14-preview-95fbee92.0",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -33,10 +33,10 @@
33
33
  "scripts": {},
34
34
  "dependencies": {
35
35
  "@snack-uikit/icons": "0.21.0",
36
- "@snack-uikit/pagination": "0.6.8",
36
+ "@snack-uikit/pagination": "0.6.9",
37
37
  "@snack-uikit/utils": "3.3.0",
38
38
  "classnames": "2.3.2",
39
39
  "uncontrollable": "8.0.4"
40
40
  },
41
- "gitHead": "59bd2ac46a341357d543ada864a34e09745b3e42"
41
+ "gitHead": "6cc00922d59ee9d6b574beb9c7009bb95c36331a"
42
42
  }
@@ -1,4 +1,4 @@
1
- import { MouseEvent, ReactElement, TouchEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';
1
+ import { MouseEvent, ReactElement, TouchEvent, useEffect, useMemo, useRef, useState } from 'react';
2
2
 
3
3
  import { TEST_IDS } from '../../testIds';
4
4
  import { getPageX } from './helpers';
@@ -26,29 +26,34 @@ export function ItemProvider({
26
26
  page,
27
27
  gap,
28
28
  }: ItemProviderProps) {
29
+ const containerRef = useRef<HTMLDivElement>(null);
30
+
29
31
  const [computedValues, setComputedValues] = useState({
30
32
  itemWidth: 200,
31
33
  gap: 0,
32
34
  });
33
35
 
34
- const ref = useCallback(
35
- (node: HTMLDivElement) => {
36
- if (node !== null) {
37
- const styles = getComputedStyle(node);
36
+ const containerElement = containerRef.current;
37
+
38
+ useEffect(() => {
39
+ if (!containerElement) {
40
+ return;
41
+ }
42
+
43
+ const styles = getComputedStyle(containerElement);
38
44
 
39
- const gap = Number.parseFloat(styles.getPropertyValue('--gap'));
40
- const paddingLeft = Number.parseFloat(styles.getPropertyValue('padding-left'));
41
- const paddingRight = Number.parseFloat(styles.getPropertyValue('padding-right'));
45
+ const gap = Number.parseFloat(styles.getPropertyValue('--gap'));
46
+ const paddingLeft = Number.parseFloat(styles.getPropertyValue('padding-left'));
47
+ const paddingRight = Number.parseFloat(styles.getPropertyValue('padding-right'));
42
48
 
43
- const itemWidth =
44
- (node.getBoundingClientRect().width - (Math.trunc(showItems) - 1) * gap - paddingLeft - paddingRight) /
45
- showItems;
46
- setComputedValues({ itemWidth, gap });
47
- }
48
- },
49
- // eslint-disable-next-line react-hooks/exhaustive-deps
50
- [computedValues.itemWidth, showItems],
51
- );
49
+ const itemWidth =
50
+ (containerElement.getBoundingClientRect().width -
51
+ (Math.trunc(showItems) - 1) * gap -
52
+ paddingLeft -
53
+ paddingRight) /
54
+ showItems;
55
+ setComputedValues({ itemWidth, gap });
56
+ }, [showItems, containerElement]);
52
57
 
53
58
  const itemsTrackerRef = useRef<HTMLDivElement>(null);
54
59
 
@@ -163,7 +168,7 @@ export function ItemProvider({
163
168
 
164
169
  return (
165
170
  <div
166
- ref={ref}
171
+ ref={containerRef}
167
172
  className={styles.itemProvider}
168
173
  data-pointers={!drag.pointers || undefined}
169
174
  data-swipe={swipe || undefined}