@growth-angels/ds-core 1.14.0 → 1.14.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.
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl';
|
|
1
2
|
export declare function useBreakpointObserver(breakpoints?: {
|
|
3
|
+
xs: number;
|
|
2
4
|
sm: number;
|
|
3
5
|
md: number;
|
|
4
6
|
lg: number;
|
|
5
7
|
xl: number;
|
|
6
|
-
|
|
8
|
+
xxl: number;
|
|
9
|
+
}): Breakpoint;
|
|
10
|
+
export {};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import { useReactAdapter } from './useReactAdaptater';
|
|
2
|
-
export function useBreakpointObserver(breakpoints = { sm: 640, md: 1024, lg: 1280, xl: 1400 }) {
|
|
2
|
+
export function useBreakpointObserver(breakpoints = { xs: 375, sm: 640, md: 1024, lg: 1280, xl: 1400, xxl: 1600 }) {
|
|
3
3
|
const { useEffect, useState } = useReactAdapter();
|
|
4
4
|
const [current, setCurrent] = useState('sm');
|
|
5
5
|
useEffect(() => {
|
|
6
6
|
let frameId;
|
|
7
7
|
const check = () => {
|
|
8
8
|
const width = window.innerWidth;
|
|
9
|
-
let bp = '
|
|
10
|
-
if (width >= breakpoints.
|
|
9
|
+
let bp = 'xs';
|
|
10
|
+
if (width >= breakpoints.xxl)
|
|
11
|
+
bp = 'xxl';
|
|
12
|
+
else if (width >= breakpoints.xl)
|
|
11
13
|
bp = 'xl';
|
|
12
14
|
else if (width >= breakpoints.lg)
|
|
13
15
|
bp = 'lg';
|
|
@@ -15,6 +17,8 @@ export function useBreakpointObserver(breakpoints = { sm: 640, md: 1024, lg: 128
|
|
|
15
17
|
bp = 'md';
|
|
16
18
|
else if (width >= breakpoints.sm)
|
|
17
19
|
bp = 'sm';
|
|
20
|
+
else if (width < breakpoints.sm)
|
|
21
|
+
bp = 'xs';
|
|
18
22
|
setCurrent((prev) => (prev !== bp ? bp : prev));
|
|
19
23
|
frameId = requestAnimationFrame(check);
|
|
20
24
|
};
|
|
@@ -3,7 +3,7 @@ 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 = { sm: 1, md: 2, lg: 3, xl: 4 }, spaceBetween = 20, navigation, pagination, context, hasPagination, hasNavigation, loop = false, } = 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;
|
|
7
7
|
const { useEffect, useState, useRef, Children } = useReactAdapter();
|
|
8
8
|
const trackRef = useRef(null);
|
|
9
9
|
const isNavigatingRef = useRef(false);
|
|
@@ -29,9 +29,11 @@ export const Carousel = (props) => {
|
|
|
29
29
|
setIsAtEnd(activeSlideIndex === totalPages - 1);
|
|
30
30
|
}
|
|
31
31
|
}, [activeSlideIndex, totalPages, loop]);
|
|
32
|
-
const breakpoint = useBreakpointObserver({ sm:
|
|
32
|
+
const breakpoint = useBreakpointObserver({ xs: 375, sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1440 });
|
|
33
33
|
useEffect(() => {
|
|
34
|
-
|
|
34
|
+
const currentSlidesPerView = slidesPerView[breakpoint] ??
|
|
35
|
+
(typeof slidesPerView === "number" ? slidesPerView : slidesPerView.xl ?? 1);
|
|
36
|
+
setTotalPages(calculatePages(slides.length, currentSlidesPerView, 1));
|
|
35
37
|
}, [breakpoint, slidesPerView]);
|
|
36
38
|
useEffect(() => {
|
|
37
39
|
const track = trackRef.current;
|
package/package.json
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { useReactAdapter } from './useReactAdaptater'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
|
|
4
|
+
type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl' | 'xxl'
|
|
5
|
+
|
|
6
|
+
export function useBreakpointObserver(breakpoints = { xs: 375, sm: 640, md: 1024, lg: 1280, xl: 1400, xxl: 1600 }): Breakpoint {
|
|
4
7
|
const { useEffect, useState } = useReactAdapter()
|
|
5
|
-
const [current, setCurrent] = useState<
|
|
8
|
+
const [current, setCurrent] = useState<Breakpoint>('sm')
|
|
6
9
|
useEffect(() => {
|
|
7
10
|
let frameId: number
|
|
8
11
|
|
|
9
12
|
const check = () => {
|
|
10
13
|
const width = window.innerWidth
|
|
11
|
-
let bp:
|
|
12
|
-
|
|
13
|
-
if (width >= breakpoints.
|
|
14
|
+
let bp: Breakpoint = 'xs'
|
|
15
|
+
|
|
16
|
+
if (width >= breakpoints.xxl) bp = 'xxl'
|
|
17
|
+
else if (width >= breakpoints.xl) bp = 'xl'
|
|
14
18
|
else if (width >= breakpoints.lg) bp = 'lg'
|
|
15
19
|
else if (width >= breakpoints.md) bp = 'md'
|
|
16
20
|
else if (width >= breakpoints.sm) bp = 'sm'
|
|
21
|
+
else if (width < breakpoints.sm) bp = 'xs'
|
|
17
22
|
|
|
18
23
|
setCurrent((prev) => (prev !== bp ? bp : prev))
|
|
19
24
|
frameId = requestAnimationFrame(check)
|
|
@@ -6,7 +6,7 @@ import { CarouselProps } from "./Carousel.types"
|
|
|
6
6
|
export const Carousel = (props: CarouselProps) => {
|
|
7
7
|
const {
|
|
8
8
|
children,
|
|
9
|
-
slidesPerView = { sm: 1, md: 2, lg: 3, xl: 4 },
|
|
9
|
+
slidesPerView = { xs: 1, sm: 1, md: 2, lg: 3, xl: 4, xxl: 5 },
|
|
10
10
|
spaceBetween = 20,
|
|
11
11
|
navigation,
|
|
12
12
|
pagination,
|
|
@@ -44,10 +44,14 @@ export const Carousel = (props: CarouselProps) => {
|
|
|
44
44
|
}
|
|
45
45
|
}, [activeSlideIndex, totalPages, loop])
|
|
46
46
|
|
|
47
|
-
const breakpoint = useBreakpointObserver({ sm:
|
|
47
|
+
const breakpoint = useBreakpointObserver({ xs: 375, sm: 576, md: 768, lg: 992, xl: 1200, xxl: 1440 })
|
|
48
48
|
|
|
49
49
|
useEffect(() => {
|
|
50
|
-
|
|
50
|
+
const currentSlidesPerView =
|
|
51
|
+
(slidesPerView as Record<string, number>)[breakpoint] ??
|
|
52
|
+
(typeof slidesPerView === "number" ? slidesPerView : (slidesPerView as any).xl ?? 1)
|
|
53
|
+
|
|
54
|
+
setTotalPages(calculatePages(slides.length, currentSlidesPerView, 1))
|
|
51
55
|
}, [breakpoint, slidesPerView])
|
|
52
56
|
|
|
53
57
|
useEffect(() => {
|