@growth-angels/ds-core 1.16.3 → 1.17.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,12 +1,12 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Carousel } from "../organisms/Carousel/Carousel";
2
+ import { CarouselSwiper } from "../organisms/Carousel/CarouselSwiper";
3
3
  import { useReactAdapter } from "../hooks/useReactAdaptater";
4
4
  import { NativeChildWrapper } from "./utils/native-child-wrapper";
5
- const { createElement, createRoot, useRef, useEffect } = useReactAdapter();
5
+ const { createElement, createRoot } = useReactAdapter();
6
6
  export function HydrateCarousel(islands) {
7
7
  console.log("HydrateCarousel called with islands:", islands);
8
8
  islands?.forEach((carousel) => {
9
- const Component = Carousel;
9
+ const Component = CarouselSwiper;
10
10
  if (!Component)
11
11
  return;
12
12
  const props = carousel.getAttribute("data-props");
@@ -6,3 +6,4 @@ type Story = StoryObj<typeof Carousel>;
6
6
  export declare const Primary: Story;
7
7
  export declare const LoopingCarousel: Story;
8
8
  export declare const NotOverflowing: Story;
9
+ export declare const SwiperCarousel: Story;
@@ -60,3 +60,27 @@ export const NotOverflowing = {
60
60
  hasPagination: true,
61
61
  },
62
62
  };
63
+ export const SwiperCarousel = {
64
+ args: {
65
+ context: "wp-editor",
66
+ children: [
67
+ _jsx("div", { children: "Slide 1" }),
68
+ _jsx("div", { children: "Slide 2" }),
69
+ _jsx("div", { children: "Slide 3" }),
70
+ _jsx("div", { children: "Slide 4" }),
71
+ _jsx("div", { children: "Slide 5" }),
72
+ _jsx("div", { children: "Slide 6" }),
73
+ _jsx("div", { children: "Slide 7" }),
74
+ ],
75
+ slidesPerView: { sm: 1, md: 2, lg: 3, xl: 4 },
76
+ spaceBetween: 16,
77
+ pagination: {
78
+ clickable: true,
79
+ },
80
+ navigation: {
81
+ positionY: "bottom",
82
+ },
83
+ hasNavigation: true,
84
+ hasPagination: true,
85
+ },
86
+ };
@@ -0,0 +1,2 @@
1
+ import { CarouselProps } from "./Carousel.types";
2
+ export declare const CarouselSwiper: (props: CarouselProps) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,60 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useReactAdapter } from "../../hooks/useReactAdaptater";
3
+ import { useBreakpointObserver } from "../../hooks/useBreakPointObserver";
4
+ import { Button } from "../../atoms/atoms";
5
+ export const CarouselSwiper = (props) => {
6
+ const { children, slidesPerView: slidesPerViewDefault, spaceBetween = 20, navigation, pagination, context, hasPagination, hasNavigation, loop = false, } = props;
7
+ const Swiper = window.Swiper.instance;
8
+ const { Autoplay, Navigation, Pagination } = window.Swiper.modules;
9
+ if (Swiper) {
10
+ const slidesPerView = { xs: 1, ...slidesPerViewDefault };
11
+ const { useEffect, useState, useRef, Children } = useReactAdapter();
12
+ const trackRef = useRef(null);
13
+ const slides = Children.toArray(children);
14
+ const breakpoint = useBreakpointObserver({ xs: 375, sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1440 });
15
+ const [swiperInstance, setSwiperInstance] = useState(null);
16
+ useEffect(() => {
17
+ if (trackRef.current && !swiperInstance) {
18
+ const currentSlidesPerView = slidesPerView[breakpoint] ??
19
+ (typeof slidesPerView === "number" ? slidesPerView : slidesPerView.xl ?? 1);
20
+ const swiper = new Swiper(trackRef.current, {
21
+ modules: [Autoplay, Navigation, Pagination],
22
+ slidesPerView: currentSlidesPerView,
23
+ spaceBetween,
24
+ loop,
25
+ navigation: hasNavigation
26
+ ? {
27
+ nextEl: ".ga-ds-carousel__button--next",
28
+ prevEl: ".ga-ds-carousel__button--prev",
29
+ }
30
+ : false,
31
+ pagination: hasPagination
32
+ ? {
33
+ el: ".ga-ds-carousel__dots",
34
+ clickable: pagination ? pagination.clickable : false,
35
+ bulletClass: "ga-ds-carousel__dot",
36
+ bulletActiveClass: "ga-ds-carousel__dot--active",
37
+ }
38
+ : false,
39
+ });
40
+ setSwiperInstance(swiper);
41
+ }
42
+ }, [
43
+ breakpoint,
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, {})] })] }));
55
+ }
56
+ return _jsx("div", { children: "Swiper library is not loaded." });
57
+ };
58
+ const CarouselNavigation = () => {
59
+ return (_jsxs("div", { className: `ga-ds-carousel__arrows`, children: [_jsx(Button, { extraClassNames: ["ga-ds-carousel__button", "ga-ds-carousel__button--prev"], icon: "chevron-left" }), _jsx(Button, { extraClassNames: ["ga-ds-carousel__button", "ga-ds-carousel__button--next"], icon: "chevron-right" })] }));
60
+ };
@@ -0,0 +1,6 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite";
2
+ import { CarouselSwiper } from "./CarouselSwiper";
3
+ declare const meta: Meta<typeof CarouselSwiper>;
4
+ export default meta;
5
+ type Story = StoryObj<typeof CarouselSwiper>;
6
+ export declare const Primary: Story;
@@ -0,0 +1,31 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { CarouselSwiper } from "./CarouselSwiper";
3
+ const meta = {
4
+ title: "Organisms/CarouselSwiper",
5
+ component: CarouselSwiper,
6
+ tags: ["autodocs"],
7
+ };
8
+ export default meta;
9
+ export const Primary = {
10
+ args: {
11
+ children: [
12
+ _jsx("div", { children: "Slide 1" }),
13
+ _jsx("div", { children: "Slide 2" }),
14
+ _jsx("div", { children: "Slide 3" }),
15
+ _jsx("div", { children: "Slide 4" }),
16
+ _jsx("div", { children: "Slide 5" }),
17
+ _jsx("div", { children: "Slide 6" }),
18
+ _jsx("div", { children: "Slide 7" }),
19
+ ],
20
+ slidesPerView: { sm: 1, md: 2, lg: 3, xl: 4 },
21
+ spaceBetween: 16,
22
+ pagination: {
23
+ clickable: true,
24
+ },
25
+ navigation: {
26
+ positionY: "bottom",
27
+ },
28
+ hasNavigation: true,
29
+ hasPagination: true,
30
+ },
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growth-angels/ds-core",
3
- "version": "1.16.3",
3
+ "version": "1.17.0",
4
4
  "description": "Design system by Growth Angels",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -37,7 +37,8 @@
37
37
  "build-storybook": "storybook build"
38
38
  },
