@yamada-ui/carousel 2.1.6 → 2.1.7-dev-20241202030831
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/carousel-control.js +7 -7
- package/dist/carousel-control.js.map +1 -1
- package/dist/carousel-control.mjs +2 -2
- package/dist/carousel-indicators.d.mts +5 -1
- package/dist/carousel-indicators.d.ts +5 -1
- package/dist/carousel-indicators.js +12 -12
- package/dist/carousel-indicators.js.map +1 -1
- package/dist/carousel-indicators.mjs +2 -2
- package/dist/carousel-slide.js +3 -3
- package/dist/carousel-slide.js.map +1 -1
- package/dist/carousel-slide.mjs +2 -2
- package/dist/carousel.js +31 -31
- package/dist/carousel.js.map +1 -1
- package/dist/carousel.mjs +5 -5
- package/dist/{chunk-HVGHVY6Y.mjs → chunk-CGOBHOLC.mjs} +3 -3
- package/dist/{chunk-HVGHVY6Y.mjs.map → chunk-CGOBHOLC.mjs.map} +1 -1
- package/dist/{chunk-GXNJ5VYJ.mjs → chunk-EW275YBT.mjs} +4 -4
- package/dist/chunk-EW275YBT.mjs.map +1 -0
- package/dist/{chunk-3TQFASU2.mjs → chunk-ULHBVLOR.mjs} +5 -5
- package/dist/{chunk-GUUMIIYD.mjs → chunk-WCX6YDIO.mjs} +2 -2
- package/dist/{chunk-2HSC64IV.mjs → chunk-Z4DY52L2.mjs} +29 -29
- package/dist/chunk-Z4DY52L2.mjs.map +1 -0
- package/dist/index.js +31 -31
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +5 -5
- package/dist/use-carousel.js +28 -28
- package/dist/use-carousel.js.map +1 -1
- package/dist/use-carousel.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-2HSC64IV.mjs.map +0 -1
- package/dist/chunk-GXNJ5VYJ.mjs.map +0 -1
- /package/dist/{chunk-3TQFASU2.mjs.map → chunk-ULHBVLOR.mjs.map} +0 -0
- /package/dist/{chunk-GUUMIIYD.mjs.map → chunk-WCX6YDIO.mjs.map} +0 -0
@@ -65,13 +65,13 @@ var useCarousel = ({
|
|
65
65
|
onChange
|
66
66
|
});
|
67
67
|
const [indexes, setIndexes] = useState([]);
|
68
|
-
const [
|
68
|
+
const [mouseEnter, setMouseEnter] = useState(false);
|
69
69
|
const timeoutId = useRef(void 0);
|
70
|
-
const
|
70
|
+
const vertical = orientation === "vertical";
|
71
71
|
const [carouselRef, carousel] = useEmblaCarousel(
|
72
72
|
{
|
73
73
|
align,
|
74
|
-
axis:
|
74
|
+
axis: vertical ? "y" : "x",
|
75
75
|
containScroll,
|
76
76
|
dragFree,
|
77
77
|
duration,
|
@@ -101,9 +101,9 @@ var useCarousel = ({
|
|
101
101
|
setSelectedIndex(index2);
|
102
102
|
}, [carousel, setSelectedIndex]);
|
103
103
|
useEffect(() => {
|
104
|
-
const
|
105
|
-
const
|
106
|
-
if (carousel && autoplay && !
|
104
|
+
const stop = mouseEnter && stopMouseEnterAutoplay;
|
105
|
+
const last = !(carousel == null ? void 0 : carousel.canScrollNext());
|
106
|
+
if (carousel && autoplay && !stop && !last) {
|
107
107
|
timeoutId.current = setInterval(() => {
|
108
108
|
carousel.scrollNext();
|
109
109
|
}, delay);
|
@@ -119,7 +119,7 @@ var useCarousel = ({
|
|
119
119
|
delay,
|
120
120
|
stopMouseEnterAutoplay,
|
121
121
|
carousel,
|
122
|
-
|
122
|
+
mouseEnter,
|
123
123
|
loop,
|
124
124
|
selectedIndex
|
125
125
|
]);
|
@@ -179,10 +179,10 @@ var useCarousel = ({
|
|
179
179
|
{ name: "slideSize", token: "sizes", value: slideSize }
|
180
180
|
]),
|
181
181
|
onMouseEnter: handlerAll(props.onMouseEnter, () => {
|
182
|
-
|
182
|
+
setMouseEnter(true);
|
183
183
|
}),
|
184
184
|
onMouseLeave: handlerAll(props.onMouseLeave, () => {
|
185
|
-
|
185
|
+
setMouseEnter(false);
|
186
186
|
})
|
187
187
|
}),
|
188
188
|
[containerProps, gap, slideSize, vars]
|
@@ -214,18 +214,18 @@ var useCarouselSlide = ({ index }) => {
|
|
214
214
|
const { id, indexes, selectedIndex, slidesToScroll } = useCarouselContext();
|
215
215
|
index = Math.floor((index != null ? index : 0) / slidesToScroll);
|
216
216
|
const totalSlides = indexes.length;
|
217
|
-
const
|
217
|
+
const selected = index === selectedIndex;
|
218
218
|
const getSlideProps = useCallback(
|
219
219
|
(props = {}) => ({
|
220
220
|
id: `${id}-${index + 1}`,
|
221
221
|
"aria-label": `${index + 1} of ${totalSlides}`,
|
222
222
|
"aria-roledescription": "slide",
|
223
223
|
"data-index": index,
|
224
|
-
"data-selected": dataAttr(
|
224
|
+
"data-selected": dataAttr(selected),
|
225
225
|
role: "tabpanel",
|
226
226
|
...props
|
227
227
|
}),
|
228
|
-
[id, index,
|
228
|
+
[id, index, selected, totalSlides]
|
229
229
|
);
|
230
230
|
return { getSlideProps };
|
231
231
|
};
|
@@ -235,33 +235,33 @@ var useCarouselControl = ({
|
|
235
235
|
}) => {
|
236
236
|
var _a, _b;
|
237
237
|
const { id, carousel } = useCarouselContext();
|
238
|
-
const
|
239
|
-
const disabled = (_b = (_a = rest.disabled) != null ? _a : rest.isDisabled) != null ? _b :
|
238
|
+
const prev = operation === "prev";
|
239
|
+
const disabled = (_b = (_a = rest.disabled) != null ? _a : rest.isDisabled) != null ? _b : prev ? !(carousel == null ? void 0 : carousel.canScrollPrev()) : !(carousel == null ? void 0 : carousel.canScrollNext());
|
240
240
|
const onClick = useCallback(() => {
|
241
241
|
if (!carousel) return;
|
242
|
-
if (
|
242
|
+
if (prev) {
|
243
243
|
carousel.scrollPrev();
|
244
244
|
} else {
|
245
245
|
carousel.scrollNext();
|
246
246
|
}
|
247
|
-
}, [carousel,
|
247
|
+
}, [carousel, prev]);
|
248
248
|
const getControlProps = useCallback(
|
249
249
|
(props = {}, ref = null) => ({
|
250
250
|
"aria-controls": id,
|
251
|
-
"aria-label": `Go to ${
|
251
|
+
"aria-label": `Go to ${prev ? "previous" : "next"} slide`,
|
252
252
|
...props,
|
253
253
|
ref,
|
254
254
|
disabled,
|
255
255
|
onClick: handlerAll(props.onClick, onClick)
|
256
256
|
}),
|
257
|
-
[disabled, id, onClick,
|
257
|
+
[disabled, id, onClick, prev]
|
258
258
|
);
|
259
259
|
return { getControlProps };
|
260
260
|
};
|
261
261
|
var useCarouselIndicators = () => {
|
262
262
|
const { id, carousel, indexes, orientation, selectedIndex } = useCarouselContext();
|
263
263
|
const refMap = useRef(/* @__PURE__ */ new Map());
|
264
|
-
const
|
264
|
+
const vertical = orientation === "vertical";
|
265
265
|
const onSelect = useCallback(
|
266
266
|
(index) => {
|
267
267
|
var _a;
|
@@ -283,7 +283,7 @@ var useCarouselIndicators = () => {
|
|
283
283
|
const lastIndex = indexes.length - 1;
|
284
284
|
const actions = {
|
285
285
|
ArrowDown: () => {
|
286
|
-
if (!
|
286
|
+
if (!vertical) return;
|
287
287
|
if (index === lastIndex) {
|
288
288
|
index = 0;
|
289
289
|
} else {
|
@@ -292,7 +292,7 @@ var useCarouselIndicators = () => {
|
|
292
292
|
onSelect(index);
|
293
293
|
},
|
294
294
|
ArrowLeft: () => {
|
295
|
-
if (
|
295
|
+
if (vertical) return;
|
296
296
|
if (index === 0) {
|
297
297
|
index = lastIndex;
|
298
298
|
} else {
|
@@ -301,7 +301,7 @@ var useCarouselIndicators = () => {
|
|
301
301
|
onSelect(index);
|
302
302
|
},
|
303
303
|
ArrowRight: () => {
|
304
|
-
if (
|
304
|
+
if (vertical) return;
|
305
305
|
if (index === lastIndex) {
|
306
306
|
index = 0;
|
307
307
|
} else {
|
@@ -310,7 +310,7 @@ var useCarouselIndicators = () => {
|
|
310
310
|
onSelect(index);
|
311
311
|
},
|
312
312
|
ArrowUp: () => {
|
313
|
-
if (!
|
313
|
+
if (!vertical) return;
|
314
314
|
if (index === 0) {
|
315
315
|
index = lastIndex;
|
316
316
|
} else {
|
@@ -326,7 +326,7 @@ var useCarouselIndicators = () => {
|
|
326
326
|
ev.preventDefault();
|
327
327
|
action(ev);
|
328
328
|
},
|
329
|
-
[indexes, onSelect,
|
329
|
+
[indexes, onSelect, vertical]
|
330
330
|
);
|
331
331
|
useUnmountEffect(() => {
|
332
332
|
refMap.current.clear();
|
@@ -343,18 +343,18 @@ var useCarouselIndicators = () => {
|
|
343
343
|
);
|
344
344
|
const getIndicatorProps = useCallback(
|
345
345
|
({ index, ...props }, ref) => {
|
346
|
-
const
|
346
|
+
const selected = index === selectedIndex;
|
347
347
|
const internalRef = createRef();
|
348
348
|
refMap.current.set(index, internalRef);
|
349
349
|
return {
|
350
350
|
ref: mergeRefs(ref, internalRef),
|
351
351
|
"aria-controls": `${id}-${index + 1}`,
|
352
352
|
"aria-label": `Go to ${index + 1} slide`,
|
353
|
-
"aria-selected":
|
353
|
+
"aria-selected": selected,
|
354
354
|
"data-index": index,
|
355
|
-
"data-selected": dataAttr(
|
355
|
+
"data-selected": dataAttr(selected),
|
356
356
|
role: "tab",
|
357
|
-
tabIndex:
|
357
|
+
tabIndex: selected ? 0 : -1,
|
358
358
|
...props,
|
359
359
|
key: index,
|
360
360
|
onClick: handlerAll(props.onClick, onClick(index)),
|
@@ -374,4 +374,4 @@ export {
|
|
374
374
|
useCarouselControl,
|
375
375
|
useCarouselIndicators
|
376
376
|
};
|
377
|
-
//# sourceMappingURL=chunk-
|
377
|
+
//# sourceMappingURL=chunk-Z4DY52L2.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/use-carousel.ts"],"sourcesContent":["import type { IconButtonProps } from \"@yamada-ui/button\"\nimport type {\n CSSUIObject,\n CSSUIProps,\n HTMLProps,\n HTMLUIProps,\n PropGetter,\n RequiredPropGetter,\n} from \"@yamada-ui/core\"\nimport type { EmblaCarouselType, EmblaOptionsType } from \"embla-carousel\"\nimport type {\n KeyboardEvent,\n KeyboardEventHandler,\n MouseEvent,\n RefObject,\n} from \"react\"\nimport { layoutStyleProperties, mergeVars } from \"@yamada-ui/core\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport {\n assignRef,\n createContext,\n dataAttr,\n handlerAll,\n mergeRefs,\n splitObject,\n useUnmountEffect,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport {\n Children,\n createRef,\n useCallback,\n useEffect,\n useId,\n useRef,\n useState,\n} from \"react\"\n\nexport type AlignmentOptionType = EmblaOptionsType[\"align\"]\nexport type ScrollContainOptionType = EmblaOptionsType[\"containScroll\"]\nexport type SlidesInViewOptionsType = EmblaOptionsType[\"inViewThreshold\"]\nexport type DragHandlerOptionType = EmblaOptionsType[\"watchDrag\"]\nexport type ResizeHandlerOptionType = EmblaOptionsType[\"watchResize\"]\nexport type SlidesHandlerOptionType = EmblaOptionsType[\"watchSlides\"]\nexport type CarouselControl = EmblaCarouselType\n\ninterface CarouselContext {\n id: string\n carousel: CarouselControl | undefined\n includeGapInSize: boolean\n indexes: number[]\n orientation: \"horizontal\" | \"vertical\"\n selectedIndex: number\n slidesToScroll: number\n styles: { [key: string]: CSSUIObject | undefined }\n}\n\nexport const [CarouselProvider, useCarouselContext] =\n createContext<CarouselContext>({\n name: \"CarouselContext\",\n errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in \"<Carousel />\"`,\n })\n\nexport interface UseCarouselProps\n extends Omit<HTMLUIProps, \"draggable\" | \"gap\" | \"onChange\"> {\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: AlignmentOptionType\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * Clear leading and trailing empty space that causes excessive scrolling.\n * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.\n *\n * @default false\n */\n containScroll?: ScrollContainOptionType\n /**\n * Ref of the resizable item callback.\n */\n controlRef?: RefObject<CarouselControl | undefined>\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, momentum scrolling will be enabled.\n *\n * @default false\n */\n dragFree?: boolean\n /**\n * If `true`, carousel can be scrolled with mouse and touch interactions.\n *\n * @default true\n */\n draggable?: boolean\n /**\n * Set scroll duration when triggered by any of the API methods.\n * Higher numbers enables slower scrolling.\n * Drag interactions are not affected because duration is then determined by the drag force.\n *\n * @default 25\n */\n duration?: number\n /**\n * The CSS `gap` property.\n *\n * @default '4'\n */\n gap?: CSSUIProps[\"gap\"]\n /**\n * If `true`, gap will be treated as part of the carousel slide size.\n *\n * @default true\n */\n includeGapInSize?: boolean\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.\n *\n * @default 0\n */\n inViewThreshold?: SlidesInViewOptionsType\n /**\n * If `true`, infinite looping.\n * Automatically falls back to false if slide content isn't enough to loop.\n *\n * @default true\n */\n loop?: boolean\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: \"horizontal\" | \"vertical\"\n /**\n * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.\n * Note that this option will be ignored if the dragFree option is set to true.\n *\n * @default false\n */\n skipSnaps?: boolean\n /**\n * The carousel slide width.\n *\n * @default '100%'\n */\n slideSize?: CSSUIProps[\"width\"]\n /**\n * The number of slides that should be scrolled with next or previous buttons.\n *\n * @default 1\n */\n slidesToScroll?: number\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\n /**\n * Enables for scrolling the carousel with mouse and touch interactions.\n * Set this to `false` to disable drag events or pass a custom callback to add your own drag logic.\n *\n * @default true\n */\n watchDrag?: DragHandlerOptionType\n /**\n * Embla automatically watches the container and slides for size changes and runs `reInit` when any size has changed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own resize logic.\n *\n * @default true\n */\n watchResize?: ResizeHandlerOptionType\n /**\n * Embla automatically watches the container for added and/or removed slides and runs `reInit` if needed.\n * Set this to `false` to disable this behaviour or pass a custom callback to add your own slides changed logic.\n *\n * @default true\n */\n watchSlides?: SlidesHandlerOptionType\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * A callback that return the current scroll amount when the carousel is scrolled.\n */\n onScrollProgress?: (progress: number) => void\n}\n\nexport const useCarousel = ({\n id,\n align = \"center\",\n autoplay = false,\n children,\n containScroll = false,\n controlRef,\n defaultIndex = 0,\n delay = 4000,\n dragFree = false,\n draggable = true,\n duration = 25,\n includeGapInSize = true,\n index,\n inViewThreshold = 0,\n loop = true,\n orientation = \"horizontal\",\n skipSnaps = false,\n slideSize = \"100%\",\n slidesToScroll = 1,\n stopMouseEnterAutoplay = true,\n watchDrag = draggable,\n watchResize = true,\n watchSlides = true,\n onChange,\n onScrollProgress,\n ...rest\n}: UseCarouselProps) => {\n const [\n { gap = \"fallback(4, 1rem)\", ...containerProps },\n { vars, ...slidesProps },\n ] = splitObject(rest, layoutStyleProperties)\n const [selectedIndex, setSelectedIndex] = useControllableState({\n defaultValue: defaultIndex,\n value: index,\n onChange,\n })\n const [indexes, setIndexes] = useState<number[]>([])\n const [mouseEnter, setMouseEnter] = useState<boolean>(false)\n const timeoutId = useRef<any>(undefined)\n const vertical = orientation === \"vertical\"\n const [carouselRef, carousel] = useEmblaCarousel(\n {\n align,\n axis: vertical ? \"y\" : \"x\",\n containScroll,\n dragFree,\n duration,\n inViewThreshold,\n loop,\n skipSnaps,\n slidesToScroll,\n startIndex: defaultIndex,\n watchDrag,\n watchResize,\n watchSlides,\n },\n [],\n )\n const uuid = useId()\n\n id ??= uuid\n\n const onScroll = useCallback(() => {\n if (!carousel) return\n\n const progress = Math.round(\n Math.max(0, Math.min(1, carousel.scrollProgress())) * 100,\n )\n\n onScrollProgress?.(progress)\n }, [carousel, onScrollProgress])\n\n const onSelect = useCallback(() => {\n if (!carousel) return\n\n const index = carousel.selectedScrollSnap()\n\n setSelectedIndex(index)\n }, [carousel, setSelectedIndex])\n\n useEffect(() => {\n const stop = mouseEnter && stopMouseEnterAutoplay\n const last = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !stop && !last) {\n timeoutId.current = setInterval(() => {\n carousel.scrollNext()\n }, delay)\n } else {\n if (timeoutId.current) clearInterval(timeoutId.current)\n\n timeoutId.current = undefined\n }\n\n return () => {\n if (timeoutId.current) clearInterval(timeoutId.current)\n }\n }, [\n autoplay,\n delay,\n stopMouseEnterAutoplay,\n carousel,\n mouseEnter,\n loop,\n selectedIndex,\n ])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n carousel.reInit()\n\n const snapList = carousel.scrollSnapList()\n const indexes = snapList.map((_, i) => i)\n\n setIndexes(indexes)\n }, [\n Children.toArray(children).length,\n align,\n orientation,\n loop,\n duration,\n gap,\n slidesToScroll,\n draggable,\n dragFree,\n inViewThreshold,\n skipSnaps,\n containScroll,\n slideSize,\n includeGapInSize,\n ])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n const snapList = carousel.scrollSnapList()\n const indexes = snapList.map((_, i) => i)\n\n setIndexes(indexes)\n }, [carousel])\n\n useUpdateEffect(() => {\n if (carousel) {\n carousel.on(\"select\", onSelect)\n carousel.on(\"scroll\", onScroll)\n\n onScroll()\n\n return () => {\n carousel.off(\"select\", onSelect)\n carousel.off(\"scroll\", onScroll)\n }\n }\n }, [carousel, onScroll])\n\n useUpdateEffect(() => {\n if (!carousel) return\n\n if (index === undefined) return\n\n carousel.scrollTo(index)\n }, [index])\n\n assignRef(controlRef, carousel)\n\n const getContainerProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n \"aria-roledescription\": \"carousel\",\n ...containerProps,\n ...props,\n ref,\n vars: mergeVars(vars, [\n { name: \"gap\", token: \"spaces\", value: gap },\n { name: \"slideSize\", token: \"sizes\", value: slideSize },\n ]),\n onMouseEnter: handlerAll(props.onMouseEnter, () => {\n setMouseEnter(true)\n }),\n onMouseLeave: handlerAll(props.onMouseLeave, () => {\n setMouseEnter(false)\n }),\n }),\n [containerProps, gap, slideSize, vars],\n )\n\n const getSlidesProps: PropGetter = useCallback(\n (props = {}) => ({\n id,\n \"aria-live\": autoplay ? \"off\" : \"polite\",\n ...slidesProps,\n ...props,\n ref: carouselRef,\n }),\n [slidesProps, id, carouselRef, autoplay],\n )\n\n return {\n id,\n carousel,\n children,\n includeGapInSize,\n indexes,\n orientation,\n selectedIndex,\n slidesToScroll,\n getContainerProps,\n getSlidesProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n\nexport interface UseCarouselSlideProps {\n index?: number\n}\n\nexport const useCarouselSlide = ({ index }: UseCarouselSlideProps) => {\n const { id, indexes, selectedIndex, slidesToScroll } = useCarouselContext()\n\n index = Math.floor((index ?? 0) / slidesToScroll)\n\n const totalSlides = indexes.length\n const selected = index === selectedIndex\n\n const getSlideProps: PropGetter = useCallback(\n (props = {}) => ({\n id: `${id}-${index + 1}`,\n \"aria-label\": `${index + 1} of ${totalSlides}`,\n \"aria-roledescription\": \"slide\",\n \"data-index\": index,\n \"data-selected\": dataAttr(selected),\n role: \"tabpanel\",\n ...props,\n }),\n [id, index, selected, totalSlides],\n )\n\n return { getSlideProps }\n}\n\nexport type UseCarouselSlideReturn = ReturnType<typeof useCarouselSlide>\n\nexport interface UseCarouselControlProps extends IconButtonProps {\n operation: \"next\" | \"prev\"\n}\n\nexport const useCarouselControl = ({\n operation,\n ...rest\n}: UseCarouselControlProps) => {\n const { id, carousel } = useCarouselContext()\n\n const prev = operation === \"prev\"\n\n const disabled =\n rest.disabled ??\n rest.isDisabled ??\n (prev ? !carousel?.canScrollPrev() : !carousel?.canScrollNext())\n\n const onClick = useCallback(() => {\n if (!carousel) return\n\n if (prev) {\n carousel.scrollPrev()\n } else {\n carousel.scrollNext()\n }\n }, [carousel, prev])\n\n const getControlProps: PropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n \"aria-controls\": id,\n \"aria-label\": `Go to ${prev ? \"previous\" : \"next\"} slide`,\n ...props,\n ref,\n disabled,\n onClick: handlerAll(props.onClick, onClick),\n }),\n [disabled, id, onClick, prev],\n )\n\n return { getControlProps }\n}\n\nexport type UseCarouselControlReturn = ReturnType<typeof useCarouselControl>\n\nexport const useCarouselIndicators = () => {\n const { id, carousel, indexes, orientation, selectedIndex } =\n useCarouselContext()\n const refMap = useRef<Map<number, RefObject<HTMLButtonElement>>>(new Map())\n const vertical = orientation === \"vertical\"\n\n const onSelect = useCallback(\n (index: number) => {\n const ref = refMap.current.get(index)\n\n ref?.current?.focus()\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onClick = useCallback(\n (index: number) => (ev: MouseEvent) => {\n ev.stopPropagation()\n\n carousel?.scrollTo(index)\n },\n [carousel],\n )\n\n const onKeyDown = useCallback(\n (index: number) => (ev: KeyboardEvent) => {\n const lastIndex = indexes.length - 1\n\n const actions: { [key: string]: KeyboardEventHandler } = {\n ArrowDown: () => {\n if (!vertical) return\n\n if (index === lastIndex) {\n index = 0\n } else {\n index += 1\n }\n\n onSelect(index)\n },\n ArrowLeft: () => {\n if (vertical) return\n\n if (index === 0) {\n index = lastIndex\n } else {\n index -= 1\n }\n\n onSelect(index)\n },\n ArrowRight: () => {\n if (vertical) return\n\n if (index === lastIndex) {\n index = 0\n } else {\n index += 1\n }\n\n onSelect(index)\n },\n ArrowUp: () => {\n if (!vertical) return\n\n if (index === 0) {\n index = lastIndex\n } else {\n index -= 1\n }\n\n onSelect(index)\n },\n End: () => onSelect(lastIndex),\n Home: () => onSelect(0),\n }\n\n const action = actions[ev.key]\n\n if (!action) return\n\n ev.preventDefault()\n action(ev)\n },\n [indexes, onSelect, vertical],\n )\n\n useUnmountEffect(() => {\n refMap.current.clear()\n })\n\n const getIndicatorsProps: PropGetter = useCallback(\n (props = {}, ref = null) => ({\n \"aria-label\": \"Sliders\",\n \"aria-orientation\": orientation,\n role: \"tablist\",\n ...props,\n ref,\n }),\n [orientation],\n )\n\n const getIndicatorProps: RequiredPropGetter<\n { index: number } & HTMLProps<\"button\">,\n HTMLProps<\"button\">\n > = useCallback(\n ({ index, ...props }, ref) => {\n const selected = index === selectedIndex\n const internalRef = createRef<HTMLButtonElement>()\n\n refMap.current.set(index, internalRef)\n\n return {\n ref: mergeRefs(ref, internalRef),\n \"aria-controls\": `${id}-${index + 1}`,\n \"aria-label\": `Go to ${index + 1} slide`,\n \"aria-selected\": selected,\n \"data-index\": index,\n \"data-selected\": dataAttr(selected),\n role: \"tab\",\n tabIndex: selected ? 0 : -1,\n ...props,\n key: index,\n onClick: handlerAll(props.onClick, onClick(index)),\n onKeyDown: handlerAll(props.onKeyDown, onKeyDown(index)),\n }\n },\n [onClick, onKeyDown, selectedIndex, id],\n )\n\n return { indexes, getIndicatorProps, getIndicatorsProps }\n}\n\nexport type UseCarouselIndicatorsReturn = ReturnType<\n typeof useCarouselIndicators\n>\n"],"mappings":";;;AAgBA,SAAS,uBAAuB,iBAAiB;AACjD,SAAS,4BAA4B;AACrC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,sBAAsB;AAC7B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAqBA,IAAM,CAAC,kBAAkB,kBAAkB,IAChD,cAA+B;AAAA,EAC7B,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AAsJI,IAAM,cAAc,CAAC;AAAA,EAC1B;AAAA,EACA,QAAQ;AAAA,EACR,WAAW;AAAA,EACX;AAAA,EACA,gBAAgB;AAAA,EAChB;AAAA,EACA,eAAe;AAAA,EACf,QAAQ;AAAA,EACR,WAAW;AAAA,EACX,YAAY;AAAA,EACZ,WAAW;AAAA,EACX,mBAAmB;AAAA,EACnB;AAAA,EACA,kBAAkB;AAAA,EAClB,OAAO;AAAA,EACP,cAAc;AAAA,EACd,YAAY;AAAA,EACZ,YAAY;AAAA,EACZ,iB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AAG;AAE7B,UAAI,CAAC,OAAQ;AAEb,SAAG,eAAe;AAClB,aAAO,EAAE;AAAA,IACX;AAAA,IACA,CAAC,SAAS,UAAU,QAAQ;AAAA,EAC9B;AAEA,mBAAiB,MAAM;AACrB,WAAO,QAAQ,MAAM;AAAA,EACvB,CAAC;AAED,QAAM,qBAAiC;AAAA,IACrC,CAAC,QAAQ,CAAC,GAAG,MAAM,UAAU;AAAA,MAC3B,cAAc;AAAA,MACd,oBAAoB;AAAA,MACpB,MAAM;AAAA,MACN,GAAG;AAAA,MACH;AAAA,IACF;AAAA,IACA,CAAC,WAAW;AAAA,EACd;AAEA,QAAM,oBAGF;AAAA,IACF,CAAC,EAAE,OAAO,GAAG,MAAM,GAAG,QAAQ;AAC5B,YAAM,WAAW,UAAU;AAC3B,YAAM,cAAc,UAA6B;AAEjD,aAAO,QAAQ,IAAI,OAAO,WAAW;AAErC,aAAO;AAAA,QACL,KAAK,UAAU,KAAK,WAAW;AAAA,QAC/B,iBAAiB,GAAG,EAAE,IAAI,QAAQ,CAAC;AAAA,QACnC,cAAc,SAAS,QAAQ,CAAC;AAAA,QAChC,iBAAiB;AAAA,QACjB,cAAc;AAAA,QACd,iBAAiB,SAAS,QAAQ;AAAA,QAClC,MAAM;AAAA,QACN,UAAU,WAAW,IAAI;AAAA,QACzB,GAAG;AAAA,QACH,KAAK;AAAA,QACL,SAAS,WAAW,MAAM,SAAS,QAAQ,KAAK,CAAC;AAAA,QACjD,WAAW,WAAW,MAAM,WAAW,UAAU,KAAK,CAAC;AAAA,MACzD;AAAA,IACF;AAAA,IACA,CAAC,SAAS,WAAW,eAAe,EAAE;AAAA,EACxC;AAEA,SAAO,EAAE,SAAS,mBAAmB,mBAAmB;AAC1D;","names":["index","indexes"]}
|
package/dist/index.js
CHANGED
@@ -99,13 +99,13 @@ var useCarousel = ({
|
|
99
99
|
onChange
|
100
100
|
});
|
101
101
|
const [indexes, setIndexes] = (0, import_react.useState)([]);
|
102
|
-
const [
|
102
|
+
const [mouseEnter, setMouseEnter] = (0, import_react.useState)(false);
|
103
103
|
const timeoutId = (0, import_react.useRef)(void 0);
|
104
|
-
const
|
104
|
+
const vertical = orientation === "vertical";
|
105
105
|
const [carouselRef, carousel] = (0, import_embla_carousel_react.default)(
|
106
106
|
{
|
107
107
|
align,
|
108
|
-
axis:
|
108
|
+
axis: vertical ? "y" : "x",
|
109
109
|
containScroll,
|
110
110
|
dragFree,
|
111
111
|
duration,
|
@@ -135,9 +135,9 @@ var useCarousel = ({
|
|
135
135
|
setSelectedIndex(index2);
|
136
136
|
}, [carousel, setSelectedIndex]);
|
137
137
|
(0, import_react.useEffect)(() => {
|
138
|
-
const
|
139
|
-
const
|
140
|
-
if (carousel && autoplay && !
|
138
|
+
const stop = mouseEnter && stopMouseEnterAutoplay;
|
139
|
+
const last = !(carousel == null ? void 0 : carousel.canScrollNext());
|
140
|
+
if (carousel && autoplay && !stop && !last) {
|
141
141
|
timeoutId.current = setInterval(() => {
|
142
142
|
carousel.scrollNext();
|
143
143
|
}, delay);
|
@@ -153,7 +153,7 @@ var useCarousel = ({
|
|
153
153
|
delay,
|
154
154
|
stopMouseEnterAutoplay,
|
155
155
|
carousel,
|
156
|
-
|
156
|
+
mouseEnter,
|
157
157
|
loop,
|
158
158
|
selectedIndex
|
159
159
|
]);
|
@@ -213,10 +213,10 @@ var useCarousel = ({
|
|
213
213
|
{ name: "slideSize", token: "sizes", value: slideSize }
|
214
214
|
]),
|
215
215
|
onMouseEnter: (0, import_utils.handlerAll)(props.onMouseEnter, () => {
|
216
|
-
|
216
|
+
setMouseEnter(true);
|
217
217
|
}),
|
218
218
|
onMouseLeave: (0, import_utils.handlerAll)(props.onMouseLeave, () => {
|
219
|
-
|
219
|
+
setMouseEnter(false);
|
220
220
|
})
|
221
221
|
}),
|
222
222
|
[containerProps, gap, slideSize, vars]
|
@@ -248,18 +248,18 @@ var useCarouselSlide = ({ index }) => {
|
|
248
248
|
const { id, indexes, selectedIndex, slidesToScroll } = useCarouselContext();
|
249
249
|
index = Math.floor((index != null ? index : 0) / slidesToScroll);
|
250
250
|
const totalSlides = indexes.length;
|
251
|
-
const
|
251
|
+
const selected = index === selectedIndex;
|
252
252
|
const getSlideProps = (0, import_react.useCallback)(
|
253
253
|
(props = {}) => ({
|
254
254
|
id: `${id}-${index + 1}`,
|
255
255
|
"aria-label": `${index + 1} of ${totalSlides}`,
|
256
256
|
"aria-roledescription": "slide",
|
257
257
|
"data-index": index,
|
258
|
-
"data-selected": (0, import_utils.dataAttr)(
|
258
|
+
"data-selected": (0, import_utils.dataAttr)(selected),
|
259
259
|
role: "tabpanel",
|
260
260
|
...props
|
261
261
|
}),
|
262
|
-
[id, index,
|
262
|
+
[id, index, selected, totalSlides]
|
263
263
|
);
|
264
264
|
return { getSlideProps };
|
265
265
|
};
|
@@ -269,33 +269,33 @@ var useCarouselControl = ({
|
|
269
269
|
}) => {
|
270
270
|
var _a, _b;
|
271
271
|
const { id, carousel } = useCarouselContext();
|
272
|
-
const
|
273
|
-
const disabled = (_b = (_a = rest.disabled) != null ? _a : rest.isDisabled) != null ? _b :
|
272
|
+
const prev = operation === "prev";
|
273
|
+
const disabled = (_b = (_a = rest.disabled) != null ? _a : rest.isDisabled) != null ? _b : prev ? !(carousel == null ? void 0 : carousel.canScrollPrev()) : !(carousel == null ? void 0 : carousel.canScrollNext());
|
274
274
|
const onClick = (0, import_react.useCallback)(() => {
|
275
275
|
if (!carousel) return;
|
276
|
-
if (
|
276
|
+
if (prev) {
|
277
277
|
carousel.scrollPrev();
|
278
278
|
} else {
|
279
279
|
carousel.scrollNext();
|
280
280
|
}
|
281
|
-
}, [carousel,
|
281
|
+
}, [carousel, prev]);
|
282
282
|
const getControlProps = (0, import_react.useCallback)(
|
283
283
|
(props = {}, ref = null) => ({
|
284
284
|
"aria-controls": id,
|
285
|
-
"aria-label": `Go to ${
|
285
|
+
"aria-label": `Go to ${prev ? "previous" : "next"} slide`,
|
286
286
|
...props,
|
287
287
|
ref,
|
288
288
|
disabled,
|
289
289
|
onClick: (0, import_utils.handlerAll)(props.onClick, onClick)
|
290
290
|
}),
|
291
|
-
[disabled, id, onClick,
|
291
|
+
[disabled, id, onClick, prev]
|
292
292
|
);
|
293
293
|
return { getControlProps };
|
294
294
|
};
|
295
295
|
var useCarouselIndicators = () => {
|
296
296
|
const { id, carousel, indexes, orientation, selectedIndex } = useCarouselContext();
|
297
297
|
const refMap = (0, import_react.useRef)(/* @__PURE__ */ new Map());
|
298
|
-
const
|
298
|
+
const vertical = orientation === "vertical";
|
299
299
|
const onSelect = (0, import_react.useCallback)(
|
300
300
|
(index) => {
|
301
301
|
var _a;
|
@@ -317,7 +317,7 @@ var useCarouselIndicators = () => {
|
|
317
317
|
const lastIndex = indexes.length - 1;
|
318
318
|
const actions = {
|
319
319
|
ArrowDown: () => {
|
320
|
-
if (!
|
320
|
+
if (!vertical) return;
|
321
321
|
if (index === lastIndex) {
|
322
322
|
index = 0;
|
323
323
|
} else {
|
@@ -326,7 +326,7 @@ var useCarouselIndicators = () => {
|
|
326
326
|
onSelect(index);
|
327
327
|
},
|
328
328
|
ArrowLeft: () => {
|
329
|
-
if (
|
329
|
+
if (vertical) return;
|
330
330
|
if (index === 0) {
|
331
331
|
index = lastIndex;
|
332
332
|
} else {
|
@@ -335,7 +335,7 @@ var useCarouselIndicators = () => {
|
|
335
335
|
onSelect(index);
|
336
336
|
},
|
337
337
|
ArrowRight: () => {
|
338
|
-
if (
|
338
|
+
if (vertical) return;
|
339
339
|
if (index === lastIndex) {
|
340
340
|
index = 0;
|
341
341
|
} else {
|
@@ -344,7 +344,7 @@ var useCarouselIndicators = () => {
|
|
344
344
|
onSelect(index);
|
345
345
|
},
|
346
346
|
ArrowUp: () => {
|
347
|
-
if (!
|
347
|
+
if (!vertical) return;
|
348
348
|
if (index === 0) {
|
349
349
|
index = lastIndex;
|
350
350
|
} else {
|
@@ -360,7 +360,7 @@ var useCarouselIndicators = () => {
|
|
360
360
|
ev.preventDefault();
|
361
361
|
action(ev);
|
362
362
|
},
|
363
|
-
[indexes, onSelect,
|
363
|
+
[indexes, onSelect, vertical]
|
364
364
|
);
|
365
365
|
(0, import_utils.useUnmountEffect)(() => {
|
366
366
|
refMap.current.clear();
|
@@ -377,18 +377,18 @@ var useCarouselIndicators = () => {
|
|
377
377
|
);
|
378
378
|
const getIndicatorProps = (0, import_react.useCallback)(
|
379
379
|
({ index, ...props }, ref) => {
|
380
|
-
const
|
380
|
+
const selected = index === selectedIndex;
|
381
381
|
const internalRef = (0, import_react.createRef)();
|
382
382
|
refMap.current.set(index, internalRef);
|
383
383
|
return {
|
384
384
|
ref: (0, import_utils.mergeRefs)(ref, internalRef),
|
385
385
|
"aria-controls": `${id}-${index + 1}`,
|
386
386
|
"aria-label": `Go to ${index + 1} slide`,
|
387
|
-
"aria-selected":
|
387
|
+
"aria-selected": selected,
|
388
388
|
"data-index": index,
|
389
|
-
"data-selected": (0, import_utils.dataAttr)(
|
389
|
+
"data-selected": (0, import_utils.dataAttr)(selected),
|
390
390
|
role: "tab",
|
391
|
-
tabIndex:
|
391
|
+
tabIndex: selected ? 0 : -1,
|
392
392
|
...props,
|
393
393
|
key: index,
|
394
394
|
onClick: (0, import_utils.handlerAll)(props.onClick, onClick(index)),
|
@@ -466,7 +466,7 @@ var CarouselControl = (0, import_core2.forwardRef)(({ className, operation, ...r
|
|
466
466
|
{
|
467
467
|
className: (0, import_utils2.cx)("ui-carousel__control", className),
|
468
468
|
colorScheme: ["whiteAlpha", "blackAlpha"],
|
469
|
-
|
469
|
+
fullRounded: true,
|
470
470
|
__css: css,
|
471
471
|
...getControlProps(rest, ref)
|
472
472
|
}
|
@@ -500,11 +500,11 @@ var CarouselIndicators = (0, import_core3.forwardRef)(
|
|
500
500
|
__css: css,
|
501
501
|
...rest,
|
502
502
|
children: indexes.map((index) => {
|
503
|
-
const
|
503
|
+
const selected = index === selectedIndex;
|
504
504
|
if (typeof component === "function") {
|
505
505
|
const child = component({
|
506
506
|
index,
|
507
|
-
|
507
|
+
selected
|
508
508
|
});
|
509
509
|
if (!child) return null;
|
510
510
|
const props = getIndicatorProps({ ...child.props, index });
|