@growth-angels/ds-core 1.15.0 → 1.16.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.
@@ -3,22 +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, step = 1) => {
12
- return Math.max(1, Math.ceil((totalSlides - slidesPerView) / step) + 1);
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;
13
19
  };
14
20
  const [activeSlideIndex, setActiveSlideIndex] = useState(0);
15
21
  const [activeDOMIndex, setActiveDOMIndex] = useState(0);
16
22
  const [isAtEnd, setIsAtEnd] = useState(false);
17
23
  const [isAtStart, setIsAtStart] = useState(true);
18
24
  const [totalPages, setTotalPages] = useState(0);
19
- const [isOverflowing, setIsOverflowing] = useState(false);
20
- const displayNavigation = hasNavigation && (loop || isOverflowing);
21
- const displayPagination = hasPagination && (loop || isOverflowing);
25
+ const displayNavigation = hasNavigation;
26
+ const displayPagination = hasPagination;
22
27
  useEffect(() => {
23
28
  if (loop) {
24
29
  setIsAtStart(false);
@@ -33,8 +38,8 @@ export const Carousel = (props) => {
33
38
  useEffect(() => {
34
39
  const currentSlidesPerView = slidesPerView[breakpoint] ??
35
40
  (typeof slidesPerView === "number" ? slidesPerView : slidesPerView.xl ?? 1);
36
- setTotalPages(calculatePages(slides.length, currentSlidesPerView, 1));
37
- }, [breakpoint, slidesPerView]);
41
+ setTotalPages(calculatePages(currentSlidesPerView));
42
+ }, [breakpoint, slidesPerView, slides.length]);
38
43
  useEffect(() => {
39
44
  const track = trackRef.current;
40
45
  if (!track)
@@ -76,18 +81,6 @@ export const Carousel = (props) => {
76
81
  }
77
82
  return () => track.removeEventListener("scroll", handleScroll);
78
83
  }, [slides.length, loop]);
79
- // Check if the slides overflow the container
80
- useEffect(() => {
81
- const track = trackRef.current;
82
- if (!track)
83
- return;
84
- const handleResize = () => {
85
- setIsOverflowing(track.scrollWidth > track.clientWidth);
86
- };
87
- handleResize(); // Initial check
88
- window.addEventListener("resize", handleResize);
89
- return () => window.removeEventListener("resize", handleResize);
90
- }, [loop]);
91
84
  const style = Object.fromEntries(Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`]));
92
85
  const goPrev = () => {
93
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.0",
3
+ "version": "1.16.0",
4
4
  "description": "Design system by Growth Angels",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -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,13 +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, step = 1) => {
24
- return Math.max(1, Math.ceil((totalSlides - slidesPerView) / step) + 1)
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
25
30
  }
26
31
 
27
32
  const [activeSlideIndex, setActiveSlideIndex] = useState(0)
@@ -29,10 +34,9 @@ export const Carousel = (props: CarouselProps) => {
29
34
  const [isAtEnd, setIsAtEnd] = useState(false)
30
35
  const [isAtStart, setIsAtStart] = useState(true)
31
36
  const [totalPages, setTotalPages] = useState(0)
32
- const [isOverflowing, setIsOverflowing] = useState(false)
33
37
 
34
- const displayNavigation = hasNavigation && (loop || isOverflowing)
35
- const displayPagination = hasPagination && (loop || isOverflowing)
38
+ const displayNavigation = hasNavigation
39
+ const displayPagination = hasPagination
36
40
 
37
41
  useEffect(() => {
38
42
  if (loop) {
@@ -51,8 +55,8 @@ export const Carousel = (props: CarouselProps) => {
51
55
  (slidesPerView as Record<string, number>)[breakpoint] ??
52
56
  (typeof slidesPerView === "number" ? slidesPerView : (slidesPerView as any).xl ?? 1)
53
57
 
54
- setTotalPages(calculatePages(slides.length, currentSlidesPerView, 1))
55
- }, [breakpoint, slidesPerView])
58
+ setTotalPages(calculatePages(currentSlidesPerView))
59
+ }, [breakpoint, slidesPerView, slides.length])
56
60
 
57
61
  useEffect(() => {
58
62
  const track = trackRef.current
@@ -99,21 +103,6 @@ export const Carousel = (props: CarouselProps) => {
99
103
  return () => track.removeEventListener("scroll", handleScroll)
100
104
  }, [slides.length, loop])
101
105
 
102
- // Check if the slides overflow the container
103
- useEffect(() => {
104
- const track = trackRef.current
105
- if (!track) return
106
-
107
- const handleResize = () => {
108
- setIsOverflowing(track.scrollWidth > track.clientWidth)
109
- }
110
-
111
- handleResize() // Initial check
112
-
113
- window.addEventListener("resize", handleResize)
114
- return () => window.removeEventListener("resize", handleResize)
115
- }, [loop])
116
-
117
106
  const style = Object.fromEntries(
118
107
  Object.entries(slidesPerView).map(([key, value]) => [`--ga-ds-slides-per-view-${key}`, `${value}`])
119
108
  )
@@ -1,10 +1,15 @@
1
1
  .ga-ds-tabs {
2
2
  $this: &;
3
-
3
+ &__list-wrapper {
4
+ max-width: 100%;
5
+ overflow: hidden;
6
+ }
4
7
  &__list {
5
8
  overflow-x: auto;
9
+ overflow-y: hidden;
10
+ white-space: nowrap;
6
11
  -webkit-overflow-scrolling: touch;
7
- scrollbar-width: none; // Firefox
12
+ max-width: 100%;
8
13
  &::-webkit-scrollbar {
9
14
  display: none; // Safari and Chrome
10
15
  }
@@ -12,6 +17,7 @@
12
17
  &__list-container {
13
18
  display: flex;
14
19
  flex-wrap: nowrap;
20
+ width: fit-content;
15
21
 
16
22
  #{$this}__tab {
17
23
  background: none;
@@ -19,7 +25,7 @@
19
25
  font-size: inherit;
20
26
  padding: inherit;
21
27
  cursor: pointer;
22
- width: fit-content;
28
+ width: max-content;
23
29
  }
24
30
  }
25
31