@snack-uikit/carousel 0.4.1 → 0.4.2

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,17 @@
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.4.2 (2024-11-06)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **PDS-1011:** carousel item width calculation fixed ([0975a99](https://github.com/cloud-ru-tech/snack-uikit/commit/0975a99b76286a9f8adf528a0aa283cfccd0d1fc))
12
+
13
+
14
+
15
+
16
+
6
17
  ## 0.4.1 (2024-10-31)
7
18
 
8
19
  ### Only dependencies have been changed
@@ -29,7 +29,7 @@ function ItemProvider(_ref) {
29
29
  } = _ref;
30
30
  const containerRef = (0, react_1.useRef)(null);
31
31
  const [computedValues, setComputedValues] = (0, react_1.useState)({
32
- itemWidth: 200,
32
+ itemWidth: 0,
33
33
  gap: 0
34
34
  });
35
35
  const recalculateItemsSize = (0, react_1.useCallback)(() => {
@@ -158,6 +158,13 @@ function ItemProvider(_ref) {
158
158
  slideCallback(slidePositionDelta);
159
159
  }
160
160
  }, [slideCallback]);
161
+ const itemWidth = (0, react_1.useMemo)(() => {
162
+ if (computedValues.itemWidth > 0) {
163
+ return computedValues.itemWidth;
164
+ }
165
+ const fallbackWidth = Math.floor(100 / showItems);
166
+ return `${fallbackWidth}%`;
167
+ }, [computedValues.itemWidth, showItems]);
161
168
  return (0, jsx_runtime_1.jsx)("div", {
162
169
  ref: containerRef,
163
170
  className: styles_module_scss_1.default.itemProvider,
@@ -179,7 +186,7 @@ function ItemProvider(_ref) {
179
186
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
180
187
  (0, jsx_runtime_1.jsx)("div", {
181
188
  style: {
182
- width: computedValues.itemWidth
189
+ width: itemWidth
183
190
  },
184
191
  className: styles_module_scss_1.default.itemContainer,
185
192
  role: 'group',
@@ -7,7 +7,7 @@ import styles from './styles.module.css';
7
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
- itemWidth: 200,
10
+ itemWidth: 0,
11
11
  gap: 0,
12
12
  });
13
13
  const recalculateItemsSize = useCallback(() => {
@@ -126,10 +126,17 @@ export function ItemProvider({ items, showItems, scrollBy, slideCallback, transi
126
126
  slideCallback(slidePositionDelta);
127
127
  }
128
128
  }, [slideCallback]);
129
+ const itemWidth = useMemo(() => {
130
+ if (computedValues.itemWidth > 0) {
131
+ return computedValues.itemWidth;
132
+ }
133
+ const fallbackWidth = Math.floor(100 / showItems);
134
+ return `${fallbackWidth}%`;
135
+ }, [computedValues.itemWidth, showItems]);
129
136
  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: {
130
137
  transform: `translateX(${transform - drag.drag}px)`,
131
138
  transition: `transform ${transition}s ease 0s`,
132
139
  }, ref: itemsTrackerRef, children: items.map((item, i) => (
133
140
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
134
- _jsx("div", { style: { width: computedValues.itemWidth }, className: styles.itemContainer, role: 'group', "data-test-id": TEST_IDS.trackItem, onClick: handleSlideClick, children: item }, i))) })) }));
141
+ _jsx("div", { style: { width: itemWidth }, className: styles.itemContainer, role: 'group', "data-test-id": TEST_IDS.trackItem, onClick: handleSlideClick, children: item }, i))) })) }));
135
142
  }
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.4.1",
7
+ "version": "0.4.2",
8
8
  "sideEffects": [
9
9
  "*.css",
10
10
  "*.woff",
@@ -43,5 +43,5 @@
43
43
  "lodash.debounce": "4.0.8",
44
44
  "uncontrollable": "8.0.4"
45
45
  },
46
- "gitHead": "b7163c6f939105eb34cabec64c9e983ac7958c26"
46
+ "gitHead": "5de970443105960cc6e30c5605d7f3deac3f064e"
47
47
  }
@@ -41,7 +41,7 @@ export function ItemProvider({
41
41
  const containerRef = useRef<HTMLDivElement>(null);
42
42
 
43
43
  const [computedValues, setComputedValues] = useState({
44
- itemWidth: 200,
44
+ itemWidth: 0,
45
45
  gap: 0,
46
46
  });
47
47
 
@@ -203,6 +203,15 @@ export function ItemProvider({
203
203
  [slideCallback],
204
204
  );
205
205
 
206
+ const itemWidth = useMemo(() => {
207
+ if (computedValues.itemWidth > 0) {
208
+ return computedValues.itemWidth;
209
+ }
210
+
211
+ const fallbackWidth = Math.floor(100 / showItems);
212
+ return `${fallbackWidth}%`;
213
+ }, [computedValues.itemWidth, showItems]);
214
+
206
215
  return (
207
216
  <div
208
217
  ref={containerRef}
@@ -228,7 +237,7 @@ export function ItemProvider({
228
237
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
229
238
  <div
230
239
  key={i}
231
- style={{ width: computedValues.itemWidth }}
240
+ style={{ width: itemWidth }}
232
241
  className={styles.itemContainer}
233
242
  role='group'
234
243
  data-test-id={TEST_IDS.trackItem}