@growth-angels/ds-core 1.15.1 → 1.16.1

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.
@@ -3,24 +3,27 @@ import { Button } from "../../atoms/atoms";
3
3
  import { useBreakpointObserver } from "../../hooks/useBreakPointObserver";
4
4
  import { useReactAdapter } from "../../hooks/useReactAdaptater";
5
5
  export const Carousel = (props) => {
6
- const { children, slidesPerView = { xs: 1, sm: 1, md: 2, lg: 3, xl: 4, xxl: 5 }, spaceBetween = 20, navigation, pagination, context, hasPagination, hasNavigation, loop = false, } = props;
6
+ const { children, slidesPerView: slidesPerViewDefault, spaceBetween = 20, navigation, pagination, context, hasPagination, hasNavigation, loop = false, } = props;
7
+ const slidesPerView = { xs: 1, ...slidesPerViewDefault };
7
8
  const { useEffect, useState, useRef, Children } = useReactAdapter();
8
9
  const trackRef = useRef(null);
9
10
  const isNavigatingRef = useRef(false);
10
11
  const slides = Children.toArray(children);
11
- const calculatePages = (totalSlides = 0, slidesPerView = 0) => {
12
- if (slidesPerView <= 0)
13
- return 1;
14
- return Math.ceil(totalSlides / slidesPerView);
12
+ const totalSlides = slides.length;
13
+ const calculatePages = (slidesPerView = 0) => {
14
+ let pagesArr = [];
15
+ for (let i = slidesPerView; i < totalSlides; i++) {
16
+ pagesArr.push({});
17
+ }
18
+ return pagesArr.length + 1;
15
19
  };
16
20
  const [activeSlideIndex, setActiveSlideIndex] = useState(0);
17
21
  const [activeDOMIndex, setActiveDOMIndex] = useState(0);
18
22
  const [isAtEnd, setIsAtEnd] = useState(false);
19
23
  const [isAtStart, setIsAtStart] = useState(true);
20
24
  const [totalPages, setTotalPages] = useState(0);
21
- const [isOverflowing, setIsOverflowing] = useState(false);
22
- const displayNavigation = hasNavigation && (loop || isOverflowing);
23
- const displayPagination = hasPagination && (loop || isOverflowing);
25
+ const displayNavigation = hasNavigation;
26
+ const displayPagination = hasPagination;
24
27
  useEffect(() => {
25
28
  if (loop) {
26
29
  setIsAtStart(false);
@@ -35,7 +38,7 @@ export const Carousel = (props) => {
35
38
  useEffect(() => {
36
39
  const currentSlidesPerView = slidesPerView[breakpoint] ??
37
40
  (typeof slidesPerView === "number" ? slidesPerView : slidesPerView.xl ?? 1);
38
- setTotalPages(calculatePages(slides.length, currentSlidesPerView));
41
+ setTotalPages(calculatePages(currentSlidesPerView));
39
42
  }, [breakpoint, slidesPerView, slides.length]);
40
43
  useEffect(() => {
41
44
  const track = trackRef.current;
@@ -78,18 +81,6 @@ export const Carousel = (props) => {
78
81
  }
79
82
  return () => track.removeEventListener("scroll", handleScroll);
80
83
  }, [slides.length, loop]);
81
- // Check if the slides overflow the container
82
- useEffect(() => {
83
- const track = trackRef.current;
84
- if (!track)
85
- return;
86
- const handleResize = () => {
87
- setIsOverflowing(track.scrollWidth > track.clientWidth);
88
- };
89
- handleResize(); // Initial check
90
- window.addEventListener("resize", handleResize);
91
- return () => window.removeEventListener("resize", handleResize);
92
- }, [loop]);
93
84
  const style = Object.fromEntries(Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`]));
94
85
  const goPrev = () => {
95
86
  if (!trackRef.current)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@growth-angels/ds-core",
3
- "version": "1.15.1",
3
+ "version": "1.16.1",
4
4
  "description": "Design system by Growth Angels",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -29,8 +29,16 @@
29
29
  }
30
30
  }
31
31
 
32
- @include bp-up("xxl", $ga-breakpoints) {
33
- .ga-ds-container--small {
32
+ .ga-ds-container--small {
33
+ @include bp-up("lg", $ga-breakpoints) {
34
+ &:not(.ga-ds-container-stretch--right) {
35
+ padding-right: calc((100% - (#{map.get($ga-containers, "sm")} / 1.2)) / 2);
36
+ }
37
+ &:not(.ga-ds-container-stretch--left) {
38
+ padding-left: calc((100% - (#{map.get($ga-containers, "sm")})) / 2);
39
+ }
40
+ }
41
+ @include bp-up("xxl", $ga-breakpoints) {
34
42
  &:not(.ga-ds-container-stretch--right) {
35
43
  padding-right: calc((100% - #{map.get($ga-containers, "sm")}) / 2);
36
44
  }
@@ -6,7 +6,7 @@ import { CarouselProps } from "./Carousel.types"
6
6
  export const Carousel = (props: CarouselProps) => {
7
7
  const {
8
8
  children,
9
- slidesPerView = { xs: 1, sm: 1, md: 2, lg: 3, xl: 4, xxl: 5 },
9
+ slidesPerView: slidesPerViewDefault,
10
10
  spaceBetween = 20,
11
11
  navigation,
12
12
  pagination,
@@ -15,14 +15,18 @@ export const Carousel = (props: CarouselProps) => {
15
15
  hasNavigation,
16
16
  loop = false,
17
17
  } = props
18
+ const slidesPerView = { xs: 1, ...slidesPerViewDefault }
18
19
  const { useEffect, useState, useRef, Children } = useReactAdapter()
19
20
  const trackRef = useRef<HTMLDivElement>(null)
20
21
  const isNavigatingRef = useRef(false)
21
22
  const slides = Children.toArray(children)
22
-
23
- const calculatePages = (totalSlides = 0, slidesPerView = 0) => {
24
- if (slidesPerView <= 0) return 1
25
- return Math.ceil(totalSlides / slidesPerView)
23
+ const totalSlides = slides.length
24
+ const calculatePages = (slidesPerView = 0) => {
25
+ let pagesArr = []
26
+ for (let i = slidesPerView; i < totalSlides; i++) {
27
+ pagesArr.push({})
28
+ }
29
+ return pagesArr.length + 1
26
30
  }
27
31
 
28
32
  const [activeSlideIndex, setActiveSlideIndex] = useState(0)
@@ -30,10 +34,9 @@ export const Carousel = (props: CarouselProps) => {
30
34
  const [isAtEnd, setIsAtEnd] = useState(false)
31
35
  const [isAtStart, setIsAtStart] = useState(true)
32
36
  const [totalPages, setTotalPages] = useState(0)
33
- const [isOverflowing, setIsOverflowing] = useState(false)
34
37
 
35
- const displayNavigation = hasNavigation && (loop || isOverflowing)
36
- const displayPagination = hasPagination && (loop || isOverflowing)
38
+ const displayNavigation = hasNavigation
39
+ const displayPagination = hasPagination
37
40
 
38
41
  useEffect(() => {
39
42
  if (loop) {
@@ -52,7 +55,7 @@ export const Carousel = (props: CarouselProps) => {
52
55
  (slidesPerView as Record<string, number>)[breakpoint] ??
53
56
  (typeof slidesPerView === "number" ? slidesPerView : (slidesPerView as any).xl ?? 1)
54
57
 
55
- setTotalPages(calculatePages(slides.length, currentSlidesPerView))
58
+ setTotalPages(calculatePages(currentSlidesPerView))
56
59
  }, [breakpoint, slidesPerView, slides.length])
57
60
 
58
61
  useEffect(() => {
@@ -100,21 +103,6 @@ export const Carousel = (props: CarouselProps) => {
100
103
  return () => track.removeEventListener("scroll", handleScroll)
101
104
  }, [slides.length, loop])
102
105
 
103
- // Check if the slides overflow the container
104
- useEffect(() => {
105
- const track = trackRef.current
106
- if (!track) return
107
-
108
- const handleResize = () => {
109
- setIsOverflowing(track.scrollWidth > track.clientWidth)
110
- }
111
-
112
- handleResize() // Initial check
113
-
114
- window.addEventListener("resize", handleResize)
115
- return () => window.removeEventListener("resize", handleResize)
116
- }, [loop])
117
-
118
106
  const style = Object.fromEntries(
119
107
  Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`])
120
108
  )