@alto-avios/alto-ui 3.8.0 → 4.1.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.
- package/dist/IconButton.module-4obqG6tY.js +1050 -0
- package/dist/IconButton.module-4obqG6tY.js.map +1 -0
- package/dist/TabPanel-DNAQ5FkE.js +49 -0
- package/dist/TabPanel-DNAQ5FkE.js.map +1 -0
- package/dist/assets/AutoplayControl.css +1 -0
- package/dist/assets/AviosCurrency.css +1 -1
- package/dist/assets/AviosCurrencyBadge.css +1 -0
- package/dist/assets/Button.css +1 -1
- package/dist/assets/Carousel.css +1 -0
- package/dist/assets/CarouselButton.css +1 -0
- package/dist/assets/CarouselDots.css +1 -0
- package/dist/assets/ComboBox.css +1 -1
- package/dist/assets/LoadingSpinner.css +1 -1
- package/dist/assets/MonthYearField.css +1 -0
- package/dist/assets/SearchField.css +1 -1
- package/dist/assets/SelectCard.css +1 -1
- package/dist/assets/SelectNative.css +1 -1
- package/dist/assets/SkeletonLoader.css +1 -0
- package/dist/assets/TabPanel.css +1 -0
- package/dist/assets/TextAreaField.css +1 -1
- package/dist/assets/ToggleButton.css +1 -1
- package/dist/assets/ToggleIconButton.css +1 -1
- package/dist/components/Accordion/Accordion.d.ts +1 -1
- package/dist/components/Accordion/Accordion.js +18 -13
- package/dist/components/Accordion/Accordion.js.map +1 -1
- package/dist/components/AviosCurrency/AviosCurrency.d.ts +1 -2
- package/dist/components/AviosCurrency/AviosCurrency.js +40 -36
- package/dist/components/AviosCurrency/AviosCurrency.js.map +1 -1
- package/dist/components/AviosCurrencyBadge/AviosCurrencyBadge.d.ts +48 -0
- package/dist/components/AviosCurrencyBadge/AviosCurrencyBadge.js +165 -0
- package/dist/components/AviosCurrencyBadge/AviosCurrencyBadge.js.map +1 -0
- package/dist/components/AviosCurrencyBadge/index.d.ts +1 -0
- package/dist/components/AviosCurrencyBadge/index.js +5 -0
- package/dist/components/AviosCurrencyBadge/index.js.map +1 -0
- package/dist/components/AviosCurrencySymbol/AviosCurrencySymbol.js +3 -3
- package/dist/components/Badge/Badge.d.ts +1 -16
- package/dist/components/Badge/Badge.js +3 -9
- package/dist/components/Badge/Badge.js.map +1 -1
- package/dist/components/Box/Box.d.ts +0 -4
- package/dist/components/Box/Box.js +1 -5
- package/dist/components/Box/Box.js.map +1 -1
- package/dist/components/Button/Button.d.ts +34 -64
- package/dist/components/Button/Button.js +61 -44
- package/dist/components/Button/Button.js.map +1 -1
- package/dist/components/ButtonGroup/ButtonGroup.js +2 -2
- package/dist/components/CalloutBanner/CalloutBanner.js +3 -3
- package/dist/components/Carousel/AutoplayControl/AutoplayControl.d.ts +27 -0
- package/dist/components/Carousel/AutoplayControl/AutoplayControl.js +115 -0
- package/dist/components/Carousel/AutoplayControl/AutoplayControl.js.map +1 -0
- package/dist/components/Carousel/Carousel.d.ts +171 -0
- package/dist/components/Carousel/Carousel.js +373 -0
- package/dist/components/Carousel/Carousel.js.map +1 -0
- package/dist/components/Carousel/CarouselButton/CarouselButton.d.ts +55 -0
- package/dist/components/Carousel/CarouselButton/CarouselButton.js +268 -0
- package/dist/components/Carousel/CarouselButton/CarouselButton.js.map +1 -0
- package/dist/components/Carousel/CarouselControls.d.ts +7 -0
- package/dist/components/Carousel/CarouselControls.js +305 -0
- package/dist/components/Carousel/CarouselControls.js.map +1 -0
- package/dist/components/Carousel/CarouselDots/CarouselDots.d.ts +16 -0
- package/dist/components/Carousel/CarouselDots/CarouselDots.js +150 -0
- package/dist/components/Carousel/CarouselDots/CarouselDots.js.map +1 -0
- package/dist/components/Carousel/index.d.ts +1 -0
- package/dist/components/Carousel/index.js +5 -0
- package/dist/components/Carousel/index.js.map +1 -0
- package/dist/components/ComboBox/ComboBox.js +10 -13
- package/dist/components/ComboBox/ComboBox.js.map +1 -1
- package/dist/components/CreditCardNumberField/CreditCardNumberField.js +5 -5
- package/dist/components/CreditCardSecurityCodeField/CreditCardSecurityCodeField.js +5 -5
- package/dist/components/Dialog/Dialog.js +4 -4
- package/dist/components/ErrorSummary/ErrorSummary.js +4 -4
- package/dist/components/FieldError/FieldError.d.ts +5 -1
- package/dist/components/FieldError/FieldError.js +8 -1
- package/dist/components/FieldError/FieldError.js.map +1 -1
- package/dist/components/FieldHeader/FieldHeader.js +1 -1
- package/dist/components/Grid/Grid.d.ts +6 -1
- package/dist/components/Grid/Grid.js +2 -0
- package/dist/components/Grid/Grid.js.map +1 -1
- package/dist/components/Heading/Heading.d.ts +1 -6
- package/dist/components/Heading/Heading.js +1 -6
- package/dist/components/Heading/Heading.js.map +1 -1
- package/dist/components/Icon/Icon.d.ts +1 -6
- package/dist/components/IconButton/IconButton.d.ts +3 -15
- package/dist/components/IconButton/IconButton.js +18 -128
- package/dist/components/IconButton/IconButton.js.map +1 -1
- package/dist/components/Image/Image.d.ts +0 -1
- package/dist/components/Image/Image.js +8 -13
- package/dist/components/Image/Image.js.map +1 -1
- package/dist/components/Link/Link.d.ts +1 -16
- package/dist/components/Link/Link.js +4 -11
- package/dist/components/Link/Link.js.map +1 -1
- package/dist/components/ListBoxItem/index.d.ts +1 -1
- package/dist/components/LoadingSpinner/LoadingSpinner.d.ts +2 -1
- package/dist/components/LoadingSpinner/LoadingSpinner.js +6 -4
- package/dist/components/LoadingSpinner/LoadingSpinner.js.map +1 -1
- package/dist/components/MonthYearField/MonthYearField.d.ts +107 -0
- package/dist/components/MonthYearField/MonthYearField.js +332 -0
- package/dist/components/MonthYearField/MonthYearField.js.map +1 -0
- package/dist/components/MonthYearField/index.d.ts +2 -0
- package/dist/components/MonthYearField/index.js +5 -0
- package/dist/components/MonthYearField/index.js.map +1 -0
- package/dist/components/Paragraph/Paragraph.d.ts +1 -6
- package/dist/components/Paragraph/Paragraph.js +1 -6
- package/dist/components/Paragraph/Paragraph.js.map +1 -1
- package/dist/components/PasswordField/PasswordField.js +3 -3
- package/dist/components/PhoneNumberField/PhoneNumberField.js +1 -1
- package/dist/components/Popover/Popover.js +2 -2
- package/dist/components/SearchField/SearchField.js +9 -7
- package/dist/components/SearchField/SearchField.js.map +1 -1
- package/dist/components/Section/Section.d.ts +42 -1
- package/dist/components/Section/Section.js +8 -13
- package/dist/components/Section/Section.js.map +1 -1
- package/dist/components/SelectCard/SelectCard.d.ts +6 -1
- package/dist/components/SelectCard/SelectCard.js +20 -17
- package/dist/components/SelectCard/SelectCard.js.map +1 -1
- package/dist/components/SelectNative/SelectNative.js +8 -3
- package/dist/components/SelectNative/SelectNative.js.map +1 -1
- package/dist/components/SkeletonLoader/SkeletonLoader.d.ts +50 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.js +150 -0
- package/dist/components/SkeletonLoader/SkeletonLoader.js.map +1 -0
- package/dist/components/SkeletonLoader/index.d.ts +1 -0
- package/dist/components/SkeletonLoader/index.js +5 -0
- package/dist/components/SkeletonLoader/index.js.map +1 -0
- package/dist/components/Slider/Slider.d.ts +75 -0
- package/dist/components/SubHeading/SubHeading.d.ts +1 -6
- package/dist/components/SubHeading/SubHeading.js +1 -6
- package/dist/components/SubHeading/SubHeading.js.map +1 -1
- package/dist/components/Tabs/Tab.d.ts +19 -0
- package/dist/components/Tabs/Tab.js +12 -0
- package/dist/components/Tabs/Tab.js.map +1 -0
- package/dist/components/Tabs/TabList.d.ts +16 -0
- package/dist/components/Tabs/TabList.js +12 -0
- package/dist/components/Tabs/TabList.js.map +1 -0
- package/dist/components/Tabs/TabPanel.d.ts +14 -0
- package/dist/components/Tabs/TabPanel.js +8 -0
- package/dist/components/Tabs/TabPanel.js.map +1 -0
- package/dist/components/Tabs/Tabs.d.ts +48 -0
- package/dist/components/Tabs/Tabs.js +302 -0
- package/dist/components/Tabs/Tabs.js.map +1 -0
- package/dist/components/Tabs/index.d.ts +1 -0
- package/dist/components/Tabs/index.js +5 -0
- package/dist/components/Tabs/index.js.map +1 -0
- package/dist/components/TextAreaField/TextAreaField.js +1 -1
- package/dist/components/ToggleButton/ToggleButton.d.ts +1 -0
- package/dist/components/ToggleButton/ToggleButton.js +8 -5
- package/dist/components/ToggleButton/ToggleButton.js.map +1 -1
- package/dist/components/ToggleIconButton/ToggleIconButton.js +8 -5
- package/dist/components/ToggleIconButton/ToggleIconButton.js.map +1 -1
- package/dist/components/_base/Field/Field.js +4 -4
- package/dist/components/index.d.ts +10 -0
- package/dist/components/index.js +10 -0
- package/dist/components/index.js.map +1 -1
- package/dist/index.js +10 -0
- package/dist/index.js.map +1 -1
- package/dist/{react-number-format.es-BjKL6crg.js → react-number-format.es-Dbc1db6s.js} +6 -6
- package/dist/{react-number-format.es-BjKL6crg.js.map → react-number-format.es-Dbc1db6s.js.map} +1 -1
- package/package.json +5 -3
|
@@ -0,0 +1,1050 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { createContext, forwardRef, Fragment, useContext, useState, useId, useCallback, useRef, useEffect, useMemo, useLayoutEffect } from "react";
|
|
3
|
+
import { jsx } from "react/jsx-runtime";
|
|
4
|
+
import './assets/IconButton.css';function useAriaBusyScroll(host) {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (!host)
|
|
7
|
+
return;
|
|
8
|
+
function onscroll() {
|
|
9
|
+
if (!host)
|
|
10
|
+
return;
|
|
11
|
+
host.setAttribute("aria-busy", "true");
|
|
12
|
+
host.addEventListener("scrollend", onscrollend, { once: true });
|
|
13
|
+
}
|
|
14
|
+
function onscrollend() {
|
|
15
|
+
if (!host)
|
|
16
|
+
return;
|
|
17
|
+
host.setAttribute("aria-busy", "false");
|
|
18
|
+
host.addEventListener("scroll", onscroll, { once: true });
|
|
19
|
+
}
|
|
20
|
+
host.addEventListener("scroll", onscroll, { once: true });
|
|
21
|
+
host.addEventListener("scrollend", onscrollend);
|
|
22
|
+
return () => {
|
|
23
|
+
host.removeEventListener("scroll", onscroll);
|
|
24
|
+
host.removeEventListener("scrollend", onscrollend);
|
|
25
|
+
};
|
|
26
|
+
}, [host]);
|
|
27
|
+
}
|
|
28
|
+
function useMouseDrag(host) {
|
|
29
|
+
const dragging = useRef(false);
|
|
30
|
+
const handleDragging = useCallback(
|
|
31
|
+
(event) => {
|
|
32
|
+
if (!host)
|
|
33
|
+
return;
|
|
34
|
+
if (!dragging.current) {
|
|
35
|
+
host.style.setProperty("scroll-snap-type", "none");
|
|
36
|
+
dragging.current = true;
|
|
37
|
+
}
|
|
38
|
+
host.scrollBy({
|
|
39
|
+
left: -event.movementX,
|
|
40
|
+
top: -event.movementY,
|
|
41
|
+
behavior: "instant"
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
[host]
|
|
45
|
+
);
|
|
46
|
+
const handleDragEnd = useCallback(() => {
|
|
47
|
+
if (!host)
|
|
48
|
+
return;
|
|
49
|
+
document.removeEventListener("pointermove", handleDragging, {
|
|
50
|
+
capture: true
|
|
51
|
+
});
|
|
52
|
+
const startLeft = host.scrollLeft;
|
|
53
|
+
const startTop = host.scrollTop;
|
|
54
|
+
host.style.removeProperty("scroll-snap-type");
|
|
55
|
+
host.style.setProperty("overflow", "hidden");
|
|
56
|
+
const finalLeft = host.scrollLeft;
|
|
57
|
+
const finalTop = host.scrollTop;
|
|
58
|
+
host.style.removeProperty("overflow");
|
|
59
|
+
host.style.setProperty("scroll-snap-type", "none");
|
|
60
|
+
host.scrollTo({ left: startLeft, top: startTop, behavior: "instant" });
|
|
61
|
+
requestAnimationFrame(async () => {
|
|
62
|
+
if (startLeft !== finalLeft || startTop !== finalTop) {
|
|
63
|
+
host.scrollTo({
|
|
64
|
+
left: finalLeft,
|
|
65
|
+
top: finalTop,
|
|
66
|
+
behavior: "smooth"
|
|
67
|
+
});
|
|
68
|
+
await waitForEvent(host, "scrollend");
|
|
69
|
+
}
|
|
70
|
+
host.style.removeProperty("scroll-snap-type");
|
|
71
|
+
});
|
|
72
|
+
dragging.current = false;
|
|
73
|
+
}, [handleDragging, host]);
|
|
74
|
+
const handleDragStart = useCallback(
|
|
75
|
+
(event) => {
|
|
76
|
+
if (!host)
|
|
77
|
+
return;
|
|
78
|
+
let canDrag = event.button === 0;
|
|
79
|
+
if (canDrag) {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
document.addEventListener("pointermove", handleDragging, {
|
|
82
|
+
capture: true,
|
|
83
|
+
passive: true
|
|
84
|
+
});
|
|
85
|
+
document.addEventListener("pointerup", handleDragEnd, {
|
|
86
|
+
capture: true,
|
|
87
|
+
once: true
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
[handleDragEnd, handleDragging, host]
|
|
92
|
+
);
|
|
93
|
+
useEffect(() => {
|
|
94
|
+
return () => {
|
|
95
|
+
document.removeEventListener("pointermove", handleDragging, {
|
|
96
|
+
capture: true
|
|
97
|
+
});
|
|
98
|
+
document.removeEventListener("pointerup", handleDragEnd, {
|
|
99
|
+
capture: true
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
}, [handleDragEnd, handleDragging]);
|
|
103
|
+
return {
|
|
104
|
+
isDraggingRef: dragging,
|
|
105
|
+
scrollerProps: {
|
|
106
|
+
onMouseDown: handleDragStart
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
function waitForEvent(el, eventName) {
|
|
111
|
+
return new Promise((resolve) => {
|
|
112
|
+
function done(event) {
|
|
113
|
+
if (event.target === el) {
|
|
114
|
+
el.removeEventListener(eventName, done);
|
|
115
|
+
resolve();
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
el.addEventListener(eventName, done);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function useCallbackRef(callback) {
|
|
122
|
+
const callbackRef = useRef(callback);
|
|
123
|
+
useEffect(() => {
|
|
124
|
+
callbackRef.current = callback;
|
|
125
|
+
});
|
|
126
|
+
return useMemo(() => (...args) => {
|
|
127
|
+
var _a;
|
|
128
|
+
return (_a = callbackRef.current) == null ? void 0 : _a.call(callbackRef, ...args);
|
|
129
|
+
}, []);
|
|
130
|
+
}
|
|
131
|
+
var QUERY = "(prefers-reduced-motion: no-preference)";
|
|
132
|
+
function usePrefersReducedMotion() {
|
|
133
|
+
const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);
|
|
134
|
+
useEffect(() => {
|
|
135
|
+
const mediaQueryList = window.matchMedia(QUERY);
|
|
136
|
+
setPrefersReducedMotion(!window.matchMedia(QUERY).matches);
|
|
137
|
+
const listener = (event) => {
|
|
138
|
+
setPrefersReducedMotion(!event.matches);
|
|
139
|
+
};
|
|
140
|
+
mediaQueryList.addEventListener("change", listener);
|
|
141
|
+
return () => {
|
|
142
|
+
mediaQueryList.removeEventListener("change", listener);
|
|
143
|
+
};
|
|
144
|
+
}, []);
|
|
145
|
+
return prefersReducedMotion;
|
|
146
|
+
}
|
|
147
|
+
function assignRef(ref, value) {
|
|
148
|
+
if (typeof ref === "function") {
|
|
149
|
+
ref(value);
|
|
150
|
+
} else if (typeof ref === "object" && ref !== null && "current" in ref) {
|
|
151
|
+
ref.current = value;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
function mergeRefs(...refs) {
|
|
155
|
+
return (node) => {
|
|
156
|
+
refs.forEach((ref) => assignRef(ref, node));
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
function useMergedRef(...refs) {
|
|
160
|
+
return useCallback(mergeRefs(...refs), refs);
|
|
161
|
+
}
|
|
162
|
+
function mergeProps(...args) {
|
|
163
|
+
let result = { ...args[0] };
|
|
164
|
+
for (let i = 1; i < args.length; i++) {
|
|
165
|
+
let props = args[i];
|
|
166
|
+
for (let key in props) {
|
|
167
|
+
let a = result[key];
|
|
168
|
+
let b = props[key];
|
|
169
|
+
if (typeof a === "function" && typeof b === "function" && // This is a lot faster than a regex.
|
|
170
|
+
key[0] === "o" && key[1] === "n" && key.charCodeAt(2) >= /* 'A' */
|
|
171
|
+
65 && key.charCodeAt(2) <= /* 'Z' */
|
|
172
|
+
90) {
|
|
173
|
+
result[key] = chain(a, b);
|
|
174
|
+
} else if (key === "className" && typeof a === "string" && typeof b === "string") {
|
|
175
|
+
result[key] = [a, b].join();
|
|
176
|
+
} else {
|
|
177
|
+
result[key] = b !== void 0 ? b : a;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
}
|
|
183
|
+
function chain(...callbacks) {
|
|
184
|
+
return (...args) => {
|
|
185
|
+
for (let callback of callbacks) {
|
|
186
|
+
if (typeof callback === "function") {
|
|
187
|
+
callback(...args);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
function noop() {
|
|
193
|
+
}
|
|
194
|
+
function clamp(min, value, max) {
|
|
195
|
+
if (value < min) {
|
|
196
|
+
return min;
|
|
197
|
+
}
|
|
198
|
+
if (value > max) {
|
|
199
|
+
return max;
|
|
200
|
+
}
|
|
201
|
+
return value;
|
|
202
|
+
}
|
|
203
|
+
function useCarouselState({
|
|
204
|
+
itemsPerPage = 1,
|
|
205
|
+
scrollBy = "page",
|
|
206
|
+
loop = false,
|
|
207
|
+
initialPages = [],
|
|
208
|
+
isDraggingRef,
|
|
209
|
+
mouseDragging,
|
|
210
|
+
onActivePageIndexChange: propChangeHandler
|
|
211
|
+
}, host) {
|
|
212
|
+
const onActivePageIndexChange = useCallbackRef(propChangeHandler);
|
|
213
|
+
const [activePageIndex, setActivePageIndex] = useState(0);
|
|
214
|
+
const [pages, setPages] = useState(initialPages);
|
|
215
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
216
|
+
const getItems = useCallback(
|
|
217
|
+
({ includeClones } = { includeClones: false }) => {
|
|
218
|
+
if (!host)
|
|
219
|
+
return [];
|
|
220
|
+
let allChildren = Array.from(host.children);
|
|
221
|
+
if (includeClones)
|
|
222
|
+
return allChildren;
|
|
223
|
+
return allChildren.filter((child) => !child.hasAttribute("data-clone"));
|
|
224
|
+
},
|
|
225
|
+
[host]
|
|
226
|
+
);
|
|
227
|
+
const scrollToItem = useCallback(
|
|
228
|
+
(slide, behavior = "smooth") => {
|
|
229
|
+
if (!host)
|
|
230
|
+
return;
|
|
231
|
+
const scrollContainerRect = host.getBoundingClientRect();
|
|
232
|
+
const nextSlideRect = slide.getBoundingClientRect();
|
|
233
|
+
const nextLeft = nextSlideRect.left - scrollContainerRect.left;
|
|
234
|
+
const nextTop = nextSlideRect.top - scrollContainerRect.top;
|
|
235
|
+
host.scrollTo({
|
|
236
|
+
left: nextLeft + host.scrollLeft,
|
|
237
|
+
top: nextTop + host.scrollTop,
|
|
238
|
+
behavior: prefersReducedMotion ? "instant" : behavior
|
|
239
|
+
});
|
|
240
|
+
},
|
|
241
|
+
[prefersReducedMotion, host]
|
|
242
|
+
);
|
|
243
|
+
const scrollToPage = useCallback(
|
|
244
|
+
(index, behavior) => {
|
|
245
|
+
const items = getItems();
|
|
246
|
+
const page = pages[index];
|
|
247
|
+
const itemIndex = page == null ? void 0 : page[0];
|
|
248
|
+
if (items[itemIndex]) {
|
|
249
|
+
scrollToItem(items[itemIndex], behavior);
|
|
250
|
+
}
|
|
251
|
+
},
|
|
252
|
+
[getItems, pages, scrollToItem]
|
|
253
|
+
);
|
|
254
|
+
const updateSnaps = useCallback(() => {
|
|
255
|
+
const actualItemsPerPage = Math.floor(itemsPerPage);
|
|
256
|
+
getItems({ includeClones: true }).forEach((item, index) => {
|
|
257
|
+
const shouldSnap = scrollBy === "item" || (index + actualItemsPerPage) % actualItemsPerPage === 0;
|
|
258
|
+
if (shouldSnap) {
|
|
259
|
+
item.style.setProperty("scroll-snap-align", "start");
|
|
260
|
+
} else {
|
|
261
|
+
item.style.removeProperty("scroll-snap-align");
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
}, [getItems, itemsPerPage, scrollBy]);
|
|
265
|
+
const calculatePages = useCallback(() => {
|
|
266
|
+
const items = getItems();
|
|
267
|
+
const actualItemsPerPage = Math.floor(itemsPerPage);
|
|
268
|
+
let newPages = items.reduce((acc, _, i) => {
|
|
269
|
+
const currPage = acc.at(-1);
|
|
270
|
+
if (currPage && currPage.length < actualItemsPerPage) {
|
|
271
|
+
currPage.push(i);
|
|
272
|
+
} else {
|
|
273
|
+
acc.push([i]);
|
|
274
|
+
}
|
|
275
|
+
return acc;
|
|
276
|
+
}, []);
|
|
277
|
+
if (newPages.length >= 2) {
|
|
278
|
+
let deficit = actualItemsPerPage - newPages.at(-1).length;
|
|
279
|
+
if (deficit > 0) {
|
|
280
|
+
const fill = [...newPages.at(-2)].splice(actualItemsPerPage - deficit);
|
|
281
|
+
newPages.at(-1).unshift(...fill);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
setPages(newPages);
|
|
285
|
+
setActivePageIndex((prev2) => {
|
|
286
|
+
const index = clamp(0, prev2, newPages.length - 1);
|
|
287
|
+
if (index !== prev2) {
|
|
288
|
+
onActivePageIndexChange == null ? void 0 : onActivePageIndexChange({ index });
|
|
289
|
+
}
|
|
290
|
+
return index;
|
|
291
|
+
});
|
|
292
|
+
}, [getItems, itemsPerPage, onActivePageIndexChange]);
|
|
293
|
+
const scrollToPageIndex = useCallback(
|
|
294
|
+
(index) => {
|
|
295
|
+
const items = getItems();
|
|
296
|
+
const itemsWithClones = getItems({ includeClones: true });
|
|
297
|
+
const pagesWithClones = [pages.at(-1), ...pages, pages[0]];
|
|
298
|
+
if (!items.length)
|
|
299
|
+
return -1;
|
|
300
|
+
let nextItem, nextPageIndex, nextPage;
|
|
301
|
+
if (loop === "infinite") {
|
|
302
|
+
let nextIndex = clamp(-1, index, pagesWithClones.length);
|
|
303
|
+
if (nextIndex < 0) {
|
|
304
|
+
nextItem = itemsWithClones[0];
|
|
305
|
+
nextPageIndex = pages.length - 1;
|
|
306
|
+
nextPage = pages[nextPageIndex];
|
|
307
|
+
} else if (nextIndex >= pages.length) {
|
|
308
|
+
nextItem = itemsWithClones.at(-1 * itemsPerPage);
|
|
309
|
+
nextPageIndex = 0;
|
|
310
|
+
nextPage = pages[0];
|
|
311
|
+
} else {
|
|
312
|
+
nextPageIndex = nextIndex;
|
|
313
|
+
nextPage = pages[nextIndex];
|
|
314
|
+
nextItem = items[nextPage[0]];
|
|
315
|
+
}
|
|
316
|
+
} else if (loop === "native") {
|
|
317
|
+
nextPageIndex = index > pages.length - 1 ? 0 : index < 0 ? pages.length - 1 : index;
|
|
318
|
+
nextPage = pages[nextPageIndex];
|
|
319
|
+
let itemIndex = nextPage[0];
|
|
320
|
+
nextItem = items[itemIndex];
|
|
321
|
+
} else {
|
|
322
|
+
nextPageIndex = clamp(0, index, pages.length - 1);
|
|
323
|
+
nextPage = pages[nextPageIndex];
|
|
324
|
+
let itemIndex = nextPage[0];
|
|
325
|
+
nextItem = items[itemIndex];
|
|
326
|
+
}
|
|
327
|
+
scrollToItem(nextItem);
|
|
328
|
+
return nextPageIndex;
|
|
329
|
+
},
|
|
330
|
+
[getItems, itemsPerPage, loop, pages, scrollToItem]
|
|
331
|
+
);
|
|
332
|
+
const next = useCallback(() => {
|
|
333
|
+
return scrollToPageIndex(activePageIndex + 1);
|
|
334
|
+
}, [activePageIndex, scrollToPageIndex]);
|
|
335
|
+
const prev = useCallback(() => {
|
|
336
|
+
return scrollToPageIndex(activePageIndex - 1);
|
|
337
|
+
}, [activePageIndex, scrollToPageIndex]);
|
|
338
|
+
useEffect(() => {
|
|
339
|
+
if (!host || pages.length === 0)
|
|
340
|
+
return;
|
|
341
|
+
getItems({ includeClones: true }).forEach((item) => {
|
|
342
|
+
if (item.hasAttribute("data-clone")) {
|
|
343
|
+
item.remove();
|
|
344
|
+
}
|
|
345
|
+
});
|
|
346
|
+
if (loop === "infinite") {
|
|
347
|
+
const items = getItems();
|
|
348
|
+
const firstPage = pages[0];
|
|
349
|
+
const lastPage = [...pages.at(-1)];
|
|
350
|
+
if (firstPage === lastPage)
|
|
351
|
+
return;
|
|
352
|
+
lastPage.reverse().forEach((slide) => {
|
|
353
|
+
const clone = items[slide].cloneNode(true);
|
|
354
|
+
clone.setAttribute("data-clone", "true");
|
|
355
|
+
clone.setAttribute("inert", "true");
|
|
356
|
+
clone.setAttribute("aria-hidden", "true");
|
|
357
|
+
host.prepend(clone);
|
|
358
|
+
});
|
|
359
|
+
firstPage.forEach((slide) => {
|
|
360
|
+
const clone = items[slide].cloneNode(true);
|
|
361
|
+
clone.setAttribute("data-clone", "true");
|
|
362
|
+
clone.setAttribute("inert", "true");
|
|
363
|
+
clone.setAttribute("aria-hidden", "true");
|
|
364
|
+
host.append(clone);
|
|
365
|
+
});
|
|
366
|
+
}
|
|
367
|
+
updateSnaps();
|
|
368
|
+
scrollToPage(activePageIndex, "instant");
|
|
369
|
+
}, [
|
|
370
|
+
// activePageIndex,
|
|
371
|
+
getItems,
|
|
372
|
+
loop,
|
|
373
|
+
pages,
|
|
374
|
+
scrollToPage,
|
|
375
|
+
host,
|
|
376
|
+
updateSnaps
|
|
377
|
+
]);
|
|
378
|
+
useEffect(() => {
|
|
379
|
+
if (!host)
|
|
380
|
+
return;
|
|
381
|
+
calculatePages();
|
|
382
|
+
updateSnaps();
|
|
383
|
+
const mutationObserver = new MutationObserver((mutations) => {
|
|
384
|
+
const childrenChanged = mutations.some(
|
|
385
|
+
(mutation) => (
|
|
386
|
+
// @ts-expect-error This is fine
|
|
387
|
+
[...mutation.addedNodes, ...mutation.removedNodes].some(
|
|
388
|
+
(el) => el.hasAttribute("data-carousel-item") && !el.hasAttribute("data-clone")
|
|
389
|
+
)
|
|
390
|
+
)
|
|
391
|
+
);
|
|
392
|
+
if (childrenChanged) {
|
|
393
|
+
calculatePages();
|
|
394
|
+
updateSnaps();
|
|
395
|
+
}
|
|
396
|
+
});
|
|
397
|
+
mutationObserver.observe(host, { childList: true, subtree: true });
|
|
398
|
+
return () => {
|
|
399
|
+
mutationObserver.disconnect();
|
|
400
|
+
};
|
|
401
|
+
}, [getItems, host, calculatePages, updateSnaps]);
|
|
402
|
+
useEffect(() => {
|
|
403
|
+
if (!host)
|
|
404
|
+
return;
|
|
405
|
+
const hasIntersected = /* @__PURE__ */ new Set();
|
|
406
|
+
const intersectionObserver = new IntersectionObserver(
|
|
407
|
+
(entries) => {
|
|
408
|
+
for (const entry of entries) {
|
|
409
|
+
if (entry.isIntersecting && !hasIntersected.has(entry.target)) {
|
|
410
|
+
hasIntersected.add(entry.target);
|
|
411
|
+
}
|
|
412
|
+
if (!entry.isIntersecting) {
|
|
413
|
+
hasIntersected.delete(entry.target);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
root: host,
|
|
419
|
+
threshold: 0.6
|
|
420
|
+
}
|
|
421
|
+
);
|
|
422
|
+
const children = getItems({ includeClones: true });
|
|
423
|
+
for (let child of children) {
|
|
424
|
+
intersectionObserver.observe(child);
|
|
425
|
+
}
|
|
426
|
+
function handleScrollEnd() {
|
|
427
|
+
if (hasIntersected.size === 0)
|
|
428
|
+
return;
|
|
429
|
+
const sorted = [...hasIntersected].sort((a, b) => {
|
|
430
|
+
return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
|
|
431
|
+
});
|
|
432
|
+
const firstIntersecting = sorted[0];
|
|
433
|
+
if (loop === "infinite" && firstIntersecting.hasAttribute("data-clone") && !(mouseDragging && (isDraggingRef == null ? void 0 : isDraggingRef.current))) {
|
|
434
|
+
const cloneIndex = firstIntersecting.getAttribute("data-carousel-item");
|
|
435
|
+
const actualItem = getItems().find(
|
|
436
|
+
(el) => el.getAttribute("data-carousel-item") === cloneIndex
|
|
437
|
+
);
|
|
438
|
+
requestAnimationFrame(() => {
|
|
439
|
+
requestAnimationFrame(() => {
|
|
440
|
+
scrollToItem(actualItem, "instant");
|
|
441
|
+
});
|
|
442
|
+
});
|
|
443
|
+
} else {
|
|
444
|
+
const indexString = firstIntersecting.dataset.carouselItem;
|
|
445
|
+
if (process.env.NODE_ENV !== "production") {
|
|
446
|
+
if (!indexString) {
|
|
447
|
+
throw new Error(
|
|
448
|
+
"Failed to find data-carousel-item HTML attribute on an item."
|
|
449
|
+
);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
setActivePageIndex((prev2) => {
|
|
453
|
+
const slideIndex = parseInt(indexString, 10);
|
|
454
|
+
const activePage = pages.findIndex((page) => page[0] === slideIndex);
|
|
455
|
+
const newIndex = clamp(0, activePage, getItems().length);
|
|
456
|
+
if (prev2 !== newIndex) {
|
|
457
|
+
onActivePageIndexChange == null ? void 0 : onActivePageIndexChange({ index: newIndex });
|
|
458
|
+
}
|
|
459
|
+
return newIndex;
|
|
460
|
+
});
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
let timeout;
|
|
464
|
+
function handleScroll() {
|
|
465
|
+
clearTimeout(timeout);
|
|
466
|
+
timeout = setTimeout(() => {
|
|
467
|
+
if (mouseDragging && (isDraggingRef == null ? void 0 : isDraggingRef.current))
|
|
468
|
+
return;
|
|
469
|
+
handleScrollEnd();
|
|
470
|
+
}, 150);
|
|
471
|
+
}
|
|
472
|
+
host.addEventListener("scroll", handleScroll, { passive: true });
|
|
473
|
+
return () => {
|
|
474
|
+
clearTimeout(timeout);
|
|
475
|
+
for (let child of children) {
|
|
476
|
+
intersectionObserver.unobserve(child);
|
|
477
|
+
}
|
|
478
|
+
intersectionObserver.disconnect();
|
|
479
|
+
host.removeEventListener("scroll", handleScroll);
|
|
480
|
+
};
|
|
481
|
+
}, [
|
|
482
|
+
getItems,
|
|
483
|
+
isDraggingRef,
|
|
484
|
+
loop,
|
|
485
|
+
mouseDragging,
|
|
486
|
+
onActivePageIndexChange,
|
|
487
|
+
pages,
|
|
488
|
+
scrollToItem,
|
|
489
|
+
host
|
|
490
|
+
]);
|
|
491
|
+
return useMemo(
|
|
492
|
+
() => ({
|
|
493
|
+
itemsPerPage,
|
|
494
|
+
activePageIndex,
|
|
495
|
+
scrollBy,
|
|
496
|
+
pages,
|
|
497
|
+
next,
|
|
498
|
+
prev,
|
|
499
|
+
scrollToPage
|
|
500
|
+
}),
|
|
501
|
+
[activePageIndex, itemsPerPage, next, pages, prev, scrollBy, scrollToPage]
|
|
502
|
+
);
|
|
503
|
+
}
|
|
504
|
+
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
505
|
+
function useAutoplay({
|
|
506
|
+
enabled,
|
|
507
|
+
interval,
|
|
508
|
+
next
|
|
509
|
+
}) {
|
|
510
|
+
const [shouldAutoplay, setShouldAutoplay] = useState(enabled);
|
|
511
|
+
const [autoplayUserPreference, setAutoplayUserPreference] = useState(enabled);
|
|
512
|
+
useInterval(
|
|
513
|
+
() => requestAnimationFrame(next),
|
|
514
|
+
autoplayUserPreference && shouldAutoplay ? interval : null
|
|
515
|
+
);
|
|
516
|
+
const pause = useCallback(() => {
|
|
517
|
+
if (!enabled)
|
|
518
|
+
return;
|
|
519
|
+
setShouldAutoplay(false);
|
|
520
|
+
}, [enabled]);
|
|
521
|
+
const play = useCallback(() => {
|
|
522
|
+
if (!enabled)
|
|
523
|
+
return;
|
|
524
|
+
setShouldAutoplay(true);
|
|
525
|
+
}, [enabled]);
|
|
526
|
+
useEffect(() => {
|
|
527
|
+
function listener() {
|
|
528
|
+
if (document.visibilityState === "hidden") {
|
|
529
|
+
pause();
|
|
530
|
+
} else {
|
|
531
|
+
play();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
document.addEventListener("visibilitychange", listener);
|
|
535
|
+
return () => {
|
|
536
|
+
document.removeEventListener("visibilitychange", listener);
|
|
537
|
+
};
|
|
538
|
+
}, [pause, play]);
|
|
539
|
+
return {
|
|
540
|
+
shouldAutoplay,
|
|
541
|
+
autoplayUserPreference,
|
|
542
|
+
setAutoplayUserPreference,
|
|
543
|
+
rootProps: {
|
|
544
|
+
onMouseEnter: pause,
|
|
545
|
+
onTouchStart: pause,
|
|
546
|
+
onFocus: pause,
|
|
547
|
+
onMouseLeave: play,
|
|
548
|
+
onTouchEnd: play,
|
|
549
|
+
onBlur: play
|
|
550
|
+
}
|
|
551
|
+
};
|
|
552
|
+
}
|
|
553
|
+
function useInterval(callback, delay) {
|
|
554
|
+
const savedCallback = useRef(callback);
|
|
555
|
+
useIsomorphicLayoutEffect(() => {
|
|
556
|
+
savedCallback.current = callback;
|
|
557
|
+
}, [callback]);
|
|
558
|
+
useEffect(() => {
|
|
559
|
+
if (delay === null) {
|
|
560
|
+
return;
|
|
561
|
+
}
|
|
562
|
+
const id = setInterval(() => {
|
|
563
|
+
savedCallback.current();
|
|
564
|
+
}, delay);
|
|
565
|
+
return () => {
|
|
566
|
+
clearInterval(id);
|
|
567
|
+
};
|
|
568
|
+
}, [delay]);
|
|
569
|
+
}
|
|
570
|
+
function useCarousel({
|
|
571
|
+
itemsPerPage = 1,
|
|
572
|
+
loop = false,
|
|
573
|
+
orientation = "horizontal",
|
|
574
|
+
spaceBetweenItems = "0px",
|
|
575
|
+
mouseDragging = false,
|
|
576
|
+
autoplay: propAutoplay = false,
|
|
577
|
+
autoplayInterval = 5e3,
|
|
578
|
+
scrollPadding,
|
|
579
|
+
onActivePageIndexChange
|
|
580
|
+
} = {}) {
|
|
581
|
+
const [host, setHost] = useState(null);
|
|
582
|
+
const {
|
|
583
|
+
isDraggingRef,
|
|
584
|
+
scrollerProps: { onMouseDown }
|
|
585
|
+
} = useMouseDrag(host);
|
|
586
|
+
const state = useCarouselState(
|
|
587
|
+
{
|
|
588
|
+
itemsPerPage,
|
|
589
|
+
loop,
|
|
590
|
+
mouseDragging,
|
|
591
|
+
isDraggingRef,
|
|
592
|
+
onActivePageIndexChange
|
|
593
|
+
},
|
|
594
|
+
host
|
|
595
|
+
);
|
|
596
|
+
const { pages, activePageIndex, next, prev, scrollToPage } = state;
|
|
597
|
+
const scrollerId = useId();
|
|
598
|
+
const prefersReducedMotion = usePrefersReducedMotion();
|
|
599
|
+
const {
|
|
600
|
+
rootProps: autoplayRootProps,
|
|
601
|
+
autoplayUserPreference,
|
|
602
|
+
setAutoplayUserPreference
|
|
603
|
+
} = useAutoplay({
|
|
604
|
+
enabled: !prefersReducedMotion && propAutoplay,
|
|
605
|
+
interval: autoplayInterval,
|
|
606
|
+
next
|
|
607
|
+
});
|
|
608
|
+
const handleKeyDown = useCallback(
|
|
609
|
+
(e) => {
|
|
610
|
+
if (![
|
|
611
|
+
"ArrowLeft",
|
|
612
|
+
"ArrowRight",
|
|
613
|
+
"ArrowUp",
|
|
614
|
+
"ArrowDown",
|
|
615
|
+
"Home",
|
|
616
|
+
"End"
|
|
617
|
+
].includes(e.key))
|
|
618
|
+
return;
|
|
619
|
+
e.preventDefault();
|
|
620
|
+
let nextPageIndex;
|
|
621
|
+
switch (e.key) {
|
|
622
|
+
case "ArrowUp": {
|
|
623
|
+
if (orientation === "vertical") {
|
|
624
|
+
nextPageIndex = prev();
|
|
625
|
+
}
|
|
626
|
+
break;
|
|
627
|
+
}
|
|
628
|
+
case "ArrowRight": {
|
|
629
|
+
if (orientation === "horizontal") {
|
|
630
|
+
nextPageIndex = next();
|
|
631
|
+
}
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
case "ArrowDown": {
|
|
635
|
+
if (orientation === "vertical") {
|
|
636
|
+
nextPageIndex = next();
|
|
637
|
+
}
|
|
638
|
+
break;
|
|
639
|
+
}
|
|
640
|
+
case "ArrowLeft": {
|
|
641
|
+
if (orientation === "horizontal") {
|
|
642
|
+
nextPageIndex = prev();
|
|
643
|
+
}
|
|
644
|
+
break;
|
|
645
|
+
}
|
|
646
|
+
case "Home": {
|
|
647
|
+
scrollToPage(0);
|
|
648
|
+
nextPageIndex = 0;
|
|
649
|
+
break;
|
|
650
|
+
}
|
|
651
|
+
case "End": {
|
|
652
|
+
scrollToPage(pages.length - 1);
|
|
653
|
+
nextPageIndex = pages.length - 1;
|
|
654
|
+
break;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
return nextPageIndex;
|
|
658
|
+
},
|
|
659
|
+
[next, orientation, pages.length, prev, scrollToPage]
|
|
660
|
+
);
|
|
661
|
+
const handleTablistKeydown = useCallback(
|
|
662
|
+
(e) => {
|
|
663
|
+
var _a;
|
|
664
|
+
const nextIndex = handleKeyDown(e);
|
|
665
|
+
if (!nextIndex)
|
|
666
|
+
return;
|
|
667
|
+
const target = e.target;
|
|
668
|
+
if (document.activeElement === target || ((_a = document.activeElement) == null ? void 0 : _a.contains(target))) {
|
|
669
|
+
const tab = document.querySelector(
|
|
670
|
+
`[data-carousel-tab="${nextIndex}"]`
|
|
671
|
+
);
|
|
672
|
+
tab == null ? void 0 : tab.focus();
|
|
673
|
+
}
|
|
674
|
+
},
|
|
675
|
+
[handleKeyDown]
|
|
676
|
+
);
|
|
677
|
+
useAriaBusyScroll(host);
|
|
678
|
+
return [
|
|
679
|
+
setHost,
|
|
680
|
+
{
|
|
681
|
+
...state,
|
|
682
|
+
autoplayUserPreference,
|
|
683
|
+
rootProps: {
|
|
684
|
+
...autoplayRootProps,
|
|
685
|
+
role: "region",
|
|
686
|
+
"aria-roledescription": "carousel"
|
|
687
|
+
},
|
|
688
|
+
tablistProps: {
|
|
689
|
+
role: "tablist",
|
|
690
|
+
"aria-controls": scrollerId,
|
|
691
|
+
"aria-orientation": orientation,
|
|
692
|
+
"aria-label": "Carousel navigation",
|
|
693
|
+
onKeyDown: handleTablistKeydown
|
|
694
|
+
},
|
|
695
|
+
prevButtonProps: {
|
|
696
|
+
"aria-label": "Previous page",
|
|
697
|
+
"aria-controls": scrollerId,
|
|
698
|
+
"data-prev-button": true,
|
|
699
|
+
onClick: () => prev(),
|
|
700
|
+
"aria-disabled": loop ? void 0 : activePageIndex <= 0 ? true : void 0
|
|
701
|
+
},
|
|
702
|
+
nextButtonProps: {
|
|
703
|
+
"aria-label": "Next page",
|
|
704
|
+
"aria-controls": scrollerId,
|
|
705
|
+
"data-next-button": true,
|
|
706
|
+
onClick: () => next(),
|
|
707
|
+
"aria-disabled": loop ? void 0 : activePageIndex >= pages.length - 1 ? true : void 0
|
|
708
|
+
},
|
|
709
|
+
scrollerProps: {
|
|
710
|
+
"data-carousel-scroller": true,
|
|
711
|
+
"aria-label": "Items Scroller",
|
|
712
|
+
"data-orientation": orientation,
|
|
713
|
+
onMouseDown: mouseDragging ? onMouseDown : noop,
|
|
714
|
+
onKeyDown: handleKeyDown,
|
|
715
|
+
tabIndex: 0,
|
|
716
|
+
"aria-atomic": true,
|
|
717
|
+
"aria-live": propAutoplay && autoplayUserPreference ? "polite" : "off",
|
|
718
|
+
"aria-busy": false,
|
|
719
|
+
id: scrollerId,
|
|
720
|
+
role: "group",
|
|
721
|
+
style: {
|
|
722
|
+
[`gridAuto${orientation === "horizontal" ? "Columns" : "Rows"}`]: `calc(100% / ${itemsPerPage} - ${spaceBetweenItems} * ${itemsPerPage - 1} / ${itemsPerPage})`,
|
|
723
|
+
[`scrollPadding${orientation === "horizontal" ? "Inline" : "Block"}`]: scrollPadding,
|
|
724
|
+
[`padding${orientation === "horizontal" ? "Inline" : "Block"}`]: scrollPadding,
|
|
725
|
+
gap: spaceBetweenItems
|
|
726
|
+
}
|
|
727
|
+
},
|
|
728
|
+
autoplayControlProps: {
|
|
729
|
+
inert: !propAutoplay ? "true" : void 0,
|
|
730
|
+
"aria-label": autoplayUserPreference ? "Disable autoplay" : "Enable autoplay",
|
|
731
|
+
"aria-controls": scrollerId,
|
|
732
|
+
onClick() {
|
|
733
|
+
setAutoplayUserPreference((prev2) => !prev2);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
];
|
|
738
|
+
}
|
|
739
|
+
function useCarouselTab(props, state) {
|
|
740
|
+
const isSelected = props.isSelected ?? state.activePageIndex === props.index;
|
|
741
|
+
let current = props.index + 1, setSize = state.pages.length;
|
|
742
|
+
return {
|
|
743
|
+
tabProps: {
|
|
744
|
+
"data-carousel-tab": props.index,
|
|
745
|
+
role: "tab",
|
|
746
|
+
"aria-label": `Go to page ${current} of ${setSize}`,
|
|
747
|
+
"aria-posinset": current,
|
|
748
|
+
"aria-setsize": setSize,
|
|
749
|
+
"aria-selected": isSelected,
|
|
750
|
+
tabIndex: isSelected ? 0 : -1,
|
|
751
|
+
onClick: () => state.scrollToPage(props.index)
|
|
752
|
+
},
|
|
753
|
+
isSelected
|
|
754
|
+
};
|
|
755
|
+
}
|
|
756
|
+
function useCarouselItem(props, state) {
|
|
757
|
+
var _a;
|
|
758
|
+
const { index } = props;
|
|
759
|
+
const {
|
|
760
|
+
pages = [],
|
|
761
|
+
activePageIndex,
|
|
762
|
+
scrollBy = "page",
|
|
763
|
+
itemsPerPage = 1
|
|
764
|
+
} = state;
|
|
765
|
+
const actualItemsPerPage = Math.floor(itemsPerPage);
|
|
766
|
+
const shouldSnap = scrollBy === "item" || (index + actualItemsPerPage) % actualItemsPerPage === 0;
|
|
767
|
+
const itemCount = new Set(pages == null ? void 0 : pages.flat()).size;
|
|
768
|
+
const label = itemCount ? `${index + 1} of ${itemCount}` : void 0;
|
|
769
|
+
const isInert = (_a = pages == null ? void 0 : pages[activePageIndex]) == null ? void 0 : _a.includes(index);
|
|
770
|
+
return {
|
|
771
|
+
itemProps: {
|
|
772
|
+
"data-carousel-item": index,
|
|
773
|
+
inert: isInert ? void 0 : "true",
|
|
774
|
+
"aria-hidden": isInert ? void 0 : true,
|
|
775
|
+
"aria-roledescription": "carousel item",
|
|
776
|
+
role: "group",
|
|
777
|
+
"aria-label": label,
|
|
778
|
+
style: {
|
|
779
|
+
scrollSnapAlign: shouldSnap ? "start" : void 0
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
var Context = createContext(void 0);
|
|
785
|
+
var useCarouselContext = () => {
|
|
786
|
+
const context = useContext(Context);
|
|
787
|
+
if (!context) {
|
|
788
|
+
throw new Error("react-aria-carousel: No Carousel found in the React tree");
|
|
789
|
+
}
|
|
790
|
+
return context;
|
|
791
|
+
};
|
|
792
|
+
var IndexContext = createContext(-1);
|
|
793
|
+
var Carousel = forwardRef(
|
|
794
|
+
function Carousel2({
|
|
795
|
+
children,
|
|
796
|
+
spaceBetweenItems = "16px",
|
|
797
|
+
scrollPadding,
|
|
798
|
+
mouseDragging,
|
|
799
|
+
autoplay,
|
|
800
|
+
autoplayInterval,
|
|
801
|
+
itemsPerPage = 1,
|
|
802
|
+
loop,
|
|
803
|
+
orientation = "horizontal",
|
|
804
|
+
scrollBy = "page",
|
|
805
|
+
initialPages = [],
|
|
806
|
+
onActivePageIndexChange,
|
|
807
|
+
...props
|
|
808
|
+
}, ref) {
|
|
809
|
+
const carouselProps = {
|
|
810
|
+
spaceBetweenItems,
|
|
811
|
+
scrollPadding,
|
|
812
|
+
mouseDragging,
|
|
813
|
+
autoplay,
|
|
814
|
+
autoplayInterval,
|
|
815
|
+
itemsPerPage,
|
|
816
|
+
loop,
|
|
817
|
+
orientation,
|
|
818
|
+
scrollBy,
|
|
819
|
+
initialPages,
|
|
820
|
+
onActivePageIndexChange
|
|
821
|
+
};
|
|
822
|
+
const [assignRef2, carouselState] = useCarousel(carouselProps);
|
|
823
|
+
return /* @__PURE__ */ jsx(
|
|
824
|
+
Context.Provider,
|
|
825
|
+
{
|
|
826
|
+
value: {
|
|
827
|
+
assignRef: assignRef2,
|
|
828
|
+
carouselState,
|
|
829
|
+
carouselProps
|
|
830
|
+
},
|
|
831
|
+
children: /* @__PURE__ */ jsx("div", { ...mergeProps(carouselState.rootProps, props), ref, children })
|
|
832
|
+
}
|
|
833
|
+
);
|
|
834
|
+
}
|
|
835
|
+
);
|
|
836
|
+
var $bdb11010cef70236$var$idsUpdaterMap = /* @__PURE__ */ new Map();
|
|
837
|
+
function $bdb11010cef70236$export$cd8c9cb68f842629(idA, idB) {
|
|
838
|
+
if (idA === idB)
|
|
839
|
+
return idA;
|
|
840
|
+
let setIdA = $bdb11010cef70236$var$idsUpdaterMap.get(idA);
|
|
841
|
+
if (setIdA) {
|
|
842
|
+
setIdA(idB);
|
|
843
|
+
return idB;
|
|
844
|
+
}
|
|
845
|
+
let setIdB = $bdb11010cef70236$var$idsUpdaterMap.get(idB);
|
|
846
|
+
if (setIdB) {
|
|
847
|
+
setIdB(idA);
|
|
848
|
+
return idA;
|
|
849
|
+
}
|
|
850
|
+
return idB;
|
|
851
|
+
}
|
|
852
|
+
function $ff5963eb1fccf552$export$e08e3b67e392101e(...callbacks) {
|
|
853
|
+
return (...args) => {
|
|
854
|
+
for (let callback of callbacks)
|
|
855
|
+
if (typeof callback === "function")
|
|
856
|
+
callback(...args);
|
|
857
|
+
};
|
|
858
|
+
}
|
|
859
|
+
function r(e) {
|
|
860
|
+
var t, f, n = "";
|
|
861
|
+
if ("string" == typeof e || "number" == typeof e)
|
|
862
|
+
n += e;
|
|
863
|
+
else if ("object" == typeof e)
|
|
864
|
+
if (Array.isArray(e)) {
|
|
865
|
+
var o = e.length;
|
|
866
|
+
for (t = 0; t < o; t++)
|
|
867
|
+
e[t] && (f = r(e[t])) && (n && (n += " "), n += f);
|
|
868
|
+
} else
|
|
869
|
+
for (f in e)
|
|
870
|
+
e[f] && (n && (n += " "), n += f);
|
|
871
|
+
return n;
|
|
872
|
+
}
|
|
873
|
+
function clsx() {
|
|
874
|
+
for (var e, t, f = 0, n = "", o = arguments.length; f < o; f++)
|
|
875
|
+
(e = arguments[f]) && (t = r(e)) && (n && (n += " "), n += t);
|
|
876
|
+
return n;
|
|
877
|
+
}
|
|
878
|
+
var clsx_default = clsx;
|
|
879
|
+
function $3ef42575df84b30b$export$9d1611c77c2fe928(...args) {
|
|
880
|
+
let result = {
|
|
881
|
+
...args[0]
|
|
882
|
+
};
|
|
883
|
+
for (let i = 1; i < args.length; i++) {
|
|
884
|
+
let props = args[i];
|
|
885
|
+
for (let key in props) {
|
|
886
|
+
let a = result[key];
|
|
887
|
+
let b = props[key];
|
|
888
|
+
if (typeof a === "function" && typeof b === "function" && // This is a lot faster than a regex.
|
|
889
|
+
key[0] === "o" && key[1] === "n" && key.charCodeAt(2) >= /* 'A' */
|
|
890
|
+
65 && key.charCodeAt(2) <= /* 'Z' */
|
|
891
|
+
90)
|
|
892
|
+
result[key] = $ff5963eb1fccf552$export$e08e3b67e392101e(a, b);
|
|
893
|
+
else if ((key === "className" || key === "UNSAFE_className") && typeof a === "string" && typeof b === "string")
|
|
894
|
+
result[key] = clsx_default(a, b);
|
|
895
|
+
else if (key === "id" && a && b)
|
|
896
|
+
result.id = $bdb11010cef70236$export$cd8c9cb68f842629(a, b);
|
|
897
|
+
else
|
|
898
|
+
result[key] = b !== void 0 ? b : a;
|
|
899
|
+
}
|
|
900
|
+
}
|
|
901
|
+
return result;
|
|
902
|
+
}
|
|
903
|
+
var CarouselTabs = forwardRef(
|
|
904
|
+
function CarouselTabs2({ children, ...props }, forwardedRef) {
|
|
905
|
+
const { carouselState } = useCarouselContext();
|
|
906
|
+
return /* @__PURE__ */ jsx(
|
|
907
|
+
"div",
|
|
908
|
+
{
|
|
909
|
+
ref: forwardedRef,
|
|
910
|
+
...$3ef42575df84b30b$export$9d1611c77c2fe928(carouselState == null ? void 0 : carouselState.tablistProps, props),
|
|
911
|
+
children: carouselState == null ? void 0 : carouselState.pages.map((_, index) => /* @__PURE__ */ jsx(Fragment, { children: children({
|
|
912
|
+
isSelected: index === (carouselState == null ? void 0 : carouselState.activePageIndex),
|
|
913
|
+
index
|
|
914
|
+
}) }, index))
|
|
915
|
+
}
|
|
916
|
+
);
|
|
917
|
+
}
|
|
918
|
+
);
|
|
919
|
+
var CarouselTab = forwardRef(
|
|
920
|
+
function CarouselTab2(props, forwardedRef) {
|
|
921
|
+
const { carouselState } = useCarouselContext();
|
|
922
|
+
const { index } = props;
|
|
923
|
+
const { tabProps } = useCarouselTab({ index }, carouselState);
|
|
924
|
+
return /* @__PURE__ */ jsx(
|
|
925
|
+
"button",
|
|
926
|
+
{
|
|
927
|
+
type: "button",
|
|
928
|
+
...$3ef42575df84b30b$export$9d1611c77c2fe928(tabProps, props),
|
|
929
|
+
ref: forwardedRef
|
|
930
|
+
}
|
|
931
|
+
);
|
|
932
|
+
}
|
|
933
|
+
);
|
|
934
|
+
var CarouselButton = forwardRef(function CarouselButton2({ dir, ...props }, forwardedRef) {
|
|
935
|
+
const { carouselState } = useCarouselContext();
|
|
936
|
+
const buttonProps = dir === "prev" ? carouselState == null ? void 0 : carouselState.prevButtonProps : carouselState == null ? void 0 : carouselState.nextButtonProps;
|
|
937
|
+
return /* @__PURE__ */ jsx(
|
|
938
|
+
"button",
|
|
939
|
+
{
|
|
940
|
+
ref: forwardedRef,
|
|
941
|
+
type: "button",
|
|
942
|
+
...$3ef42575df84b30b$export$9d1611c77c2fe928(buttonProps, props)
|
|
943
|
+
}
|
|
944
|
+
);
|
|
945
|
+
});
|
|
946
|
+
function _CarouselScroller({ children, items, ...props }, forwardedRef) {
|
|
947
|
+
const context = useCarouselContext();
|
|
948
|
+
const { assignRef: assignRef2, carouselState } = context;
|
|
949
|
+
const ref = useMergedRef(assignRef2, forwardedRef);
|
|
950
|
+
const kids = typeof children === "function" ? items.map(children) : children;
|
|
951
|
+
function getChildren() {
|
|
952
|
+
let kidsArr = React.Children.toArray(kids);
|
|
953
|
+
if (kidsArr.length === 1 && kidsArr[0].type === React.Fragment) {
|
|
954
|
+
kidsArr = React.Children.toArray(kidsArr[0].props.children);
|
|
955
|
+
}
|
|
956
|
+
return kidsArr;
|
|
957
|
+
}
|
|
958
|
+
return /* @__PURE__ */ jsx(
|
|
959
|
+
"div",
|
|
960
|
+
{
|
|
961
|
+
ref,
|
|
962
|
+
...mergeProps(carouselState == null ? void 0 : carouselState.scrollerProps, props),
|
|
963
|
+
style: { ...carouselState == null ? void 0 : carouselState.scrollerProps.style, ...props == null ? void 0 : props.style },
|
|
964
|
+
children: getChildren().map((child, index) => {
|
|
965
|
+
return /* @__PURE__ */ jsx(IndexContext.Provider, { value: index, children: child }, index);
|
|
966
|
+
})
|
|
967
|
+
}
|
|
968
|
+
);
|
|
969
|
+
}
|
|
970
|
+
var CarouselScroller = React.forwardRef(_CarouselScroller);
|
|
971
|
+
var CarouselAutoplayControl = forwardRef(function CarouselAutoplayControl2({ children, ...props }, forwardedRef) {
|
|
972
|
+
const { carouselState } = useCarouselContext();
|
|
973
|
+
return /* @__PURE__ */ jsx(
|
|
974
|
+
"button",
|
|
975
|
+
{
|
|
976
|
+
type: "button",
|
|
977
|
+
ref: forwardedRef,
|
|
978
|
+
...$3ef42575df84b30b$export$9d1611c77c2fe928(carouselState == null ? void 0 : carouselState.autoplayControlProps, props),
|
|
979
|
+
children: typeof children === "function" ? children({
|
|
980
|
+
autoplayUserPreference: carouselState.autoplayUserPreference
|
|
981
|
+
}) : children
|
|
982
|
+
}
|
|
983
|
+
);
|
|
984
|
+
});
|
|
985
|
+
var CarouselItem = forwardRef(
|
|
986
|
+
function CarouselItem2({ index, ...props }, forwardedRef) {
|
|
987
|
+
const ctx = useCarouselContext();
|
|
988
|
+
const itemIndex = useContext(IndexContext);
|
|
989
|
+
const { itemProps } = useCarouselItem(
|
|
990
|
+
{ index: index ?? itemIndex },
|
|
991
|
+
ctx.carouselState
|
|
992
|
+
);
|
|
993
|
+
return /* @__PURE__ */ jsx("div", { ref: forwardedRef, ...mergeProps(itemProps, props) });
|
|
994
|
+
}
|
|
995
|
+
);
|
|
996
|
+
const iconButton = "_iconButton_kb1oz_1";
|
|
997
|
+
const sm = "_sm_kb1oz_24";
|
|
998
|
+
const md = "_md_kb1oz_30";
|
|
999
|
+
const lg = "_lg_kb1oz_36";
|
|
1000
|
+
const accentPrimary = "_accentPrimary_kb1oz_46";
|
|
1001
|
+
const accentSecondary = "_accentSecondary_kb1oz_69";
|
|
1002
|
+
const accentTertiary = "_accentTertiary_kb1oz_98";
|
|
1003
|
+
const accentQuaternary = "_accentQuaternary_kb1oz_127";
|
|
1004
|
+
const criticalPrimary = "_criticalPrimary_kb1oz_151";
|
|
1005
|
+
const criticalSecondary = "_criticalSecondary_kb1oz_175";
|
|
1006
|
+
const criticalTertiary = "_criticalTertiary_kb1oz_204";
|
|
1007
|
+
const criticalQuaternary = "_criticalQuaternary_kb1oz_229";
|
|
1008
|
+
const neutralPrimary = "_neutralPrimary_kb1oz_254";
|
|
1009
|
+
const neutralSecondary = "_neutralSecondary_kb1oz_278";
|
|
1010
|
+
const neutralTertiary = "_neutralTertiary_kb1oz_305";
|
|
1011
|
+
const neutralQuaternary = "_neutralQuaternary_kb1oz_330";
|
|
1012
|
+
const whitePrimary = "_whitePrimary_kb1oz_356";
|
|
1013
|
+
const whiteSecondary = "_whiteSecondary_kb1oz_385";
|
|
1014
|
+
const whiteTertiary = "_whiteTertiary_kb1oz_416";
|
|
1015
|
+
const whiteQuaternary = "_whiteQuaternary_kb1oz_445";
|
|
1016
|
+
const iconButtonStyles = {
|
|
1017
|
+
iconButton,
|
|
1018
|
+
sm,
|
|
1019
|
+
md,
|
|
1020
|
+
lg,
|
|
1021
|
+
accentPrimary,
|
|
1022
|
+
accentSecondary,
|
|
1023
|
+
accentTertiary,
|
|
1024
|
+
accentQuaternary,
|
|
1025
|
+
criticalPrimary,
|
|
1026
|
+
criticalSecondary,
|
|
1027
|
+
criticalTertiary,
|
|
1028
|
+
criticalQuaternary,
|
|
1029
|
+
neutralPrimary,
|
|
1030
|
+
neutralSecondary,
|
|
1031
|
+
neutralTertiary,
|
|
1032
|
+
neutralQuaternary,
|
|
1033
|
+
whitePrimary,
|
|
1034
|
+
whiteSecondary,
|
|
1035
|
+
whiteTertiary,
|
|
1036
|
+
whiteQuaternary,
|
|
1037
|
+
"fa-spinner-third": "_fa-spinner-third_kb1oz_476",
|
|
1038
|
+
"icon-wrapper": "_icon-wrapper_kb1oz_481"
|
|
1039
|
+
};
|
|
1040
|
+
export {
|
|
1041
|
+
Carousel as C,
|
|
1042
|
+
CarouselScroller as a,
|
|
1043
|
+
CarouselItem as b,
|
|
1044
|
+
CarouselTabs as c,
|
|
1045
|
+
CarouselTab as d,
|
|
1046
|
+
CarouselButton as e,
|
|
1047
|
+
CarouselAutoplayControl as f,
|
|
1048
|
+
iconButtonStyles as i
|
|
1049
|
+
};
|
|
1050
|
+
//# sourceMappingURL=IconButton.module-4obqG6tY.js.map
|