@growth-angels/ds-core 1.8.3 → 1.9.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/organisms/Carousel/Carousel.js +17 -2
- package/dist/organisms/Carousel/Carousel.stories.d.ts +1 -0
- package/dist/organisms/Carousel/Carousel.stories.js +15 -0
- package/package.json +1 -1
- package/src/layout/Container/Container.scss +2 -1
- package/src/organisms/Carousel/Carousel.scss +1 -1
- package/src/organisms/Carousel/Carousel.stories.tsx +16 -0
- package/src/organisms/Carousel/Carousel.tsx +22 -3
|
@@ -16,6 +16,9 @@ export const Carousel = (props) => {
|
|
|
16
16
|
const [isAtEnd, setIsAtEnd] = useState(false);
|
|
17
17
|
const [isAtStart, setIsAtStart] = useState(true);
|
|
18
18
|
const [totalPages, setTotalPages] = useState(0);
|
|
19
|
+
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
20
|
+
const displayNavigation = hasNavigation && (loop || isOverflowing);
|
|
21
|
+
const displayPagination = hasPagination && (loop || isOverflowing);
|
|
19
22
|
useEffect(() => {
|
|
20
23
|
if (loop) {
|
|
21
24
|
setIsAtStart(false);
|
|
@@ -71,6 +74,18 @@ export const Carousel = (props) => {
|
|
|
71
74
|
}
|
|
72
75
|
return () => track.removeEventListener("scroll", handleScroll);
|
|
73
76
|
}, [slides.length, loop]);
|
|
77
|
+
// Check if the slides overflow the container
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const track = trackRef.current;
|
|
80
|
+
if (!track)
|
|
81
|
+
return;
|
|
82
|
+
const handleResize = () => {
|
|
83
|
+
setIsOverflowing(track.scrollWidth > track.clientWidth);
|
|
84
|
+
};
|
|
85
|
+
handleResize(); // Initial check
|
|
86
|
+
window.addEventListener("resize", handleResize);
|
|
87
|
+
return () => window.removeEventListener("resize", handleResize);
|
|
88
|
+
}, [loop]);
|
|
74
89
|
const style = Object.fromEntries(Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`]));
|
|
75
90
|
const goPrev = () => {
|
|
76
91
|
if (!trackRef.current)
|
|
@@ -148,13 +163,13 @@ export const Carousel = (props) => {
|
|
|
148
163
|
classes.push(...props.extraClassNames);
|
|
149
164
|
}
|
|
150
165
|
}
|
|
151
|
-
return (_jsxs("div", { className: classes.join(" "), style: style, children: [navigation?.positionY === "top" &&
|
|
166
|
+
return (_jsxs("div", { className: classes.join(" "), style: style, children: [navigation?.positionY === "top" && displayNavigation && (_jsx(CarouselNavigation, { goPrev: goPrev, goNext: goNext, isAtStart: isAtStart, isAtEnd: isAtEnd })), _jsx("div", { className: "ga-ds-carousel__track", ref: trackRef, style: {
|
|
152
167
|
"--ga-ds-space-between": `${spaceBetween / 10}rem`,
|
|
153
168
|
}, children: context === "wp-editor"
|
|
154
169
|
? children
|
|
155
170
|
: slides.map((child, index) => {
|
|
156
171
|
return (_jsx("div", { className: `ga-ds-carousel__slide ${index === activeDOMIndex ? "ga-ds-carousel__slide--active" : ""}`, children: child }, index));
|
|
157
|
-
}) }), _jsxs("div", { className: "ga-ds-carousel__navigation", children: [pagination &&
|
|
172
|
+
}) }), _jsxs("div", { className: "ga-ds-carousel__navigation", children: [pagination && displayPagination && (_jsx(CarouselPagination, { totalPages: totalPages, activeSlideIndex: activeSlideIndex, goTo: goTo, clickable: pagination.clickable })), displayNavigation && navigation?.positionY === "bottom" && (_jsx(CarouselNavigation, { goPrev: goPrev, goNext: goNext, isAtStart: isAtStart, isAtEnd: isAtEnd }))] })] }));
|
|
158
173
|
};
|
|
159
174
|
const CarouselNavigation = ({ goPrev, goNext, isAtStart, isAtEnd, }) => {
|
|
160
175
|
return (_jsxs("div", { className: `ga-ds-carousel__arrows`, children: [_jsx(Button, { extraClassNames: ["ga-ds-carousel__button", "ga-ds-carousel__button--prev"], icon: "chevron-left", onClick: goPrev, disabled: isAtStart }), _jsx(Button, { extraClassNames: ["ga-ds-carousel__button", "ga-ds-carousel__button--next"], icon: "chevron-right", onClick: goNext, disabled: isAtEnd })] }));
|
|
@@ -45,3 +45,18 @@ export const LoopingCarousel = {
|
|
|
45
45
|
hasPagination: true,
|
|
46
46
|
},
|
|
47
47
|
};
|
|
48
|
+
export const NotOverflowing = {
|
|
49
|
+
args: {
|
|
50
|
+
children: [_jsx("div", { children: "Item 1" }), _jsx("div", { children: "Item 2" }), _jsx("div", { children: "Item 3" }), _jsx("div", { children: "Item 4" })],
|
|
51
|
+
slidesPerView: { sm: 1, md: 2, lg: 2, xl: 4 },
|
|
52
|
+
spaceBetween: 12,
|
|
53
|
+
navigation: {
|
|
54
|
+
positionY: "top",
|
|
55
|
+
},
|
|
56
|
+
pagination: {
|
|
57
|
+
clickable: true,
|
|
58
|
+
},
|
|
59
|
+
hasNavigation: true,
|
|
60
|
+
hasPagination: true,
|
|
61
|
+
},
|
|
62
|
+
};
|
package/package.json
CHANGED
|
@@ -50,3 +50,19 @@ export const LoopingCarousel: Story = {
|
|
|
50
50
|
hasPagination: true,
|
|
51
51
|
},
|
|
52
52
|
}
|
|
53
|
+
|
|
54
|
+
export const NotOverflowing: Story = {
|
|
55
|
+
args: {
|
|
56
|
+
children: [<div>Item 1</div>, <div>Item 2</div>, <div>Item 3</div>, <div>Item 4</div>],
|
|
57
|
+
slidesPerView: { sm: 1, md: 2, lg: 2, xl: 4 },
|
|
58
|
+
spaceBetween: 12,
|
|
59
|
+
navigation: {
|
|
60
|
+
positionY: "top",
|
|
61
|
+
},
|
|
62
|
+
pagination: {
|
|
63
|
+
clickable: true,
|
|
64
|
+
},
|
|
65
|
+
hasNavigation: true,
|
|
66
|
+
hasPagination: true,
|
|
67
|
+
},
|
|
68
|
+
}
|
|
@@ -29,6 +29,10 @@ export const Carousel = (props: CarouselProps) => {
|
|
|
29
29
|
const [isAtEnd, setIsAtEnd] = useState(false)
|
|
30
30
|
const [isAtStart, setIsAtStart] = useState(true)
|
|
31
31
|
const [totalPages, setTotalPages] = useState(0)
|
|
32
|
+
const [isOverflowing, setIsOverflowing] = useState(false)
|
|
33
|
+
|
|
34
|
+
const displayNavigation = hasNavigation && (loop || isOverflowing)
|
|
35
|
+
const displayPagination = hasPagination && (loop || isOverflowing)
|
|
32
36
|
|
|
33
37
|
useEffect(() => {
|
|
34
38
|
if (loop) {
|
|
@@ -91,6 +95,21 @@ export const Carousel = (props: CarouselProps) => {
|
|
|
91
95
|
return () => track.removeEventListener("scroll", handleScroll)
|
|
92
96
|
}, [slides.length, loop])
|
|
93
97
|
|
|
98
|
+
// Check if the slides overflow the container
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
const track = trackRef.current
|
|
101
|
+
if (!track) return
|
|
102
|
+
|
|
103
|
+
const handleResize = () => {
|
|
104
|
+
setIsOverflowing(track.scrollWidth > track.clientWidth)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
handleResize() // Initial check
|
|
108
|
+
|
|
109
|
+
window.addEventListener("resize", handleResize)
|
|
110
|
+
return () => window.removeEventListener("resize", handleResize)
|
|
111
|
+
}, [loop])
|
|
112
|
+
|
|
94
113
|
const style = Object.fromEntries(
|
|
95
114
|
Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`])
|
|
96
115
|
)
|
|
@@ -176,7 +195,7 @@ export const Carousel = (props: CarouselProps) => {
|
|
|
176
195
|
|
|
177
196
|
return (
|
|
178
197
|
<div className={classes.join(" ")} style={style}>
|
|
179
|
-
{navigation?.positionY === "top" &&
|
|
198
|
+
{navigation?.positionY === "top" && displayNavigation && (
|
|
180
199
|
<CarouselNavigation goPrev={goPrev} goNext={goNext} isAtStart={isAtStart} isAtEnd={isAtEnd} />
|
|
181
200
|
)}
|
|
182
201
|
<div
|
|
@@ -203,7 +222,7 @@ export const Carousel = (props: CarouselProps) => {
|
|
|
203
222
|
</div>
|
|
204
223
|
|
|
205
224
|
<div className="ga-ds-carousel__navigation">
|
|
206
|
-
{pagination &&
|
|
225
|
+
{pagination && displayPagination && (
|
|
207
226
|
<CarouselPagination
|
|
208
227
|
totalPages={totalPages}
|
|
209
228
|
activeSlideIndex={activeSlideIndex}
|
|
@@ -211,7 +230,7 @@ export const Carousel = (props: CarouselProps) => {
|
|
|
211
230
|
clickable={pagination.clickable}
|
|
212
231
|
/>
|
|
213
232
|
)}
|
|
214
|
-
{
|
|
233
|
+
{displayNavigation && navigation?.positionY === "bottom" && (
|
|
215
234
|
<CarouselNavigation goPrev={goPrev} goNext={goNext} isAtStart={isAtStart} isAtEnd={isAtEnd} />
|
|
216
235
|
)}
|
|
217
236
|
</div>
|