@snack-uikit/carousel 0.2.21-preview-e6983aad.0 → 0.2.21-preview-1f246c4a.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/dist/cjs/components/Carousel/Carousel.js +104 -0
- package/dist/cjs/components/Carousel/index.js +25 -0
- package/dist/cjs/components/Control/Control.js +45 -0
- package/dist/cjs/components/Control/index.js +25 -0
- package/dist/cjs/components/ItemProvider/ItemProvider.js +177 -0
- package/dist/cjs/components/ItemProvider/helpers.js +14 -0
- package/dist/cjs/components/ItemProvider/index.js +25 -0
- package/dist/cjs/components/index.js +25 -0
- package/dist/cjs/index.js +25 -0
- package/dist/cjs/testIds.js +13 -0
- package/dist/esm/components/Carousel/Carousel.d.ts +32 -0
- package/dist/esm/components/Control/Control.d.ts +6 -0
- package/dist/{components → esm/components}/Control/Control.js +3 -1
- package/dist/esm/components/Control/index.js +1 -0
- package/dist/esm/components/ItemProvider/ItemProvider.d.ts +13 -0
- package/dist/{components → esm/components}/ItemProvider/ItemProvider.js +12 -23
- package/dist/esm/components/ItemProvider/helpers.d.ts +2 -0
- package/dist/esm/components/ItemProvider/index.js +1 -0
- package/dist/esm/components/index.d.ts +1 -0
- package/dist/esm/components/index.js +1 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/testIds.d.ts +7 -0
- package/package.json +10 -8
- package/src/components/Control/Control.tsx +3 -1
- package/src/components/ItemProvider/ItemProvider.tsx +13 -41
- package/src/components/ItemProvider/styles.module.scss +1 -1
- package/dist/components/Carousel/styles.module.css +0 -21
- package/dist/components/Control/styles.module.css +0 -45
- package/dist/components/ItemProvider/styles.module.css +0 -39
- /package/dist/{components → cjs/components}/Carousel/Carousel.d.ts +0 -0
- /package/dist/{components → cjs/components}/Carousel/index.d.ts +0 -0
- /package/dist/{components → cjs/components}/Control/Control.d.ts +0 -0
- /package/dist/{components → cjs/components}/Control/index.d.ts +0 -0
- /package/dist/{components → cjs/components}/ItemProvider/ItemProvider.d.ts +0 -0
- /package/dist/{components → cjs/components}/ItemProvider/helpers.d.ts +0 -0
- /package/dist/{components → cjs/components}/ItemProvider/index.d.ts +0 -0
- /package/dist/{components → cjs/components}/index.d.ts +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{testIds.d.ts → cjs/testIds.d.ts} +0 -0
- /package/dist/{components → esm/components}/Carousel/Carousel.js +0 -0
- /package/dist/{components/Carousel/index.js → esm/components/Carousel/index.d.ts} +0 -0
- /package/dist/{components → esm/components/Carousel}/index.js +0 -0
- /package/dist/{components/Control/index.js → esm/components/Control/index.d.ts} +0 -0
- /package/dist/{components → esm/components}/ItemProvider/helpers.js +0 -0
- /package/dist/{components/ItemProvider/index.js → esm/components/ItemProvider/index.d.ts} +0 -0
- /package/dist/{index.js → esm/index.d.ts} +0 -0
- /package/dist/{testIds.js → esm/testIds.js} +0 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
12
|
+
return mod && mod.__esModule ? mod : {
|
|
13
|
+
"default": mod
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
exports.Carousel = Carousel;
|
|
20
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
21
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
22
|
+
const react_1 = require("react");
|
|
23
|
+
const uncontrollable_1 = require("uncontrollable");
|
|
24
|
+
const pagination_1 = require("@snack-uikit/pagination");
|
|
25
|
+
const utils_1 = require("@snack-uikit/utils");
|
|
26
|
+
const testIds_1 = require("../../testIds");
|
|
27
|
+
const Control_1 = require("../Control");
|
|
28
|
+
const ItemProvider_1 = require("../ItemProvider");
|
|
29
|
+
const styles_module_scss_1 = __importDefault({});
|
|
30
|
+
function Carousel(_a) {
|
|
31
|
+
var _b;
|
|
32
|
+
var {
|
|
33
|
+
children: items,
|
|
34
|
+
showItems = 1,
|
|
35
|
+
scrollBy: scrollByProp,
|
|
36
|
+
transition = 0.4,
|
|
37
|
+
swipe = true,
|
|
38
|
+
arrows = true,
|
|
39
|
+
pagination = true,
|
|
40
|
+
className,
|
|
41
|
+
gap,
|
|
42
|
+
state,
|
|
43
|
+
infiniteScroll = false,
|
|
44
|
+
swipeActivateLength = 48
|
|
45
|
+
} = _a,
|
|
46
|
+
rest = __rest(_a, ["children", "showItems", "scrollBy", "transition", "swipe", "arrows", "pagination", "className", "gap", "state", "infiniteScroll", "swipeActivateLength"]);
|
|
47
|
+
const scrollBy = (0, react_1.useMemo)(() => scrollByProp !== null && scrollByProp !== void 0 ? scrollByProp : Math.trunc(showItems), [showItems, scrollByProp]);
|
|
48
|
+
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
|
+
const result = typeof newPage === 'function' ? newPage(page) : newPage;
|
|
50
|
+
state === null || state === void 0 ? void 0 : state.onChange(result);
|
|
51
|
+
});
|
|
52
|
+
const total = (0, react_1.useMemo)(() => Math.trunc(items.length / scrollBy) + (items.length % scrollBy ? 1 : 0), [items.length, scrollBy]);
|
|
53
|
+
const onLeftArrowClick = (0, react_1.useCallback)(() => {
|
|
54
|
+
setPage(page => infiniteScroll ? (total + page - 1) % total : Math.max(0, page - 1));
|
|
55
|
+
}, [infiniteScroll, setPage, total]);
|
|
56
|
+
const onRightArrowClick = (0, react_1.useCallback)(() => {
|
|
57
|
+
setPage(page => infiniteScroll ? (page + 1) % total : Math.min(total - 1, page + 1));
|
|
58
|
+
}, [infiniteScroll, setPage, total]);
|
|
59
|
+
const slideCallback = (0, react_1.useCallback)(direction => {
|
|
60
|
+
if (direction < 0) {
|
|
61
|
+
onRightArrowClick();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
onLeftArrowClick();
|
|
65
|
+
}, [onLeftArrowClick, onRightArrowClick]);
|
|
66
|
+
return (0, jsx_runtime_1.jsxs)("div", Object.assign({
|
|
67
|
+
className: (0, classnames_1.default)(styles_module_scss_1.default.carousel, className)
|
|
68
|
+
}, (0, utils_1.extractSupportProps)(rest), {
|
|
69
|
+
children: [(0, jsx_runtime_1.jsxs)("div", {
|
|
70
|
+
className: styles_module_scss_1.default.carouselBase,
|
|
71
|
+
children: [(0, jsx_runtime_1.jsx)(ItemProvider_1.ItemProvider, {
|
|
72
|
+
showItems: showItems,
|
|
73
|
+
scrollBy: scrollBy,
|
|
74
|
+
swipe: swipe,
|
|
75
|
+
transition: transition,
|
|
76
|
+
items: items,
|
|
77
|
+
slideCallback: slideCallback,
|
|
78
|
+
page: page,
|
|
79
|
+
gap: gap,
|
|
80
|
+
swipeActivateLength: swipeActivateLength
|
|
81
|
+
}), arrows && (0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, {
|
|
82
|
+
children: [(infiniteScroll || page > 0) && (0, jsx_runtime_1.jsx)(Control_1.Control, {
|
|
83
|
+
onClick: onLeftArrowClick,
|
|
84
|
+
variant: 'prev',
|
|
85
|
+
"data-test-id": testIds_1.TEST_IDS.arrowPrev
|
|
86
|
+
}), (infiniteScroll || page + 1 < total) && (0, jsx_runtime_1.jsx)(Control_1.Control, {
|
|
87
|
+
onClick: onRightArrowClick,
|
|
88
|
+
variant: 'next',
|
|
89
|
+
"data-test-id": testIds_1.TEST_IDS.arrowNext
|
|
90
|
+
})]
|
|
91
|
+
})]
|
|
92
|
+
}), pagination && (0, jsx_runtime_1.jsx)("div", {
|
|
93
|
+
className: styles_module_scss_1.default.pagination,
|
|
94
|
+
children: (0, jsx_runtime_1.jsx)(pagination_1.PaginationSlider, {
|
|
95
|
+
"data-test-id": testIds_1.TEST_IDS.pagination,
|
|
96
|
+
page: page + 1,
|
|
97
|
+
onChange: page => {
|
|
98
|
+
setPage(page - 1);
|
|
99
|
+
},
|
|
100
|
+
total: total
|
|
101
|
+
})
|
|
102
|
+
})]
|
|
103
|
+
}));
|
|
104
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./Carousel"), exports);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __rest = void 0 && (void 0).__rest || function (s, e) {
|
|
4
|
+
var t = {};
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
12
|
+
return mod && mod.__esModule ? mod : {
|
|
13
|
+
"default": mod
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
exports.Control = void 0;
|
|
20
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
21
|
+
const react_1 = require("react");
|
|
22
|
+
const icons_1 = require("@snack-uikit/icons");
|
|
23
|
+
const utils_1 = require("@snack-uikit/utils");
|
|
24
|
+
const styles_module_scss_1 = __importDefault({});
|
|
25
|
+
exports.Control = (0, react_1.forwardRef)((_a, ref) => {
|
|
26
|
+
var {
|
|
27
|
+
onClick,
|
|
28
|
+
variant
|
|
29
|
+
} = _a,
|
|
30
|
+
rest = __rest(_a, ["onClick", "variant"]);
|
|
31
|
+
return (0, jsx_runtime_1.jsx)("button", Object.assign({
|
|
32
|
+
ref: ref,
|
|
33
|
+
className: styles_module_scss_1.default.control,
|
|
34
|
+
onClick: () => {
|
|
35
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
36
|
+
},
|
|
37
|
+
type: 'button',
|
|
38
|
+
"data-variant": variant
|
|
39
|
+
}, (0, utils_1.extractSupportProps)(rest), {
|
|
40
|
+
children: (0, jsx_runtime_1.jsx)(icons_1.ChevronLeftSVG, {
|
|
41
|
+
size: 24,
|
|
42
|
+
className: styles_module_scss_1.default.icon
|
|
43
|
+
})
|
|
44
|
+
}));
|
|
45
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./Control"), exports);
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __importDefault = void 0 && (void 0).__importDefault || function (mod) {
|
|
4
|
+
return mod && mod.__esModule ? mod : {
|
|
5
|
+
"default": mod
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", {
|
|
9
|
+
value: true
|
|
10
|
+
});
|
|
11
|
+
exports.ItemProvider = ItemProvider;
|
|
12
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
13
|
+
const lodash_debounce_1 = __importDefault(require("lodash.debounce"));
|
|
14
|
+
const react_1 = require("react");
|
|
15
|
+
const testIds_1 = require("../../testIds");
|
|
16
|
+
const helpers_1 = require("./helpers");
|
|
17
|
+
const styles_module_scss_1 = __importDefault({});
|
|
18
|
+
function ItemProvider(_ref) {
|
|
19
|
+
let {
|
|
20
|
+
items,
|
|
21
|
+
showItems,
|
|
22
|
+
scrollBy,
|
|
23
|
+
slideCallback,
|
|
24
|
+
transition,
|
|
25
|
+
swipe,
|
|
26
|
+
swipeActivateLength,
|
|
27
|
+
page,
|
|
28
|
+
gap
|
|
29
|
+
} = _ref;
|
|
30
|
+
const containerRef = (0, react_1.useRef)(null);
|
|
31
|
+
const [computedValues, setComputedValues] = (0, react_1.useState)({
|
|
32
|
+
itemWidth: 200,
|
|
33
|
+
gap: 0
|
|
34
|
+
});
|
|
35
|
+
const recalculateItemsSize = (0, react_1.useCallback)(() => {
|
|
36
|
+
const containerElement = containerRef.current;
|
|
37
|
+
if (!containerElement) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const styles = getComputedStyle(containerElement);
|
|
41
|
+
const gap = Number.parseFloat(styles.getPropertyValue('--gap'));
|
|
42
|
+
const paddingLeft = Number.parseFloat(styles.getPropertyValue('padding-left'));
|
|
43
|
+
const paddingRight = Number.parseFloat(styles.getPropertyValue('padding-right'));
|
|
44
|
+
const itemWidth = (containerElement.getBoundingClientRect().width - (Math.trunc(showItems) - 1) * gap - paddingLeft - paddingRight) / showItems;
|
|
45
|
+
setComputedValues({
|
|
46
|
+
itemWidth,
|
|
47
|
+
gap
|
|
48
|
+
});
|
|
49
|
+
}, [showItems]);
|
|
50
|
+
(0, react_1.useEffect)(() => {
|
|
51
|
+
const node = containerRef.current;
|
|
52
|
+
if (!node) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
recalculateItemsSize();
|
|
56
|
+
const observer = new ResizeObserver((0, lodash_debounce_1.default)(recalculateItemsSize, 100));
|
|
57
|
+
observer.observe(node);
|
|
58
|
+
return () => observer.disconnect();
|
|
59
|
+
}, [recalculateItemsSize]);
|
|
60
|
+
const itemsTrackerRef = (0, react_1.useRef)(null);
|
|
61
|
+
function hideNonVisibleItems() {
|
|
62
|
+
var _a;
|
|
63
|
+
(_a = itemsTrackerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`[data-test-id=${testIds_1.TEST_IDS.trackItem}]`).forEach(function (slide) {
|
|
64
|
+
slide.setAttribute('aria-hidden', '0');
|
|
65
|
+
slide.querySelectorAll('a, button, select, input, textarea, [tabindex="0"]').forEach(function (focusableElement) {
|
|
66
|
+
focusableElement.setAttribute('tabindex', '-5');
|
|
67
|
+
focusableElement.classList.add(styles_module_scss_1.default.hiddenItem);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
function showVisibleItems(slide, page, show) {
|
|
72
|
+
var _a;
|
|
73
|
+
(_a = itemsTrackerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`[data-test-id=${testIds_1.TEST_IDS.trackItem}]`).forEach((item, i) => {
|
|
74
|
+
if (i >= page * slide && i < page * slide + Math.trunc(show)) {
|
|
75
|
+
item.removeAttribute('aria-hidden');
|
|
76
|
+
item.querySelectorAll('a, button, select, input, textarea, [tabindex="-5"]').forEach(function (focusableElement) {
|
|
77
|
+
focusableElement.setAttribute('tabindex', '0');
|
|
78
|
+
focusableElement.classList.remove(styles_module_scss_1.default.hiddenItem);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const transform = (0, react_1.useMemo)(() => Number(-(page * scrollBy * computedValues.itemWidth + computedValues.gap * page * scrollBy)), [computedValues.gap, computedValues.itemWidth, page, scrollBy]);
|
|
84
|
+
(0, react_1.useEffect)(() => {
|
|
85
|
+
hideNonVisibleItems();
|
|
86
|
+
showVisibleItems(scrollBy, page, showItems);
|
|
87
|
+
}, [page, scrollBy, showItems]);
|
|
88
|
+
const [drag, setDrag] = (0, react_1.useState)({
|
|
89
|
+
initial: transform,
|
|
90
|
+
start: 0,
|
|
91
|
+
isDown: false,
|
|
92
|
+
drag: 0,
|
|
93
|
+
finished: true,
|
|
94
|
+
pointers: true
|
|
95
|
+
});
|
|
96
|
+
const handleDragStart = e => {
|
|
97
|
+
e.persist();
|
|
98
|
+
setDrag(Object.assign(Object.assign({}, drag), {
|
|
99
|
+
isDown: true,
|
|
100
|
+
start: (0, helpers_1.getPageX)(e),
|
|
101
|
+
initial: transform,
|
|
102
|
+
finished: false
|
|
103
|
+
}));
|
|
104
|
+
};
|
|
105
|
+
const handleDragFinish = e => {
|
|
106
|
+
e.persist();
|
|
107
|
+
if (drag.finished) {
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (Math.abs(drag.drag) < swipeActivateLength) {
|
|
111
|
+
return setDrag({
|
|
112
|
+
initial: transform,
|
|
113
|
+
start: 0,
|
|
114
|
+
isDown: false,
|
|
115
|
+
drag: 0,
|
|
116
|
+
finished: true,
|
|
117
|
+
pointers: true
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
slideCallback(drag.drag > 0 ? -1 : 1);
|
|
121
|
+
setDrag(Object.assign(Object.assign({}, drag), {
|
|
122
|
+
drag: 0,
|
|
123
|
+
isDown: false,
|
|
124
|
+
finished: true,
|
|
125
|
+
pointers: true
|
|
126
|
+
}));
|
|
127
|
+
return;
|
|
128
|
+
};
|
|
129
|
+
const handleDragMove = e => {
|
|
130
|
+
e.persist();
|
|
131
|
+
if (!drag.isDown) {
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
const pos = (0, helpers_1.getPageX)(e);
|
|
135
|
+
setDrag(Object.assign(Object.assign({}, drag), {
|
|
136
|
+
drag: drag.start - pos,
|
|
137
|
+
pointers: Math.abs(drag.start - pos) < Number.MIN_SAFE_INTEGER
|
|
138
|
+
}));
|
|
139
|
+
};
|
|
140
|
+
const swipeProps = swipe ? {
|
|
141
|
+
onTouchCancel: handleDragFinish,
|
|
142
|
+
onTouchEnd: handleDragFinish,
|
|
143
|
+
onTouchMove: handleDragMove,
|
|
144
|
+
onTouchStart: handleDragStart,
|
|
145
|
+
onMouseDown: handleDragStart,
|
|
146
|
+
onMouseLeave: handleDragFinish,
|
|
147
|
+
onMouseUp: handleDragFinish,
|
|
148
|
+
onMouseMove: handleDragMove
|
|
149
|
+
} : {};
|
|
150
|
+
return (0, jsx_runtime_1.jsx)("div", {
|
|
151
|
+
ref: containerRef,
|
|
152
|
+
className: styles_module_scss_1.default.itemProvider,
|
|
153
|
+
"data-pointers": !drag.pointers || undefined,
|
|
154
|
+
"data-swipe": swipe || undefined,
|
|
155
|
+
style: Object.assign({}, Boolean(gap) ? {
|
|
156
|
+
'--gap': gap
|
|
157
|
+
} : {}),
|
|
158
|
+
children: (0, jsx_runtime_1.jsx)("div", Object.assign({}, swipeProps, {
|
|
159
|
+
className: styles_module_scss_1.default.itemTracker,
|
|
160
|
+
"data-test-id": testIds_1.TEST_IDS.trackLine,
|
|
161
|
+
style: {
|
|
162
|
+
transform: `translateX(${transform - drag.drag}px)`,
|
|
163
|
+
transition: `transform ${transition}s ease 0s`
|
|
164
|
+
},
|
|
165
|
+
ref: itemsTrackerRef,
|
|
166
|
+
children: items.map((item, i) => (0, jsx_runtime_1.jsx)("div", {
|
|
167
|
+
style: {
|
|
168
|
+
width: computedValues.itemWidth
|
|
169
|
+
},
|
|
170
|
+
className: styles_module_scss_1.default.itemContainer,
|
|
171
|
+
role: 'group',
|
|
172
|
+
"data-test-id": testIds_1.TEST_IDS.trackItem,
|
|
173
|
+
children: item
|
|
174
|
+
}, i))
|
|
175
|
+
}))
|
|
176
|
+
});
|
|
177
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getPageX = getPageX;
|
|
7
|
+
function getPageX(e) {
|
|
8
|
+
if (e.nativeEvent instanceof globalThis.MouseEvent) {
|
|
9
|
+
return e.nativeEvent.pageX;
|
|
10
|
+
} else if (e.nativeEvent instanceof globalThis.TouchEvent) {
|
|
11
|
+
return e.nativeEvent.changedTouches[0].pageX;
|
|
12
|
+
}
|
|
13
|
+
return 0;
|
|
14
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./ItemProvider"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./Carousel"), exports);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var __createBinding = void 0 && (void 0).__createBinding || (Object.create ? function (o, m, k, k2) {
|
|
4
|
+
if (k2 === undefined) k2 = k;
|
|
5
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
6
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
7
|
+
desc = {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () {
|
|
10
|
+
return m[k];
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
} : function (o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
});
|
|
19
|
+
var __exportStar = void 0 && (void 0).__exportStar || function (m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", {
|
|
23
|
+
value: true
|
|
24
|
+
});
|
|
25
|
+
__exportStar(require("./components"), exports);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.TEST_IDS = void 0;
|
|
7
|
+
exports.TEST_IDS = {
|
|
8
|
+
arrowNext: 'carousel__arrow-next',
|
|
9
|
+
arrowPrev: 'carousel__arrow-prev',
|
|
10
|
+
pagination: 'carousel__pagination',
|
|
11
|
+
trackLine: 'carousel__track-line',
|
|
12
|
+
trackItem: 'carousel__track-item'
|
|
13
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
import { WithSupportProps } from '@snack-uikit/utils';
|
|
3
|
+
export type CarouselProps = WithSupportProps<{
|
|
4
|
+
/** CSS - класснейм */
|
|
5
|
+
className?: string;
|
|
6
|
+
/** Массив айтемов */
|
|
7
|
+
children: ReactElement[];
|
|
8
|
+
/** Кол-во отображаемых единовременно айтемов @default 1 */
|
|
9
|
+
showItems?: number;
|
|
10
|
+
/** Сдвиг айтемов при смене 1 страницы @default Math.trunc(show) */
|
|
11
|
+
scrollBy?: number;
|
|
12
|
+
/** Время переключения 1 страницы (в s) @default 0.4 */
|
|
13
|
+
transition?: number;
|
|
14
|
+
/** Переключение страниц свайпом @default true */
|
|
15
|
+
swipe?: boolean;
|
|
16
|
+
/** Минимальная длина в px для активации свайпа @default 48 */
|
|
17
|
+
swipeActivateLength?: number;
|
|
18
|
+
/** Использовать стрелки для переключения страниц @default true */
|
|
19
|
+
arrows?: boolean;
|
|
20
|
+
/** Использовать пагинацию для переключения страниц @default true */
|
|
21
|
+
pagination?: boolean;
|
|
22
|
+
/** Расстояние между айтемами @default var(--dimension-2m)*/
|
|
23
|
+
gap?: string;
|
|
24
|
+
/** Управление состоянием извне */
|
|
25
|
+
state?: {
|
|
26
|
+
page: number;
|
|
27
|
+
onChange(page: number): void;
|
|
28
|
+
};
|
|
29
|
+
/** Цикличная прокрутка @default false*/
|
|
30
|
+
infiniteScroll?: boolean;
|
|
31
|
+
}>;
|
|
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;
|
|
@@ -16,5 +16,7 @@ import { extractSupportProps } from '@snack-uikit/utils';
|
|
|
16
16
|
import styles from './styles.module.css';
|
|
17
17
|
export const Control = forwardRef((_a, ref) => {
|
|
18
18
|
var { onClick, variant } = _a, rest = __rest(_a, ["onClick", "variant"]);
|
|
19
|
-
return (_jsx("button", Object.assign({ ref: ref, className: styles.control, onClick:
|
|
19
|
+
return (_jsx("button", Object.assign({ ref: ref, className: styles.control, onClick: () => {
|
|
20
|
+
onClick === null || onClick === void 0 ? void 0 : onClick();
|
|
21
|
+
}, type: 'button', "data-variant": variant }, extractSupportProps(rest), { children: _jsx(ChevronLeftSVG, { size: 24, className: styles.icon }) })));
|
|
20
22
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Control';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ReactElement } from 'react';
|
|
2
|
+
export type ItemProviderProps = {
|
|
3
|
+
items: ReactElement[];
|
|
4
|
+
showItems: number;
|
|
5
|
+
scrollBy: number;
|
|
6
|
+
slideCallback(direction: number): void;
|
|
7
|
+
transition: number;
|
|
8
|
+
swipe: boolean;
|
|
9
|
+
swipeActivateLength: number;
|
|
10
|
+
page: number;
|
|
11
|
+
gap?: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function ItemProvider({ items, showItems, scrollBy, slideCallback, transition, swipe, swipeActivateLength, page, gap, }: ItemProviderProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import debounce from 'lodash.debounce';
|
|
3
|
-
import { useCallback, useEffect, useMemo, useRef, useState
|
|
3
|
+
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';
|
|
@@ -37,28 +37,30 @@ export function ItemProvider({ items, showItems, scrollBy, slideCallback, transi
|
|
|
37
37
|
return () => observer.disconnect();
|
|
38
38
|
}, [recalculateItemsSize]);
|
|
39
39
|
const itemsTrackerRef = useRef(null);
|
|
40
|
-
|
|
40
|
+
function hideNonVisibleItems() {
|
|
41
41
|
var _a;
|
|
42
|
-
(_a = itemsTrackerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`[data-test-id=${TEST_IDS.trackItem}]`).forEach(slide
|
|
42
|
+
(_a = itemsTrackerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`[data-test-id=${TEST_IDS.trackItem}]`).forEach(function (slide) {
|
|
43
43
|
slide.setAttribute('aria-hidden', '0');
|
|
44
|
-
slide.querySelectorAll('a, button, select, input, textarea, [tabindex="0"]').forEach(focusableElement
|
|
44
|
+
slide.querySelectorAll('a, button, select, input, textarea, [tabindex="0"]').forEach(function (focusableElement) {
|
|
45
45
|
focusableElement.setAttribute('tabindex', '-5');
|
|
46
46
|
focusableElement.classList.add(styles.hiddenItem);
|
|
47
47
|
});
|
|
48
48
|
});
|
|
49
|
-
}
|
|
50
|
-
|
|
49
|
+
}
|
|
50
|
+
function showVisibleItems(slide, page, show) {
|
|
51
51
|
var _a;
|
|
52
52
|
(_a = itemsTrackerRef.current) === null || _a === void 0 ? void 0 : _a.querySelectorAll(`[data-test-id=${TEST_IDS.trackItem}]`).forEach((item, i) => {
|
|
53
53
|
if (i >= page * slide && i < page * slide + Math.trunc(show)) {
|
|
54
54
|
item.removeAttribute('aria-hidden');
|
|
55
|
-
item
|
|
55
|
+
item
|
|
56
|
+
.querySelectorAll('a, button, select, input, textarea, [tabindex="-5"]')
|
|
57
|
+
.forEach(function (focusableElement) {
|
|
56
58
|
focusableElement.setAttribute('tabindex', '0');
|
|
57
59
|
focusableElement.classList.remove(styles.hiddenItem);
|
|
58
60
|
});
|
|
59
61
|
}
|
|
60
62
|
});
|
|
61
|
-
}
|
|
63
|
+
}
|
|
62
64
|
const transform = useMemo(() => Number(-(page * scrollBy * computedValues.itemWidth + computedValues.gap * page * scrollBy)), [computedValues.gap, computedValues.itemWidth, page, scrollBy]);
|
|
63
65
|
useEffect(() => {
|
|
64
66
|
hideNonVisibleItems();
|
|
@@ -115,21 +117,8 @@ export function ItemProvider({ items, showItems, scrollBy, slideCallback, transi
|
|
|
115
117
|
onMouseMove: handleDragMove,
|
|
116
118
|
}
|
|
117
119
|
: {};
|
|
118
|
-
|
|
119
|
-
var _a, _b;
|
|
120
|
-
const slideRect = e.currentTarget.getBoundingClientRect();
|
|
121
|
-
const containerRect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
122
|
-
const containerViewport = (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _b !== void 0 ? _b : 0;
|
|
123
|
-
const slidePositionDelta = containerViewport - slideRect.right;
|
|
124
|
-
const minPos = Math.min(slidePositionDelta, slideRect.x);
|
|
125
|
-
if (minPos < 0) {
|
|
126
|
-
slideCallback(slidePositionDelta);
|
|
127
|
-
}
|
|
128
|
-
}, [slideCallback]);
|
|
129
|
-
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: {
|
|
120
|
+
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: {
|
|
130
121
|
transform: `translateX(${transform - drag.drag}px)`,
|
|
131
122
|
transition: `transform ${transition}s ease 0s`,
|
|
132
|
-
}, ref: itemsTrackerRef, children: items.map((item, i) => (
|
|
133
|
-
// 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))) })) }));
|
|
123
|
+
}, 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))) })) }));
|
|
135
124
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ItemProvider';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Carousel';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Carousel';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './components';
|
package/package.json
CHANGED
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.2.21-preview-
|
|
7
|
+
"version": "0.2.21-preview-1f246c4a.0",
|
|
8
8
|
"sideEffects": [
|
|
9
9
|
"*.css",
|
|
10
10
|
"*.woff",
|
|
11
11
|
"*.woff2"
|
|
12
12
|
],
|
|
13
13
|
"description": "",
|
|
14
|
-
"
|
|
15
|
-
"
|
|
14
|
+
"types": "./dist/esm/index.d.ts",
|
|
15
|
+
"main": "./dist/cjs/index.js",
|
|
16
|
+
"module": "./dist/esm/index.js",
|
|
16
17
|
"homepage": "https://github.com/cloud-ru-tech/snack-uikit/tree/master/packages/carousel",
|
|
17
18
|
"repository": {
|
|
18
19
|
"type": "git",
|
|
@@ -24,7 +25,8 @@
|
|
|
24
25
|
"Nikita Ershov <niershov@cloud.ru>"
|
|
25
26
|
],
|
|
26
27
|
"files": [
|
|
27
|
-
"dist",
|
|
28
|
+
"dist/cjs",
|
|
29
|
+
"dist/esm",
|
|
28
30
|
"src",
|
|
29
31
|
"./CHANGELOG.md",
|
|
30
32
|
"./LICENSE"
|
|
@@ -32,12 +34,12 @@
|
|
|
32
34
|
"license": "Apache-2.0",
|
|
33
35
|
"scripts": {},
|
|
34
36
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/icons": "0.22.
|
|
36
|
-
"@snack-uikit/pagination": "0.7.
|
|
37
|
-
"@snack-uikit/utils": "3.4.0",
|
|
37
|
+
"@snack-uikit/icons": "0.22.2-preview-1f246c4a.0",
|
|
38
|
+
"@snack-uikit/pagination": "0.7.2-preview-1f246c4a.0",
|
|
39
|
+
"@snack-uikit/utils": "3.4.1-preview-1f246c4a.0",
|
|
38
40
|
"classnames": "2.3.2",
|
|
39
41
|
"lodash.debounce": "4.0.8",
|
|
40
42
|
"uncontrollable": "8.0.4"
|
|
41
43
|
},
|
|
42
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "a185a55c0722b19f70dd168cf299e6f53a0fd93f"
|
|
43
45
|
}
|
|
@@ -15,7 +15,9 @@ export const Control = forwardRef<HTMLButtonElement, ControlProps>(
|
|
|
15
15
|
<button
|
|
16
16
|
ref={ref}
|
|
17
17
|
className={styles.control}
|
|
18
|
-
onClick={
|
|
18
|
+
onClick={() => {
|
|
19
|
+
onClick?.();
|
|
20
|
+
}}
|
|
19
21
|
type='button'
|
|
20
22
|
data-variant={variant}
|
|
21
23
|
{...extractSupportProps(rest)}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
1
|
import debounce from 'lodash.debounce';
|
|
2
|
-
import {
|
|
3
|
-
MouseEvent,
|
|
4
|
-
MouseEventHandler,
|
|
5
|
-
ReactElement,
|
|
6
|
-
TouchEvent,
|
|
7
|
-
useCallback,
|
|
8
|
-
useEffect,
|
|
9
|
-
useMemo,
|
|
10
|
-
useRef,
|
|
11
|
-
useState,
|
|
12
|
-
} from 'react';
|
|
2
|
+
import { MouseEvent, ReactElement, TouchEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
13
3
|
|
|
14
4
|
import { TEST_IDS } from '../../testIds';
|
|
15
5
|
import { getPageX } from './helpers';
|
|
@@ -83,28 +73,30 @@ export function ItemProvider({
|
|
|
83
73
|
|
|
84
74
|
const itemsTrackerRef = useRef<HTMLDivElement>(null);
|
|
85
75
|
|
|
86
|
-
|
|
87
|
-
itemsTrackerRef.current?.querySelectorAll(`[data-test-id=${TEST_IDS.trackItem}]`).forEach(slide
|
|
76
|
+
function hideNonVisibleItems() {
|
|
77
|
+
itemsTrackerRef.current?.querySelectorAll(`[data-test-id=${TEST_IDS.trackItem}]`).forEach(function (slide) {
|
|
88
78
|
slide.setAttribute('aria-hidden', '0');
|
|
89
79
|
|
|
90
|
-
slide.querySelectorAll('a, button, select, input, textarea, [tabindex="0"]').forEach(focusableElement
|
|
80
|
+
slide.querySelectorAll('a, button, select, input, textarea, [tabindex="0"]').forEach(function (focusableElement) {
|
|
91
81
|
focusableElement.setAttribute('tabindex', '-5');
|
|
92
82
|
focusableElement.classList.add(styles.hiddenItem);
|
|
93
83
|
});
|
|
94
84
|
});
|
|
95
|
-
}
|
|
85
|
+
}
|
|
96
86
|
|
|
97
|
-
|
|
87
|
+
function showVisibleItems(slide: number, page: number, show: number) {
|
|
98
88
|
itemsTrackerRef.current?.querySelectorAll(`[data-test-id=${TEST_IDS.trackItem}]`).forEach((item, i) => {
|
|
99
89
|
if (i >= page * slide && i < page * slide + Math.trunc(show)) {
|
|
100
90
|
item.removeAttribute('aria-hidden');
|
|
101
|
-
item
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
91
|
+
item
|
|
92
|
+
.querySelectorAll('a, button, select, input, textarea, [tabindex="-5"]')
|
|
93
|
+
.forEach(function (focusableElement) {
|
|
94
|
+
focusableElement.setAttribute('tabindex', '0');
|
|
95
|
+
focusableElement.classList.remove(styles.hiddenItem);
|
|
96
|
+
});
|
|
105
97
|
}
|
|
106
98
|
});
|
|
107
|
-
}
|
|
99
|
+
}
|
|
108
100
|
|
|
109
101
|
const transform = useMemo(
|
|
110
102
|
() => Number(-(page * scrollBy * computedValues.itemWidth + computedValues.gap * page * scrollBy)),
|
|
@@ -138,11 +130,9 @@ export function ItemProvider({
|
|
|
138
130
|
|
|
139
131
|
const handleDragFinish = (e: MouseEvent | TouchEvent) => {
|
|
140
132
|
e.persist();
|
|
141
|
-
|
|
142
133
|
if (drag.finished) {
|
|
143
134
|
return;
|
|
144
135
|
}
|
|
145
|
-
|
|
146
136
|
if (Math.abs(drag.drag) < swipeActivateLength) {
|
|
147
137
|
return setDrag({
|
|
148
138
|
initial: transform,
|
|
@@ -188,28 +178,12 @@ export function ItemProvider({
|
|
|
188
178
|
}
|
|
189
179
|
: {};
|
|
190
180
|
|
|
191
|
-
const handleSlideClick: MouseEventHandler = useCallback(
|
|
192
|
-
e => {
|
|
193
|
-
const slideRect = e.currentTarget.getBoundingClientRect();
|
|
194
|
-
const containerRect = containerRef.current?.getBoundingClientRect();
|
|
195
|
-
const containerViewport = containerRect?.right ?? 0;
|
|
196
|
-
const slidePositionDelta = containerViewport - slideRect.right;
|
|
197
|
-
const minPos = Math.min(slidePositionDelta, slideRect.x);
|
|
198
|
-
|
|
199
|
-
if (minPos < 0) {
|
|
200
|
-
slideCallback(slidePositionDelta);
|
|
201
|
-
}
|
|
202
|
-
},
|
|
203
|
-
[slideCallback],
|
|
204
|
-
);
|
|
205
|
-
|
|
206
181
|
return (
|
|
207
182
|
<div
|
|
208
183
|
ref={containerRef}
|
|
209
184
|
className={styles.itemProvider}
|
|
210
185
|
data-pointers={!drag.pointers || undefined}
|
|
211
186
|
data-swipe={swipe || undefined}
|
|
212
|
-
data-gap={gap}
|
|
213
187
|
style={{
|
|
214
188
|
...(Boolean(gap) ? { '--gap': gap } : {}),
|
|
215
189
|
}}
|
|
@@ -225,14 +199,12 @@ export function ItemProvider({
|
|
|
225
199
|
ref={itemsTrackerRef}
|
|
226
200
|
>
|
|
227
201
|
{items.map((item, i) => (
|
|
228
|
-
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
229
202
|
<div
|
|
230
203
|
key={i}
|
|
231
204
|
style={{ width: computedValues.itemWidth }}
|
|
232
205
|
className={styles.itemContainer}
|
|
233
206
|
role='group'
|
|
234
207
|
data-test-id={TEST_IDS.trackItem}
|
|
235
|
-
onClick={handleSlideClick}
|
|
236
208
|
>
|
|
237
209
|
{item}
|
|
238
210
|
</div>
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
.carouselBase{
|
|
2
|
-
position:relative;
|
|
3
|
-
display:flex;
|
|
4
|
-
box-sizing:border-box;
|
|
5
|
-
width:100%;
|
|
6
|
-
outline:none;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.carousel{
|
|
10
|
-
display:flex;
|
|
11
|
-
flex-direction:column;
|
|
12
|
-
align-items:center;
|
|
13
|
-
box-sizing:border-box;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
.pagination{
|
|
17
|
-
padding-top:var(--space-carousel-sliders-wrap-padding-top, 8px);
|
|
18
|
-
display:flex;
|
|
19
|
-
justify-content:center;
|
|
20
|
-
box-sizing:border-box;
|
|
21
|
-
}
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
.control{
|
|
2
|
-
width:var(--size-carousel-control-container, 40px);
|
|
3
|
-
height:var(--size-carousel-control-container, 40px);
|
|
4
|
-
border-radius:var(--radius-carousel-control-container, 24px);
|
|
5
|
-
border-width:var(--border-width-025m, 2px);
|
|
6
|
-
cursor:pointer;
|
|
7
|
-
position:absolute;
|
|
8
|
-
top:50%;
|
|
9
|
-
left:calc(var(--size-carousel-control-wrap-width, 20px) - var(--size-carousel-control-container, 40px));
|
|
10
|
-
transform:translateY(-50%);
|
|
11
|
-
display:flex;
|
|
12
|
-
flex-shrink:0;
|
|
13
|
-
align-items:center;
|
|
14
|
-
justify-content:center;
|
|
15
|
-
color:var(--sys-neutral-text-light, #8b8e9b);
|
|
16
|
-
background-color:var(--sys-neutral-background1-level, #fdfdfd);
|
|
17
|
-
border-color:transparent;
|
|
18
|
-
border-style:solid;
|
|
19
|
-
outline-color:transparent;
|
|
20
|
-
box-shadow:var(--box-shadow-elevation-level3, 0px 0px 8px 0px rgba(0, 0, 0, 0.0784313725), 0px 8px 16px 0px rgba(0, 0, 0, 0.0784313725));
|
|
21
|
-
}
|
|
22
|
-
.control:hover, .control:focus-visible{
|
|
23
|
-
color:var(--sys-neutral-text-main, #41424e);
|
|
24
|
-
}
|
|
25
|
-
.control:hover{
|
|
26
|
-
box-shadow:var(--box-shadow-elevation-level4, 0px 0px 8px 0px rgba(0, 0, 0, 0.0784313725), 0px 16px 16px 0px rgba(0, 0, 0, 0.0784313725));
|
|
27
|
-
}
|
|
28
|
-
.control:focus-visible{
|
|
29
|
-
outline-width:var(--border-state-focus-s-border-width, 2px);
|
|
30
|
-
outline-style:var(--border-state-focus-s-border-style, solid);
|
|
31
|
-
outline-color:var(--border-state-focus-s-border-color, );
|
|
32
|
-
border-color:var(--sys-available-complementary, #1c1c24);
|
|
33
|
-
outline-color:var(--sys-available-on-complementary, #ffffff);
|
|
34
|
-
box-shadow:none;
|
|
35
|
-
}
|
|
36
|
-
.control[data-variant=next]{
|
|
37
|
-
right:calc(var(--size-carousel-control-wrap-width, 20px) - var(--size-carousel-control-container, 40px));
|
|
38
|
-
left:auto;
|
|
39
|
-
}
|
|
40
|
-
.control[data-variant=next]:focus-visible{
|
|
41
|
-
outline-offset:var(--dimension-025m, 2px);
|
|
42
|
-
}
|
|
43
|
-
.control[data-variant=next] .icon{
|
|
44
|
-
transform:rotate(180deg);
|
|
45
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
.itemProvider{
|
|
2
|
-
--gap:var(--dimension-2m, 16px);
|
|
3
|
-
padding-top:var(--space-carousel-content-layout-padding, 4px);
|
|
4
|
-
padding-bottom:var(--space-carousel-content-layout-padding, 4px);
|
|
5
|
-
padding-left:var(--space-carousel-content-layout-padding, 4px);
|
|
6
|
-
padding-right:var(--space-carousel-content-layout-padding, 4px);
|
|
7
|
-
overflow:hidden;
|
|
8
|
-
width:100%;
|
|
9
|
-
margin:calc(0px - var(--space-carousel-content-layout-padding, 4px));
|
|
10
|
-
}
|
|
11
|
-
.itemProvider[data-swipe]{
|
|
12
|
-
cursor:grab;
|
|
13
|
-
}
|
|
14
|
-
.itemProvider[data-swipe][data-pointers]{
|
|
15
|
-
cursor:grabbing;
|
|
16
|
-
-webkit-user-select:none;
|
|
17
|
-
-moz-user-select:none;
|
|
18
|
-
user-select:none;
|
|
19
|
-
-webkit-user-drag:none;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
.itemContainer{
|
|
23
|
-
flex-shrink:0;
|
|
24
|
-
box-sizing:border-box;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
.itemTracker{
|
|
28
|
-
display:flex;
|
|
29
|
-
gap:var(--gap, var(--dimension-2m, 16px));
|
|
30
|
-
box-sizing:border-box;
|
|
31
|
-
height:100%;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
.hiddenItem{
|
|
35
|
-
pointer-events:none;
|
|
36
|
-
}
|
|
37
|
-
.hiddenItem *{
|
|
38
|
-
pointer-events:none;
|
|
39
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|