@growth-angels/ds-core 1.25.4 → 2.0.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/hooks/useWindowSize.d.ts +4 -0
- package/dist/hooks/useWindowSize.js +22 -0
- package/dist/organisms/Carousel/Carousel.types.d.ts +1 -0
- package/dist/organisms/Carousel/CarouselSwiper.js +94 -56
- package/package.json +2 -2
- package/src/organisms/Carousel/Carousel.types.ts +1 -0
- package/src/organisms/Carousel/CarouselSwiper.tsx +119 -70
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { useReactAdapter } from "./useReactAdaptater";
|
|
2
|
+
export function useWindowSize() {
|
|
3
|
+
const React = useReactAdapter();
|
|
4
|
+
const [size, setSize] = React.useState({
|
|
5
|
+
width: null,
|
|
6
|
+
height: null,
|
|
7
|
+
});
|
|
8
|
+
React.useLayoutEffect(() => {
|
|
9
|
+
const handleResize = () => {
|
|
10
|
+
setSize({
|
|
11
|
+
width: window.innerWidth,
|
|
12
|
+
height: window.innerHeight,
|
|
13
|
+
});
|
|
14
|
+
};
|
|
15
|
+
handleResize();
|
|
16
|
+
window.addEventListener("resize", handleResize);
|
|
17
|
+
return () => {
|
|
18
|
+
window.removeEventListener("resize", handleResize);
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
return size;
|
|
22
|
+
}
|
|
@@ -4,7 +4,7 @@ import { Button } from "../../atoms/atoms";
|
|
|
4
4
|
import Swiper from "swiper";
|
|
5
5
|
import { Autoplay, Navigation, Pagination } from "swiper/modules";
|
|
6
6
|
export const CarouselSwiper = (props) => {
|
|
7
|
-
const { children, slidesPerView: slidesPerViewDefault, spaceBetween = 48, navigation, pagination, hasPagination, hasNavigation, loop = false, autoplay, speed, } = props;
|
|
7
|
+
const { children, slidesPerView: slidesPerViewDefault, spaceBetween = 48, navigation, pagination, hasPagination, hasNavigation, loop = false, autoplay, speed, loopOnMobile = false, } = props;
|
|
8
8
|
const classes = ["ga-ds-carousel"];
|
|
9
9
|
if (props.extraClassNames) {
|
|
10
10
|
if (typeof props.extraClassNames === "string") {
|
|
@@ -14,64 +14,102 @@ export const CarouselSwiper = (props) => {
|
|
|
14
14
|
classes.push(...props.extraClassNames);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
17
|
+
const slidesPerView = { xs: 1, ...slidesPerViewDefault };
|
|
18
|
+
const { useLayoutEffect, useRef, Children } = useReactAdapter();
|
|
19
|
+
const trackRef = useRef(null);
|
|
20
|
+
const containerRef = useRef(null);
|
|
21
|
+
const slides = Children.toArray(children);
|
|
22
|
+
const initSwiper = (current, track, windowWidth) => {
|
|
23
|
+
if (!current || !track) {
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
return new Swiper(track, loopOnMobile && windowWidth && windowWidth < 768
|
|
27
|
+
? {
|
|
28
|
+
modules: [Autoplay],
|
|
29
|
+
slidesPerView: "auto",
|
|
30
|
+
spaceBetween: 80,
|
|
31
|
+
loop: true,
|
|
32
|
+
speed: 5000,
|
|
33
|
+
allowTouchMove: false,
|
|
34
|
+
autoplay: {
|
|
35
|
+
delay: 1,
|
|
36
|
+
disableOnInteraction: false,
|
|
37
|
+
},
|
|
38
|
+
}
|
|
39
|
+
: {
|
|
40
|
+
modules: [Autoplay, Navigation, Pagination],
|
|
41
|
+
slidesPerView: 1,
|
|
42
|
+
breakpoints: {
|
|
43
|
+
375: {
|
|
44
|
+
slidesPerView: slidesPerView.xs ?? 1,
|
|
45
|
+
},
|
|
46
|
+
576: {
|
|
47
|
+
slidesPerView: slidesPerView.sm ?? 1,
|
|
48
|
+
},
|
|
49
|
+
768: {
|
|
50
|
+
slidesPerView: slidesPerView.md ?? 1,
|
|
46
51
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
: false,
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
52
|
+
992: {
|
|
53
|
+
slidesPerView: slidesPerView.lg ?? 1,
|
|
54
|
+
},
|
|
55
|
+
1200: {
|
|
56
|
+
slidesPerView: slidesPerView.xl ?? 1,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
spaceBetween,
|
|
60
|
+
loop,
|
|
61
|
+
mousewheel: true,
|
|
62
|
+
navigation: hasNavigation
|
|
63
|
+
? {
|
|
64
|
+
nextEl: current.querySelector(".ga-ds-carousel__button--next"),
|
|
65
|
+
prevEl: current.querySelector(".ga-ds-carousel__button--prev"),
|
|
66
|
+
}
|
|
67
|
+
: false,
|
|
68
|
+
pagination: hasPagination
|
|
69
|
+
? {
|
|
70
|
+
el: current.querySelector(".ga-ds-carousel__dots"),
|
|
71
|
+
clickable: pagination ? pagination.clickable : false,
|
|
72
|
+
bulletClass: "ga-ds-carousel__dot",
|
|
73
|
+
bulletActiveClass: "ga-ds-carousel__dot--active",
|
|
74
|
+
}
|
|
75
|
+
: false,
|
|
76
|
+
autoplay: autoplay
|
|
77
|
+
? {
|
|
78
|
+
delay: autoplay.delay || 5000,
|
|
79
|
+
disableOnInteraction: autoplay.disableOnInteraction ?? false,
|
|
80
|
+
}
|
|
81
|
+
: false,
|
|
82
|
+
speed: speed || 300,
|
|
83
|
+
});
|
|
84
|
+
};
|
|
85
|
+
useLayoutEffect(() => {
|
|
86
|
+
if (!trackRef.current || !containerRef.current) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
const container = containerRef.current;
|
|
90
|
+
let swiper = initSwiper(container, trackRef.current, window.innerWidth);
|
|
91
|
+
let wasMobile = window.innerWidth < 768;
|
|
92
|
+
if (!loopOnMobile) {
|
|
93
|
+
return () => swiper?.destroy(true, true);
|
|
94
|
+
}
|
|
95
|
+
const handleResize = () => {
|
|
96
|
+
const isMobile = window.innerWidth < 768;
|
|
97
|
+
if (isMobile !== wasMobile) {
|
|
98
|
+
swiper?.destroy(true, true);
|
|
99
|
+
swiper = initSwiper(container, trackRef.current, window.innerWidth);
|
|
100
|
+
wasMobile = isMobile;
|
|
70
101
|
}
|
|
71
|
-
}
|
|
72
|
-
|
|
102
|
+
};
|
|
103
|
+
window.addEventListener("resize", handleResize);
|
|
104
|
+
return () => {
|
|
105
|
+
window.removeEventListener("resize", handleResize);
|
|
106
|
+
swiper?.destroy(true, true);
|
|
107
|
+
};
|
|
108
|
+
}, []);
|
|
109
|
+
if (!Swiper) {
|
|
110
|
+
return _jsx("div", { children: "Swiper library is not loaded." });
|
|
73
111
|
}
|
|
74
|
-
return _jsx("div", { children: "
|
|
112
|
+
return (_jsxs("div", { className: `ga-carousel-swiper ${loopOnMobile ? "ga-carousel-swiper--loop-on-mobile" : ""} ${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] }));
|
|
75
113
|
};
|
|
76
114
|
const CarouselNavigation = () => {
|
|
77
115
|
return (_jsxs("div", { className: `ga-ds-carousel__arrows`, children: [_jsx(Button, { extraClassNames: ["ga-ds-carousel__button", "ga-ds-carousel__button--prev"], icon: "chevron-left", ariaLabel: "Slide pr\u00E9c\u00E9dente" }), _jsx(Button, { extraClassNames: ["ga-ds-carousel__button", "ga-ds-carousel__button--next"], icon: "chevron-right", ariaLabel: "Slide suivante" })] }));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@growth-angels/ds-core",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Design system by Growth Angels",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"private": false,
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"build-storybook": "storybook build"
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"@growth-angels/foundation": "1.5.
|
|
43
|
+
"@growth-angels/foundation": "1.5.1",
|
|
44
44
|
"swiper": "^12.0.3"
|
|
45
45
|
},
|
|
46
46
|
"peerDependencies": {
|
|
@@ -16,6 +16,7 @@ export const CarouselSwiper = (props: CarouselProps) => {
|
|
|
16
16
|
loop = false,
|
|
17
17
|
autoplay,
|
|
18
18
|
speed,
|
|
19
|
+
loopOnMobile = false,
|
|
19
20
|
} = props
|
|
20
21
|
|
|
21
22
|
const classes = ["ga-ds-carousel"]
|
|
@@ -27,86 +28,134 @@ export const CarouselSwiper = (props: CarouselProps) => {
|
|
|
27
28
|
classes.push(...props.extraClassNames)
|
|
28
29
|
}
|
|
29
30
|
}
|
|
30
|
-
if (Swiper) {
|
|
31
|
-
const slidesPerView = { xs: 1, ...slidesPerViewDefault }
|
|
32
|
-
const { useEffect, useState, useRef, Children } = useReactAdapter()
|
|
33
|
-
const trackRef = useRef<HTMLDivElement>(null)
|
|
34
|
-
const containerRef = useRef<HTMLDivElement>(null)
|
|
35
|
-
const slides = Children.toArray(children)
|
|
36
31
|
|
|
37
|
-
|
|
32
|
+
const slidesPerView = { xs: 1, ...slidesPerViewDefault }
|
|
33
|
+
const { useLayoutEffect, useRef, Children } = useReactAdapter()
|
|
34
|
+
const trackRef = useRef<HTMLDivElement>(null)
|
|
35
|
+
const containerRef = useRef<HTMLDivElement>(null)
|
|
36
|
+
const slides = Children.toArray(children)
|
|
38
37
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
slidesPerView: (slidesPerView as Record<string, number>).lg ?? 1,
|
|
38
|
+
const initSwiper = (current: HTMLElement | null, track: HTMLElement | null, windowWidth: number | null) => {
|
|
39
|
+
if (!current || !track) {
|
|
40
|
+
return null
|
|
41
|
+
}
|
|
42
|
+
return new Swiper(
|
|
43
|
+
track,
|
|
44
|
+
loopOnMobile && windowWidth && windowWidth < 768
|
|
45
|
+
? {
|
|
46
|
+
modules: [Autoplay],
|
|
47
|
+
slidesPerView: "auto",
|
|
48
|
+
spaceBetween: 80,
|
|
49
|
+
loop: true,
|
|
50
|
+
speed: 5000,
|
|
51
|
+
allowTouchMove: false,
|
|
52
|
+
autoplay: {
|
|
53
|
+
delay: 1,
|
|
54
|
+
disableOnInteraction: false,
|
|
57
55
|
},
|
|
58
|
-
|
|
59
|
-
|
|
56
|
+
}
|
|
57
|
+
: {
|
|
58
|
+
modules: [Autoplay, Navigation, Pagination],
|
|
59
|
+
slidesPerView: 1,
|
|
60
|
+
breakpoints: {
|
|
61
|
+
375: {
|
|
62
|
+
slidesPerView: (slidesPerView as Record<string, number>).xs ?? 1,
|
|
63
|
+
},
|
|
64
|
+
576: {
|
|
65
|
+
slidesPerView: (slidesPerView as Record<string, number>).sm ?? 1,
|
|
66
|
+
},
|
|
67
|
+
768: {
|
|
68
|
+
slidesPerView: (slidesPerView as Record<string, number>).md ?? 1,
|
|
69
|
+
},
|
|
70
|
+
992: {
|
|
71
|
+
slidesPerView: (slidesPerView as Record<string, number>).lg ?? 1,
|
|
72
|
+
},
|
|
73
|
+
1200: {
|
|
74
|
+
slidesPerView: (slidesPerView as Record<string, number>).xl ?? 1,
|
|
75
|
+
},
|
|
60
76
|
},
|
|
77
|
+
spaceBetween,
|
|
78
|
+
loop,
|
|
79
|
+
mousewheel: true,
|
|
80
|
+
navigation: hasNavigation
|
|
81
|
+
? {
|
|
82
|
+
nextEl: current.querySelector(".ga-ds-carousel__button--next") as HTMLElement,
|
|
83
|
+
prevEl: current.querySelector(".ga-ds-carousel__button--prev") as HTMLElement,
|
|
84
|
+
}
|
|
85
|
+
: false,
|
|
86
|
+
pagination: hasPagination
|
|
87
|
+
? {
|
|
88
|
+
el: current.querySelector(".ga-ds-carousel__dots") as HTMLElement,
|
|
89
|
+
clickable: pagination ? pagination.clickable : false,
|
|
90
|
+
bulletClass: "ga-ds-carousel__dot",
|
|
91
|
+
bulletActiveClass: "ga-ds-carousel__dot--active",
|
|
92
|
+
}
|
|
93
|
+
: false,
|
|
94
|
+
autoplay: autoplay
|
|
95
|
+
? {
|
|
96
|
+
delay: autoplay.delay || 5000,
|
|
97
|
+
disableOnInteraction: autoplay.disableOnInteraction ?? false,
|
|
98
|
+
}
|
|
99
|
+
: false,
|
|
100
|
+
speed: speed || 300,
|
|
61
101
|
},
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
bulletClass: "ga-ds-carousel__dot",
|
|
76
|
-
bulletActiveClass: "ga-ds-carousel__dot--active",
|
|
77
|
-
}
|
|
78
|
-
: false,
|
|
79
|
-
autoplay: autoplay
|
|
80
|
-
? { delay: autoplay.delay || 5000, disableOnInteraction: autoplay.disableOnInteraction ?? false }
|
|
81
|
-
: false,
|
|
82
|
-
speed: speed || 300,
|
|
83
|
-
})
|
|
102
|
+
)
|
|
103
|
+
}
|
|
104
|
+
useLayoutEffect(() => {
|
|
105
|
+
if (!trackRef.current || !containerRef.current) {
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
const container = containerRef.current
|
|
109
|
+
let swiper = initSwiper(container, trackRef.current, window.innerWidth)
|
|
110
|
+
let wasMobile = window.innerWidth < 768
|
|
111
|
+
|
|
112
|
+
if (!loopOnMobile) {
|
|
113
|
+
return () => swiper?.destroy(true, true)
|
|
114
|
+
}
|
|
84
115
|
|
|
85
|
-
|
|
116
|
+
const handleResize = () => {
|
|
117
|
+
const isMobile = window.innerWidth < 768
|
|
118
|
+
if (isMobile !== wasMobile) {
|
|
119
|
+
swiper?.destroy(true, true)
|
|
120
|
+
swiper = initSwiper(container, trackRef.current, window.innerWidth)
|
|
121
|
+
wasMobile = isMobile
|
|
86
122
|
}
|
|
87
|
-
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
window.addEventListener("resize", handleResize)
|
|
88
126
|
|
|
89
|
-
return (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
127
|
+
return () => {
|
|
128
|
+
window.removeEventListener("resize", handleResize)
|
|
129
|
+
swiper?.destroy(true, true)
|
|
130
|
+
}
|
|
131
|
+
}, [])
|
|
132
|
+
|
|
133
|
+
if (!Swiper) {
|
|
134
|
+
return <div>Swiper library is not loaded.</div>
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return (
|
|
138
|
+
<div
|
|
139
|
+
className={`ga-carousel-swiper ${loopOnMobile ? "ga-carousel-swiper--loop-on-mobile" : ""} ${classes.join(" ")}`}
|
|
140
|
+
ref={containerRef}
|
|
141
|
+
>
|
|
142
|
+
<div className="swiper" ref={trackRef}>
|
|
143
|
+
<div className="swiper-wrapper">
|
|
144
|
+
{slides.map((slide, index) => (
|
|
145
|
+
<div className="swiper-slide" key={index}>
|
|
146
|
+
{slide}
|
|
147
|
+
</div>
|
|
148
|
+
))}
|
|
99
149
|
</div>
|
|
100
|
-
{hasNavigation || hasPagination ? (
|
|
101
|
-
<div className="ga-ds-carousel__navigation">
|
|
102
|
-
{hasPagination && <div className="ga-ds-carousel__dots"></div>}
|
|
103
|
-
{hasNavigation && <CarouselNavigation />}
|
|
104
|
-
</div>
|
|
105
|
-
) : null}
|
|
106
150
|
</div>
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
151
|
+
{hasNavigation || hasPagination ? (
|
|
152
|
+
<div className="ga-ds-carousel__navigation">
|
|
153
|
+
{hasPagination && <div className="ga-ds-carousel__dots"></div>}
|
|
154
|
+
{hasNavigation && <CarouselNavigation />}
|
|
155
|
+
</div>
|
|
156
|
+
) : null}
|
|
157
|
+
</div>
|
|
158
|
+
)
|
|
110
159
|
}
|
|
111
160
|
|
|
112
161
|
const CarouselNavigation = () => {
|