39
39
  "dependencies": {
40
- "@growth-angels/foundation": "^1.4.1"
40
+ "@growth-angels/foundation": "^1.4.1",
41
+ "swiper": "^12.0.3"
41
42
  },
42
43
  "peerDependencies": {
43
44
  "react": ">=18"
@@ -1,12 +1,12 @@
1
- import { Carousel } from "../organisms/Carousel/Carousel"
1
+ import { CarouselSwiper } from "../organisms/Carousel/CarouselSwiper"
2
2
  import { useReactAdapter } from "../hooks/useReactAdaptater"
3
3
  import { NativeChildWrapper } from "./utils/native-child-wrapper"
4
- const { createElement, createRoot, useRef, useEffect } = useReactAdapter()
4
+ const { createElement, createRoot } = useReactAdapter()
5
5
 
6
6
  export function HydrateCarousel(islands: NodeListOf<Element> | null) {
7
7
  console.log("HydrateCarousel called with islands:", islands)
8
8
  islands?.forEach((carousel) => {
9
- const Component = Carousel
9
+ const Component = CarouselSwiper
10
10
  if (!Component) return
11
11
  const props = carousel.getAttribute("data-props")
12
12
  carousel.removeAttribute("data-props")
@@ -50,6 +50,7 @@
50
50
 
51
51
  &__arrows {
52
52
  display: flex;
53
+ gap: 0.8rem;
53
54
 
54
55
  &.left {
55
56
  justify-content: flex-start;
@@ -66,3 +66,28 @@ export const NotOverflowing: Story = {
66
66
  hasPagination: true,
67
67
  },
68
68
  }
69
+
70
+ export const SwiperCarousel: Story = {
71
+ args: {
72
+ context: "wp-editor",
73
+ children: [
74
+ <div>Slide 1</div>,
75
+ <div>Slide 2</div>,
76
+ <div>Slide 3</div>,
77
+ <div>Slide 4</div>,
78
+ <div>Slide 5</div>,
79
+ <div>Slide 6</div>,
80
+ <div>Slide 7</div>,
81
+ ],
82
+ slidesPerView: { sm: 1, md: 2, lg: 3, xl: 4 },
83
+ spaceBetween: 16,
84
+ pagination: {
85
+ clickable: true,
86
+ },
87
+ navigation: {
88
+ positionY: "bottom",
89
+ },
90
+ hasNavigation: true,
91
+ hasPagination: true,
92
+ },
93
+ }
@@ -0,0 +1,35 @@
1
+ import type { Meta, StoryObj } from "@storybook/react-vite"
2
+ import { CarouselSwiper } from "./CarouselSwiper"
3
+
4
+ const meta: Meta<typeof CarouselSwiper> = {
5
+ title: "Organisms/CarouselSwiper",
6
+ component: CarouselSwiper,
7
+ tags: ["autodocs"],
8
+ }
9
+
10
+ export default meta
11
+ type Story = StoryObj<typeof CarouselSwiper>
12
+
13
+ export const Primary: Story = {
14
+ args: {
15
+ children: [
16
+ <div>Slide 1</div>,
17
+ <div>Slide 2</div>,
18
+ <div>Slide 3</div>,
19
+ <div>Slide 4</div>,
20
+ <div>Slide 5</div>,
21
+ <div>Slide 6</div>,
22
+ <div>Slide 7</div>,
23
+ ],
24
+ slidesPerView: { sm: 1, md: 2, lg: 3, xl: 4 },
25
+ spaceBetween: 16,
26
+ pagination: {
27
+ clickable: true,
28
+ },
29
+ navigation: {
30
+ positionY: "bottom",
31
+ },
32
+ hasNavigation: true,
33
+ hasPagination: true,
34
+ },
35
+ }
@@ -0,0 +1,99 @@
1
+ import { useReactAdapter } from "../../hooks/useReactAdaptater"
2
+ import { useBreakpointObserver } from "../../hooks/useBreakPointObserver"
3
+ import { CarouselProps } from "./Carousel.types"
4
+ import { Button } from "../../atoms/atoms"
5
+
6
+ export const CarouselSwiper = (props: CarouselProps) => {
7
+ const {
8
+ children,
9
+ slidesPerView: slidesPerViewDefault,
10
+ spaceBetween = 20,
11
+ navigation,
12
+ pagination,
13
+ context,
14
+ hasPagination,
15
+ hasNavigation,
16
+ loop = false,
17
+ } = props
18
+ const Swiper = (window as any).Swiper.instance
19
+ const { Autoplay, Navigation, Pagination } = (window as any).Swiper.modules
20
+ if (Swiper) {
21
+ const slidesPerView = { xs: 1, ...slidesPerViewDefault }
22
+ const { useEffect, useState, useRef, Children } = useReactAdapter()
23
+ const trackRef = useRef<HTMLDivElement>(null)
24
+ const slides = Children.toArray(children)
25
+
26
+ const breakpoint = useBreakpointObserver({ xs: 375, sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1440 })
27
+ const [swiperInstance, setSwiperInstance] = useState<any>(null)
28
+
29
+ useEffect(() => {
30
+ if (trackRef.current && !swiperInstance) {
31
+ const currentSlidesPerView =
32
+ (slidesPerView as Record<string, number>)[breakpoint] ??
33
+ (typeof slidesPerView === "number" ? slidesPerView : (slidesPerView as any).xl ?? 1)
34
+
35
+ const swiper = new Swiper(trackRef.current, {
36
+ modules: [Autoplay, Navigation, Pagination],
37
+ slidesPerView: currentSlidesPerView,
38
+ spaceBetween,
39
+ loop,
40
+ navigation: hasNavigation
41
+ ? {
42
+ nextEl: ".ga-ds-carousel__button--next",
43
+ prevEl: ".ga-ds-carousel__button--prev",
44
+ }
45
+ : false,
46
+ pagination: hasPagination
47
+ ? {
48
+ el: ".ga-ds-carousel__dots",
49
+ clickable: pagination ? pagination.clickable : false,
50
+ bulletClass: "ga-ds-carousel__dot",
51
+ bulletActiveClass: "ga-ds-carousel__dot--active",
52
+ }
53
+ : false,
54
+ })
55
+
56
+ setSwiperInstance(swiper)
57
+ }
58
+ }, [
59
+ breakpoint,
60
+ slidesPerView,
61
+ spaceBetween,
62
+ navigation,
63
+ pagination,
64
+ hasNavigation,
65
+ hasPagination,
66
+ loop,
67
+ trackRef,
68
+ swiperInstance,
69
+ ])
70
+
71
+ return (
72
+ <div className="ga-carousel-swiper">
73
+ <div className="swiper" ref={trackRef}>
74
+ <div className="swiper-wrapper">
75
+ {slides.map((slide, index) => (
76
+ <div className="swiper-slide" key={index}>
77
+ {slide}
78
+ </div>
79
+ ))}
80
+ </div>
81
+ </div>
82
+ <div className="ga-ds-carousel__navigation">
83
+ <div className="ga-ds-carousel__dots"></div>
84
+ <CarouselNavigation />
85
+ </div>
86
+ </div>
87
+ )
88
+ }
89
+ return <div>Swiper library is not loaded.</div>
90
+ }
91
+
92
+ const CarouselNavigation = () => {
93
+ return (
94
+ <div className={`ga-ds-carousel__arrows`}>
95
+ <Button extraClassNames={["ga-ds-carousel__button", "ga-ds-carousel__button--prev"]} icon="chevron-left" />
96
+ <Button extraClassNames={["ga-ds-carousel__button", "ga-ds-carousel__button--next"]} icon="chevron-right" />
97
+ </div>
98
+ )
99
+ }