@growth-angels/ds-core 1.17.0 → 1.17.1
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.
|
@@ -2,9 +2,16 @@ import { jsx as _jsx } from "react/jsx-runtime";
|
|
|
2
2
|
import { CarouselSwiper } from "../organisms/Carousel/CarouselSwiper";
|
|
3
3
|
import { useReactAdapter } from "../hooks/useReactAdaptater";
|
|
4
4
|
import { NativeChildWrapper } from "./utils/native-child-wrapper";
|
|
5
|
+
import Swiper from "swiper";
|
|
6
|
+
import * as modules from "swiper/modules";
|
|
7
|
+
window.Swiper = {
|
|
8
|
+
instance: Swiper,
|
|
9
|
+
modules,
|
|
10
|
+
};
|
|
11
|
+
import "swiper/css";
|
|
12
|
+
import "swiper/css/autoplay";
|
|
5
13
|
const { createElement, createRoot } = useReactAdapter();
|
|
6
14
|
export function HydrateCarousel(islands) {
|
|
7
|
-
console.log("HydrateCarousel called with islands:", islands);
|
|
8
15
|
islands?.forEach((carousel) => {
|
|
9
16
|
const Component = CarouselSwiper;
|
|
10
17
|
if (!Component)
|
|
@@ -1,36 +1,61 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useReactAdapter } from "../../hooks/useReactAdaptater";
|
|
3
|
-
import { useBreakpointObserver } from "../../hooks/useBreakPointObserver";
|
|
4
3
|
import { Button } from "../../atoms/atoms";
|
|
4
|
+
import Swiper from "swiper";
|
|
5
|
+
import { Autoplay, Navigation, Pagination } from "swiper/modules";
|
|
5
6
|
export const CarouselSwiper = (props) => {
|
|
6
|
-
const { children, slidesPerView: slidesPerViewDefault, spaceBetween =
|
|
7
|
-
const
|
|
8
|
-
|
|
7
|
+
const { children, slidesPerView: slidesPerViewDefault, spaceBetween = 48, navigation, pagination, hasPagination, hasNavigation, loop = false, } = props;
|
|
8
|
+
const classes = ["ga-ds-carousel"];
|
|
9
|
+
if (props.extraClassNames) {
|
|
10
|
+
if (typeof props.extraClassNames === "string") {
|
|
11
|
+
classes.push(props.extraClassNames);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
classes.push(...props.extraClassNames);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
9
17
|
if (Swiper) {
|
|
10
18
|
const slidesPerView = { xs: 1, ...slidesPerViewDefault };
|
|
11
19
|
const { useEffect, useState, useRef, Children } = useReactAdapter();
|
|
12
20
|
const trackRef = useRef(null);
|
|
21
|
+
const containerRef = useRef(null);
|
|
13
22
|
const slides = Children.toArray(children);
|
|
14
|
-
const breakpoint = useBreakpointObserver({ xs: 375, sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1440 });
|
|
15
23
|
const [swiperInstance, setSwiperInstance] = useState(null);
|
|
16
24
|
useEffect(() => {
|
|
17
|
-
if (trackRef.current && !swiperInstance) {
|
|
18
|
-
const
|
|
19
|
-
(typeof slidesPerView === "number" ? slidesPerView : slidesPerView.xl ?? 1);
|
|
25
|
+
if (trackRef.current && containerRef.current && !swiperInstance) {
|
|
26
|
+
const { current } = containerRef;
|
|
20
27
|
const swiper = new Swiper(trackRef.current, {
|
|
21
28
|
modules: [Autoplay, Navigation, Pagination],
|
|
22
|
-
slidesPerView:
|
|
29
|
+
slidesPerView: 1,
|
|
30
|
+
breakpoints: {
|
|
31
|
+
375: {
|
|
32
|
+
slidesPerView: slidesPerView.xs ?? 1,
|
|
33
|
+
},
|
|
34
|
+
576: {
|
|
35
|
+
slidesPerView: slidesPerView.sm ?? 1,
|
|
36
|
+
},
|
|
37
|
+
768: {
|
|
38
|
+
slidesPerView: slidesPerView.md ?? 1,
|
|
39
|
+
},
|
|
40
|
+
992: {
|
|
41
|
+
slidesPerView: slidesPerView.lg ?? 1,
|
|
42
|
+
},
|
|
43
|
+
1200: {
|
|
44
|
+
slidesPerView: slidesPerView.xl ?? 1,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
23
47
|
spaceBetween,
|
|
24
48
|
loop,
|
|
49
|
+
mousewheel: true,
|
|
25
50
|
navigation: hasNavigation
|
|
26
51
|
? {
|
|
27
|
-
nextEl: ".ga-ds-carousel__button--next",
|
|
28
|
-
prevEl: ".ga-ds-carousel__button--prev",
|
|
52
|
+
nextEl: current.querySelector(".ga-ds-carousel__button--next"),
|
|
53
|
+
prevEl: current.querySelector(".ga-ds-carousel__button--prev"),
|
|
29
54
|
}
|
|
30
55
|
: false,
|
|
31
56
|
pagination: hasPagination
|
|
32
57
|
? {
|
|
33
|
-
el: ".ga-ds-carousel__dots",
|
|
58
|
+
el: current.querySelector(".ga-ds-carousel__dots"),
|
|
34
59
|
clickable: pagination ? pagination.clickable : false,
|
|
35
60
|
bulletClass: "ga-ds-carousel__dot",
|
|
36
61
|
bulletActiveClass: "ga-ds-carousel__dot--active",
|
|
@@ -39,19 +64,8 @@ export const CarouselSwiper = (props) => {
|
|
|
39
64
|
});
|
|
40
65
|
setSwiperInstance(swiper);
|
|
41
66
|
}
|
|
42
|
-
}, [
|
|
43
|
-
|
|
44
|
-
slidesPerView,
|
|
45
|
-
spaceBetween,
|
|
46
|
-
navigation,
|
|
47
|
-
pagination,
|
|
48
|
-
hasNavigation,
|
|
49
|
-
hasPagination,
|
|
50
|
-
loop,
|
|
51
|
-
trackRef,
|
|
52
|
-
swiperInstance,
|
|
53
|
-
]);
|
|
54
|
-
return (_jsxs("div", { className: "ga-carousel-swiper", children: [_jsx("div", { className: "swiper", ref: trackRef, children: _jsx("div", { className: "swiper-wrapper", children: slides.map((slide, index) => (_jsx("div", { className: "swiper-slide", children: slide }, index))) }) }), _jsxs("div", { className: "ga-ds-carousel__navigation", children: [_jsx("div", { className: "ga-ds-carousel__dots" }), _jsx(CarouselNavigation, {})] })] }));
|
|
67
|
+
}, [slidesPerView, spaceBetween, navigation, pagination, hasNavigation, hasPagination, loop, trackRef, swiperInstance]);
|
|
68
|
+
return (_jsxs("div", { className: `ga-carousel-swiper ${classes.join(" ")}`, ref: containerRef, children: [_jsx("div", { className: "swiper", ref: trackRef, children: _jsx("div", { className: "swiper-wrapper", children: slides.map((slide, index) => (_jsx("div", { className: "swiper-slide", children: slide }, index))) }) }), hasNavigation || hasPagination ? (_jsxs("div", { className: "ga-ds-carousel__navigation", children: [hasPagination && _jsx("div", { className: "ga-ds-carousel__dots" }), hasNavigation && _jsx(CarouselNavigation, {})] })) : null] }));
|
|
55
69
|
}
|
|
56
70
|
return _jsx("div", { children: "Swiper library is not loaded." });
|
|
57
71
|
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { CarouselSwiper } from "../organisms/Carousel/CarouselSwiper"
|
|
2
2
|
import { useReactAdapter } from "../hooks/useReactAdaptater"
|
|
3
3
|
import { NativeChildWrapper } from "./utils/native-child-wrapper"
|
|
4
|
+
import Swiper from "swiper"
|
|
5
|
+
import * as modules from "swiper/modules"
|
|
6
|
+
;(window as any).Swiper = {
|
|
7
|
+
instance: Swiper,
|
|
8
|
+
modules,
|
|
9
|
+
}
|
|
10
|
+
import "swiper/css"
|
|
11
|
+
import "swiper/css/autoplay"
|
|
4
12
|
const { createElement, createRoot } = useReactAdapter()
|
|
5
13
|
|
|
6
14
|
export function HydrateCarousel(islands: NodeListOf<Element> | null) {
|
|
7
|
-
console.log("HydrateCarousel called with islands:", islands)
|
|
8
15
|
islands?.forEach((carousel) => {
|
|
9
16
|
const Component = CarouselSwiper
|
|
10
17
|
if (!Component) return
|
|
@@ -1,51 +1,74 @@
|
|
|
1
1
|
import { useReactAdapter } from "../../hooks/useReactAdaptater"
|
|
2
|
-
import { useBreakpointObserver } from "../../hooks/useBreakPointObserver"
|
|
3
2
|
import { CarouselProps } from "./Carousel.types"
|
|
4
3
|
import { Button } from "../../atoms/atoms"
|
|
4
|
+
import Swiper from "swiper"
|
|
5
|
+
import { Autoplay, Navigation, Pagination } from "swiper/modules"
|
|
5
6
|
|
|
6
7
|
export const CarouselSwiper = (props: CarouselProps) => {
|
|
7
8
|
const {
|
|
8
9
|
children,
|
|
9
10
|
slidesPerView: slidesPerViewDefault,
|
|
10
|
-
spaceBetween =
|
|
11
|
+
spaceBetween = 48,
|
|
11
12
|
navigation,
|
|
12
13
|
pagination,
|
|
13
|
-
context,
|
|
14
14
|
hasPagination,
|
|
15
15
|
hasNavigation,
|
|
16
16
|
loop = false,
|
|
17
17
|
} = props
|
|
18
|
-
|
|
19
|
-
const
|
|
18
|
+
|
|
19
|
+
const classes = ["ga-ds-carousel"]
|
|
20
|
+
|
|
21
|
+
if (props.extraClassNames) {
|
|
22
|
+
if (typeof props.extraClassNames === "string") {
|
|
23
|
+
classes.push(props.extraClassNames)
|
|
24
|
+
} else {
|
|
25
|
+
classes.push(...props.extraClassNames)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
20
28
|
if (Swiper) {
|
|
21
29
|
const slidesPerView = { xs: 1, ...slidesPerViewDefault }
|
|
22
30
|
const { useEffect, useState, useRef, Children } = useReactAdapter()
|
|
23
31
|
const trackRef = useRef<HTMLDivElement>(null)
|
|
32
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
24
33
|
const slides = Children.toArray(children)
|
|
25
34
|
|
|
26
|
-
const breakpoint = useBreakpointObserver({ xs: 375, sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1440 })
|
|
27
35
|
const [swiperInstance, setSwiperInstance] = useState<any>(null)
|
|
28
36
|
|
|
29
37
|
useEffect(() => {
|
|
30
|
-
if (trackRef.current && !swiperInstance) {
|
|
31
|
-
const
|
|
32
|
-
(slidesPerView as Record<string, number>)[breakpoint] ??
|
|
33
|
-
(typeof slidesPerView === "number" ? slidesPerView : (slidesPerView as any).xl ?? 1)
|
|
34
|
-
|
|
38
|
+
if (trackRef.current && containerRef.current && !swiperInstance) {
|
|
39
|
+
const { current } = containerRef
|
|
35
40
|
const swiper = new Swiper(trackRef.current, {
|
|
36
41
|
modules: [Autoplay, Navigation, Pagination],
|
|
37
|
-
slidesPerView:
|
|
42
|
+
slidesPerView: 1,
|
|
43
|
+
breakpoints: {
|
|
44
|
+
375: {
|
|
45
|
+
slidesPerView: (slidesPerView as Record<string, number>).xs ?? 1,
|
|
46
|
+
},
|
|
47
|
+
576: {
|
|
48
|
+
slidesPerView: (slidesPerView as Record<string, number>).sm ?? 1,
|
|
49
|
+
},
|
|
50
|
+
768: {
|
|
51
|
+
slidesPerView: (slidesPerView as Record<string, number>).md ?? 1,
|
|
52
|
+
},
|
|
53
|
+
992: {
|
|
54
|
+
slidesPerView: (slidesPerView as Record<string, number>).lg ?? 1,
|
|
55
|
+
},
|
|
56
|
+
1200: {
|
|
57
|
+
slidesPerView: (slidesPerView as Record<string, number>).xl ?? 1,
|
|
58
|
+
},
|
|
59
|
+
},
|
|
38
60
|
spaceBetween,
|
|
39
61
|
loop,
|
|
62
|
+
mousewheel: true,
|
|
40
63
|
navigation: hasNavigation
|
|
41
64
|
? {
|
|
42
|
-
nextEl: ".ga-ds-carousel__button--next",
|
|
43
|
-
prevEl: ".ga-ds-carousel__button--prev",
|
|
65
|
+
nextEl: current.querySelector(".ga-ds-carousel__button--next") as HTMLElement,
|
|
66
|
+
prevEl: current.querySelector(".ga-ds-carousel__button--prev") as HTMLElement,
|
|
44
67
|
}
|
|
45
68
|
: false,
|
|
46
69
|
pagination: hasPagination
|
|
47
70
|
? {
|
|
48
|
-
el: ".ga-ds-carousel__dots",
|
|
71
|
+
el: current.querySelector(".ga-ds-carousel__dots") as HTMLElement,
|
|
49
72
|
clickable: pagination ? pagination.clickable : false,
|
|
50
73
|
bulletClass: "ga-ds-carousel__dot",
|
|
51
74
|
bulletActiveClass: "ga-ds-carousel__dot--active",
|
|
@@ -55,21 +78,10 @@ export const CarouselSwiper = (props: CarouselProps) => {
|
|
|
55
78
|
|
|
56
79
|
setSwiperInstance(swiper)
|
|
57
80
|
}
|
|
58
|
-
}, [
|
|
59
|
-
breakpoint,
|
|
60
|
-
slidesPerView,
|
|
61
|
-
spaceBetween,
|
|
62
|
-
navigation,
|
|
63
|
-
pagination,
|
|
64
|
-
hasNavigation,
|
|
65
|
-
hasPagination,
|
|
66
|
-
loop,
|
|
67
|
-
trackRef,
|
|
68
|
-
swiperInstance,
|
|
69
|
-
])
|
|
81
|
+
}, [slidesPerView, spaceBetween, navigation, pagination, hasNavigation, hasPagination, loop, trackRef, swiperInstance])
|
|
70
82
|
|
|
71
83
|
return (
|
|
72
|
-
<div className=
|
|
84
|
+
<div className={`ga-carousel-swiper ${classes.join(" ")}`} ref={containerRef}>
|
|
73
85
|
<div className="swiper" ref={trackRef}>
|
|
74
86
|
<div className="swiper-wrapper">
|
|
75
87
|
{slides.map((slide, index) => (
|
|
@@ -79,10 +91,12 @@ export const CarouselSwiper = (props: CarouselProps) => {
|
|
|
79
91
|
))}
|
|
80
92
|
</div>
|
|
81
93
|
</div>
|
|
82
|
-
|
|
83
|
-
<div className="ga-ds-
|
|
84
|
-
|
|
85
|
-
|
|
94
|
+
{hasNavigation || hasPagination ? (
|
|
95
|
+
<div className="ga-ds-carousel__navigation">
|
|
96
|
+
{hasPagination && <div className="ga-ds-carousel__dots"></div>}
|
|
97
|
+
{hasNavigation && <CarouselNavigation />}
|
|
98
|
+
</div>
|
|
99
|
+
) : null}
|
|
86
100
|
</div>
|
|
87
101
|
)
|
|
88
102
|
}
|