@snack-uikit/carousel 0.2.21 → 0.2.22-preview-ba12ca94.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 +43 -0
- package/dist/cjs/components/Control/index.js +25 -0
- package/dist/cjs/components/ItemProvider/ItemProvider.js +192 -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/Carousel/styles.module.css +21 -0
- package/dist/esm/components/Control/Control.d.ts +6 -0
- package/dist/esm/components/Control/index.js +1 -0
- package/dist/esm/components/Control/styles.module.css +45 -0
- package/dist/esm/components/ItemProvider/ItemProvider.d.ts +13 -0
- package/dist/esm/components/ItemProvider/helpers.d.ts +2 -0
- package/dist/esm/components/ItemProvider/index.js +1 -0
- package/dist/esm/components/ItemProvider/styles.module.css +39 -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 +12 -8
- /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}/Carousel/styles.module.css +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}/Control/styles.module.css +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}/ItemProvider/styles.module.css +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 → esm/components}/Control/Control.js +0 -0
- /package/dist/{components/Control/index.js → esm/components/Control/index.d.ts} +0 -0
- /package/dist/{components → esm/components}/ItemProvider/ItemProvider.js +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(require('./styles.module.css'));
|
|
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,43 @@
|
|
|
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(require('./styles.module.css'));
|
|
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: onClick,
|
|
35
|
+
type: 'button',
|
|
36
|
+
"data-variant": variant
|
|
37
|
+
}, (0, utils_1.extractSupportProps)(rest), {
|
|
38
|
+
children: (0, jsx_runtime_1.jsx)(icons_1.ChevronLeftSVG, {
|
|
39
|
+
size: 24,
|
|
40
|
+
className: styles_module_scss_1.default.icon
|
|
41
|
+
})
|
|
42
|
+
}));
|
|
43
|
+
});
|
|
@@ -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,192 @@
|
|
|
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(require('./styles.module.css'));
|
|
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
|
+
const 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(slide => {
|
|
64
|
+
slide.setAttribute('aria-hidden', '0');
|
|
65
|
+
slide.querySelectorAll('a, button, select, input, textarea, [tabindex="0"]').forEach(focusableElement => {
|
|
66
|
+
focusableElement.setAttribute('tabindex', '-5');
|
|
67
|
+
focusableElement.classList.add(styles_module_scss_1.default.hiddenItem);
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
};
|
|
71
|
+
const 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(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
|
+
const handleSlideClick = (0, react_1.useCallback)(e => {
|
|
151
|
+
var _a, _b;
|
|
152
|
+
const slideRect = e.currentTarget.getBoundingClientRect();
|
|
153
|
+
const containerRect = (_a = containerRef.current) === null || _a === void 0 ? void 0 : _a.getBoundingClientRect();
|
|
154
|
+
const containerViewport = (_b = containerRect === null || containerRect === void 0 ? void 0 : containerRect.right) !== null && _b !== void 0 ? _b : 0;
|
|
155
|
+
const slidePositionDelta = containerViewport - slideRect.right;
|
|
156
|
+
const minPos = Math.min(slidePositionDelta, slideRect.x);
|
|
157
|
+
if (minPos < 0) {
|
|
158
|
+
slideCallback(slidePositionDelta);
|
|
159
|
+
}
|
|
160
|
+
}, [slideCallback]);
|
|
161
|
+
return (0, jsx_runtime_1.jsx)("div", {
|
|
162
|
+
ref: containerRef,
|
|
163
|
+
className: styles_module_scss_1.default.itemProvider,
|
|
164
|
+
"data-pointers": !drag.pointers || undefined,
|
|
165
|
+
"data-swipe": swipe || undefined,
|
|
166
|
+
"data-gap": gap,
|
|
167
|
+
style: Object.assign({}, Boolean(gap) ? {
|
|
168
|
+
'--gap': gap
|
|
169
|
+
} : {}),
|
|
170
|
+
children: (0, jsx_runtime_1.jsx)("div", Object.assign({}, swipeProps, {
|
|
171
|
+
className: styles_module_scss_1.default.itemTracker,
|
|
172
|
+
"data-test-id": testIds_1.TEST_IDS.trackLine,
|
|
173
|
+
style: {
|
|
174
|
+
transform: `translateX(${transform - drag.drag}px)`,
|
|
175
|
+
transition: `transform ${transition}s ease 0s`
|
|
176
|
+
},
|
|
177
|
+
ref: itemsTrackerRef,
|
|
178
|
+
children: items.map((item, i) =>
|
|
179
|
+
// eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
|
|
180
|
+
(0, jsx_runtime_1.jsx)("div", {
|
|
181
|
+
style: {
|
|
182
|
+
width: computedValues.itemWidth
|
|
183
|
+
},
|
|
184
|
+
className: styles_module_scss_1.default.itemContainer,
|
|
185
|
+
role: 'group',
|
|
186
|
+
"data-test-id": testIds_1.TEST_IDS.trackItem,
|
|
187
|
+
onClick: handleSlideClick,
|
|
188
|
+
children: item
|
|
189
|
+
}, i))
|
|
190
|
+
}))
|
|
191
|
+
});
|
|
192
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './Control';
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './ItemProvider';
|
|
@@ -0,0 +1,39 @@
|
|
|
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
|
+
}
|
|
@@ -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,18 @@
|
|
|
4
4
|
"publishConfig": {
|
|
5
5
|
"access": "public"
|
|
6
6
|
},
|
|
7
|
-
"version": "0.2.
|
|
7
|
+
"version": "0.2.22-preview-ba12ca94.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
|
+
"exports": {
|
|
16
|
+
"import": "./dist/esm/index.js",
|
|
17
|
+
"require": "./dist/cjs/index.js"
|
|
18
|
+
},
|
|
16
19
|
"homepage": "https://github.com/cloud-ru-tech/snack-uikit/tree/master/packages/carousel",
|
|
17
20
|
"repository": {
|
|
18
21
|
"type": "git",
|
|
@@ -24,7 +27,8 @@
|
|
|
24
27
|
"Nikita Ershov <niershov@cloud.ru>"
|
|
25
28
|
],
|
|
26
29
|
"files": [
|
|
27
|
-
"dist",
|
|
30
|
+
"dist/cjs",
|
|
31
|
+
"dist/esm",
|
|
28
32
|
"src",
|
|
29
33
|
"./CHANGELOG.md",
|
|
30
34
|
"./LICENSE"
|
|
@@ -32,12 +36,12 @@
|
|
|
32
36
|
"license": "Apache-2.0",
|
|
33
37
|
"scripts": {},
|
|
34
38
|
"dependencies": {
|
|
35
|
-
"@snack-uikit/icons": "0.22.
|
|
36
|
-
"@snack-uikit/pagination": "0.7.
|
|
37
|
-
"@snack-uikit/utils": "3.4.0",
|
|
39
|
+
"@snack-uikit/icons": "0.22.2-preview-ba12ca94.0",
|
|
40
|
+
"@snack-uikit/pagination": "0.7.2-preview-ba12ca94.0",
|
|
41
|
+
"@snack-uikit/utils": "3.4.1-preview-ba12ca94.0",
|
|
38
42
|
"classnames": "2.3.2",
|
|
39
43
|
"lodash.debounce": "4.0.8",
|
|
40
44
|
"uncontrollable": "8.0.4"
|
|
41
45
|
},
|
|
42
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "9ac0a3e5e530c09fa4dc050f9bc08d1849962129"
|
|
43
47
|
}
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|