@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.
@@ -1,3 +1,4 @@
1
+ import React from 'react';
1
2
  type ReactType = typeof import('react');
2
3
  type ExtendedReactType = ReactType & {
3
4
  createRoot: (container: Element | DocumentFragment) => {
@@ -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 import('react');
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 displayNavigation = hasNavigation;
20
- const displayPagination = hasPagination;
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)
@@ -2,6 +2,7 @@ import { WordpressDefault } from "../../global.types";
2
2
  export type CarouselAttributes = {
3
3
  context?: 'wp-editor';
4
4
  slidesPerView?: {
5
+ xs?: number;
5
6
  sm: number;
6
7
  md: number;
7
8
  lg: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growth-angels/ds-core",
3
- "version": "1.12.10",
3
+ "version": "1.14.0",
4
4
  "description": "Design system by Growth Angels",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -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 import('react') as unknown as ExtendedReactType
31
+ return React as ExtendedReactType
31
32
  }
32
33
 
@@ -46,9 +46,6 @@
46
46
  flex: 0 0 auto;
47
47
  width: 100%;
48
48
  scroll-snap-align: start;
49
- width: 100%;
50
- max-width: 100%;
51
- min-width: 0;
52
49
  }
53
50
 
54
51
  &__arrows {
@@ -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
  )
@@ -3,6 +3,7 @@ import { WordpressDefault } from "../../global.types"
3
3
  export type CarouselAttributes = {
4
4
  context?: 'wp-editor'
5
5
  slidesPerView?: {
6
+ xs?: number
6
7
  sm: number
7
8
  md: number
8
9
  lg: number