@growth-angels/ds-core 1.12.10 → 1.14.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/useReactAdaptater.d.ts +1 -0
- package/dist/hooks/useReactAdaptater.js +2 -1
- package/dist/organisms/Carousel/Carousel.js +15 -2
- package/dist/organisms/Carousel/Carousel.types.d.ts +1 -0
- package/package.json +1 -1
- package/src/hooks/useReactAdaptater.ts +2 -1
- package/src/organisms/Carousel/Carousel.scss +0 -3
- package/src/organisms/Carousel/Carousel.tsx +18 -2
- package/src/organisms/Carousel/Carousel.types.ts +1 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
1
2
|
export const useReactAdapter = () => {
|
|
2
3
|
// Check if WordPress element is available (WordPress context)
|
|
3
4
|
if (typeof window !== 'undefined' && window.wp?.element) {
|
|
@@ -5,5 +6,5 @@ export const useReactAdapter = () => {
|
|
|
5
6
|
}
|
|
6
7
|
// Fallback for non-WordPress environments (Storybook, tests, SSR)
|
|
7
8
|
// This will bundle React only in non-WordPress builds
|
|
8
|
-
return
|
|
9
|
+
return React;
|
|
9
10
|
};
|
|
@@ -16,8 +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
|
|
20
|
-
const
|
|
19
|
+
const [isOverflowing, setIsOverflowing] = useState(false);
|
|
20
|
+
const displayNavigation = hasNavigation && (loop || isOverflowing);
|
|
21
|
+
const displayPagination = hasPagination && (loop || isOverflowing);
|
|
21
22
|
useEffect(() => {
|
|
22
23
|
if (loop) {
|
|
23
24
|
setIsAtStart(false);
|
|
@@ -73,6 +74,18 @@ export const Carousel = (props) => {
|
|
|
73
74
|
}
|
|
74
75
|
return () => track.removeEventListener("scroll", handleScroll);
|
|
75
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]);
|
|
76
89
|
const style = Object.fromEntries(Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`]));
|
|
77
90
|
const goPrev = () => {
|
|
78
91
|
if (!trackRef.current)
|
package/package.json
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import React from 'react'
|
|
1
2
|
// @ts-ignore - React types from window.wp.element
|
|
2
3
|
type ReactType = typeof import('react')
|
|
3
4
|
|
|
@@ -27,6 +28,6 @@ export const useReactAdapter = (): ExtendedReactType => {
|
|
|
27
28
|
|
|
28
29
|
// Fallback for non-WordPress environments (Storybook, tests, SSR)
|
|
29
30
|
// This will bundle React only in non-WordPress builds
|
|
30
|
-
return
|
|
31
|
+
return React as ExtendedReactType
|
|
31
32
|
}
|
|
32
33
|
|
|
@@ -29,9 +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)
|
|
32
33
|
|
|
33
|
-
const displayNavigation = hasNavigation
|
|
34
|
-
const displayPagination = hasPagination
|
|
34
|
+
const displayNavigation = hasNavigation && (loop || isOverflowing)
|
|
35
|
+
const displayPagination = hasPagination && (loop || isOverflowing)
|
|
35
36
|
|
|
36
37
|
useEffect(() => {
|
|
37
38
|
if (loop) {
|
|
@@ -94,6 +95,21 @@ export const Carousel = (props: CarouselProps) => {
|
|
|
94
95
|
return () => track.removeEventListener("scroll", handleScroll)
|
|
95
96
|
}, [slides.length, loop])
|
|
96
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
|
+
|
|
97
113
|
const style = Object.fromEntries(
|
|
98
114
|
Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`])
|
|
99
115
|
)
|