@lt-ui/slider 0.0.0-stage → 0.0.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/cjs/index.js +17 -0
- package/cjs/locale/messages.js +9 -0
- package/cjs/locale/use-locale.js +10 -0
- package/cjs/slider/dots.js +16 -0
- package/cjs/slider/index.js +7 -0
- package/cjs/slider/slider.js +109 -0
- package/cjs/slider/styles.module.css +84 -0
- package/cjs/slider/types.js +2 -0
- package/cjs/slider/use-preview-slider.js +11 -0
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/locale/messages.d.ts +10 -0
- package/locale/messages.js +6 -0
- package/locale/use-locale.d.ts +9 -0
- package/locale/use-locale.js +7 -0
- package/package.json +30 -4
- package/slider/dots.d.ts +9 -0
- package/slider/dots.js +9 -0
- package/slider/index.d.ts +3 -0
- package/slider/index.js +2 -0
- package/slider/slider.d.ts +243 -0
- package/slider/slider.js +70 -0
- package/slider/styles.module.css +84 -0
- package/slider/types.d.ts +83 -0
- package/slider/types.js +1 -0
- package/slider/use-preview-slider.d.ts +3 -0
- package/slider/use-preview-slider.js +7 -0
- package/README.md +0 -3
package/cjs/index.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./slider"), exports);
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.en = exports.ru = void 0;
|
|
4
|
+
exports.ru = {
|
|
5
|
+
slider: { previous: 'Назад', next: 'Вперёд', slide: 'Слайд {number}' },
|
|
6
|
+
};
|
|
7
|
+
exports.en = {
|
|
8
|
+
slider: { previous: 'Previous', next: 'Next', slide: 'Slide {number}' },
|
|
9
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useLocale = void 0;
|
|
4
|
+
const i18n_1 = require("@lt-ui/i18n");
|
|
5
|
+
const messages_1 = require("./messages");
|
|
6
|
+
/**
|
|
7
|
+
* Язык и переводчик строк пакета: язык берётся у ближайшего `ThemeProvider` или `LocaleProvider`
|
|
8
|
+
* из `@lt-ui/uikit`, строки переопределяются в `messages` под своим ключом.
|
|
9
|
+
*/
|
|
10
|
+
exports.useLocale = (0, i18n_1.createUseLocale)({ en: messages_1.en, ru: messages_1.ru });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.Dots = void 0;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
const use_locale_1 = require("../locale/use-locale");
|
|
11
|
+
const styles_module_scss_1 = __importDefault(require("./styles.module.css"));
|
|
12
|
+
const Dots = ({ count, current, direction = 'horizontal', onSelect }) => {
|
|
13
|
+
const { t } = (0, use_locale_1.useLocale)();
|
|
14
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: styles_module_scss_1.default.dots, "data-direction": direction, children: Array.from({ length: count }, (_, index) => ((0, jsx_runtime_1.jsx)("button", { type: "button", className: styles_module_scss_1.default.dot, "data-active": index === current || undefined, "aria-label": t('slider.slide', { number: index + 1 }), "aria-current": index === current || undefined, onClick: () => onSelect(index) }, index))) }));
|
|
15
|
+
};
|
|
16
|
+
exports.Dots = Dots;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.usePreviewSlider = exports.Slider = void 0;
|
|
4
|
+
var slider_1 = require("./slider");
|
|
5
|
+
Object.defineProperty(exports, "Slider", { enumerable: true, get: function () { return slider_1.Slider; } });
|
|
6
|
+
var use_preview_slider_1 = require("./use-preview-slider");
|
|
7
|
+
Object.defineProperty(exports, "usePreviewSlider", { enumerable: true, get: function () { return use_preview_slider_1.usePreviewSlider; } });
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
var __createBinding = (this && this.__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 = { enumerable: true, get: function() { return m[k]; } };
|
|
8
|
+
}
|
|
9
|
+
Object.defineProperty(o, k2, desc);
|
|
10
|
+
}) : (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
o[k2] = m[k];
|
|
13
|
+
}));
|
|
14
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
15
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
16
|
+
}) : function(o, v) {
|
|
17
|
+
o["default"] = v;
|
|
18
|
+
});
|
|
19
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
20
|
+
var ownKeys = function(o) {
|
|
21
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
22
|
+
var ar = [];
|
|
23
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
24
|
+
return ar;
|
|
25
|
+
};
|
|
26
|
+
return ownKeys(o);
|
|
27
|
+
};
|
|
28
|
+
return function (mod) {
|
|
29
|
+
if (mod && mod.__esModule) return mod;
|
|
30
|
+
var result = {};
|
|
31
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
32
|
+
__setModuleDefault(result, mod);
|
|
33
|
+
return result;
|
|
34
|
+
};
|
|
35
|
+
})();
|
|
36
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
37
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.Slider = void 0;
|
|
41
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
42
|
+
const uikit_1 = require("@lt-ui/uikit");
|
|
43
|
+
const react_1 = __importStar(require("react"));
|
|
44
|
+
const react_2 = require("swiper/react");
|
|
45
|
+
const modules_1 = require("swiper/modules");
|
|
46
|
+
const uikit_2 = require("@lt-ui/uikit");
|
|
47
|
+
const icons_1 = require("@lt-ui/icons");
|
|
48
|
+
require("swiper/css");
|
|
49
|
+
require("swiper/css/grid");
|
|
50
|
+
const use_locale_1 = require("../locale/use-locale");
|
|
51
|
+
const dots_1 = require("./dots");
|
|
52
|
+
const styles_module_scss_1 = __importDefault(require("./styles.module.css"));
|
|
53
|
+
const toSwiperBreakpoints = (breakpoints, defaults) => {
|
|
54
|
+
if (!(breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.length))
|
|
55
|
+
return undefined;
|
|
56
|
+
return Object.fromEntries([...breakpoints]
|
|
57
|
+
.sort((a, b) => a.width - b.width)
|
|
58
|
+
.map(({ width, itemsPerView, rowsCount, slideGap }) => [
|
|
59
|
+
width,
|
|
60
|
+
{
|
|
61
|
+
slidesPerView: itemsPerView !== null && itemsPerView !== void 0 ? itemsPerView : defaults.itemsPerView,
|
|
62
|
+
spaceBetween: slideGap !== null && slideGap !== void 0 ? slideGap : defaults.slideGap,
|
|
63
|
+
...((rowsCount !== null && rowsCount !== void 0 ? rowsCount : defaults.rowsCount) > 1 && {
|
|
64
|
+
grid: { rows: rowsCount !== null && rowsCount !== void 0 ? rowsCount : defaults.rowsCount, fill: 'row' },
|
|
65
|
+
}),
|
|
66
|
+
},
|
|
67
|
+
]));
|
|
68
|
+
};
|
|
69
|
+
exports.Slider = react_1.default.forwardRef(function Slider({ children, itemsPerView = 1, slideGap = 0, loop = false, navigation = true, pagination = true, rowsCount = 1, breakpoints, onInitial, thumb, main, direction = 'horizontal', modules: extraModules, ...swiperProps }, ref) {
|
|
70
|
+
const { t } = (0, use_locale_1.useLocale)();
|
|
71
|
+
const [swiper, setSwiper] = (0, react_1.useState)(null);
|
|
72
|
+
const [activeIndex, setActiveIndex] = (0, react_1.useState)(0);
|
|
73
|
+
const [isBeginning, setIsBeginning] = (0, react_1.useState)(true);
|
|
74
|
+
const [isEnd, setIsEnd] = (0, react_1.useState)(false);
|
|
75
|
+
const slides = (0, react_1.useMemo)(() => react_1.default.Children.toArray(children), [children]);
|
|
76
|
+
const swiperBreakpoints = (0, react_1.useMemo)(() => toSwiperBreakpoints(breakpoints, { itemsPerView, rowsCount, slideGap }), [breakpoints, itemsPerView, rowsCount, slideGap]);
|
|
77
|
+
const sync = (0, react_1.useCallback)((instance) => {
|
|
78
|
+
setActiveIndex(instance.realIndex);
|
|
79
|
+
setIsBeginning(instance.isBeginning);
|
|
80
|
+
setIsEnd(instance.isEnd);
|
|
81
|
+
}, []);
|
|
82
|
+
const handleSwiper = (0, react_1.useCallback)((instance) => {
|
|
83
|
+
setSwiper(instance);
|
|
84
|
+
sync(instance);
|
|
85
|
+
onInitial === null || onInitial === void 0 ? void 0 : onInitial({
|
|
86
|
+
setCurrentIndex: index => instance.slideTo(index),
|
|
87
|
+
currentIndex: instance.activeIndex,
|
|
88
|
+
nextSlide: () => instance.slideNext(),
|
|
89
|
+
prevSlide: () => instance.slidePrev(),
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
// onInitial намеренно вызывается один раз — при инициализации Swiper
|
|
93
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
94
|
+
[sync]);
|
|
95
|
+
const handleSlideChange = (0, react_1.useCallback)((instance) => {
|
|
96
|
+
sync(instance);
|
|
97
|
+
thumb === null || thumb === void 0 ? void 0 : thumb.onSlideChange(instance.realIndex);
|
|
98
|
+
}, [sync, thumb]);
|
|
99
|
+
const selectedSlide = main === null || main === void 0 ? void 0 : main.selectedSlide;
|
|
100
|
+
(0, react_1.useEffect)(() => {
|
|
101
|
+
if (swiper && typeof selectedSlide === 'number')
|
|
102
|
+
swiper.slideTo(selectedSlide);
|
|
103
|
+
}, [swiper, selectedSlide]);
|
|
104
|
+
const modules = (0, react_1.useMemo)(() => [modules_1.A11y, ...(rowsCount > 1 ? [modules_1.Grid] : []), ...(extraModules !== null && extraModules !== void 0 ? extraModules : [])], [rowsCount, extraModules]);
|
|
105
|
+
const vertical = direction === 'vertical';
|
|
106
|
+
const showNavigation = navigation && slides.length > itemsPerView;
|
|
107
|
+
const showDots = pagination && itemsPerView === 1 && slides.length > 1;
|
|
108
|
+
return ((0, jsx_runtime_1.jsxs)("div", { ...(0, uikit_1.getDataAttributes)(swiperProps, 'slider'), className: styles_module_scss_1.default.container, ref: ref, role: "group", "data-direction": direction, children: [(0, jsx_runtime_1.jsx)(react_2.Swiper, { ...(0, uikit_1.splitDataAttributes)(swiperProps).nativeProps, modules: modules, className: styles_module_scss_1.default.swiper, direction: direction, loop: loop, spaceBetween: slideGap, slidesPerView: itemsPerView, breakpoints: swiperBreakpoints, grid: rowsCount > 1 ? { rows: rowsCount, fill: 'row' } : undefined, onSwiper: handleSwiper, onSlideChange: handleSlideChange, children: slides.map((slide, index) => ((0, jsx_runtime_1.jsx)(react_2.SwiperSlide, { children: slide }, index))) }), showNavigation && swiper && ((0, jsx_runtime_1.jsxs)("div", { className: styles_module_scss_1.default.controls, "data-direction": direction, children: [(0, jsx_runtime_1.jsx)(uikit_2.Button, { iconOnly: true, size: "s", variant: "shadow", "aria-label": t('slider.previous'), className: styles_module_scss_1.default.control, disabled: !loop && isBeginning, onClick: () => swiper.slidePrev(), children: vertical ? (0, jsx_runtime_1.jsx)(icons_1.ArrowUpIcon, {}) : (0, jsx_runtime_1.jsx)(icons_1.ArrowLeftIcon, {}) }), (0, jsx_runtime_1.jsx)(uikit_2.Button, { iconOnly: true, size: "s", variant: "shadow", "aria-label": t('slider.next'), className: styles_module_scss_1.default.control, disabled: !loop && isEnd, onClick: () => swiper.slideNext(), children: vertical ? (0, jsx_runtime_1.jsx)(icons_1.ArrowDownIcon, {}) : (0, jsx_runtime_1.jsx)(icons_1.ArrowRightIcon, {}) })] })), showDots && swiper && ((0, jsx_runtime_1.jsx)(dots_1.Dots, { count: slides.length, current: activeIndex, direction: direction, onSelect: i => swiper.slideTo(i) }))] }));
|
|
109
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
position: relative;
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
width: 100%;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
max-width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
padding: 0 var(--space-20);
|
|
9
|
+
user-select: none;
|
|
10
|
+
}
|
|
11
|
+
.container[data-direction=vertical] {
|
|
12
|
+
padding: var(--space-20) 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.swiper {
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
}
|
|
20
|
+
.swiper :global(.swiper-slide) {
|
|
21
|
+
flex-shrink: 0;
|
|
22
|
+
height: auto;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.controls {
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 50%;
|
|
28
|
+
left: 2px;
|
|
29
|
+
z-index: 2;
|
|
30
|
+
display: flex;
|
|
31
|
+
justify-content: space-between;
|
|
32
|
+
width: calc(100% - 4px);
|
|
33
|
+
padding: var(--space-8) 0;
|
|
34
|
+
pointer-events: none;
|
|
35
|
+
transform: translateY(-50%);
|
|
36
|
+
}
|
|
37
|
+
.controls[data-direction=vertical] {
|
|
38
|
+
top: 2px;
|
|
39
|
+
left: 50%;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
width: auto;
|
|
42
|
+
height: calc(100% - 4px);
|
|
43
|
+
padding: 0 var(--space-8);
|
|
44
|
+
transform: translateX(-50%);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.control {
|
|
48
|
+
pointer-events: all;
|
|
49
|
+
}
|
|
50
|
+
.control:disabled {
|
|
51
|
+
opacity: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.dots {
|
|
55
|
+
position: absolute;
|
|
56
|
+
bottom: 0;
|
|
57
|
+
left: 0;
|
|
58
|
+
z-index: 2;
|
|
59
|
+
display: flex;
|
|
60
|
+
gap: var(--space-8);
|
|
61
|
+
justify-content: center;
|
|
62
|
+
width: 100%;
|
|
63
|
+
transform: translateY(50%);
|
|
64
|
+
}
|
|
65
|
+
.dots[data-direction=vertical] {
|
|
66
|
+
inset: 50% 0 auto auto;
|
|
67
|
+
flex-direction: column;
|
|
68
|
+
align-items: center;
|
|
69
|
+
width: auto;
|
|
70
|
+
transform: translate(50%, -50%);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.dot {
|
|
74
|
+
width: 8px;
|
|
75
|
+
height: 8px;
|
|
76
|
+
padding: 0;
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
background: var(--control-minor);
|
|
79
|
+
border: 0;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
}
|
|
82
|
+
.dot[data-active] {
|
|
83
|
+
background: var(--control-primary);
|
|
84
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
"use strict";
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.usePreviewSlider = void 0;
|
|
5
|
+
const react_1 = require("react");
|
|
6
|
+
/** Связывает главный слайдер с миниатюрами: выбор миниатюры листает главный слайд. */
|
|
7
|
+
const usePreviewSlider = () => {
|
|
8
|
+
const [index, setIndex] = (0, react_1.useState)(0);
|
|
9
|
+
return (0, react_1.useMemo)(() => ({ mainSlider: { selectedSlide: index }, thumbSlider: { onSlideChange: setIndex } }), [index]);
|
|
10
|
+
};
|
|
11
|
+
exports.usePreviewSlider = usePreviewSlider;
|
package/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slider';
|
package/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './slider';
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** Строки `@lt-ui/slider`: подписи кнопок и точек для скринридера. Переопределяются через `messages` провайдера */
|
|
2
|
+
export interface SliderMessages {
|
|
3
|
+
slider: {
|
|
4
|
+
previous: string;
|
|
5
|
+
next: string;
|
|
6
|
+
slide: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
export declare const ru: SliderMessages;
|
|
10
|
+
export declare const en: SliderMessages;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SliderMessages } from './messages';
|
|
2
|
+
/**
|
|
3
|
+
* Язык и переводчик строк пакета: язык берётся у ближайшего `ThemeProvider` или `LocaleProvider`
|
|
4
|
+
* из `@lt-ui/uikit`, строки переопределяются в `messages` под своим ключом.
|
|
5
|
+
*/
|
|
6
|
+
export declare const useLocale: () => {
|
|
7
|
+
locale: import("@lt-ui/i18n").Locale;
|
|
8
|
+
t: import("@lt-ui/i18n").Translate<SliderMessages>;
|
|
9
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { createUseLocale } from '@lt-ui/i18n';
|
|
2
|
+
import { en, ru } from './messages';
|
|
3
|
+
/**
|
|
4
|
+
* Язык и переводчик строк пакета: язык берётся у ближайшего `ThemeProvider` или `LocaleProvider`
|
|
5
|
+
* из `@lt-ui/uikit`, строки переопределяются в `messages` под своим ключом.
|
|
6
|
+
*/
|
|
7
|
+
export const useLocale = createUseLocale({ en, ru });
|
package/package.json
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lt-ui/slider",
|
|
3
|
-
"version": "0.0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "LT UI",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"peerDependencies": {
|
|
7
|
+
"@lt-ui/icons": "0.0.2",
|
|
8
|
+
"@lt-ui/uikit": "0.0.2",
|
|
9
|
+
"react": "^18.0.0 || ^19.0.0",
|
|
10
|
+
"swiper": "^12.0.0 || ^13.0.0 || ^14.0.0"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"@lt-ui/i18n": "0.0.1"
|
|
14
|
+
},
|
|
15
|
+
"main": "./cjs/index.js",
|
|
16
|
+
"module": "./index.js",
|
|
17
|
+
"types": "./index.d.ts",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./index.d.ts",
|
|
21
|
+
"import": "./index.js",
|
|
22
|
+
"require": "./cjs/index.js"
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
"sideEffects": [
|
|
26
|
+
"*.css"
|
|
27
|
+
],
|
|
28
|
+
"private": false,
|
|
29
|
+
"publishConfig": {
|
|
30
|
+
"access": "public"
|
|
31
|
+
}
|
|
32
|
+
}
|
package/slider/dots.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
type DotsProps = {
|
|
3
|
+
count: number;
|
|
4
|
+
current: number;
|
|
5
|
+
direction?: 'horizontal' | 'vertical';
|
|
6
|
+
onSelect: (index: number) => void;
|
|
7
|
+
};
|
|
8
|
+
export declare const Dots: ({ count, current, direction, onSelect }: DotsProps) => React.JSX.Element;
|
|
9
|
+
export {};
|
package/slider/dots.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useLocale } from '../locale/use-locale';
|
|
5
|
+
import styles from './styles.module.css';
|
|
6
|
+
export const Dots = ({ count, current, direction = 'horizontal', onSelect }) => {
|
|
7
|
+
const { t } = useLocale();
|
|
8
|
+
return (_jsx("div", { className: styles.dots, "data-direction": direction, children: Array.from({ length: count }, (_, index) => (_jsx("button", { type: "button", className: styles.dot, "data-active": index === current || undefined, "aria-label": t('slider.slide', { number: index + 1 }), "aria-current": index === current || undefined, onClick: () => onSelect(index) }, index))) }));
|
|
9
|
+
};
|
package/slider/index.js
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { Swiper as SwiperType } from 'swiper';
|
|
3
|
+
import type { SwiperOptions } from 'swiper/types';
|
|
4
|
+
import 'swiper/css';
|
|
5
|
+
import 'swiper/css/grid';
|
|
6
|
+
import type { SliderBreakpoint } from './types';
|
|
7
|
+
export declare const Slider: React.ForwardRefExoticComponent<(Omit<import("@lt-ui/uikit").DataAttributes & {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
itemsPerView?: number;
|
|
10
|
+
slideGap?: number;
|
|
11
|
+
loop?: boolean;
|
|
12
|
+
navigation?: boolean;
|
|
13
|
+
pagination?: boolean;
|
|
14
|
+
rowsCount?: number;
|
|
15
|
+
breakpoints?: SliderBreakpoint[];
|
|
16
|
+
onInitial?: (slider: import("./types").SliderApi) => void;
|
|
17
|
+
direction?: "horizontal" | "vertical";
|
|
18
|
+
} & {
|
|
19
|
+
thumb?: import("./types").ThumbSlider;
|
|
20
|
+
main?: never;
|
|
21
|
+
} & Omit<React.RefAttributes<import("swiper/react").SwiperRef> & Omit<React.HTMLAttributes<HTMLElement>, "onClick" | "onProgress" | "onTouchEnd" | "onTouchMove" | "onTouchStart" | "onTransitionEnd" | "onKeyPress" | "onDoubleClick" | "onScroll" | "onResize"> & SwiperOptions & {
|
|
22
|
+
tag?: string;
|
|
23
|
+
wrapperTag?: string;
|
|
24
|
+
onSwiper?: (swiper: SwiperType) => void;
|
|
25
|
+
onAutoplayStart?: (swiper: SwiperType) => void;
|
|
26
|
+
onAutoplayStop?: (swiper: SwiperType) => void;
|
|
27
|
+
onAutoplayPause?: (swiper: SwiperType) => void;
|
|
28
|
+
onAutoplayResume?: (swiper: SwiperType) => void;
|
|
29
|
+
onAutoplayTimeLeft?: (swiper: SwiperType, timeLeft: number, percentage: number) => void;
|
|
30
|
+
onAutoplay?: (swiper: SwiperType) => void;
|
|
31
|
+
onKeyPress?: (swiper: SwiperType, keyCode: string) => void;
|
|
32
|
+
onHashChange?: (swiper: SwiperType) => void;
|
|
33
|
+
onHashSet?: (swiper: SwiperType) => void;
|
|
34
|
+
onPaginationRender?: (swiper: SwiperType, paginationEl: HTMLElement) => void;
|
|
35
|
+
onPaginationUpdate?: (swiper: SwiperType, paginationEl: HTMLElement) => void;
|
|
36
|
+
onPaginationHide?: (swiper: SwiperType) => void;
|
|
37
|
+
onPaginationShow?: (swiper: SwiperType) => void;
|
|
38
|
+
onNavigationHide?: (swiper: SwiperType) => void;
|
|
39
|
+
onNavigationShow?: (swiper: SwiperType) => void;
|
|
40
|
+
onNavigationPrev?: (swiper: SwiperType) => void;
|
|
41
|
+
onNavigationNext?: (swiper: SwiperType) => void;
|
|
42
|
+
onScroll?: (swiper: SwiperType, event: WheelEvent) => void;
|
|
43
|
+
onZoomChange?: (swiper: SwiperType, scale: number, imageEl: HTMLElement, slideEl: HTMLElement) => void;
|
|
44
|
+
onScrollbarDragStart?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
45
|
+
onScrollbarDragMove?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
46
|
+
onScrollbarDragEnd?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
47
|
+
onVirtualUpdate?: (swiper: SwiperType) => void;
|
|
48
|
+
onInit?: (swiper: SwiperType) => any;
|
|
49
|
+
onBeforeDestroy?: (swiper: SwiperType) => void;
|
|
50
|
+
onSlidesUpdated?: (swiper: SwiperType) => void;
|
|
51
|
+
onSlideChange?: (swiper: SwiperType) => void;
|
|
52
|
+
onSlideChangeTransitionStart?: (swiper: SwiperType) => void;
|
|
53
|
+
onSlideChangeTransitionEnd?: (swiper: SwiperType) => void;
|
|
54
|
+
onSlideNextTransitionStart?: (swiper: SwiperType) => void;
|
|
55
|
+
onSlideNextTransitionEnd?: (swiper: SwiperType) => void;
|
|
56
|
+
onSlidePrevTransitionStart?: (swiper: SwiperType) => void;
|
|
57
|
+
onSlidePrevTransitionEnd?: (swiper: SwiperType) => void;
|
|
58
|
+
onTransitionStart?: (swiper: SwiperType) => void;
|
|
59
|
+
onTransitionEnd?: (swiper: SwiperType) => void;
|
|
60
|
+
onTouchStart?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
61
|
+
onTouchMove?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
62
|
+
onTouchMoveOpposite?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
63
|
+
onSliderMove?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
64
|
+
onTouchEnd?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
65
|
+
onClick?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
66
|
+
onTap?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
67
|
+
onDoubleTap?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
68
|
+
onProgress?: (swiper: SwiperType, progress: number) => void;
|
|
69
|
+
onReachBeginning?: (swiper: SwiperType) => void;
|
|
70
|
+
onReachEnd?: (swiper: SwiperType) => void;
|
|
71
|
+
onToEdge?: (swiper: SwiperType) => void;
|
|
72
|
+
onFromEdge?: (swiper: SwiperType) => void;
|
|
73
|
+
onSetTranslate?: (swiper: SwiperType, translate: number, byController?: boolean | SwiperType) => void;
|
|
74
|
+
onSetTransition?: (swiper: SwiperType, transition: number, byController?: boolean | SwiperType) => void;
|
|
75
|
+
onResize?: (swiper: SwiperType) => void;
|
|
76
|
+
onObserverUpdate?: (swiper: SwiperType) => void;
|
|
77
|
+
onBeforeLoopFix?: (swiper: SwiperType) => void;
|
|
78
|
+
onLoopFix?: (swiper: SwiperType) => void;
|
|
79
|
+
onBreakpoint?: (swiper: SwiperType, breakpointParams: SwiperOptions) => void;
|
|
80
|
+
_beforeBreakpoint?: (swiper: SwiperType, breakpointParams: SwiperOptions) => void;
|
|
81
|
+
_containerClasses?: (swiper: SwiperType, classNames: string) => void;
|
|
82
|
+
_slideClass?: (swiper: SwiperType, slideEl: HTMLElement, classNames: string) => void;
|
|
83
|
+
_slideClasses?: (swiper: SwiperType, slides: {
|
|
84
|
+
slideEl: HTMLElement;
|
|
85
|
+
classNames: string;
|
|
86
|
+
index: number;
|
|
87
|
+
}[]) => void;
|
|
88
|
+
_swiper?: (swiper: SwiperType) => void;
|
|
89
|
+
_freeModeNoMomentumRelease?: (swiper: SwiperType) => void;
|
|
90
|
+
onActiveIndexChange?: (swiper: SwiperType) => void;
|
|
91
|
+
onSnapIndexChange?: (swiper: SwiperType) => void;
|
|
92
|
+
onRealIndexChange?: (swiper: SwiperType) => void;
|
|
93
|
+
onAfterInit?: (swiper: SwiperType) => void;
|
|
94
|
+
onBeforeInit?: (swiper: SwiperType) => void;
|
|
95
|
+
onBeforeResize?: (swiper: SwiperType) => void;
|
|
96
|
+
onBeforeSlideChangeStart?: (swiper: SwiperType) => void;
|
|
97
|
+
onBeforeTransitionStart?: (swiper: SwiperType, speed: number, internal: unknown) => void;
|
|
98
|
+
onChangeDirection?: (swiper: SwiperType) => void;
|
|
99
|
+
onDoubleClick?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
100
|
+
onDestroy?: (swiper: SwiperType) => void;
|
|
101
|
+
onMomentumBounce?: (swiper: SwiperType) => void;
|
|
102
|
+
onOrientationchange?: (swiper: SwiperType) => void;
|
|
103
|
+
onSlideResetTransitionStart?: (swiper: SwiperType) => void;
|
|
104
|
+
onSlideResetTransitionEnd?: (swiper: SwiperType) => void;
|
|
105
|
+
onSliderFirstMove?: (swiper: SwiperType, event: TouchEvent) => void;
|
|
106
|
+
onSlidesLengthChange?: (swiper: SwiperType) => void;
|
|
107
|
+
onSlidesGridLengthChange?: (swiper: SwiperType) => void;
|
|
108
|
+
onSnapGridLengthChange?: (swiper: SwiperType) => void;
|
|
109
|
+
onUpdate?: (swiper: SwiperType) => void;
|
|
110
|
+
onLock?: (swiper: SwiperType) => void;
|
|
111
|
+
onUnlock?: (swiper: SwiperType) => void;
|
|
112
|
+
} & {
|
|
113
|
+
children?: React.ReactNode | undefined;
|
|
114
|
+
}, keyof {
|
|
115
|
+
children: React.ReactNode;
|
|
116
|
+
itemsPerView?: number;
|
|
117
|
+
slideGap?: number;
|
|
118
|
+
loop?: boolean;
|
|
119
|
+
navigation?: boolean;
|
|
120
|
+
pagination?: boolean;
|
|
121
|
+
rowsCount?: number;
|
|
122
|
+
breakpoints?: SliderBreakpoint[];
|
|
123
|
+
onInitial?: (slider: import("./types").SliderApi) => void;
|
|
124
|
+
direction?: "horizontal" | "vertical";
|
|
125
|
+
} | "spaceBetween" | "slidesPerView" | "onSwiper" | "onSlideChange" | "grid">, "ref"> | Omit<import("@lt-ui/uikit").DataAttributes & {
|
|
126
|
+
children: React.ReactNode;
|
|
127
|
+
itemsPerView?: number;
|
|
128
|
+
slideGap?: number;
|
|
129
|
+
loop?: boolean;
|
|
130
|
+
navigation?: boolean;
|
|
131
|
+
pagination?: boolean;
|
|
132
|
+
rowsCount?: number;
|
|
133
|
+
breakpoints?: SliderBreakpoint[];
|
|
134
|
+
onInitial?: (slider: import("./types").SliderApi) => void;
|
|
135
|
+
direction?: "horizontal" | "vertical";
|
|
136
|
+
} & {
|
|
137
|
+
main?: import("./types").MainSlider;
|
|
138
|
+
thumb?: never;
|
|
139
|
+
} & Omit<React.RefAttributes<import("swiper/react").SwiperRef> & Omit<React.HTMLAttributes<HTMLElement>, "onClick" | "onProgress" | "onTouchEnd" | "onTouchMove" | "onTouchStart" | "onTransitionEnd" | "onKeyPress" | "onDoubleClick" | "onScroll" | "onResize"> & SwiperOptions & {
|
|
140
|
+
tag?: string;
|
|
141
|
+
wrapperTag?: string;
|
|
142
|
+
onSwiper?: (swiper: SwiperType) => void;
|
|
143
|
+
onAutoplayStart?: (swiper: SwiperType) => void;
|
|
144
|
+
onAutoplayStop?: (swiper: SwiperType) => void;
|
|
145
|
+
onAutoplayPause?: (swiper: SwiperType) => void;
|
|
146
|
+
onAutoplayResume?: (swiper: SwiperType) => void;
|
|
147
|
+
onAutoplayTimeLeft?: (swiper: SwiperType, timeLeft: number, percentage: number) => void;
|
|
148
|
+
onAutoplay?: (swiper: SwiperType) => void;
|
|
149
|
+
onKeyPress?: (swiper: SwiperType, keyCode: string) => void;
|
|
150
|
+
onHashChange?: (swiper: SwiperType) => void;
|
|
151
|
+
onHashSet?: (swiper: SwiperType) => void;
|
|
152
|
+
onPaginationRender?: (swiper: SwiperType, paginationEl: HTMLElement) => void;
|
|
153
|
+
onPaginationUpdate?: (swiper: SwiperType, paginationEl: HTMLElement) => void;
|
|
154
|
+
onPaginationHide?: (swiper: SwiperType) => void;
|
|
155
|
+
onPaginationShow?: (swiper: SwiperType) => void;
|
|
156
|
+
onNavigationHide?: (swiper: SwiperType) => void;
|
|
157
|
+
onNavigationShow?: (swiper: SwiperType) => void;
|
|
158
|
+
onNavigationPrev?: (swiper: SwiperType) => void;
|
|
159
|
+
onNavigationNext?: (swiper: SwiperType) => void;
|
|
160
|
+
onScroll?: (swiper: SwiperType, event: WheelEvent) => void;
|
|
161
|
+
onZoomChange?: (swiper: SwiperType, scale: number, imageEl: HTMLElement, slideEl: HTMLElement) => void;
|
|
162
|
+
onScrollbarDragStart?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
163
|
+
onScrollbarDragMove?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
164
|
+
onScrollbarDragEnd?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
165
|
+
onVirtualUpdate?: (swiper: SwiperType) => void;
|
|
166
|
+
onInit?: (swiper: SwiperType) => any;
|
|
167
|
+
onBeforeDestroy?: (swiper: SwiperType) => void;
|
|
168
|
+
onSlidesUpdated?: (swiper: SwiperType) => void;
|
|
169
|
+
onSlideChange?: (swiper: SwiperType) => void;
|
|
170
|
+
onSlideChangeTransitionStart?: (swiper: SwiperType) => void;
|
|
171
|
+
onSlideChangeTransitionEnd?: (swiper: SwiperType) => void;
|
|
172
|
+
onSlideNextTransitionStart?: (swiper: SwiperType) => void;
|
|
173
|
+
onSlideNextTransitionEnd?: (swiper: SwiperType) => void;
|
|
174
|
+
onSlidePrevTransitionStart?: (swiper: SwiperType) => void;
|
|
175
|
+
onSlidePrevTransitionEnd?: (swiper: SwiperType) => void;
|
|
176
|
+
onTransitionStart?: (swiper: SwiperType) => void;
|
|
177
|
+
onTransitionEnd?: (swiper: SwiperType) => void;
|
|
178
|
+
onTouchStart?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
179
|
+
onTouchMove?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
180
|
+
onTouchMoveOpposite?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
181
|
+
onSliderMove?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
182
|
+
onTouchEnd?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
183
|
+
onClick?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
184
|
+
onTap?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
185
|
+
onDoubleTap?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
186
|
+
onProgress?: (swiper: SwiperType, progress: number) => void;
|
|
187
|
+
onReachBeginning?: (swiper: SwiperType) => void;
|
|
188
|
+
onReachEnd?: (swiper: SwiperType) => void;
|
|
189
|
+
onToEdge?: (swiper: SwiperType) => void;
|
|
190
|
+
onFromEdge?: (swiper: SwiperType) => void;
|
|
191
|
+
onSetTranslate?: (swiper: SwiperType, translate: number, byController?: boolean | SwiperType) => void;
|
|
192
|
+
onSetTransition?: (swiper: SwiperType, transition: number, byController?: boolean | SwiperType) => void;
|
|
193
|
+
onResize?: (swiper: SwiperType) => void;
|
|
194
|
+
onObserverUpdate?: (swiper: SwiperType) => void;
|
|
195
|
+
onBeforeLoopFix?: (swiper: SwiperType) => void;
|
|
196
|
+
onLoopFix?: (swiper: SwiperType) => void;
|
|
197
|
+
onBreakpoint?: (swiper: SwiperType, breakpointParams: SwiperOptions) => void;
|
|
198
|
+
_beforeBreakpoint?: (swiper: SwiperType, breakpointParams: SwiperOptions) => void;
|
|
199
|
+
_containerClasses?: (swiper: SwiperType, classNames: string) => void;
|
|
200
|
+
_slideClass?: (swiper: SwiperType, slideEl: HTMLElement, classNames: string) => void;
|
|
201
|
+
_slideClasses?: (swiper: SwiperType, slides: {
|
|
202
|
+
slideEl: HTMLElement;
|
|
203
|
+
classNames: string;
|
|
204
|
+
index: number;
|
|
205
|
+
}[]) => void;
|
|
206
|
+
_swiper?: (swiper: SwiperType) => void;
|
|
207
|
+
_freeModeNoMomentumRelease?: (swiper: SwiperType) => void;
|
|
208
|
+
onActiveIndexChange?: (swiper: SwiperType) => void;
|
|
209
|
+
onSnapIndexChange?: (swiper: SwiperType) => void;
|
|
210
|
+
onRealIndexChange?: (swiper: SwiperType) => void;
|
|
211
|
+
onAfterInit?: (swiper: SwiperType) => void;
|
|
212
|
+
onBeforeInit?: (swiper: SwiperType) => void;
|
|
213
|
+
onBeforeResize?: (swiper: SwiperType) => void;
|
|
214
|
+
onBeforeSlideChangeStart?: (swiper: SwiperType) => void;
|
|
215
|
+
onBeforeTransitionStart?: (swiper: SwiperType, speed: number, internal: unknown) => void;
|
|
216
|
+
onChangeDirection?: (swiper: SwiperType) => void;
|
|
217
|
+
onDoubleClick?: (swiper: SwiperType, event: MouseEvent | TouchEvent | PointerEvent) => void;
|
|
218
|
+
onDestroy?: (swiper: SwiperType) => void;
|
|
219
|
+
onMomentumBounce?: (swiper: SwiperType) => void;
|
|
220
|
+
onOrientationchange?: (swiper: SwiperType) => void;
|
|
221
|
+
onSlideResetTransitionStart?: (swiper: SwiperType) => void;
|
|
222
|
+
onSlideResetTransitionEnd?: (swiper: SwiperType) => void;
|
|
223
|
+
onSliderFirstMove?: (swiper: SwiperType, event: TouchEvent) => void;
|
|
224
|
+
onSlidesLengthChange?: (swiper: SwiperType) => void;
|
|
225
|
+
onSlidesGridLengthChange?: (swiper: SwiperType) => void;
|
|
226
|
+
onSnapGridLengthChange?: (swiper: SwiperType) => void;
|
|
227
|
+
onUpdate?: (swiper: SwiperType) => void;
|
|
228
|
+
onLock?: (swiper: SwiperType) => void;
|
|
229
|
+
onUnlock?: (swiper: SwiperType) => void;
|
|
230
|
+
} & {
|
|
231
|
+
children?: React.ReactNode | undefined;
|
|
232
|
+
}, keyof {
|
|
233
|
+
children: React.ReactNode;
|
|
234
|
+
itemsPerView?: number;
|
|
235
|
+
slideGap?: number;
|
|
236
|
+
loop?: boolean;
|
|
237
|
+
navigation?: boolean;
|
|
238
|
+
pagination?: boolean;
|
|
239
|
+
rowsCount?: number;
|
|
240
|
+
breakpoints?: SliderBreakpoint[];
|
|
241
|
+
onInitial?: (slider: import("./types").SliderApi) => void;
|
|
242
|
+
direction?: "horizontal" | "vertical";
|
|
243
|
+
} | "spaceBetween" | "slidesPerView" | "onSwiper" | "onSlideChange" | "grid">, "ref">) & React.RefAttributes<HTMLDivElement>>;
|
package/slider/slider.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { getDataAttributes, splitDataAttributes } from '@lt-ui/uikit';
|
|
4
|
+
import React, { useCallback, useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import { Swiper, SwiperSlide } from 'swiper/react';
|
|
6
|
+
import { A11y, Grid } from 'swiper/modules';
|
|
7
|
+
import { Button } from '@lt-ui/uikit';
|
|
8
|
+
import { ArrowDownIcon, ArrowLeftIcon, ArrowRightIcon, ArrowUpIcon } from '@lt-ui/icons';
|
|
9
|
+
import 'swiper/css';
|
|
10
|
+
import 'swiper/css/grid';
|
|
11
|
+
import { useLocale } from '../locale/use-locale';
|
|
12
|
+
import { Dots } from './dots';
|
|
13
|
+
import styles from './styles.module.css';
|
|
14
|
+
const toSwiperBreakpoints = (breakpoints, defaults) => {
|
|
15
|
+
if (!(breakpoints === null || breakpoints === void 0 ? void 0 : breakpoints.length))
|
|
16
|
+
return undefined;
|
|
17
|
+
return Object.fromEntries([...breakpoints]
|
|
18
|
+
.sort((a, b) => a.width - b.width)
|
|
19
|
+
.map(({ width, itemsPerView, rowsCount, slideGap }) => [
|
|
20
|
+
width,
|
|
21
|
+
{
|
|
22
|
+
slidesPerView: itemsPerView !== null && itemsPerView !== void 0 ? itemsPerView : defaults.itemsPerView,
|
|
23
|
+
spaceBetween: slideGap !== null && slideGap !== void 0 ? slideGap : defaults.slideGap,
|
|
24
|
+
...((rowsCount !== null && rowsCount !== void 0 ? rowsCount : defaults.rowsCount) > 1 && {
|
|
25
|
+
grid: { rows: rowsCount !== null && rowsCount !== void 0 ? rowsCount : defaults.rowsCount, fill: 'row' },
|
|
26
|
+
}),
|
|
27
|
+
},
|
|
28
|
+
]));
|
|
29
|
+
};
|
|
30
|
+
export const Slider = React.forwardRef(function Slider({ children, itemsPerView = 1, slideGap = 0, loop = false, navigation = true, pagination = true, rowsCount = 1, breakpoints, onInitial, thumb, main, direction = 'horizontal', modules: extraModules, ...swiperProps }, ref) {
|
|
31
|
+
const { t } = useLocale();
|
|
32
|
+
const [swiper, setSwiper] = useState(null);
|
|
33
|
+
const [activeIndex, setActiveIndex] = useState(0);
|
|
34
|
+
const [isBeginning, setIsBeginning] = useState(true);
|
|
35
|
+
const [isEnd, setIsEnd] = useState(false);
|
|
36
|
+
const slides = useMemo(() => React.Children.toArray(children), [children]);
|
|
37
|
+
const swiperBreakpoints = useMemo(() => toSwiperBreakpoints(breakpoints, { itemsPerView, rowsCount, slideGap }), [breakpoints, itemsPerView, rowsCount, slideGap]);
|
|
38
|
+
const sync = useCallback((instance) => {
|
|
39
|
+
setActiveIndex(instance.realIndex);
|
|
40
|
+
setIsBeginning(instance.isBeginning);
|
|
41
|
+
setIsEnd(instance.isEnd);
|
|
42
|
+
}, []);
|
|
43
|
+
const handleSwiper = useCallback((instance) => {
|
|
44
|
+
setSwiper(instance);
|
|
45
|
+
sync(instance);
|
|
46
|
+
onInitial === null || onInitial === void 0 ? void 0 : onInitial({
|
|
47
|
+
setCurrentIndex: index => instance.slideTo(index),
|
|
48
|
+
currentIndex: instance.activeIndex,
|
|
49
|
+
nextSlide: () => instance.slideNext(),
|
|
50
|
+
prevSlide: () => instance.slidePrev(),
|
|
51
|
+
});
|
|
52
|
+
},
|
|
53
|
+
// onInitial намеренно вызывается один раз — при инициализации Swiper
|
|
54
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
55
|
+
[sync]);
|
|
56
|
+
const handleSlideChange = useCallback((instance) => {
|
|
57
|
+
sync(instance);
|
|
58
|
+
thumb === null || thumb === void 0 ? void 0 : thumb.onSlideChange(instance.realIndex);
|
|
59
|
+
}, [sync, thumb]);
|
|
60
|
+
const selectedSlide = main === null || main === void 0 ? void 0 : main.selectedSlide;
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
if (swiper && typeof selectedSlide === 'number')
|
|
63
|
+
swiper.slideTo(selectedSlide);
|
|
64
|
+
}, [swiper, selectedSlide]);
|
|
65
|
+
const modules = useMemo(() => [A11y, ...(rowsCount > 1 ? [Grid] : []), ...(extraModules !== null && extraModules !== void 0 ? extraModules : [])], [rowsCount, extraModules]);
|
|
66
|
+
const vertical = direction === 'vertical';
|
|
67
|
+
const showNavigation = navigation && slides.length > itemsPerView;
|
|
68
|
+
const showDots = pagination && itemsPerView === 1 && slides.length > 1;
|
|
69
|
+
return (_jsxs("div", { ...getDataAttributes(swiperProps, 'slider'), className: styles.container, ref: ref, role: "group", "data-direction": direction, children: [_jsx(Swiper, { ...splitDataAttributes(swiperProps).nativeProps, modules: modules, className: styles.swiper, direction: direction, loop: loop, spaceBetween: slideGap, slidesPerView: itemsPerView, breakpoints: swiperBreakpoints, grid: rowsCount > 1 ? { rows: rowsCount, fill: 'row' } : undefined, onSwiper: handleSwiper, onSlideChange: handleSlideChange, children: slides.map((slide, index) => (_jsx(SwiperSlide, { children: slide }, index))) }), showNavigation && swiper && (_jsxs("div", { className: styles.controls, "data-direction": direction, children: [_jsx(Button, { iconOnly: true, size: "s", variant: "shadow", "aria-label": t('slider.previous'), className: styles.control, disabled: !loop && isBeginning, onClick: () => swiper.slidePrev(), children: vertical ? _jsx(ArrowUpIcon, {}) : _jsx(ArrowLeftIcon, {}) }), _jsx(Button, { iconOnly: true, size: "s", variant: "shadow", "aria-label": t('slider.next'), className: styles.control, disabled: !loop && isEnd, onClick: () => swiper.slideNext(), children: vertical ? _jsx(ArrowDownIcon, {}) : _jsx(ArrowRightIcon, {}) })] })), showDots && swiper && (_jsx(Dots, { count: slides.length, current: activeIndex, direction: direction, onSelect: i => swiper.slideTo(i) }))] }));
|
|
70
|
+
});
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
.container {
|
|
2
|
+
position: relative;
|
|
3
|
+
box-sizing: border-box;
|
|
4
|
+
width: 100%;
|
|
5
|
+
min-width: 0;
|
|
6
|
+
max-width: 100%;
|
|
7
|
+
height: 100%;
|
|
8
|
+
padding: 0 var(--space-20);
|
|
9
|
+
user-select: none;
|
|
10
|
+
}
|
|
11
|
+
.container[data-direction=vertical] {
|
|
12
|
+
padding: var(--space-20) 0;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.swiper {
|
|
16
|
+
width: 100%;
|
|
17
|
+
height: 100%;
|
|
18
|
+
overflow: hidden;
|
|
19
|
+
}
|
|
20
|
+
.swiper :global(.swiper-slide) {
|
|
21
|
+
flex-shrink: 0;
|
|
22
|
+
height: auto;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.controls {
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 50%;
|
|
28
|
+
left: 2px;
|
|
29
|
+
z-index: 2;
|
|
30
|
+
display: flex;
|
|
31
|
+
justify-content: space-between;
|
|
32
|
+
width: calc(100% - 4px);
|
|
33
|
+
padding: var(--space-8) 0;
|
|
34
|
+
pointer-events: none;
|
|
35
|
+
transform: translateY(-50%);
|
|
36
|
+
}
|
|
37
|
+
.controls[data-direction=vertical] {
|
|
38
|
+
top: 2px;
|
|
39
|
+
left: 50%;
|
|
40
|
+
flex-direction: column;
|
|
41
|
+
width: auto;
|
|
42
|
+
height: calc(100% - 4px);
|
|
43
|
+
padding: 0 var(--space-8);
|
|
44
|
+
transform: translateX(-50%);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.control {
|
|
48
|
+
pointer-events: all;
|
|
49
|
+
}
|
|
50
|
+
.control:disabled {
|
|
51
|
+
opacity: 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.dots {
|
|
55
|
+
position: absolute;
|
|
56
|
+
bottom: 0;
|
|
57
|
+
left: 0;
|
|
58
|
+
z-index: 2;
|
|
59
|
+
display: flex;
|
|
60
|
+
gap: var(--space-8);
|
|
61
|
+
justify-content: center;
|
|
62
|
+
width: 100%;
|
|
63
|
+
transform: translateY(50%);
|
|
64
|
+
}
|
|
65
|
+
.dots[data-direction=vertical] {
|
|
66
|
+
inset: 50% 0 auto auto;
|
|
67
|
+
flex-direction: column;
|
|
68
|
+
align-items: center;
|
|
69
|
+
width: auto;
|
|
70
|
+
transform: translate(50%, -50%);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.dot {
|
|
74
|
+
width: 8px;
|
|
75
|
+
height: 8px;
|
|
76
|
+
padding: 0;
|
|
77
|
+
cursor: pointer;
|
|
78
|
+
background: var(--control-minor);
|
|
79
|
+
border: 0;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
}
|
|
82
|
+
.dot[data-active] {
|
|
83
|
+
background: var(--control-primary);
|
|
84
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { DataAttributes } from '@lt-ui/uikit';
|
|
2
|
+
import type { ComponentProps, ReactNode } from 'react';
|
|
3
|
+
import type { Swiper } from 'swiper/react';
|
|
4
|
+
/** Параметры, которые меняются от ширины контейнера. Ключ — минимальная ширина в px. */
|
|
5
|
+
export type SliderBreakpoint = {
|
|
6
|
+
/** Минимальная ширина окна, с которой действует набор параметров */
|
|
7
|
+
width: number;
|
|
8
|
+
itemsPerView?: number;
|
|
9
|
+
rowsCount?: number;
|
|
10
|
+
slideGap?: number;
|
|
11
|
+
};
|
|
12
|
+
/** Состояние главного слайдера, связанного с миниатюрами. */
|
|
13
|
+
export type MainSlider = {
|
|
14
|
+
selectedSlide: number;
|
|
15
|
+
};
|
|
16
|
+
/** Обработчик миниатюр, связанных с главным слайдером. */
|
|
17
|
+
export type ThumbSlider = {
|
|
18
|
+
onSlideChange: (index: number) => void;
|
|
19
|
+
};
|
|
20
|
+
export type UsePreviewSliderResult = {
|
|
21
|
+
mainSlider: MainSlider;
|
|
22
|
+
thumbSlider: ThumbSlider;
|
|
23
|
+
};
|
|
24
|
+
/** Управление слайдером снаружи; приходит в `onInitial`. */
|
|
25
|
+
export type SliderApi = {
|
|
26
|
+
setCurrentIndex: (index: number) => void;
|
|
27
|
+
currentIndex: number;
|
|
28
|
+
nextSlide: () => void;
|
|
29
|
+
prevSlide: () => void;
|
|
30
|
+
};
|
|
31
|
+
type SwiperProps = ComponentProps<typeof Swiper>;
|
|
32
|
+
type OwnProps = {
|
|
33
|
+
children: ReactNode;
|
|
34
|
+
/**
|
|
35
|
+
* Сколько слайдов видно одновременно.
|
|
36
|
+
* @default 1
|
|
37
|
+
*/
|
|
38
|
+
itemsPerView?: number;
|
|
39
|
+
/**
|
|
40
|
+
* Расстояние между слайдами, px.
|
|
41
|
+
* @default 0
|
|
42
|
+
*/
|
|
43
|
+
slideGap?: number;
|
|
44
|
+
/**
|
|
45
|
+
* Бесконечная прокрутка.
|
|
46
|
+
* @default false
|
|
47
|
+
*/
|
|
48
|
+
loop?: boolean;
|
|
49
|
+
/**
|
|
50
|
+
* Кнопки «Назад/Вперёд». Показываются, если слайдов больше, чем помещается.
|
|
51
|
+
* @default true
|
|
52
|
+
*/
|
|
53
|
+
navigation?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Точки. Показываются при `itemsPerView = 1`.
|
|
56
|
+
* @default true
|
|
57
|
+
*/
|
|
58
|
+
pagination?: boolean;
|
|
59
|
+
/**
|
|
60
|
+
* Число рядов (сетка).
|
|
61
|
+
* @default 1
|
|
62
|
+
*/
|
|
63
|
+
rowsCount?: number;
|
|
64
|
+
/** Адаптивные параметры: применяется последний подходящий по ширине. */
|
|
65
|
+
breakpoints?: SliderBreakpoint[];
|
|
66
|
+
/** Вызывается один раз после инициализации; отдаёт API управления. */
|
|
67
|
+
onInitial?: (slider: SliderApi) => void;
|
|
68
|
+
/**
|
|
69
|
+
* Направление прокрутки.
|
|
70
|
+
* @default 'horizontal'
|
|
71
|
+
*/
|
|
72
|
+
direction?: 'horizontal' | 'vertical';
|
|
73
|
+
};
|
|
74
|
+
/** Слайдер миниатюр (`thumb`) или главный слайдер (`main`) — одновременно только один из режимов. */
|
|
75
|
+
type LinkedProps = {
|
|
76
|
+
thumb?: ThumbSlider;
|
|
77
|
+
main?: never;
|
|
78
|
+
} | {
|
|
79
|
+
main?: MainSlider;
|
|
80
|
+
thumb?: never;
|
|
81
|
+
};
|
|
82
|
+
export type SliderProps = DataAttributes & OwnProps & LinkedProps & Omit<SwiperProps, keyof OwnProps | 'spaceBetween' | 'slidesPerView' | 'onSwiper' | 'onSlideChange' | 'grid' | 'navigation' | 'pagination' | 'breakpoints'>;
|
|
83
|
+
export {};
|
package/slider/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useMemo, useState } from 'react';
|
|
3
|
+
/** Связывает главный слайдер с миниатюрами: выбор миниатюры листает главный слайд. */
|
|
4
|
+
export const usePreviewSlider = () => {
|
|
5
|
+
const [index, setIndex] = useState(0);
|
|
6
|
+
return useMemo(() => ({ mainSlider: { selectedSlide: index }, thumbSlider: { onSlideChange: setIndex } }), [index]);
|
|
7
|
+
};
|
package/README.md
DELETED