@bonprix-ds/react-carousel-v2 1.0.1 → 1.0.2
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.
- package/dist/index.d.ts +2 -93
- package/dist/src/CarouselArrow.d.ts +12 -0
- package/dist/src/CarouselArrow.js.map +1 -1
- package/dist/src/CarouselV2.d.ts +20 -0
- package/dist/src/CarouselV2Root.d.ts +53 -0
- package/dist/src/CarouselV2Root.js.map +1 -1
- package/dist/src/PositionIndicator/PositionIndicator.d.ts +10 -0
- package/dist/src/Slide/Slide.d.ts +14 -0
- package/dist/src/Slides/Slides.d.ts +10 -0
- package/dist/src/carouselContext.d.ts +17 -0
- package/dist/src/useConsumeCarousel.d.ts +2 -0
- package/dist/src/useCreateCarousel.d.ts +31 -0
- package/dist/src/useCreateCarousel.js.map +1 -1
- package/dist/src/useSimulateTouch.d.ts +7 -0
- package/dist/src/useStart.d.ts +8 -0
- package/dist/src/utils.d.ts +68 -0
- package/package.json +29 -28
package/dist/index.d.ts
CHANGED
|
@@ -1,93 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
import { ReactNode } from 'react';
|
|
4
|
-
import { Ref } from 'react';
|
|
5
|
-
|
|
6
|
-
declare type AccessibilityLabel = {
|
|
7
|
-
/** Sets an invisible header for the carousel to create a landmark. Do not use both `title` and `aria-labelledby`. */
|
|
8
|
-
title: string;
|
|
9
|
-
/** Defines the level of the used header element. Only applicable if using `title` instead of `aria-labelledby`. */
|
|
10
|
-
titleLevel?: "h2" | "h3" | "h4" | "h5" | "h6";
|
|
11
|
-
"aria-labelledby"?: never;
|
|
12
|
-
} | {
|
|
13
|
-
/** Use if a title already exists on the page. Do not use both `title`and `aria-labelledby`. */
|
|
14
|
-
"aria-labelledby": string;
|
|
15
|
-
title?: never;
|
|
16
|
-
titleLevel?: never;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
declare const CarouselV2: {
|
|
20
|
-
(props: CarouselV2Props): default_2.JSX.Element;
|
|
21
|
-
displayName: string;
|
|
22
|
-
Slides: {
|
|
23
|
-
({ children }: SlidesProps): default_2.JSX.Element;
|
|
24
|
-
displayName: string;
|
|
25
|
-
};
|
|
26
|
-
Slide: {
|
|
27
|
-
({ children, ...props }: SlideProps): default_2.JSX.Element;
|
|
28
|
-
displayName: string;
|
|
29
|
-
};
|
|
30
|
-
PositionIndicator: {
|
|
31
|
-
({ ref }: PositionIndicatorProps): default_2.JSX.Element;
|
|
32
|
-
displayName: string;
|
|
33
|
-
};
|
|
34
|
-
};
|
|
35
|
-
export default CarouselV2;
|
|
36
|
-
|
|
37
|
-
export declare type CarouselV2Props = AccessibilityLabel & {
|
|
38
|
-
/** The content of the carousel. Here, all of the subcomponents should be placed. */
|
|
39
|
-
children: ReactNode;
|
|
40
|
-
/** Amount of slides that will be visible at the same time, thus building a page. */
|
|
41
|
-
perPage?: number | ResponsiveNumber;
|
|
42
|
-
/** Amount of slides to move per arrow icon button click. */
|
|
43
|
-
perMove?: number | ResponsiveNumber;
|
|
44
|
-
/** If true, the carousel will rewind to the beginning when reaching the end or going to end when going before the first slide. There must be more than two pages for this to work! Doesn't run smoothly with `padding` right now. */
|
|
45
|
-
rewind?: boolean;
|
|
46
|
-
/** If set to `true`, the primary variant of icon buttons will be used to achieve a high contrast. */
|
|
47
|
-
buttonsContrast?: boolean;
|
|
48
|
-
/** The padding at the right side of the page in pixels. Can be used to implement the so-called "scroll hint" */
|
|
49
|
-
padding?: number;
|
|
50
|
-
/** Callback function that is called when the slide changes. */
|
|
51
|
-
onMove?: (destIndex: number, prevIndex: number) => void;
|
|
52
|
-
/** Manages the behavior of the arrow icon buttons. */
|
|
53
|
-
showArrows?: "always" | "hover" | "never";
|
|
54
|
-
/** The gap between slides in pixels. */
|
|
55
|
-
gap?: number;
|
|
56
|
-
/** If set to `true`, the color of the arrow buttons will be inverted. */
|
|
57
|
-
invertButtons?: boolean;
|
|
58
|
-
/** If set to `true`, the horizontal padding for the arrow buttons will be removed. */
|
|
59
|
-
disableHorizontalPadding?: boolean;
|
|
60
|
-
/** If set to `true`, scrolling via mouse drag will be enabled just like you would expect from a mobile touch pointer. */
|
|
61
|
-
simulateTouch?: boolean;
|
|
62
|
-
/** The index of the initial slide to be displayed. For programmatic scrolling after initial mount, use `ref`'s `moveToPage`. */
|
|
63
|
-
start?: number;
|
|
64
|
-
/** A reference to the Carousel instance. You can call `moveToPage(pageNumber: number)` on this one, e.g. `carouselRef.current.moveToPage(2)`. To set an initial slide, use `start` prop instead. */
|
|
65
|
-
ref?: Ref<CarouselV2Ref>;
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export declare interface CarouselV2Ref {
|
|
69
|
-
moveToPage: (pageNumber: number) => void;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
declare interface PositionIndicatorProps {
|
|
73
|
-
/** Ref to the element */
|
|
74
|
-
ref?: Ref<HTMLDivElement>;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
export declare type ResponsiveNumber = Partial<Record<Breakpoint, number>>;
|
|
78
|
-
|
|
79
|
-
declare interface SlideProps {
|
|
80
|
-
/** The content of the slide item. */
|
|
81
|
-
children: ReactNode;
|
|
82
|
-
/** An optional label of the slide item. */
|
|
83
|
-
"aria-label"?: string;
|
|
84
|
-
/** An optional id of a DOM element that labels the slide item. */
|
|
85
|
-
"aria-labelledby"?: string;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
declare interface SlidesProps {
|
|
89
|
-
/** The content of the slides section. This is where `<CarouselV2.Slide>` items go. */
|
|
90
|
-
children: ReactNode;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export { }
|
|
1
|
+
export { default } from "./src/CarouselV2";
|
|
2
|
+
export type { CarouselV2Props, CarouselV2Ref, ResponsiveNumber } from "./src/CarouselV2";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface Props {
|
|
3
|
+
position: "left" | "right";
|
|
4
|
+
buttonsContrast: boolean;
|
|
5
|
+
invertButtons: boolean;
|
|
6
|
+
disableHorizontalPadding: boolean;
|
|
7
|
+
onClick: () => void;
|
|
8
|
+
disabled: boolean;
|
|
9
|
+
show?: "always" | "hover" | "never";
|
|
10
|
+
}
|
|
11
|
+
declare const CarouselArrow: ({ position, buttonsContrast, invertButtons, disableHorizontalPadding, onClick, disabled, show, }: Props) => React.JSX.Element;
|
|
12
|
+
export default CarouselArrow;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselArrow.js","names":[],"sources":["../../src/CarouselArrow.tsx"],"sourcesContent":["\"use client\";\n\nimport { BaseButton } from \"@bonprix-ds/internal-components\";\nimport ThemeForcer from \"@bonprix-ds/react-theme-forcer\";\
|
|
1
|
+
{"version":3,"file":"CarouselArrow.js","names":[],"sources":["../../src/CarouselArrow.tsx"],"sourcesContent":["\"use client\";\n\nimport React from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { BaseButton } from \"@bonprix-ds/internal-components\";\nimport ThemeForcer from \"@bonprix-ds/react-theme-forcer\";\n\nconst generateClasses = tv({\n slots: {\n wrapper: \"z-[1] absolute top-1/2 transform -translate-y-1/2\",\n button: \"disabled:hidden\",\n },\n variants: {\n position: {\n left: {\n wrapper: \"start-3\",\n },\n right: {\n wrapper: \"end-3\",\n },\n },\n disableHorizontalPadding: {\n true: \"\",\n false: \"\",\n },\n show: {\n always: { button: \"\" },\n hover: { button: \"hidden group-hover:block\" },\n never: { button: \"hidden\" },\n },\n },\n compoundVariants: [\n {\n disableHorizontalPadding: true,\n position: \"left\",\n class: {\n wrapper: \"start-0\",\n },\n },\n {\n disableHorizontalPadding: true,\n position: \"right\",\n class: {\n wrapper: \"end-0\",\n },\n },\n ],\n});\n\ninterface Props {\n position: \"left\" | \"right\";\n buttonsContrast: boolean;\n invertButtons: boolean;\n disableHorizontalPadding: boolean;\n onClick: () => void;\n disabled: boolean;\n show?: \"always\" | \"hover\" | \"never\";\n}\n\nconst CarouselArrow = ({\n position,\n buttonsContrast,\n invertButtons,\n disableHorizontalPadding,\n onClick,\n disabled,\n show = \"always\",\n}: Props) => {\n const isLeftArrow = position === \"left\" ? true : false;\n const icon = isLeftArrow ? \"arrow-left\" : \"arrow-right\";\n const label = isLeftArrow ? \"zurück\" : \"weiter\";\n const variant = buttonsContrast ? \"primary\" : \"tertiary\";\n const themeMode = invertButtons ? \"dark\" : \"light\";\n const { wrapper, button } = generateClasses({ position, disableHorizontalPadding, show });\n\n return (\n <ThemeForcer theme={themeMode}>\n <span className={wrapper()}>\n <BaseButton\n type=\"button\"\n className={button()}\n variant={variant}\n icon={icon}\n componentName=\"icon-button\"\n onClick={onClick}\n disabled={disabled}\n >\n {label}\n </BaseButton>\n </span>\n </ThemeForcer>\n );\n};\n\nexport default CarouselArrow;\n"],"mappings":";;;;;;;AAQA,IAAM,IAAkB,EAAG;CACzB,OAAO;EACL,SAAS;EACT,QAAQ;CACV;CACA,UAAU;EACR,UAAU;GACR,MAAM,EACJ,SAAS,UACX;GACA,OAAO,EACL,SAAS,QACX;EACF;EACA,0BAA0B;GACxB,MAAM;GACN,OAAO;EACT;EACA,MAAM;GACJ,QAAQ,EAAE,QAAQ,GAAG;GACrB,OAAO,EAAE,QAAQ,2BAA2B;GAC5C,OAAO,EAAE,QAAQ,SAAS;EAC5B;CACF;CACA,kBAAkB,CAChB;EACE,0BAA0B;EAC1B,UAAU;EACV,OAAO,EACL,SAAS,UACX;CACF,GACA;EACE,0BAA0B;EAC1B,UAAU;EACV,OAAO,EACL,SAAS,QACX;CACF,CACF;AACF,CAAC,GAYK,KAAiB,EACrB,aACA,oBACA,kBACA,6BACA,YACA,aACA,UAAO,eACI;CACX,IAAM,IAAc,MAAa,QAC3B,IAAO,IAAc,eAAe,eACpC,IAAQ,IAAc,WAAW,UACjC,IAAU,IAAkB,YAAY,YACxC,IAAY,IAAgB,SAAS,SACrC,EAAE,YAAS,cAAW,EAAgB;EAAE;EAAU;EAA0B;CAAK,CAAC;CAExF,OACE,kBAAC,GAAD;EAAa,OAAO;EAClB,UAAA,kBAAC,QAAD;GAAM,WAAW,EAAQ;GACvB,UAAA,kBAAC,GAAD;IACE,MAAK;IACL,WAAW,EAAO;IACT;IACH;IACN,eAAc;IACL;IACC;IAET,UAAA;GACS,CAAA;EACR,CAAA;CACK,CAAA;AAEjB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type CarouselV2Props } from "./CarouselV2Root";
|
|
3
|
+
export type { CarouselV2Props, CarouselV2Ref, ResponsiveNumber } from "./CarouselV2Root";
|
|
4
|
+
declare const CarouselV2: {
|
|
5
|
+
(props: CarouselV2Props): React.JSX.Element;
|
|
6
|
+
displayName: string;
|
|
7
|
+
Slides: {
|
|
8
|
+
({ children }: import("./Slides/Slides").SlidesProps): React.JSX.Element;
|
|
9
|
+
displayName: string;
|
|
10
|
+
};
|
|
11
|
+
Slide: {
|
|
12
|
+
({ children, ...props }: import("./Slide/Slide").SlideProps): React.JSX.Element;
|
|
13
|
+
displayName: string;
|
|
14
|
+
};
|
|
15
|
+
PositionIndicator: {
|
|
16
|
+
({ ref }: import("./PositionIndicator/PositionIndicator").PositionIndicatorProps): React.JSX.Element;
|
|
17
|
+
displayName: string;
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export default CarouselV2;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React, { ReactNode, Ref } from "react";
|
|
2
|
+
import { Breakpoint } from "@bonprix-ds/utils";
|
|
3
|
+
export type ResponsiveNumber = Partial<Record<Breakpoint, number>>;
|
|
4
|
+
type AccessibilityLabel = {
|
|
5
|
+
/** Sets an invisible header for the carousel to create a landmark. Do not use both `title` and `aria-labelledby`. */
|
|
6
|
+
title: string;
|
|
7
|
+
/** Defines the level of the used header element. Only applicable if using `title` instead of `aria-labelledby`. */
|
|
8
|
+
titleLevel?: "h2" | "h3" | "h4" | "h5" | "h6";
|
|
9
|
+
"aria-labelledby"?: never;
|
|
10
|
+
} | {
|
|
11
|
+
/** Use if a title already exists on the page. Do not use both `title`and `aria-labelledby`. */
|
|
12
|
+
"aria-labelledby": string;
|
|
13
|
+
title?: never;
|
|
14
|
+
titleLevel?: never;
|
|
15
|
+
};
|
|
16
|
+
export interface CarouselV2Ref {
|
|
17
|
+
moveToPage: (pageNumber: number) => void;
|
|
18
|
+
}
|
|
19
|
+
export type CarouselV2Props = AccessibilityLabel & {
|
|
20
|
+
/** The content of the carousel. Here, all of the subcomponents should be placed. */
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
/** Amount of slides that will be visible at the same time, thus building a page. */
|
|
23
|
+
perPage?: number | ResponsiveNumber;
|
|
24
|
+
/** Amount of slides to move per arrow icon button click. */
|
|
25
|
+
perMove?: number | ResponsiveNumber;
|
|
26
|
+
/** If true, the carousel will rewind to the beginning when reaching the end or going to end when going before the first slide. There must be more than two pages for this to work! Doesn't run smoothly with `padding` right now. */
|
|
27
|
+
rewind?: boolean;
|
|
28
|
+
/** If set to `true`, the primary variant of icon buttons will be used to achieve a high contrast. */
|
|
29
|
+
buttonsContrast?: boolean;
|
|
30
|
+
/** The padding at the right side of the page in pixels. Can be used to implement the so-called "scroll hint" */
|
|
31
|
+
padding?: number;
|
|
32
|
+
/** Callback function that is called when the slide changes. */
|
|
33
|
+
onMove?: (destIndex: number, prevIndex: number) => void;
|
|
34
|
+
/** Manages the behavior of the arrow icon buttons. */
|
|
35
|
+
showArrows?: "always" | "hover" | "never";
|
|
36
|
+
/** The gap between slides in pixels. */
|
|
37
|
+
gap?: number;
|
|
38
|
+
/** If set to `true`, the color of the arrow buttons will be inverted. */
|
|
39
|
+
invertButtons?: boolean;
|
|
40
|
+
/** If set to `true`, the horizontal padding for the arrow buttons will be removed. */
|
|
41
|
+
disableHorizontalPadding?: boolean;
|
|
42
|
+
/** If set to `true`, scrolling via mouse drag will be enabled just like you would expect from a mobile touch pointer. */
|
|
43
|
+
simulateTouch?: boolean;
|
|
44
|
+
/** The index of the initial slide to be displayed. For programmatic scrolling after initial mount, use `ref`'s `moveToPage`. */
|
|
45
|
+
start?: number;
|
|
46
|
+
/** A reference to the Carousel instance. You can call `moveToPage(pageNumber: number)` on this one, e.g. `carouselRef.current.moveToPage(2)`. To set an initial slide, use `start` prop instead. */
|
|
47
|
+
ref?: Ref<CarouselV2Ref>;
|
|
48
|
+
};
|
|
49
|
+
declare const CarouselV2Root: {
|
|
50
|
+
({ children, title, titleLevel: TitleComponent, perPage, perMove, rewind, buttonsContrast, padding, onMove, showArrows, gap, invertButtons, disableHorizontalPadding, simulateTouch, start, ref, ...props }: CarouselV2Props): React.JSX.Element;
|
|
51
|
+
displayName: string;
|
|
52
|
+
};
|
|
53
|
+
export default CarouselV2Root;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CarouselV2Root.js","names":[],"sources":["../../src/CarouselV2Root.tsx"],"sourcesContent":["\"use client\";\n\nimport { Breakpoint } from \"@bonprix-ds/utils\";\nimport React, { ReactNode, Ref, useId, useImperativeHandle, useRef, useState } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport CarouselArrow from \"./CarouselArrow\";\nimport CarouselContext from \"./carouselContext\";\nimport useCreateCarousel from \"./useCreateCarousel\";\nimport { getActiveSlide, getFirstSlideIndexOnPage } from \"./utils\";\n\nconst generateClasses = tv({\n base: \"relative min-h-8 touch-manipulation group\", // group is for arrows on hover\n slots: {\n header: \"sr-only\",\n status: \"sr-only\",\n },\n});\n\nexport type ResponsiveNumber = Partial<Record<Breakpoint, number>>;\n\ntype AccessibilityLabel =\n | {\n /** Sets an invisible header for the carousel to create a landmark. Do not use both `title` and `aria-labelledby`. */\n title: string;\n /** Defines the level of the used header element. Only applicable if using `title` instead of `aria-labelledby`. */\n titleLevel?: \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n \"aria-labelledby\"?: never;\n }\n | {\n /** Use if a title already exists on the page. Do not use both `title`and `aria-labelledby`. */\n \"aria-labelledby\": string;\n title?: never;\n titleLevel?: never;\n };\n\nexport interface CarouselV2Ref {\n moveToPage: (pageNumber: number) => void;\n}\n\nexport type CarouselV2Props = AccessibilityLabel & {\n /** The content of the carousel. Here, all of the subcomponents should be placed. */\n children: ReactNode;\n /** Amount of slides that will be visible at the same time, thus building a page. */\n perPage?: number | ResponsiveNumber;\n /** Amount of slides to move per arrow icon button click. */\n perMove?: number | ResponsiveNumber;\n /** If true, the carousel will rewind to the beginning when reaching the end or going to end when going before the first slide. There must be more than two pages for this to work! Doesn't run smoothly with `padding` right now. */\n rewind?: boolean;\n /** If set to `true`, the primary variant of icon buttons will be used to achieve a high contrast. */\n buttonsContrast?: boolean;\n /** The padding at the right side of the page in pixels. Can be used to implement the so-called \"scroll hint\" */\n padding?: number;\n /** Callback function that is called when the slide changes. */\n onMove?: (destIndex: number, prevIndex: number) => void;\n /** Manages the behavior of the arrow icon buttons. */\n showArrows?: \"always\" | \"hover\" | \"never\";\n /** The gap between slides in pixels. */\n gap?: number;\n /** If set to `true`, the color of the arrow buttons will be inverted. */\n invertButtons?: boolean;\n /** If set to `true`, the horizontal padding for the arrow buttons will be removed. */\n disableHorizontalPadding?: boolean;\n /** If set to `true`, scrolling via mouse drag will be enabled just like you would expect from a mobile touch pointer. */\n simulateTouch?: boolean;\n /** The index of the initial slide to be displayed. For programmatic scrolling after initial mount, use `ref`'s `moveToPage`. */\n start?: number;\n /** A reference to the Carousel instance. You can call `moveToPage(pageNumber: number)` on this one, e.g. `carouselRef.current.moveToPage(2)`. To set an initial slide, use `start` prop instead. */\n ref?: Ref<CarouselV2Ref>;\n};\nconst CarouselV2Root = ({\n children,\n title,\n titleLevel: TitleComponent = \"h3\",\n perPage = 1,\n perMove = perPage,\n rewind = false,\n buttonsContrast = false,\n padding = 0,\n onMove,\n showArrows = \"always\",\n gap = 0,\n invertButtons = false,\n disableHorizontalPadding = false,\n simulateTouch = false,\n start,\n ref,\n ...props\n}: CarouselV2Props) => {\n const options = useCreateCarousel({ rewind, perPage, perMove, padding, gap, children, simulateTouch, start });\n const headerId = useId();\n const focusManagerRef = useRef<HTMLDivElement>(null);\n const {\n listRef,\n pages,\n activePage,\n activeSlide,\n canScrollPrev,\n canScrollNext,\n onClickLeft,\n onClickRight,\n slideWidth,\n getIntersectionObserver,\n setIntersectionObserver,\n buttonTriggeredScroll,\n scrollDirection,\n finishButtonTriggeredScroll,\n slidesCount,\n currentPerPage,\n } = options;\n const { base, header, status: statusClass } = generateClasses({ showArrows });\n const [status, setStatus] = useState<string>(\"\");\n const [previousActiveSlide, setPreviousActiveSlide] = useState<number>(0);\n\n // executed on scroll end in Slides component\n const handleScrollEnd = () => {\n // When calling handleScrollEnd, `activeSlide` might be stale due to a race condition with our handleScroll callback and its throttling.\n // Therefore, we get the currentActiveSlide from the browser scroll position fresh here. Otherwise, `moveToPage` would result in wrong `onMove` callbacks.\n const currentActiveSlide = listRef.current\n ? getActiveSlide({ scrollPosition: listRef.current.scrollLeft, slidesContainer: listRef.current })\n : activeSlide;\n\n if (currentActiveSlide !== previousActiveSlide) {\n onMove?.(currentActiveSlide, previousActiveSlide);\n setPreviousActiveSlide(currentActiveSlide);\n }\n\n const activeSlideNumbers = [];\n const slides = listRef.current?.querySelectorAll(\"li[aria-roledescription='slide']\") ?? [];\n for (let i = 0; i < slides.length; i++) {\n const slide = slides[i];\n if (!slide.hasAttribute(\"inert\")) {\n activeSlideNumbers.push(i);\n }\n }\n\n if (buttonTriggeredScroll) {\n if ((scrollDirection === \"left\" && !canScrollPrev) || (scrollDirection === \"right\" && !canScrollNext))\n focusManagerRef.current?.focus();\n\n finishButtonTriggeredScroll();\n }\n\n // TODO: Set this on initial load, too. It only gets set after scrolling right now.\n // This is the only place where we use 1-indexes because it is actually read to users and more intuitive than 0-based indexes.\n let newStatus = \"\";\n if (activeSlideNumbers.length === 1) {\n newStatus = `Slide ${activeSlideNumbers[0] + 1} aus ${slidesCount}`;\n } else if (activeSlideNumbers.length > 1) {\n newStatus = `Slides ${activeSlideNumbers[0] + 1} bis ${activeSlideNumbers[activeSlideNumbers.length - 1] + 1} aus ${slidesCount}`;\n }\n setStatus(newStatus);\n };\n\n useImperativeHandle(ref, () => ({\n moveToPage(pageNumber: number) {\n if (!listRef.current || pageNumber < 0 || pageNumber >= pages || pages === 1) return;\n\n const firstSlideIndexOnPage = getFirstSlideIndexOnPage({ pageNumber, perPage: currentPerPage });\n const firstSlideOfPage = listRef.current.querySelector(`[data-index='${firstSlideIndexOnPage}']`);\n\n firstSlideOfPage?.scrollIntoView({ behavior: \"instant\", inline: \"start\" });\n },\n }));\n\n return (\n <section\n className={base()}\n data-bpds=\"carousel-v2\"\n aria-roledescription=\"carousel\"\n aria-labelledby={props[\"aria-labelledby\"] ?? headerId}\n data-bpds-per-page={perPage}\n data-bpds-per-move={perMove}\n data-bpds-rewind={rewind}\n data-bpds-buttons-contrast={buttonsContrast}\n data-bpds-show-arrows={showArrows}\n data-bpds-invert-buttons={invertButtons}\n data-bpds-disable-horizontal-padding={disableHorizontalPadding}\n data-bpds-gap={gap}\n data-bpds-padding={padding}\n >\n {!props[\"aria-labelledby\"] && (\n <TitleComponent id={headerId} className={header()}>\n {title}\n </TitleComponent>\n )}\n <div className={statusClass()} role=\"status\">\n {status}\n </div>\n <div tabIndex={-1} ref={focusManagerRef}></div>\n <CarouselArrow\n invertButtons={invertButtons}\n position=\"left\"\n buttonsContrast={buttonsContrast}\n disableHorizontalPadding={disableHorizontalPadding}\n onClick={onClickLeft}\n disabled={!canScrollPrev}\n show={showArrows}\n />\n <CarouselContext.Provider\n value={{\n perPage,\n activeSlide,\n activePage,\n pages,\n listRef,\n handleScrollEnd,\n gap,\n slideWidth,\n getIntersectionObserver,\n setIntersectionObserver,\n simulateTouch,\n }}\n >\n {children}\n </CarouselContext.Provider>\n <CarouselArrow\n invertButtons={invertButtons}\n position=\"right\"\n buttonsContrast={buttonsContrast}\n disableHorizontalPadding={disableHorizontalPadding}\n onClick={onClickRight}\n disabled={!canScrollNext}\n show={showArrows}\n />\n </section>\n );\n};\n\nCarouselV2Root.displayName = \"CarouselV2\";\n\nexport default CarouselV2Root;\n"],"mappings":";;;;;;;;;AAWA,IAAM,IAAkB,EAAG;CACzB,MAAM;CACN,OAAO;EACL,QAAQ;EACR,QAAQ;CACV;AACF,CAAC,GAqDK,KAAkB,EACtB,aACA,UACA,YAAY,IAAiB,MAC7B,aAAU,GACV,aAAU,GACV,YAAS,IACT,qBAAkB,IAClB,aAAU,GACV,WACA,gBAAa,UACb,SAAM,GACN,mBAAgB,IAChB,8BAA2B,IAC3B,mBAAgB,IAChB,UACA,QACA,GAAG,QACkB;CACrB,IAAM,IAAU,EAAkB;EAAE;EAAQ;EAAS;EAAS;EAAS;EAAK;EAAU;EAAe;CAAM,CAAC,GACtG,IAAW,EAAM,GACjB,IAAkB,EAAuB,IAAI,GAC7C,EACJ,YACA,UACA,eACA,gBACA,kBACA,kBACA,gBACA,iBACA,eACA,4BACA,4BACA,0BACA,oBACA,gCACA,gBACA,sBACE,GACE,EAAE,SAAM,WAAQ,QAAQ,MAAgB,EAAgB,EAAE,cAAW,CAAC,GACtE,CAAC,GAAQ,KAAa,EAAiB,EAAE,GACzC,CAAC,GAAqB,MAA0B,EAAiB,CAAC;CAqDxE,OAXA,EAAoB,UAAY,EAC9B,WAAW,GAAoB;EAC7B,IAAI,CAAC,EAAQ,WAAW,IAAa,KAAK,KAAc,KAAS,MAAU,GAAG;EAE9E,IAAM,IAAwB,EAAyB;GAAE;GAAY,SAAS;EAAe,CAAC;EAG9F,EAFiC,QAAQ,cAAc,gBAAgB,EAAsB,GAE7F,CAAA,EAAkB,eAAe;GAAE,UAAU;GAAW,QAAQ;EAAQ,CAAC;CAC3E,EACF,EAAE,GAGA,kBAAC,WAAD;EACE,WAAW,EAAK;EAChB,aAAU;EACV,wBAAqB;EACrB,mBAAiB,EAAM,sBAAsB;EAC7C,sBAAoB;EACpB,sBAAoB;EACpB,oBAAkB;EAClB,8BAA4B;EAC5B,yBAAuB;EAC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ACiB;IACf,UAAS;IACQ;IACS;IAC1B,SAAS;IACT,UAAU,CAAC;IACX,MAAM;GACP,CAAA;EACM;;AAEb;AAEA,EAAe,cAAc"}
|
|
1
|
+
{"version":3,"file":"CarouselV2Root.js","names":[],"sources":["../../src/CarouselV2Root.tsx"],"sourcesContent":["\"use client\";\n\nimport React, { ReactNode, Ref, useId, useImperativeHandle, useRef, useState } from \"react\";\nimport { tv } from \"tailwind-variants\";\n\nimport { Breakpoint } from \"@bonprix-ds/utils\";\n\nimport CarouselArrow from \"./CarouselArrow\";\nimport CarouselContext from \"./carouselContext\";\nimport useCreateCarousel from \"./useCreateCarousel\";\nimport { getActiveSlide, getFirstSlideIndexOnPage } from \"./utils\";\n\nconst generateClasses = tv({\n base: \"relative min-h-8 touch-manipulation group\", // group is for arrows on hover\n slots: {\n header: \"sr-only\",\n status: \"sr-only\",\n },\n});\n\nexport type ResponsiveNumber = Partial<Record<Breakpoint, number>>;\n\ntype AccessibilityLabel =\n | {\n /** Sets an invisible header for the carousel to create a landmark. Do not use both `title` and `aria-labelledby`. */\n title: string;\n /** Defines the level of the used header element. Only applicable if using `title` instead of `aria-labelledby`. */\n titleLevel?: \"h2\" | \"h3\" | \"h4\" | \"h5\" | \"h6\";\n \"aria-labelledby\"?: never;\n }\n | {\n /** Use if a title already exists on the page. Do not use both `title`and `aria-labelledby`. */\n \"aria-labelledby\": string;\n title?: never;\n titleLevel?: never;\n };\n\nexport interface CarouselV2Ref {\n moveToPage: (pageNumber: number) => void;\n}\n\nexport type CarouselV2Props = AccessibilityLabel & {\n /** The content of the carousel. Here, all of the subcomponents should be placed. */\n children: ReactNode;\n /** Amount of slides that will be visible at the same time, thus building a page. */\n perPage?: number | ResponsiveNumber;\n /** Amount of slides to move per arrow icon button click. */\n perMove?: number | ResponsiveNumber;\n /** If true, the carousel will rewind to the beginning when reaching the end or going to end when going before the first slide. There must be more than two pages for this to work! Doesn't run smoothly with `padding` right now. */\n rewind?: boolean;\n /** If set to `true`, the primary variant of icon buttons will be used to achieve a high contrast. */\n buttonsContrast?: boolean;\n /** The padding at the right side of the page in pixels. Can be used to implement the so-called \"scroll hint\" */\n padding?: number;\n /** Callback function that is called when the slide changes. */\n onMove?: (destIndex: number, prevIndex: number) => void;\n /** Manages the behavior of the arrow icon buttons. */\n showArrows?: \"always\" | \"hover\" | \"never\";\n /** The gap between slides in pixels. */\n gap?: number;\n /** If set to `true`, the color of the arrow buttons will be inverted. */\n invertButtons?: boolean;\n /** If set to `true`, the horizontal padding for the arrow buttons will be removed. */\n disableHorizontalPadding?: boolean;\n /** If set to `true`, scrolling via mouse drag will be enabled just like you would expect from a mobile touch pointer. */\n simulateTouch?: boolean;\n /** The index of the initial slide to be displayed. For programmatic scrolling after initial mount, use `ref`'s `moveToPage`. */\n start?: number;\n /** A reference to the Carousel instance. You can call `moveToPage(pageNumber: number)` on this one, e.g. `carouselRef.current.moveToPage(2)`. To set an initial slide, use `start` prop instead. */\n ref?: Ref<CarouselV2Ref>;\n};\nconst CarouselV2Root = ({\n children,\n title,\n titleLevel: TitleComponent = \"h3\",\n perPage = 1,\n perMove = perPage,\n rewind = false,\n buttonsContrast = false,\n padding = 0,\n onMove,\n showArrows = \"always\",\n gap = 0,\n invertButtons = false,\n disableHorizontalPadding = false,\n simulateTouch = false,\n start,\n ref,\n ...props\n}: CarouselV2Props) => {\n const options = useCreateCarousel({ rewind, perPage, perMove, padding, gap, children, simulateTouch, start });\n const headerId = useId();\n const focusManagerRef = useRef<HTMLDivElement>(null);\n const {\n listRef,\n pages,\n activePage,\n activeSlide,\n canScrollPrev,\n canScrollNext,\n onClickLeft,\n onClickRight,\n slideWidth,\n getIntersectionObserver,\n setIntersectionObserver,\n buttonTriggeredScroll,\n scrollDirection,\n finishButtonTriggeredScroll,\n slidesCount,\n currentPerPage,\n } = options;\n const { base, header, status: statusClass } = generateClasses({ showArrows });\n const [status, setStatus] = useState<string>(\"\");\n const [previousActiveSlide, setPreviousActiveSlide] = useState<number>(0);\n\n // executed on scroll end in Slides component\n const handleScrollEnd = () => {\n // When calling handleScrollEnd, `activeSlide` might be stale due to a race condition with our handleScroll callback and its throttling.\n // Therefore, we get the currentActiveSlide from the browser scroll position fresh here. Otherwise, `moveToPage` would result in wrong `onMove` callbacks.\n const currentActiveSlide = listRef.current\n ? getActiveSlide({ scrollPosition: listRef.current.scrollLeft, slidesContainer: listRef.current })\n : activeSlide;\n\n if (currentActiveSlide !== previousActiveSlide) {\n onMove?.(currentActiveSlide, previousActiveSlide);\n setPreviousActiveSlide(currentActiveSlide);\n }\n\n const activeSlideNumbers = [];\n const slides = listRef.current?.querySelectorAll(\"li[aria-roledescription='slide']\") ?? [];\n for (let i = 0; i < slides.length; i++) {\n const slide = slides[i];\n if (!slide.hasAttribute(\"inert\")) {\n activeSlideNumbers.push(i);\n }\n }\n\n if (buttonTriggeredScroll) {\n if ((scrollDirection === \"left\" && !canScrollPrev) || (scrollDirection === \"right\" && !canScrollNext))\n focusManagerRef.current?.focus();\n\n finishButtonTriggeredScroll();\n }\n\n // TODO: Set this on initial load, too. It only gets set after scrolling right now.\n // This is the only place where we use 1-indexes because it is actually read to users and more intuitive than 0-based indexes.\n let newStatus = \"\";\n if (activeSlideNumbers.length === 1) {\n newStatus = `Slide ${activeSlideNumbers[0] + 1} aus ${slidesCount}`;\n } else if (activeSlideNumbers.length > 1) {\n newStatus = `Slides ${activeSlideNumbers[0] + 1} bis ${activeSlideNumbers[activeSlideNumbers.length - 1] + 1} aus ${slidesCount}`;\n }\n setStatus(newStatus);\n };\n\n useImperativeHandle(ref, () => ({\n moveToPage(pageNumber: number) {\n if (!listRef.current || pageNumber < 0 || pageNumber >= pages || pages === 1) return;\n\n const firstSlideIndexOnPage = getFirstSlideIndexOnPage({ pageNumber, perPage: currentPerPage });\n const firstSlideOfPage = listRef.current.querySelector(`[data-index='${firstSlideIndexOnPage}']`);\n\n firstSlideOfPage?.scrollIntoView({ behavior: \"instant\", inline: \"start\" });\n },\n }));\n\n return (\n <section\n className={base()}\n data-bpds=\"carousel-v2\"\n aria-roledescription=\"carousel\"\n aria-labelledby={props[\"aria-labelledby\"] ?? headerId}\n data-bpds-per-page={perPage}\n data-bpds-per-move={perMove}\n data-bpds-rewind={rewind}\n data-bpds-buttons-contrast={buttonsContrast}\n data-bpds-show-arrows={showArrows}\n data-bpds-invert-buttons={invertButtons}\n data-bpds-disable-horizontal-padding={disableHorizontalPadding}\n data-bpds-gap={gap}\n data-bpds-padding={padding}\n >\n {!props[\"aria-labelledby\"] && (\n <TitleComponent id={headerId} className={header()}>\n {title}\n </TitleComponent>\n )}\n <div className={statusClass()} role=\"status\">\n {status}\n </div>\n <div tabIndex={-1} ref={focusManagerRef}></div>\n <CarouselArrow\n invertButtons={invertButtons}\n position=\"left\"\n buttonsContrast={buttonsContrast}\n disableHorizontalPadding={disableHorizontalPadding}\n onClick={onClickLeft}\n disabled={!canScrollPrev}\n show={showArrows}\n />\n <CarouselContext.Provider\n value={{\n perPage,\n activeSlide,\n activePage,\n pages,\n listRef,\n handleScrollEnd,\n gap,\n slideWidth,\n getIntersectionObserver,\n setIntersectionObserver,\n simulateTouch,\n }}\n >\n {children}\n </CarouselContext.Provider>\n <CarouselArrow\n invertButtons={invertButtons}\n position=\"right\"\n buttonsContrast={buttonsContrast}\n disableHorizontalPadding={disableHorizontalPadding}\n onClick={onClickRight}\n disabled={!canScrollNext}\n show={showArrows}\n />\n </section>\n );\n};\n\nCarouselV2Root.displayName = \"CarouselV2\";\n\nexport default CarouselV2Root;\n"],"mappings":";;;;;;;;;AAYA,IAAM,IAAkB,EAAG;CACzB,MAAM;CACN,OAAO;EACL,QAAQ;EACR,QAAQ;CACV;AACF,CAAC,GAqDK,KAAkB,EACtB,aACA,UACA,YAAY,IAAiB,MAC7B,aAAU,GACV,aAAU,GACV,YAAS,IACT,qBAAkB,IAClB,aAAU,GACV,WACA,gBAAa,UACb,SAAM,GACN,mBAAgB,IAChB,8BAA2B,IAC3B,mBAAgB,IAChB,UACA,QACA,GA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GACP,CAAA;GACD,kBAAC,EAAgB,UAAjB;IACE,OAAO;KACL;KACA;KACA;KACA;KACA;KACA,uBA3FsB;MAG5B,IAAM,IAAqB,EAAQ,UAC/B,EAAe;OAAE,gBAAgB,EAAQ,QAAQ;OAAY,iBAAiB,EAAQ;MAAQ,CAAC,IAC/F;MAEJ,AAAI,MAAuB,MACzB,IAAS,GAAoB,CAAmB,GAChD,GAAuB,CAAkB;MAG3C,IAAM,IAAqB,CAAC,GACtB,IAAS,EAAQ,SAAS,iBAAiB,kCAAkC,KAAK,CAAC;MACzF,KAAK,IAAI,IAAI,GAAG,IAAI,EAAO,QAAQ,KAEjC,AADc,EAAO,EAChB,CAAM,aAAa,OAAO,KAC7B,EAAmB,KAAK,CAAC;MAI7B,AAAI,OACG,MAAoB,UAAU,CAAC,KAAmB,MAAoB,WAAW,CAAC,MACrF,EAAgB,SAAS,MAAM,GAEjC,EAA4B;MAK9B,IAAI,IAAY;MAMhB,AALI,EAAmB,WAAW,IAChC,IAAY,SAAS,EAAmB,KAAK,EAAE,OAAO,MAC7C,EAAmB,SAAS,MACrC,IAAY,UAAU,EAAmB,KAAK,EAAE,OAAO,EAAmB,EAAmB,SAAS,KAAK,EAAE,OAAO,MAEtH,EAAU,CAAS;KACrB;KAuDQ;KACA;KACA;KACA;KACA;IACF;IAEC;GACuB,CAAA;GAC1B,kBAAC,GAAD;IACiB;IACf,UAAS;IACQ;IACS;IAC1B,SAAS;IACT,UAAU,CAAC;IACX,MAAM;GACP,CAAA;EACM;;AAEb;AAEA,EAAe,cAAc"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { Ref } from "react";
|
|
2
|
+
export interface PositionIndicatorProps {
|
|
3
|
+
/** Ref to the element */
|
|
4
|
+
ref?: Ref<HTMLDivElement>;
|
|
5
|
+
}
|
|
6
|
+
declare const PositionIndicator: {
|
|
7
|
+
({ ref }: PositionIndicatorProps): React.JSX.Element;
|
|
8
|
+
displayName: string;
|
|
9
|
+
};
|
|
10
|
+
export default PositionIndicator;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
export interface SlideProps {
|
|
3
|
+
/** The content of the slide item. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
/** An optional label of the slide item. */
|
|
6
|
+
"aria-label"?: string;
|
|
7
|
+
/** An optional id of a DOM element that labels the slide item. */
|
|
8
|
+
"aria-labelledby"?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const Slide: {
|
|
11
|
+
({ children, ...props }: SlideProps): React.JSX.Element;
|
|
12
|
+
displayName: string;
|
|
13
|
+
};
|
|
14
|
+
export default Slide;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import React, { ReactNode } from "react";
|
|
2
|
+
export interface SlidesProps {
|
|
3
|
+
/** The content of the slides section. This is where `<CarouselV2.Slide>` items go. */
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
}
|
|
6
|
+
declare const Slides: {
|
|
7
|
+
({ children }: SlidesProps): React.JSX.Element;
|
|
8
|
+
displayName: string;
|
|
9
|
+
};
|
|
10
|
+
export default Slides;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
import type { ResponsiveNumber } from "./CarouselV2";
|
|
3
|
+
export interface CarouselContextProps {
|
|
4
|
+
activePage: number;
|
|
5
|
+
activeSlide: number;
|
|
6
|
+
pages: number;
|
|
7
|
+
perPage: number | ResponsiveNumber;
|
|
8
|
+
listRef: RefObject<HTMLUListElement | null> | null;
|
|
9
|
+
handleScrollEnd?: () => void;
|
|
10
|
+
gap?: number;
|
|
11
|
+
slideWidth: string;
|
|
12
|
+
setIntersectionObserver: (observer: IntersectionObserver | null) => void;
|
|
13
|
+
getIntersectionObserver: () => IntersectionObserver | null;
|
|
14
|
+
simulateTouch?: boolean;
|
|
15
|
+
}
|
|
16
|
+
declare const CarouselContext: import("react").Context<CarouselContextProps>;
|
|
17
|
+
export default CarouselContext;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import type { ResponsiveNumber } from "./CarouselV2";
|
|
3
|
+
interface UseCarouselProps {
|
|
4
|
+
perPage?: number | ResponsiveNumber;
|
|
5
|
+
perMove?: number | ResponsiveNumber;
|
|
6
|
+
rewind?: boolean;
|
|
7
|
+
gap?: number;
|
|
8
|
+
padding?: number;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
simulateTouch?: boolean;
|
|
11
|
+
start?: number;
|
|
12
|
+
}
|
|
13
|
+
declare const useCreateCarousel: ({ perPage, perMove, rewind, padding, gap, children, simulateTouch, start, }: UseCarouselProps) => {
|
|
14
|
+
activePage: number;
|
|
15
|
+
activeSlide: number;
|
|
16
|
+
pages: number;
|
|
17
|
+
listRef: import("react").RefObject<HTMLUListElement | null>;
|
|
18
|
+
canScrollPrev: boolean;
|
|
19
|
+
canScrollNext: boolean;
|
|
20
|
+
onClickLeft: () => void;
|
|
21
|
+
onClickRight: () => void;
|
|
22
|
+
slideWidth: string;
|
|
23
|
+
getIntersectionObserver: () => IntersectionObserver | null;
|
|
24
|
+
setIntersectionObserver: (observer: IntersectionObserver | null) => void;
|
|
25
|
+
buttonTriggeredScroll: boolean;
|
|
26
|
+
finishButtonTriggeredScroll: () => void;
|
|
27
|
+
scrollDirection: "left" | "right" | null;
|
|
28
|
+
slidesCount: number;
|
|
29
|
+
currentPerPage: number;
|
|
30
|
+
};
|
|
31
|
+
export default useCreateCarousel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useCreateCarousel.js","names":[],"sources":["../../src/useCreateCarousel.ts"],"sourcesContent":["import throttle from \"lodash.throttle\";\nimport { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport type { ResponsiveNumber } from \"./CarouselV2\";\nimport useSimulateTouch from \"./useSimulateTouch\";\nimport useStart from \"./useStart\";\nimport {\n getActivePage,\n getActiveSlide,\n getBreakpoint,\n getCanScrollNext,\n getCanScrollPrev,\n getCurrentPerMove,\n getCurrentPerPage,\n getPages,\n getScrollDistanceNext,\n getScrollDistancePrev,\n getSlideWidthStyle,\n roughlyEqual,\n} from \"./utils\";\n\ninterface UseCarouselProps {\n perPage?: number | ResponsiveNumber;\n perMove?: number | ResponsiveNumber;\n rewind?: boolean;\n gap?: number;\n padding?: number;\n children?: ReactNode;\n simulateTouch?: boolean;\n start?: number;\n}\n\nconst useCreateCarousel = ({\n perPage = 1,\n perMove = perPage,\n rewind = false,\n padding = 0,\n gap = 0,\n children,\n simulateTouch = false,\n start,\n}: UseCarouselProps) => {\n ////// STATE //////\n const listRef = useRef<HTMLUListElement>(null);\n\n const initialViewportWidth = typeof document !== \"undefined\" ? document.documentElement.clientWidth : 0;\n const [viewportWidth, setViewportWidth] = useState(initialViewportWidth);\n\n /** The overall width of the scroll container (also the overflowed part).\n * It's dynamic, because the slides are growing and shrinking according to the viewport width! */\n const [scrollContainerWidth, setScrollContainerWidth] = useState(0);\n // The width that is available for the slides. https://developer.mozilla.org/en-US/docs/Glossary/Scroll_container.\n const [scrollPortWidth, setScrollPortWidth] = useState(0);\n /** Position within the scroll container, measured from the left corner. Equals to \"scrollLeft\". */\n const [scrollPosition, setScrollPosition] = useState(0);\n const [canScrollPrev, setCanScrollPrev] = useState(false);\n const [canScrollNext, setCanScrollNext] = useState(true);\n /** If `true`, the carousel is scrolled with help of one of the arrow icon buttons. */\n const [buttonTriggeredScroll, setButtonTriggeredScroll] = useState(false);\n /** If not null, it indicates the direction of the button-triggered scroll. */\n const [scrollDirection, setScrollDirection] = useState<\"left\" | \"right\" | null>(null);\n\n const [slidesCount, setSlidesCount] = useState(0);\n\n const finishButtonTriggeredScroll = () => {\n setButtonTriggeredScroll(false);\n setScrollDirection(null);\n };\n\n const observerRef = useRef<IntersectionObserver | null>(null);\n const getIntersectionObserver = useCallback(() => observerRef.current, []);\n const setIntersectionObserver = useCallback((observer: IntersectionObserver | null) => {\n observerRef.current = observer;\n }, []);\n\n ////// DERIVED STATE //////\n\n const breakpoint = getBreakpoint({ viewportWidth });\n const currentPerPage = getCurrentPerPage({ perPage, breakpoint });\n const currentPerMove = getCurrentPerMove({ perMove, breakpoint });\n const distanceMultiplier = currentPerMove / currentPerPage;\n const slideWidth = getSlideWidthStyle({ perPage: currentPerPage, padding, gap });\n\n /** Overall amount of pages in the carousel. a page can hold one or multiple slides. */\n const pages = useMemo(() => getPages({ slidesCount, currentPerPage }), [slidesCount, currentPerPage]);\n\n // Disable rewind if there are less than 3 pages to avoid infinite prepending/appending loop\n const forceDisableRewind = useMemo(() => pages < 3, [pages]);\n\n /** Currently active slide */\n const [activeSlide, setActiveSlide] = useState(0);\n\n /** Currently active page, derived from activeSlide */\n const activePage = getActivePage({\n activeSlide,\n currentPerPage,\n slidesCount,\n pages,\n rewind,\n });\n\n /** Scroll distance is the amount in px the scroll port will be moved either to left or right. */\n const scrollDistancePrev = getScrollDistancePrev({ scrollPosition, scrollPortWidth, scrollContainerWidth, rewind, distanceMultiplier });\n const scrollDistanceNext = getScrollDistanceNext({\n scrollPosition,\n scrollPortWidth,\n scrollContainerWidth,\n rewind,\n distanceMultiplier,\n });\n\n ////// EFFECTS //////\n\n useEffect(() => {\n const slidesRef = listRef.current;\n if (!slidesRef) return;\n\n const items = Array.from(slidesRef.children) as HTMLLIElement[];\n\n // Add index to each slide item to figure out the current slide and page later on.\n // This effect runs when re-rendering children, so also when context changes due to resizing.\n // We need to ensure the item ids stay the same even in that case, so we only apply indexes if we don't have them already.\n items.forEach((item, i) => (item.dataset.index ??= i.toString()));\n }, [children]);\n\n // inspired by `updateSort` from here: https://codepen.io/scottjehl/pen/jOEzYWw\n const rearrangeSlides = useCallback(\n (el: HTMLUListElement) => {\n const scrollWidth = el.scrollWidth;\n const scrollLeft = el.scrollLeft;\n const width = el.offsetWidth;\n const items = Array.from(el.children);\n\n if (forceDisableRewind) return;\n\n // When teleported, width and scrollWidth might be 0 temporarily,\n // so we don't rearrange in that case to not mess up item order.\n if (!width || !scrollWidth) return;\n\n if (roughlyEqual(scrollLeft, 0)) {\n requestAnimationFrame(() => {\n const itemsToPrepend = items.slice(-currentPerPage).reverse();\n itemsToPrepend.forEach((item) => el.prepend(item));\n el.scrollLeft = scrollLeft + width;\n });\n }\n // roughly right edge\n if (roughlyEqual(scrollWidth - scrollLeft, width)) {\n requestAnimationFrame(() => {\n const itemsToAppend = items.slice(0, currentPerPage);\n itemsToAppend.forEach((item) => el.append(item));\n el.scrollLeft = scrollLeft - width;\n });\n }\n },\n [currentPerPage, forceDisableRewind],\n );\n\n const rearrangeSlidesTimeout = useRef<NodeJS.Timeout | undefined>(undefined);\n useEffect(() => {\n if (!rewind) return;\n\n const slidesRef = listRef.current;\n if (!slidesRef) return;\n\n const callRearrangeSlides = () => {\n if (rearrangeSlidesTimeout) clearTimeout(rearrangeSlidesTimeout.current);\n rearrangeSlidesTimeout.current = setTimeout(() => rearrangeSlides(slidesRef), 50);\n };\n\n slidesRef.addEventListener(\"scroll\", callRearrangeSlides);\n\n return () => {\n if (rearrangeSlidesTimeout.current) clearTimeout(rearrangeSlidesTimeout.current);\n slidesRef.removeEventListener(\"scroll\", callRearrangeSlides);\n };\n }, [rewind, rearrangeSlides]);\n\n useEffect(() => {\n const slidesRef = listRef.current;\n if (!slidesRef) return;\n\n const resizeObserver = new ResizeObserver(([{ target }]) => {\n // When teleporting, `scrollPortWidth`, `scrollContainerWidth` and `pages` are temporarily 0,\n // so we need to check once dimensions have stabilized.\n const newScrollPortWidth = target.getBoundingClientRect().width;\n const newScrollContainerWidth = target.scrollWidth;\n\n setScrollPortWidth(newScrollPortWidth);\n setScrollContainerWidth(newScrollContainerWidth);\n\n // This gets called on initial mount, but also after teleporting which is what we need in order\n // to fix a bug where you can't rewind from first to last page when clicking the prev button.\n if (rewind) rearrangeSlides(slidesRef);\n });\n\n resizeObserver.observe(slidesRef);\n\n return () => {\n resizeObserver.disconnect();\n };\n }, [currentPerPage, rearrangeSlides, rewind, slidesCount]);\n\n useEffect(() => {\n if (!listRef.current) return;\n\n const _slidesCount = listRef.current.querySelectorAll(\"li[aria-roledescription='slide']\").length;\n setSlidesCount(_slidesCount);\n\n const handleResize = () => {\n const newViewportWidth = document.documentElement.clientWidth;\n setViewportWidth(newViewportWidth);\n };\n\n const handleScroll = (event: Event) => {\n if (!event.target) return;\n\n const slidesContainer = event.target as HTMLUListElement;\n\n const newScrollPosition = slidesContainer.scrollLeft;\n const newActiveSlide = getActiveSlide({ scrollPosition: newScrollPosition, slidesContainer });\n\n setScrollPosition(newScrollPosition);\n setActiveSlide(newActiveSlide);\n };\n\n const throttledHandleResize = throttle(handleResize, 200, { trailing: true });\n const throttledHandleScroll = throttle(handleScroll, 200, { trailing: true });\n\n window.addEventListener(\"resize\", throttledHandleResize);\n const slidesRef = listRef.current;\n slidesRef.addEventListener(\"scroll\", throttledHandleScroll);\n\n return () => {\n window.removeEventListener(\"resize\", throttledHandleResize);\n slidesRef.removeEventListener(\"scroll\", throttledHandleScroll);\n };\n }, []);\n\n useSimulateTouch({ simulateTouch, listRef });\n useStart({ start, slidesCount, listRef });\n\n /////////////////////\n\n useEffect(() => {\n if (listRef.current) {\n const _canScrollLeft = getCanScrollPrev({ scrollPosition, rewind, forceDisableRewind });\n const _canScrollNext = getCanScrollNext({ scrollPosition, scrollPortWidth, scrollContainerWidth, rewind, forceDisableRewind });\n setCanScrollPrev(_canScrollLeft);\n setCanScrollNext(_canScrollNext);\n }\n }, [rewind, scrollPosition, scrollPortWidth, scrollContainerWidth, forceDisableRewind]);\n\n ////// CALLBACKS //////\n\n const onClickLeft = useCallback(() => {\n if (!listRef.current || !canScrollPrev) return;\n listRef.current.scrollBy({ left: -scrollDistancePrev, behavior: \"smooth\" });\n setButtonTriggeredScroll(true);\n setScrollDirection(\"left\");\n }, [canScrollPrev, scrollDistancePrev]);\n\n const onClickRight = useCallback(() => {\n if (!listRef.current || !canScrollNext) return;\n listRef.current.scrollBy({ left: scrollDistanceNext, behavior: \"smooth\" });\n setButtonTriggeredScroll(true);\n setScrollDirection(\"right\");\n }, [canScrollNext, scrollDistanceNext]);\n\n return {\n activePage,\n activeSlide,\n pages,\n listRef,\n canScrollPrev,\n canScrollNext,\n onClickLeft,\n onClickRight,\n slideWidth,\n getIntersectionObserver,\n setIntersectionObserver,\n buttonTriggeredScroll,\n finishButtonTriggeredScroll,\n scrollDirection,\n slidesCount,\n currentPerPage,\n };\n};\n\nexport default useCreateCarousel;\n"],"mappings":";;;;;;AAgCA,IAAM,KAAqB,EACzB,aAAU,GACV,aAAU,GACV,YAAS,IACT,aAAU,GACV,SAAM,GACN,cACA,oBAAgB,IAChB,gBACsB;CAEtB,IAAM,IAAU,EAAyB,IAAI,GAEvC,IAAuB,OAAO,WAAa,MAAc,SAAS,gBAAgB,cAAc,GAChG,CAAC,GAAe,KAAoB,EAAS,CAAoB,GAIjE,CAAC,GAAsB,MAA2B,EAAS,CAAC,GAE5D,CAAC,GAAiB,MAAsB,EAAS,CAAC,GAElD,CAAC,GAAgB,MAAqB,EAAS,CAAC,GAChD,CAAC,GAAe,KAAoB,EAAS,EAAK,GAClD,CAAC,GAAe,KAAoB,EAAS,EAAI,GAEjD,CAAC,GAAuB,KAA4B,EAAS,EAAK,GAElE,CAAC,GAAiB,KAAsB,EAAkC,IAAI,GAE9E,CAAC,GAAa,KAAkB,EAAS,CAAC,GAE1C,UAAoC;EAExC,AADA,EAAyB,EAAK,GAC9B,EAAmB,IAAI;CACzB,GAEM,IAAc,EAAoC,IAAI,GACtD,IAA0B,QAAkB,EAAY,SAAS,CAAC,CAAC,GACnE,IAA0B,GAAa,MAA0C;EACrF,EAAY,UAAU;CACxB,GAAG,CAAC,CAAC,GAIC,IAAa,EAAc,EAAE,iBAAc,CAAC,GAC5C,IAAiB,EAAkB;EAAE;EAAS;CAAW,CAAC,GAE1D,IADiB,GAAkB;EAAE;EAAS;CAAW,CACpC,IAAiB,GACtC,KAAa,EAAmB;EAAE,SAAS;EAAgB;EAAS;CAAI,CAA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1B,OAFA,EAAU,iBAAiB,UAAU,CAAqB,SAE7C;GAEX,AADA,OAAO,oBAAoB,UAAU,CAAqB,GAC1D,EAAU,oBAAoB,UAAU,CAAqB;EAC/D;CACF,GAAG,CAAC,CAAC,GAEL,EAAiB;EAAE;EAAe;CAAQ,CAAC,GAC3C,EAAS;EAAE;EAAO;EAAa;CAAQ,CAAC,GAIxC,QAAgB;EACd,IAAI,EAAQ,SAAS;GACnB,IAAM,IAAiB,EAAiB;IAAE;IAAgB;IAAQ;GAAmB,CAAC,GAChF,IAAiB,EAAiB;IAAE;IAAgB;IAAiB;IAAsB;IAAQ;GAAmB,CAAC;GAE7H,AADA,EAAiB,CAAc,GAC/B,EAAiB,CAAc;EACjC;CACF,GAAG;EAAC;EAAQ;EAAgB;EAAiB;EAAsB;CAAkB,CAAC,GAkB/E;EACL;EACA;EACA;EACA;EACA;EACA;EACA,aArBkB,QAAkB;GAChC,CAAC,EAAQ,WAAW,CAAC,MACzB,EAAQ,QAAQ,SAAS;IAAE,MAAM,CAAC;IAAoB,UAAU;GAAS,CAAC,GAC1E,EAAyB,EAAI,GAC7B,EAAmB,MAAM;EAC3B,GAAG,CAAC,GAAe,CAAkB,CAgBnC;EACA,cAfmB,QAAkB;GACjC,CAAC,EAAQ,WAAW,CAAC,MACzB,EAAQ,QAAQ,SAAS;IAAE,MAAM;IAAoB,UAAU;GAAS,CAAC,GACzE,EAAyB,EAAI,GAC7B,EAAmB,OAAO;EAC5B,GAAG,CAAC,GAAe,CAAkB,CAUnC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"useCreateCarousel.js","names":[],"sources":["../../src/useCreateCarousel.ts"],"sourcesContent":["import throttle from \"lodash.throttle\";\nimport { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from \"react\";\n\nimport type { ResponsiveNumber } from \"./CarouselV2\";\nimport useSimulateTouch from \"./useSimulateTouch\";\nimport useStart from \"./useStart\";\nimport {\n getActivePage,\n getActiveSlide,\n getBreakpoint,\n getCanScrollNext,\n getCanScrollPrev,\n getCurrentPerMove,\n getCurrentPerPage,\n getPages,\n getScrollDistanceNext,\n getScrollDistancePrev,\n getSlideWidthStyle,\n roughlyEqual,\n} from \"./utils\";\n\ninterface UseCarouselProps {\n perPage?: number | ResponsiveNumber;\n perMove?: number | ResponsiveNumber;\n rewind?: boolean;\n gap?: number;\n padding?: number;\n children?: ReactNode;\n simulateTouch?: boolean;\n start?: number;\n}\n\nconst useCreateCarousel = ({\n perPage = 1,\n perMove = perPage,\n rewind = false,\n padding = 0,\n gap = 0,\n children,\n simulateTouch = false,\n start,\n}: UseCarouselProps) => {\n ////// STATE //////\n const listRef = useRef<HTMLUListElement>(null);\n\n const initialViewportWidth = typeof document !== \"undefined\" ? document.documentElement.clientWidth : 0;\n const [viewportWidth, setViewportWidth] = useState(initialViewportWidth);\n\n /** The overall width of the scroll container (also the overflowed part).\n * It's dynamic, because the slides are growing and shrinking according to the viewport width! */\n const [scrollContainerWidth, setScrollContainerWidth] = useState(0);\n // The width that is available for the slides. https://developer.mozilla.org/en-US/docs/Glossary/Scroll_container.\n const [scrollPortWidth, setScrollPortWidth] = useState(0);\n /** Position within the scroll container, measured from the left corner. Equals to \"scrollLeft\". */\n const [scrollPosition, setScrollPosition] = useState(0);\n const [canScrollPrev, setCanScrollPrev] = useState(false);\n const [canScrollNext, setCanScrollNext] = useState(true);\n /** If `true`, the carousel is scrolled with help of one of the arrow icon buttons. */\n const [buttonTriggeredScroll, setButtonTriggeredScroll] = useState(false);\n /** If not null, it indicates the direction of the button-triggered scroll. */\n const [scrollDirection, setScrollDirection] = useState<\"left\" | \"right\" | null>(null);\n\n const [slidesCount, setSlidesCount] = useState(0);\n\n const finishButtonTriggeredScroll = () => {\n setButtonTriggeredScroll(false);\n setScrollDirection(null);\n };\n\n const observerRef = useRef<IntersectionObserver | null>(null);\n const getIntersectionObserver = useCallback(() => observerRef.current, []);\n const setIntersectionObserver = useCallback((observer: IntersectionObserver | null) => {\n observerRef.current = observer;\n }, []);\n\n ////// DERIVED STATE //////\n\n const breakpoint = getBreakpoint({ viewportWidth });\n const currentPerPage = getCurrentPerPage({ perPage, breakpoint });\n const currentPerMove = getCurrentPerMove({ perMove, breakpoint });\n const distanceMultiplier = currentPerMove / currentPerPage;\n const slideWidth = getSlideWidthStyle({ perPage: currentPerPage, padding, gap });\n\n /** Overall amount of pages in the carousel. a page can hold one or multiple slides. */\n const pages = useMemo(() => getPages({ slidesCount, currentPerPage }), [slidesCount, currentPerPage]);\n\n // Disable rewind if there are less than 3 pages to avoid infinite prepending/appending loop\n const forceDisableRewind = useMemo(() => pages < 3, [pages]);\n\n /** Currently active slide */\n const [activeSlide, setActiveSlide] = useState(0);\n\n /** Currently active page, derived from activeSlide */\n const activePage = getActivePage({\n activeSlide,\n currentPerPage,\n slidesCount,\n pages,\n rewind,\n });\n\n /** Scroll distance is the amount in px the scroll port will be moved either to left or right. */\n const scrollDistancePrev = getScrollDistancePrev({ scrollPosition, scrollPortWidth, scrollContainerWidth, rewind, distanceMultiplier });\n const scrollDistanceNext = getScrollDistanceNext({\n scrollPosition,\n scrollPortWidth,\n scrollContainerWidth,\n rewind,\n distanceMultiplier,\n });\n\n ////// EFFECTS //////\n\n useEffect(() => {\n const slidesRef = listRef.current;\n if (!slidesRef) return;\n\n const items = Array.from(slidesRef.children) as HTMLLIElement[];\n\n // Add index to each slide item to figure out the current slide and page later on.\n // This effect runs when re-rendering children, so also when context changes due to resizing.\n // We need to ensure the item ids stay the same even in that case, so we only apply indexes if we don't have them already.\n items.forEach((item, i) => (item.dataset.index ??= i.toString()));\n }, [children]);\n\n // inspired by `updateSort` from here: https://codepen.io/scottjehl/pen/jOEzYWw\n const rearrangeSlides = useCallback(\n (el: HTMLUListElement) => {\n const scrollWidth = el.scrollWidth;\n const scrollLeft = el.scrollLeft;\n const width = el.offsetWidth;\n const items = Array.from(el.children);\n\n if (forceDisableRewind) return;\n\n // When teleported, width and scrollWidth might be 0 temporarily,\n // so we don't rearrange in that case to not mess up item order.\n if (!width || !scrollWidth) return;\n\n if (roughlyEqual(scrollLeft, 0)) {\n requestAnimationFrame(() => {\n const itemsToPrepend = items.slice(-currentPerPage).reverse();\n itemsToPrepend.forEach((item) => el.prepend(item));\n el.scrollLeft = scrollLeft + width;\n });\n }\n // roughly right edge\n if (roughlyEqual(scrollWidth - scrollLeft, width)) {\n requestAnimationFrame(() => {\n const itemsToAppend = items.slice(0, currentPerPage);\n itemsToAppend.forEach((item) => el.append(item));\n el.scrollLeft = scrollLeft - width;\n });\n }\n },\n [currentPerPage, forceDisableRewind],\n );\n\n const rearrangeSlidesTimeout = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);\n useEffect(() => {\n if (!rewind) return;\n\n const slidesRef = listRef.current;\n if (!slidesRef) return;\n\n const callRearrangeSlides = () => {\n if (rearrangeSlidesTimeout) clearTimeout(rearrangeSlidesTimeout.current);\n rearrangeSlidesTimeout.current = setTimeout(() => rearrangeSlides(slidesRef), 50);\n };\n\n slidesRef.addEventListener(\"scroll\", callRearrangeSlides);\n\n return () => {\n if (rearrangeSlidesTimeout.current) clearTimeout(rearrangeSlidesTimeout.current);\n slidesRef.removeEventListener(\"scroll\", callRearrangeSlides);\n };\n }, [rewind, rearrangeSlides]);\n\n useEffect(() => {\n const slidesRef = listRef.current;\n if (!slidesRef) return;\n\n const resizeObserver = new ResizeObserver(([{ target }]) => {\n // When teleporting, `scrollPortWidth`, `scrollContainerWidth` and `pages` are temporarily 0,\n // so we need to check once dimensions have stabilized.\n const newScrollPortWidth = target.getBoundingClientRect().width;\n const newScrollContainerWidth = target.scrollWidth;\n\n setScrollPortWidth(newScrollPortWidth);\n setScrollContainerWidth(newScrollContainerWidth);\n\n // This gets called on initial mount, but also after teleporting which is what we need in order\n // to fix a bug where you can't rewind from first to last page when clicking the prev button.\n if (rewind) rearrangeSlides(slidesRef);\n });\n\n resizeObserver.observe(slidesRef);\n\n return () => {\n resizeObserver.disconnect();\n };\n }, [currentPerPage, rearrangeSlides, rewind, slidesCount]);\n\n useEffect(() => {\n if (!listRef.current) return;\n\n const _slidesCount = listRef.current.querySelectorAll(\"li[aria-roledescription='slide']\").length;\n setSlidesCount(_slidesCount);\n\n const handleResize = () => {\n const newViewportWidth = document.documentElement.clientWidth;\n setViewportWidth(newViewportWidth);\n };\n\n const handleScroll = (event: Event) => {\n if (!event.target) return;\n\n const slidesContainer = event.target as HTMLUListElement;\n\n const newScrollPosition = slidesContainer.scrollLeft;\n const newActiveSlide = getActiveSlide({ scrollPosition: newScrollPosition, slidesContainer });\n\n setScrollPosition(newScrollPosition);\n setActiveSlide(newActiveSlide);\n };\n\n const throttledHandleResize = throttle(handleResize, 200, { trailing: true });\n const throttledHandleScroll = throttle(handleScroll, 200, { trailing: true });\n\n window.addEventListener(\"resize\", throttledHandleResize);\n const slidesRef = listRef.current;\n slidesRef.addEventListener(\"scroll\", throttledHandleScroll);\n\n return () => {\n window.removeEventListener(\"resize\", throttledHandleResize);\n slidesRef.removeEventListener(\"scroll\", throttledHandleScroll);\n };\n }, []);\n\n useSimulateTouch({ simulateTouch, listRef });\n useStart({ start, slidesCount, listRef });\n\n /////////////////////\n\n useEffect(() => {\n if (listRef.current) {\n const _canScrollLeft = getCanScrollPrev({ scrollPosition, rewind, forceDisableRewind });\n const _canScrollNext = getCanScrollNext({ scrollPosition, scrollPortWidth, scrollContainerWidth, rewind, forceDisableRewind });\n setCanScrollPrev(_canScrollLeft);\n setCanScrollNext(_canScrollNext);\n }\n }, [rewind, scrollPosition, scrollPortWidth, scrollContainerWidth, forceDisableRewind]);\n\n ////// CALLBACKS //////\n\n const onClickLeft = useCallback(() => {\n if (!listRef.current || !canScrollPrev) return;\n listRef.current.scrollBy({ left: -scrollDistancePrev, behavior: \"smooth\" });\n setButtonTriggeredScroll(true);\n setScrollDirection(\"left\");\n }, [canScrollPrev, scrollDistancePrev]);\n\n const onClickRight = useCallback(() => {\n if (!listRef.current || !canScrollNext) return;\n listRef.current.scrollBy({ left: scrollDistanceNext, behavior: \"smooth\" });\n setButtonTriggeredScroll(true);\n setScrollDirection(\"right\");\n }, [canScrollNext, scrollDistanceNext]);\n\n return {\n activePage,\n activeSlide,\n pages,\n listRef,\n canScrollPrev,\n canScrollNext,\n onClickLeft,\n onClickRight,\n slideWidth,\n getIntersectionObserver,\n setIntersectionObserver,\n buttonTriggeredScroll,\n finishButtonTriggeredScroll,\n scrollDirection,\n slidesCount,\n currentPerPage,\n };\n};\n\nexport default useCreateCarousel;\n"],"mappings":";;;;;;AAgCA,IAAM,KAAqB,EACzB,aAAU,GACV,aAAU,GACV,YAAS,IACT,aAAU,GACV,SAAM,GACN,cACA,oBAAgB,IAChB,gBACsB;CAEtB,IAAM,IAAU,EAAyB,IAAI,GAEvC,IAAuB,OAAO,WAAa,MAAc,SAAS,gBAAgB,cAAc,GAChG,CAAC,GAAe,KAAoB,EAAS,CAAoB,GAIjE,CAAC,GAAsB,MAA2B,EAAS,CAAC,GAE5D,CAAC,GAAiB,MAAsB,EAAS,CAAC,GAElD,CAAC,GAAgB,MAAqB,EAAS,CAAC,GAChD,CAAC,GAAe,KAAoB,EAAS,EAAK,GAClD,CAAC,GAAe,KAAoB,EAAS,EAAI,GAEjD,CAAC,GAAuB,KAA4B,EAAS,EAAK,GAElE,CAAC,GAAiB,KAAsB,EAAkC,IAAI,GAE9E,CAAC,GAAa,KAAkB,EAAS,CAAC,GAE1C,UAAoC;EAExC,AADA,EAAyB,EAAK,GAC9B,EAAmB,IAAI;CACzB,GAEM,IAAc,EAAoC,IAAI,GACtD,IAA0B,QAAkB,EAAY,SAAS,CAAC,CAAC,GACnE,IAA0B,GAAa,MAA0C;EACrF,EAAY,UAAU;CACxB,GAAG,CAAC,CAAC,GAIC,IAAa,EAAc,EAAE,iBAAc,CAAC,GAC5C,IAAiB,EAAkB;EAAE;EAAS;CAAW,CAAC,GAE1D,IADiB,GAAkB;EAAE;EAAS;CAAW,CACpC,IAAiB,GACtC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BAAiB,UAAU,CAAqB;EACvD,IAAM,IAAY,EAAQ;EAG1B,OAFA,EAAU,iBAAiB,UAAU,CAAqB,SAE7C;GAEX,AADA,OAAO,oBAAoB,UAAU,CAAqB,GAC1D,EAAU,oBAAoB,UAAU,CAAqB;EAC/D;CACF,GAAG,CAAC,CAAC,GAEL,EAAiB;EAAE;EAAe;CAAQ,CAAC,GAC3C,EAAS;EAAE;EAAO;EAAa;CAAQ,CAAC,GAIxC,QAAgB;EACd,IAAI,EAAQ,SAAS;GACnB,IAAM,IAAiB,EAAiB;IAAE;IAAgB;IAAQ;GAAmB,CAAC,GAChF,IAAiB,EAAiB;IAAE;IAAgB;IAAiB;IAAsB;IAAQ;GAAmB,CAAC;GAE7H,AADA,EAAiB,CAAc,GAC/B,EAAiB,CAAc;EACjC;CACF,GAAG;EAAC;EAAQ;EAAgB;EAAiB;EAAsB;CAAkB,CAAC,GAkB/E;EACL;EACA;EACA;EACA;EACA;EACA;EACA,aArBkB,QAAkB;GAChC,CAAC,EAAQ,WAAW,CAAC,MACzB,EAAQ,QAAQ,SAAS;IAAE,MAAM,CAAC;IAAoB,UAAU;GAAS,CAAC,GAC1E,EAAyB,EAAI,GAC7B,EAAmB,MAAM;EAC3B,GAAG,CAAC,GAAe,CAAkB,CAgBnC;EACA,cAfmB,QAAkB;GACjC,CAAC,EAAQ,WAAW,CAAC,MACzB,EAAQ,QAAQ,SAAS;IAAE,MAAM;IAAoB,UAAU;GAAS,CAAC,GACzE,EAAyB,EAAI,GAC7B,EAAmB,OAAO;EAC5B,GAAG,CAAC,GAAe,CAAkB,CAUnC;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { RefObject } from "react";
|
|
2
|
+
interface UseSimulateTouchProps {
|
|
3
|
+
listRef: RefObject<HTMLUListElement | null>;
|
|
4
|
+
simulateTouch: boolean;
|
|
5
|
+
}
|
|
6
|
+
declare const useSimulateTouch: ({ simulateTouch, listRef }: UseSimulateTouchProps) => void;
|
|
7
|
+
export default useSimulateTouch;
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Breakpoint } from "@bonprix-ds/utils";
|
|
2
|
+
import type { ResponsiveNumber } from "./CarouselV2";
|
|
3
|
+
/** There is a bug at least on Google Phones + Chrome where scroll snaps to weird numbers like 130.13 instead of 130
|
|
4
|
+
* and thus messing up the calculations. So we need to check for "roughly equal" and "roughly divisible" for now.
|
|
5
|
+
*/
|
|
6
|
+
export declare const roughlyEqual: (a: number, b: number, tolerance?: number) => boolean;
|
|
7
|
+
export declare const getPages: ({ slidesCount, currentPerPage }: {
|
|
8
|
+
slidesCount: number;
|
|
9
|
+
currentPerPage: number;
|
|
10
|
+
}) => number;
|
|
11
|
+
interface GetSlideWidthOptions {
|
|
12
|
+
perPage: number;
|
|
13
|
+
padding: number;
|
|
14
|
+
gap: number;
|
|
15
|
+
}
|
|
16
|
+
export declare const getSlideWidthStyle: ({ perPage, padding, gap }: GetSlideWidthOptions) => string;
|
|
17
|
+
interface CanScrollPrevOptions {
|
|
18
|
+
scrollPosition: number;
|
|
19
|
+
rewind: boolean;
|
|
20
|
+
forceDisableRewind?: boolean;
|
|
21
|
+
}
|
|
22
|
+
export declare const getCanScrollPrev: ({ scrollPosition, rewind, forceDisableRewind }: CanScrollPrevOptions) => boolean;
|
|
23
|
+
interface ScrollFunctionOptions {
|
|
24
|
+
scrollPosition: number;
|
|
25
|
+
scrollPortWidth: number;
|
|
26
|
+
scrollContainerWidth: number;
|
|
27
|
+
rewind?: boolean;
|
|
28
|
+
forceDisableRewind?: boolean;
|
|
29
|
+
}
|
|
30
|
+
export declare const getCanScrollNext: ({ scrollPosition, scrollPortWidth, scrollContainerWidth, rewind, forceDisableRewind, }: ScrollFunctionOptions) => boolean;
|
|
31
|
+
interface ScrollDistanceFunctionOptions extends Omit<ScrollFunctionOptions, "forceDisableRewind"> {
|
|
32
|
+
distanceMultiplier?: number;
|
|
33
|
+
}
|
|
34
|
+
export declare const getScrollDistancePrev: ({ scrollPosition, scrollPortWidth, rewind, distanceMultiplier, }: ScrollDistanceFunctionOptions) => number;
|
|
35
|
+
export declare const getScrollDistanceNext: ({ scrollPosition, scrollPortWidth, scrollContainerWidth, rewind, distanceMultiplier, }: ScrollDistanceFunctionOptions) => number;
|
|
36
|
+
export declare const getBreakpoint: ({ viewportWidth }: {
|
|
37
|
+
viewportWidth: number;
|
|
38
|
+
}) => "s";
|
|
39
|
+
export declare const getActiveSlide: ({ scrollPosition, slidesContainer }: {
|
|
40
|
+
scrollPosition: number;
|
|
41
|
+
slidesContainer: HTMLUListElement;
|
|
42
|
+
}) => number;
|
|
43
|
+
export declare const getActivePage: ({ pages, slidesCount, currentPerPage, rewind, activeSlide, }: {
|
|
44
|
+
pages: number;
|
|
45
|
+
slidesCount: number;
|
|
46
|
+
currentPerPage: number;
|
|
47
|
+
rewind: boolean;
|
|
48
|
+
activeSlide: number;
|
|
49
|
+
}) => number;
|
|
50
|
+
export declare const rightEdgeReached: ({ activeSlide, currentPerPage, slidesCount, }: {
|
|
51
|
+
activeSlide: number;
|
|
52
|
+
currentPerPage: number;
|
|
53
|
+
slidesCount: number;
|
|
54
|
+
}) => boolean;
|
|
55
|
+
export declare const getClosestSlideIndex: (slideOffsets: Record<number, number>, scrollPosition: number) => number;
|
|
56
|
+
export declare const getCurrentPerPage: (options: {
|
|
57
|
+
perPage: number | ResponsiveNumber;
|
|
58
|
+
breakpoint: Breakpoint;
|
|
59
|
+
}) => number;
|
|
60
|
+
export declare const getCurrentPerMove: (options: {
|
|
61
|
+
perMove: number | ResponsiveNumber;
|
|
62
|
+
breakpoint: Breakpoint;
|
|
63
|
+
}) => number;
|
|
64
|
+
export declare const getFirstSlideIndexOnPage: ({ pageNumber, perPage }: {
|
|
65
|
+
pageNumber: number;
|
|
66
|
+
perPage: number;
|
|
67
|
+
}) => number;
|
|
68
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,14 +1,25 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bonprix-ds/react-carousel-v2",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"description": "CarouselV2 component, implemented in React, for the Bonprix Design System.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"license": "UNLICENSED",
|
|
7
|
+
"author": "",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/bonprix/design-system.git",
|
|
11
|
+
"directory": "packages/react/carousel-v2"
|
|
9
12
|
},
|
|
10
|
-
"
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"!dist/tsconfig.tsbuildinfo",
|
|
16
|
+
"!dist/vite.config.d.ts",
|
|
17
|
+
"!dist/**/*.test.d.ts"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
11
20
|
"sideEffects": false,
|
|
21
|
+
"module": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
12
23
|
"exports": {
|
|
13
24
|
".": {
|
|
14
25
|
"import": "./dist/index.js",
|
|
@@ -16,40 +27,30 @@
|
|
|
16
27
|
"default": "./dist/index.js"
|
|
17
28
|
}
|
|
18
29
|
},
|
|
19
|
-
"
|
|
20
|
-
|
|
21
|
-
"
|
|
22
|
-
],
|
|
23
|
-
"keywords": [],
|
|
24
|
-
"author": "",
|
|
25
|
-
"license": "UNLICENSED",
|
|
26
|
-
"repository": {
|
|
27
|
-
"type": "git",
|
|
28
|
-
"url": "git+https://github.com/bonprix/design-system.git",
|
|
29
|
-
"directory": "packages/react/carousel-v2"
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"provenance": true
|
|
30
33
|
},
|
|
31
34
|
"dependencies": {
|
|
32
35
|
"lodash.throttle": "4.1.1",
|
|
33
|
-
"@bonprix-ds/internal-components": "0.2.
|
|
36
|
+
"@bonprix-ds/internal-components": "0.2.1",
|
|
34
37
|
"@bonprix-ds/react-theme-forcer": "1.0.0",
|
|
35
38
|
"@bonprix-ds/utils": "0.2.2"
|
|
36
39
|
},
|
|
37
|
-
"peerDependencies": {
|
|
38
|
-
"react": "^19.0.0",
|
|
39
|
-
"react-dom": "^19.0.0",
|
|
40
|
-
"tailwind-variants": "0.3.1"
|
|
41
|
-
},
|
|
42
40
|
"devDependencies": {
|
|
43
|
-
"vite": "8.2.2",
|
|
44
|
-
"vitest": "4.1.11",
|
|
45
41
|
"@testing-library/dom": "10.4.2",
|
|
46
42
|
"@testing-library/react": "16.3.3",
|
|
47
43
|
"@types/lodash.throttle": "4.1.9",
|
|
48
|
-
"@types/react": "19.
|
|
44
|
+
"@types/react": "19.3.0",
|
|
49
45
|
"@vitejs/plugin-react": "6.1.1",
|
|
50
46
|
"rollup-preserve-directives": "1.1.3",
|
|
51
|
-
"
|
|
52
|
-
"
|
|
47
|
+
"vite": "8.3.0",
|
|
48
|
+
"vitest": "4.1.11"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"react": "^19.3.0",
|
|
52
|
+
"react-dom": "^19.3.0",
|
|
53
|
+
"tailwind-variants": "0.3.1"
|
|
53
54
|
},
|
|
54
55
|
"scripts": {
|
|
55
56
|
"build": "vite build"
|