@yamada-ui/carousel 1.0.28 → 1.0.29
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.d.mts +8 -0
- package/dist/carousel-control.d.ts +8 -0
- package/dist/carousel-control.js +158 -0
- package/dist/carousel-control.js.map +1 -0
- package/dist/carousel-control.mjs +11 -0
- package/dist/carousel-control.mjs.map +1 -0
- package/dist/carousel-indicators.d.mts +17 -0
- package/dist/carousel-indicators.d.ts +17 -0
- package/dist/carousel-indicators.js +141 -0
- package/dist/carousel-indicators.js.map +1 -0
- package/dist/carousel-indicators.mjs +9 -0
- package/dist/carousel-indicators.mjs.map +1 -0
- package/dist/carousel-slide.d.mts +17 -0
- package/dist/carousel-slide.d.ts +17 -0
- package/dist/carousel-slide.js +106 -0
- package/dist/carousel-slide.js.map +1 -0
- package/dist/carousel-slide.mjs +9 -0
- package/dist/carousel-slide.mjs.map +1 -0
- package/dist/carousel.d.mts +144 -0
- package/dist/carousel.d.ts +144 -0
- package/dist/carousel.js +599 -0
- package/dist/carousel.js.map +1 -0
- package/dist/carousel.mjs +12 -0
- package/dist/carousel.mjs.map +1 -0
- package/dist/chunk-ABN4VJ2X.mjs +171 -0
- package/dist/chunk-ABN4VJ2X.mjs.map +1 -0
- package/dist/chunk-DDY7Q2IV.mjs +87 -0
- package/dist/chunk-DDY7Q2IV.mjs.map +1 -0
- package/dist/chunk-QQ2HS4J4.mjs +260 -0
- package/dist/chunk-QQ2HS4J4.mjs.map +1 -0
- package/dist/chunk-SDWORTZY.mjs +72 -0
- package/dist/chunk-SDWORTZY.mjs.map +1 -0
- package/dist/chunk-VQX7S5CU.mjs +50 -0
- package/dist/chunk-VQX7S5CU.mjs.map +1 -0
- package/dist/index.d.mts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +609 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +23 -0
- package/dist/index.mjs.map +1 -0
- package/dist/use-carousel.d.mts +176 -0
- package/dist/use-carousel.d.ts +176 -0
- package/dist/use-carousel.js +292 -0
- package/dist/use-carousel.js.map +1 -0
- package/dist/use-carousel.mjs +18 -0
- package/dist/use-carousel.mjs.map +1 -0
- package/package.json +3 -3
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
+
import { IconButtonProps } from '@yamada-ui/button';
|
3
|
+
|
4
|
+
type CarouselControlProps = IconButtonProps;
|
5
|
+
declare const CarouselControlPrev: _yamada_ui_core.Component<"button", IconButtonProps>;
|
6
|
+
declare const CarouselControlNext: _yamada_ui_core.Component<"button", IconButtonProps>;
|
7
|
+
|
8
|
+
export { CarouselControlNext, CarouselControlPrev, type CarouselControlProps };
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
+
import { IconButtonProps } from '@yamada-ui/button';
|
3
|
+
|
4
|
+
type CarouselControlProps = IconButtonProps;
|
5
|
+
declare const CarouselControlPrev: _yamada_ui_core.Component<"button", IconButtonProps>;
|
6
|
+
declare const CarouselControlNext: _yamada_ui_core.Component<"button", IconButtonProps>;
|
7
|
+
|
8
|
+
export { CarouselControlNext, CarouselControlPrev, type CarouselControlProps };
|
@@ -0,0 +1,158 @@
|
|
1
|
+
"use client"
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __export = (target, all) => {
|
10
|
+
for (var name in all)
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
+
};
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
15
|
+
for (let key of __getOwnPropNames(from))
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
|
+
}
|
19
|
+
return to;
|
20
|
+
};
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
+
mod
|
28
|
+
));
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
|
+
|
31
|
+
// src/carousel-control.tsx
|
32
|
+
var carousel_control_exports = {};
|
33
|
+
__export(carousel_control_exports, {
|
34
|
+
CarouselControlNext: () => CarouselControlNext,
|
35
|
+
CarouselControlPrev: () => CarouselControlPrev
|
36
|
+
});
|
37
|
+
module.exports = __toCommonJS(carousel_control_exports);
|
38
|
+
var import_button = require("@yamada-ui/button");
|
39
|
+
var import_core2 = require("@yamada-ui/core");
|
40
|
+
var import_icon = require("@yamada-ui/icon");
|
41
|
+
var import_utils2 = require("@yamada-ui/utils");
|
42
|
+
|
43
|
+
// src/use-carousel.ts
|
44
|
+
var import_core = require("@yamada-ui/core");
|
45
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
46
|
+
var import_utils = require("@yamada-ui/utils");
|
47
|
+
var import_embla_carousel_react = __toESM(require("embla-carousel-react"));
|
48
|
+
var import_react = require("react");
|
49
|
+
var [CarouselProvider, useCarouselContext] = (0, import_utils.createContext)({
|
50
|
+
name: "CarouselContext",
|
51
|
+
errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in "<Carousel />"`
|
52
|
+
});
|
53
|
+
var useCarouselControl = ({
|
54
|
+
operation,
|
55
|
+
...rest
|
56
|
+
}) => {
|
57
|
+
var _a, _b;
|
58
|
+
const { carousel } = useCarouselContext();
|
59
|
+
const isPrev = operation === "prev";
|
60
|
+
const disabled = (_b = (_a = rest.disabled) != null ? _a : rest.isDisabled) != null ? _b : isPrev ? !(carousel == null ? void 0 : carousel.canScrollPrev()) : !(carousel == null ? void 0 : carousel.canScrollNext());
|
61
|
+
const onClick = (0, import_react.useCallback)(() => {
|
62
|
+
if (!carousel)
|
63
|
+
return;
|
64
|
+
if (isPrev) {
|
65
|
+
carousel.scrollPrev();
|
66
|
+
} else {
|
67
|
+
carousel.scrollNext();
|
68
|
+
}
|
69
|
+
}, [carousel, isPrev]);
|
70
|
+
const getControlProps = (0, import_react.useCallback)(
|
71
|
+
(props = {}, ref = null) => ({
|
72
|
+
...props,
|
73
|
+
ref,
|
74
|
+
disabled,
|
75
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, onClick)
|
76
|
+
}),
|
77
|
+
[disabled, onClick]
|
78
|
+
);
|
79
|
+
return { getControlProps };
|
80
|
+
};
|
81
|
+
|
82
|
+
// src/carousel-control.tsx
|
83
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
84
|
+
var CarouselControlPrev = (0, import_core2.forwardRef)(
|
85
|
+
({ className, ...rest }, ref) => {
|
86
|
+
const { orientation } = useCarouselContext();
|
87
|
+
const { getControlProps } = useCarouselControl({ operation: "prev" });
|
88
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
89
|
+
CarouselControl,
|
90
|
+
{
|
91
|
+
operation: "prev",
|
92
|
+
className: (0, import_utils2.cx)("ui-carousel__control--prev", className),
|
93
|
+
"aria-label": "Go to previous slide",
|
94
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
95
|
+
import_icon.ChevronIcon,
|
96
|
+
{
|
97
|
+
__css: {
|
98
|
+
fontSize: "1.5em",
|
99
|
+
transform: orientation === "vertical" ? "rotate(180deg)" : "rotate(90deg)"
|
100
|
+
}
|
101
|
+
}
|
102
|
+
),
|
103
|
+
...getControlProps(rest, ref)
|
104
|
+
}
|
105
|
+
);
|
106
|
+
}
|
107
|
+
);
|
108
|
+
var CarouselControlNext = (0, import_core2.forwardRef)(
|
109
|
+
({ className, ...rest }, ref) => {
|
110
|
+
const { orientation } = useCarouselContext();
|
111
|
+
const { getControlProps } = useCarouselControl({ operation: "next" });
|
112
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
113
|
+
CarouselControl,
|
114
|
+
{
|
115
|
+
operation: "next",
|
116
|
+
className: (0, import_utils2.cx)("ui-carousel__control--next", className),
|
117
|
+
"aria-label": "Go to next slide",
|
118
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
119
|
+
import_icon.ChevronIcon,
|
120
|
+
{
|
121
|
+
__css: {
|
122
|
+
fontSize: "1.5em",
|
123
|
+
transform: orientation === "vertical" ? "rotate(0deg)" : "rotate(-90deg)"
|
124
|
+
}
|
125
|
+
}
|
126
|
+
),
|
127
|
+
...getControlProps(rest, ref)
|
128
|
+
}
|
129
|
+
);
|
130
|
+
}
|
131
|
+
);
|
132
|
+
var CarouselControl = (0, import_core2.forwardRef)(({ className, operation, ...rest }, ref) => {
|
133
|
+
const { styles } = useCarouselContext();
|
134
|
+
const colorScheme = (0, import_core2.useColorModeValue)("whiteAlpha", "blackAlpha");
|
135
|
+
const css = {
|
136
|
+
position: "absolute",
|
137
|
+
zIndex: "fallback(kurillin, 9)",
|
138
|
+
...styles.control,
|
139
|
+
...styles[operation]
|
140
|
+
};
|
141
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
142
|
+
import_button.IconButton,
|
143
|
+
{
|
144
|
+
ref,
|
145
|
+
className: (0, import_utils2.cx)("ui-carousel__control", className),
|
146
|
+
colorScheme,
|
147
|
+
isRounded: true,
|
148
|
+
__css: css,
|
149
|
+
...rest
|
150
|
+
}
|
151
|
+
);
|
152
|
+
});
|
153
|
+
// Annotate the CommonJS export names for ESM import in node:
|
154
|
+
0 && (module.exports = {
|
155
|
+
CarouselControlNext,
|
156
|
+
CarouselControlPrev
|
157
|
+
});
|
158
|
+
//# sourceMappingURL=carousel-control.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/carousel-control.tsx","../src/use-carousel.ts"],"sourcesContent":["import type { IconButtonProps } from \"@yamada-ui/button\"\nimport { IconButton } from \"@yamada-ui/button\"\nimport type { CSSUIObject } from \"@yamada-ui/core\"\nimport { forwardRef, useColorModeValue } from \"@yamada-ui/core\"\nimport { ChevronIcon } from \"@yamada-ui/icon\"\nimport { cx } from \"@yamada-ui/utils\"\nimport { useCarouselContext, useCarouselControl } from \"./use-carousel\"\n\nexport type CarouselControlProps = IconButtonProps\n\nexport const CarouselControlPrev = forwardRef<CarouselControlProps, \"button\">(\n ({ className, ...rest }, ref) => {\n const { orientation } = useCarouselContext()\n\n const { getControlProps } = useCarouselControl({ operation: \"prev\" })\n\n return (\n <CarouselControl\n operation=\"prev\"\n className={cx(\"ui-carousel__control--prev\", className)}\n aria-label=\"Go to previous slide\"\n icon={\n <ChevronIcon\n __css={{\n fontSize: \"1.5em\",\n transform:\n orientation === \"vertical\" ? \"rotate(180deg)\" : \"rotate(90deg)\",\n }}\n />\n }\n {...getControlProps(rest, ref)}\n />\n )\n },\n)\n\nexport const CarouselControlNext = forwardRef<CarouselControlProps, \"button\">(\n ({ className, ...rest }, ref) => {\n const { orientation } = useCarouselContext()\n\n const { getControlProps } = useCarouselControl({ operation: \"next\" })\n\n return (\n <CarouselControl\n operation=\"next\"\n className={cx(\"ui-carousel__control--next\", className)}\n aria-label=\"Go to next slide\"\n icon={\n <ChevronIcon\n __css={{\n fontSize: \"1.5em\",\n transform:\n orientation === \"vertical\" ? \"rotate(0deg)\" : \"rotate(-90deg)\",\n }}\n />\n }\n {...getControlProps(rest, ref)}\n />\n )\n },\n)\n\nconst CarouselControl = forwardRef<\n CarouselControlProps & { operation: \"prev\" | \"next\" },\n \"button\"\n>(({ className, operation, ...rest }, ref) => {\n const { styles } = useCarouselContext()\n const colorScheme = useColorModeValue(\"whiteAlpha\", \"blackAlpha\")\n\n const css: CSSUIObject = {\n position: \"absolute\",\n zIndex: \"fallback(kurillin, 9)\",\n ...styles.control,\n ...styles[operation],\n }\n\n return (\n <IconButton\n ref={ref}\n className={cx(\"ui-carousel__control\", className)}\n colorScheme={colorScheme}\n isRounded\n __css={css}\n {...rest}\n />\n )\n})\n","import type { IconButtonProps } from \"@yamada-ui/button\"\nimport type {\n CSSUIObject,\n HTMLUIProps,\n CSSUIProps,\n UIPropGetter,\n RequiredUIPropGetter,\n} from \"@yamada-ui/core\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport {\n createContext,\n dataAttr,\n handlerAll,\n splitObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { EmblaCarouselType } from \"embla-carousel-react\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport type { MouseEvent } from \"react\"\nimport { Children, useCallback, useEffect, useRef, useState } from \"react\"\n\ntype CarouselContext = {\n carousel: EmblaCarouselType | undefined\n indexes: number[]\n selectedIndex: number\n orientation: \"vertical\" | \"horizontal\"\n includeGapInSize: boolean\n slidesToScroll: number\n slideSize: string | number\n gap: CSSUIProps[\"gap\"]\n styles: Record<string, CSSUIObject>\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 type UseCarouselProps = Omit<\n HTMLUIProps<\"div\">,\n \"onChange\" | \"draggable\" | \"gap\"\n> & {\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: \"start\" | \"center\" | \"end\" | number\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 ''\n */\n containScroll?: \"trimSnaps\" | \"keepSnaps\" | \"\"\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`, 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 * 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?: number\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 * 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 * Adjusts scroll speed when triggered by any of the methods.\n * Higher numbers enables faster scrolling.\n *\n * @default 10\n */\n speed?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\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 CSS `gap` property.\n *\n * @default '4'\n */\n gap?: CSSUIProps[\"gap\"]\n /**\n * The carousel slide width.\n *\n * @default '100%'\n */\n slideSize?: string | number\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 index,\n defaultIndex = 0,\n onChange,\n align = \"center\",\n orientation = \"horizontal\",\n autoplay = false,\n stopMouseEnterAutoplay = true,\n loop = true,\n speed = 10,\n delay = 4000,\n gap = \"fallback(4, 1rem)\",\n slidesToScroll = 1,\n draggable = true,\n dragFree = false,\n inViewThreshold = 0,\n skipSnaps = false,\n containScroll = \"\",\n slideSize = \"100%\",\n includeGapInSize = true,\n onScrollProgress,\n children,\n ...rest\n}: UseCarouselProps) => {\n const computedProps = splitObject(rest, layoutStyleProperties)\n\n const [selectedIndex, setSelectedIndex] = useControllableState({\n value: index,\n defaultValue: defaultIndex,\n onChange,\n })\n\n const isVertical = orientation === \"vertical\"\n\n const [carouselRef, carousel] = useEmblaCarousel({\n axis: isVertical ? \"y\" : \"x\",\n startIndex: defaultIndex,\n loop,\n align,\n slidesToScroll,\n draggable,\n dragFree,\n speed,\n inViewThreshold,\n skipSnaps,\n containScroll,\n })\n\n const [indexes, setIndexes] = useState<number[]>([])\n const [isMouseEnter, setIsMouseEnter] = useState<boolean>(false)\n\n const timeoutId = useRef<any>(undefined)\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 isStop = isMouseEnter && stopMouseEnterAutoplay\n const isLast = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !isStop && !isLast) {\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 isMouseEnter,\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 speed,\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 const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...computedProps[0],\n ...props,\n ref,\n onMouseEnter: handlerAll(props.onMouseEnter, () => {\n setIsMouseEnter(true)\n }),\n onMouseLeave: handlerAll(props.onMouseLeave, () => {\n setIsMouseEnter(false)\n }),\n }),\n [computedProps],\n )\n\n const getSlidesProps: UIPropGetter = useCallback(\n (props = {}) => ({\n ...computedProps[1],\n ...props,\n ref: carouselRef,\n }),\n [computedProps, carouselRef],\n )\n\n return {\n carousel,\n children,\n indexes,\n selectedIndex,\n orientation,\n slideSize,\n gap,\n slidesToScroll,\n includeGapInSize,\n getContainerProps,\n getSlidesProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n\nexport type UseCarouselSlideProps = {\n index?: number\n}\n\nexport const useCarouselSlide = ({ index }: UseCarouselSlideProps) => {\n const { selectedIndex, slidesToScroll } = useCarouselContext()\n\n index = Math.floor((index ?? 0) / (slidesToScroll ?? 1))\n\n const isSelected = index === selectedIndex\n\n const getSlideProps: UIPropGetter = useCallback(\n (props = {}) => ({\n ...props,\n \"data-index\": index,\n \"data-selected\": dataAttr(isSelected),\n }),\n [isSelected, index],\n )\n\n return { getSlideProps }\n}\n\nexport type UseCarouselSlideReturn = ReturnType<typeof useCarouselSlide>\n\nexport type UseCarouselControlProps = IconButtonProps & {\n operation: \"prev\" | \"next\"\n}\n\nexport const useCarouselControl = ({\n operation,\n ...rest\n}: UseCarouselControlProps) => {\n const { carousel } = useCarouselContext()\n\n const isPrev = operation === \"prev\"\n\n const disabled =\n rest.disabled ??\n rest.isDisabled ??\n (isPrev ? !carousel?.canScrollPrev() : !carousel?.canScrollNext())\n\n const onClick = useCallback(() => {\n if (!carousel) return\n\n if (isPrev) {\n carousel.scrollPrev()\n } else {\n carousel.scrollNext()\n }\n }, [carousel, isPrev])\n\n const getControlProps: UIPropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref,\n disabled,\n onClick: handlerAll(props.onClick, onClick),\n }),\n [disabled, onClick],\n )\n\n return { getControlProps }\n}\n\nexport type UseCarouselControlReturn = ReturnType<typeof useCarouselControl>\n\nexport const useCarouselIndicators = () => {\n const { selectedIndex, carousel, indexes } = useCarouselContext()\n\n const onClick = useCallback(\n (ev: MouseEvent, index: number) => {\n if (!carousel) return\n\n ev.stopPropagation()\n\n carousel.scrollTo(index)\n },\n [carousel],\n )\n\n const getIndicatorProps: RequiredUIPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ index, ...props }) => {\n const isSelected = index === selectedIndex\n\n return {\n \"aria-label\": `Go to ${index + 1} slide`,\n ...props,\n key: index,\n \"data-index\": index,\n \"data-selected\": dataAttr(isSelected),\n onClick: handlerAll(props.onClick, (ev) => onClick(ev, index)),\n }\n },\n [onClick, selectedIndex],\n )\n\n return { indexes, getIndicatorProps }\n}\n\nexport type UseCarouselIndicatorsReturn = ReturnType<\n typeof useCarouselIndicators\n>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AA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":"","names":[]}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
+
import { HTMLUIProps } from '@yamada-ui/core';
|
3
|
+
import { FC } from 'react';
|
4
|
+
|
5
|
+
type CarouselIndicatorsOptions = {
|
6
|
+
/**
|
7
|
+
* The custom caroucel indicator to use.
|
8
|
+
*/
|
9
|
+
component?: FC<{
|
10
|
+
index: number;
|
11
|
+
isSelected: boolean;
|
12
|
+
}>;
|
13
|
+
};
|
14
|
+
type CarouselIndicatorsProps = Omit<HTMLUIProps<"div">, "children"> & CarouselIndicatorsOptions;
|
15
|
+
declare const CarouselIndicators: _yamada_ui_core.Component<"div", CarouselIndicatorsProps>;
|
16
|
+
|
17
|
+
export { CarouselIndicators, type CarouselIndicatorsProps };
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
+
import { HTMLUIProps } from '@yamada-ui/core';
|
3
|
+
import { FC } from 'react';
|
4
|
+
|
5
|
+
type CarouselIndicatorsOptions = {
|
6
|
+
/**
|
7
|
+
* The custom caroucel indicator to use.
|
8
|
+
*/
|
9
|
+
component?: FC<{
|
10
|
+
index: number;
|
11
|
+
isSelected: boolean;
|
12
|
+
}>;
|
13
|
+
};
|
14
|
+
type CarouselIndicatorsProps = Omit<HTMLUIProps<"div">, "children"> & CarouselIndicatorsOptions;
|
15
|
+
declare const CarouselIndicators: _yamada_ui_core.Component<"div", CarouselIndicatorsProps>;
|
16
|
+
|
17
|
+
export { CarouselIndicators, type CarouselIndicatorsProps };
|
@@ -0,0 +1,141 @@
|
|
1
|
+
"use client"
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __export = (target, all) => {
|
10
|
+
for (var name in all)
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
+
};
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
15
|
+
for (let key of __getOwnPropNames(from))
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
|
+
}
|
19
|
+
return to;
|
20
|
+
};
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
+
mod
|
28
|
+
));
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
|
+
|
31
|
+
// src/carousel-indicators.tsx
|
32
|
+
var carousel_indicators_exports = {};
|
33
|
+
__export(carousel_indicators_exports, {
|
34
|
+
CarouselIndicators: () => CarouselIndicators
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(carousel_indicators_exports);
|
37
|
+
var import_core2 = require("@yamada-ui/core");
|
38
|
+
var import_utils2 = require("@yamada-ui/utils");
|
39
|
+
var import_react2 = require("react");
|
40
|
+
|
41
|
+
// src/use-carousel.ts
|
42
|
+
var import_core = require("@yamada-ui/core");
|
43
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
44
|
+
var import_utils = require("@yamada-ui/utils");
|
45
|
+
var import_embla_carousel_react = __toESM(require("embla-carousel-react"));
|
46
|
+
var import_react = require("react");
|
47
|
+
var [CarouselProvider, useCarouselContext] = (0, import_utils.createContext)({
|
48
|
+
name: "CarouselContext",
|
49
|
+
errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in "<Carousel />"`
|
50
|
+
});
|
51
|
+
var useCarouselIndicators = () => {
|
52
|
+
const { selectedIndex, carousel, indexes } = useCarouselContext();
|
53
|
+
const onClick = (0, import_react.useCallback)(
|
54
|
+
(ev, index) => {
|
55
|
+
if (!carousel)
|
56
|
+
return;
|
57
|
+
ev.stopPropagation();
|
58
|
+
carousel.scrollTo(index);
|
59
|
+
},
|
60
|
+
[carousel]
|
61
|
+
);
|
62
|
+
const getIndicatorProps = (0, import_react.useCallback)(
|
63
|
+
({ index, ...props }) => {
|
64
|
+
const isSelected = index === selectedIndex;
|
65
|
+
return {
|
66
|
+
"aria-label": `Go to ${index + 1} slide`,
|
67
|
+
...props,
|
68
|
+
key: index,
|
69
|
+
"data-index": index,
|
70
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected),
|
71
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, (ev) => onClick(ev, index))
|
72
|
+
};
|
73
|
+
},
|
74
|
+
[onClick, selectedIndex]
|
75
|
+
);
|
76
|
+
return { indexes, getIndicatorProps };
|
77
|
+
};
|
78
|
+
|
79
|
+
// src/carousel-indicators.tsx
|
80
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
81
|
+
var CarouselIndicators = (0, import_core2.forwardRef)(
|
82
|
+
({ className, component, ...rest }, ref) => {
|
83
|
+
const { selectedIndex, orientation, styles } = useCarouselContext();
|
84
|
+
const { indexes, getIndicatorProps } = useCarouselIndicators();
|
85
|
+
const css = {
|
86
|
+
position: "absolute",
|
87
|
+
zIndex: "fallback(kurillin, 9)",
|
88
|
+
display: "flex",
|
89
|
+
justifyContent: "center",
|
90
|
+
...styles.indicators,
|
91
|
+
...orientation === "vertical" ? { flexDirection: "column" } : { flexDirection: "row" }
|
92
|
+
};
|
93
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
94
|
+
import_core2.ui.div,
|
95
|
+
{
|
96
|
+
ref,
|
97
|
+
className: (0, import_utils2.cx)("ui-carousel__indicators", className),
|
98
|
+
__css: css,
|
99
|
+
...rest,
|
100
|
+
children: indexes.map((index) => {
|
101
|
+
const isSelected = index === selectedIndex;
|
102
|
+
if (typeof component === "function") {
|
103
|
+
const child = component({
|
104
|
+
index,
|
105
|
+
isSelected
|
106
|
+
});
|
107
|
+
if (!child)
|
108
|
+
return null;
|
109
|
+
const props = getIndicatorProps({ ...child.props, index });
|
110
|
+
return (0, import_react2.cloneElement)(child, props);
|
111
|
+
} else {
|
112
|
+
const { key, ...props } = getIndicatorProps({ index });
|
113
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CarouselIndicator, { ...props }, key);
|
114
|
+
}
|
115
|
+
})
|
116
|
+
}
|
117
|
+
);
|
118
|
+
}
|
119
|
+
);
|
120
|
+
var CarouselIndicator = ({
|
121
|
+
className,
|
122
|
+
...rest
|
123
|
+
}) => {
|
124
|
+
const { styles } = useCarouselContext();
|
125
|
+
const css = { ...styles.indicator };
|
126
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
127
|
+
import_core2.ui.button,
|
128
|
+
{
|
129
|
+
type: "button",
|
130
|
+
tabIndex: -1,
|
131
|
+
className: (0, import_utils2.cx)("ui-carousel__indicators__indicator", className),
|
132
|
+
__css: css,
|
133
|
+
...rest
|
134
|
+
}
|
135
|
+
);
|
136
|
+
};
|
137
|
+
// Annotate the CommonJS export names for ESM import in node:
|
138
|
+
0 && (module.exports = {
|
139
|
+
CarouselIndicators
|
140
|
+
});
|
141
|
+
//# sourceMappingURL=carousel-indicators.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/carousel-indicators.tsx","../src/use-carousel.ts"],"sourcesContent":["import type { HTMLUIProps, CSSUIObject } from \"@yamada-ui/core\"\nimport { ui, forwardRef } from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport type { FC, ReactElement } from \"react\"\nimport { cloneElement } from \"react\"\nimport { useCarouselContext, useCarouselIndicators } from \"./use-carousel\"\n\ntype CarouselIndicatorsOptions = {\n /**\n * The custom caroucel indicator to use.\n */\n component?: FC<{ index: number; isSelected: boolean }>\n}\n\nexport type CarouselIndicatorsProps = Omit<HTMLUIProps<\"div\">, \"children\"> &\n CarouselIndicatorsOptions\n\nexport const CarouselIndicators = forwardRef<CarouselIndicatorsProps, \"div\">(\n ({ className, component, ...rest }, ref) => {\n const { selectedIndex, orientation, styles } = useCarouselContext()\n\n const { indexes, getIndicatorProps } = useCarouselIndicators()\n\n const css: CSSUIObject = {\n position: \"absolute\",\n zIndex: \"fallback(kurillin, 9)\",\n display: \"flex\",\n justifyContent: \"center\",\n ...styles.indicators,\n ...(orientation === \"vertical\"\n ? { flexDirection: \"column\" }\n : { flexDirection: \"row\" }),\n }\n\n return (\n <ui.div\n ref={ref}\n className={cx(\"ui-carousel__indicators\", className)}\n __css={css}\n {...rest}\n >\n {indexes.map((index) => {\n const isSelected = index === selectedIndex\n\n if (typeof component === \"function\") {\n const child = component({\n index,\n isSelected,\n }) as ReactElement | null\n\n if (!child) return null\n\n const props = getIndicatorProps({ ...child.props, index })\n\n return cloneElement(child as ReactElement, props)\n } else {\n const { key, ...props } = getIndicatorProps({ index })\n\n return <CarouselIndicator key={key} {...props} />\n }\n })}\n </ui.div>\n )\n },\n)\n\ntype CarouselIndicatorProps = HTMLUIProps<\"button\">\n\nconst CarouselIndicator: FC<CarouselIndicatorProps> = ({\n className,\n ...rest\n}) => {\n const { styles } = useCarouselContext()\n\n const css: CSSUIObject = { ...styles.indicator }\n\n return (\n <ui.button\n type=\"button\"\n tabIndex={-1}\n className={cx(\"ui-carousel__indicators__indicator\", className)}\n __css={css}\n {...rest}\n />\n )\n}\n","import type { IconButtonProps } from \"@yamada-ui/button\"\nimport type {\n CSSUIObject,\n HTMLUIProps,\n CSSUIProps,\n UIPropGetter,\n RequiredUIPropGetter,\n} from \"@yamada-ui/core\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport {\n createContext,\n dataAttr,\n handlerAll,\n splitObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { EmblaCarouselType } from \"embla-carousel-react\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport type { MouseEvent } from \"react\"\nimport { Children, useCallback, useEffect, useRef, useState } from \"react\"\n\ntype CarouselContext = {\n carousel: EmblaCarouselType | undefined\n indexes: number[]\n selectedIndex: number\n orientation: \"vertical\" | \"horizontal\"\n includeGapInSize: boolean\n slidesToScroll: number\n slideSize: string | number\n gap: CSSUIProps[\"gap\"]\n styles: Record<string, CSSUIObject>\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 type UseCarouselProps = Omit<\n HTMLUIProps<\"div\">,\n \"onChange\" | \"draggable\" | \"gap\"\n> & {\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: \"start\" | \"center\" | \"end\" | number\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 ''\n */\n containScroll?: \"trimSnaps\" | \"keepSnaps\" | \"\"\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`, 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 * 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?: number\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 * 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 * Adjusts scroll speed when triggered by any of the methods.\n * Higher numbers enables faster scrolling.\n *\n * @default 10\n */\n speed?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\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 CSS `gap` property.\n *\n * @default '4'\n */\n gap?: CSSUIProps[\"gap\"]\n /**\n * The carousel slide width.\n *\n * @default '100%'\n */\n slideSize?: string | number\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 index,\n defaultIndex = 0,\n onChange,\n align = \"center\",\n orientation = \"horizontal\",\n autoplay = false,\n stopMouseEnterAutoplay = true,\n loop = true,\n speed = 10,\n delay = 4000,\n gap = \"fallback(4, 1rem)\",\n slidesToScroll = 1,\n draggable = true,\n dragFree = false,\n inViewThreshold = 0,\n skipSnaps = false,\n containScroll = \"\",\n slideSize = \"100%\",\n includeGapInSize = true,\n onScrollProgress,\n children,\n ...rest\n}: UseCarouselProps) => {\n const computedProps = splitObject(rest, layoutStyleProperties)\n\n const [selectedIndex, setSelectedIndex] = useControllableState({\n value: index,\n defaultValue: defaultIndex,\n onChange,\n })\n\n const isVertical = orientation === \"vertical\"\n\n const [carouselRef, carousel] = useEmblaCarousel({\n axis: isVertical ? \"y\" : \"x\",\n startIndex: defaultIndex,\n loop,\n align,\n slidesToScroll,\n draggable,\n dragFree,\n speed,\n inViewThreshold,\n skipSnaps,\n containScroll,\n })\n\n const [indexes, setIndexes] = useState<number[]>([])\n const [isMouseEnter, setIsMouseEnter] = useState<boolean>(false)\n\n const timeoutId = useRef<any>(undefined)\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 isStop = isMouseEnter && stopMouseEnterAutoplay\n const isLast = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !isStop && !isLast) {\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 isMouseEnter,\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 speed,\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 const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...computedProps[0],\n ...props,\n ref,\n onMouseEnter: handlerAll(props.onMouseEnter, () => {\n setIsMouseEnter(true)\n }),\n onMouseLeave: handlerAll(props.onMouseLeave, () => {\n setIsMouseEnter(false)\n }),\n }),\n [computedProps],\n )\n\n const getSlidesProps: UIPropGetter = useCallback(\n (props = {}) => ({\n ...computedProps[1],\n ...props,\n ref: carouselRef,\n }),\n [computedProps, carouselRef],\n )\n\n return {\n carousel,\n children,\n indexes,\n selectedIndex,\n orientation,\n slideSize,\n gap,\n slidesToScroll,\n includeGapInSize,\n getContainerProps,\n getSlidesProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n\nexport type UseCarouselSlideProps = {\n index?: number\n}\n\nexport const useCarouselSlide = ({ index }: UseCarouselSlideProps) => {\n const { selectedIndex, slidesToScroll } = useCarouselContext()\n\n index = Math.floor((index ?? 0) / (slidesToScroll ?? 1))\n\n const isSelected = index === selectedIndex\n\n const getSlideProps: UIPropGetter = useCallback(\n (props = {}) => ({\n ...props,\n \"data-index\": index,\n \"data-selected\": dataAttr(isSelected),\n }),\n [isSelected, index],\n )\n\n return { getSlideProps }\n}\n\nexport type UseCarouselSlideReturn = ReturnType<typeof useCarouselSlide>\n\nexport type UseCarouselControlProps = IconButtonProps & {\n operation: \"prev\" | \"next\"\n}\n\nexport const useCarouselControl = ({\n operation,\n ...rest\n}: UseCarouselControlProps) => {\n const { carousel } = useCarouselContext()\n\n const isPrev = operation === \"prev\"\n\n const disabled =\n rest.disabled ??\n rest.isDisabled ??\n (isPrev ? !carousel?.canScrollPrev() : !carousel?.canScrollNext())\n\n const onClick = useCallback(() => {\n if (!carousel) return\n\n if (isPrev) {\n carousel.scrollPrev()\n } else {\n carousel.scrollNext()\n }\n }, [carousel, isPrev])\n\n const getControlProps: UIPropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref,\n disabled,\n onClick: handlerAll(props.onClick, onClick),\n }),\n [disabled, onClick],\n )\n\n return { getControlProps }\n}\n\nexport type UseCarouselControlReturn = ReturnType<typeof useCarouselControl>\n\nexport const useCarouselIndicators = () => {\n const { selectedIndex, carousel, indexes } = useCarouselContext()\n\n const onClick = useCallback(\n (ev: MouseEvent, index: number) => {\n if (!carousel) return\n\n ev.stopPropagation()\n\n carousel.scrollTo(index)\n },\n [carousel],\n )\n\n const getIndicatorProps: RequiredUIPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ index, ...props }) => {\n const isSelected = index === selectedIndex\n\n return {\n \"aria-label\": `Go to ${index + 1} slide`,\n ...props,\n key: index,\n \"data-index\": index,\n \"data-selected\": dataAttr(isSelected),\n onClick: handlerAll(props.onClick, (ev) => onClick(ev, index)),\n }\n },\n [onClick, selectedIndex],\n )\n\n return { indexes, getIndicatorProps }\n}\n\nexport type UseCarouselIndicatorsReturn = ReturnType<\n typeof useCarouselIndicators\n>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,eAA+B;AAC/B,IAAAC,gBAAmB;AAEnB,IAAAC,gBAA6B;;;ACI7B,kBAAsC;AACtC,oCAAqC;AACrC,mBAMO;AAEP,kCAA6B;AAE7B,mBAAmE;AAc5D,IAAM,CAAC,kBAAkB,kBAAkB,QAChD,4BAA+B;AAAA,EAC7B,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AA6XI,IAAM,wBAAwB,MAAM;AACzC,QAAM,EAAE,eAAe,UAAU,QAAQ,IAAI,mBAAmB;AAEhE,QAAM,cAAU;AAAA,IACd,CAAC,IAAgB,UAAkB;AACjC,UAAI,CAAC;AAAU;AAEf,SAA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EAAE,GAAG,MAAM,OAAO,MAAM,CAAC;AAEzD,uBAAO,4BAAa,OAAuB,KAAK;AAAA,UAClD,OAAO;AACL,kBAAM,EAAE,KAAK,GAAG,MAAM,IAAI,kBAAkB,EAAE,MAAM,CAAC;AAErD,mBAAO,4CAAC,qBAA6B,GAAG,SAAT,GAAgB;AAAA,UACjD;AAAA,QACF,CAAC;AAAA;AAAA,IACH;AAAA,EAEJ;AACF;AAIA,IAAM,oBAAgD,CAAC;AAAA,EACrD;AAAA,EACA,GAAG;AACL,MAAM;AACJ,QAAM,EAAE,OAAO,IAAI,mBAAmB;AAEtC,QAAM,MAAmB,EAAE,GAAG,OAAO,UAAU;AAE/C,SACE;AAAA,IAAC,gBAAG;AAAA,IAAH;AAAA,MACC,MAAK;AAAA,MACL,UAAU;AAAA,MACV,eAAW,kBAAG,sCAAsC,SAAS;AAAA,MAC7D,OAAO;AAAA,MACN,GAAG;AAAA;AAAA,EACN;AAEJ;","names":["import_core","import_utils","import_react"]}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
+
import { HTMLUIProps, CSSUIObject } from '@yamada-ui/core';
|
3
|
+
import { UseCarouselSlideProps } from './use-carousel.mjs';
|
4
|
+
import 'react';
|
5
|
+
import '@yamada-ui/button';
|
6
|
+
import 'embla-carousel-react';
|
7
|
+
|
8
|
+
type CarouselSlideOptions = {
|
9
|
+
/**
|
10
|
+
* The CSS `width` property.
|
11
|
+
*/
|
12
|
+
size?: CSSUIObject["width"];
|
13
|
+
};
|
14
|
+
type CarouselSlideProps = HTMLUIProps<"div"> & UseCarouselSlideProps & CarouselSlideOptions;
|
15
|
+
declare const CarouselSlide: _yamada_ui_core.Component<"div", CarouselSlideProps>;
|
16
|
+
|
17
|
+
export { CarouselSlide, type CarouselSlideProps };
|
@@ -0,0 +1,17 @@
|
|
1
|
+
import * as _yamada_ui_core from '@yamada-ui/core';
|
2
|
+
import { HTMLUIProps, CSSUIObject } from '@yamada-ui/core';
|
3
|
+
import { UseCarouselSlideProps } from './use-carousel.js';
|
4
|
+
import 'react';
|
5
|
+
import '@yamada-ui/button';
|
6
|
+
import 'embla-carousel-react';
|
7
|
+
|
8
|
+
type CarouselSlideOptions = {
|
9
|
+
/**
|
10
|
+
* The CSS `width` property.
|
11
|
+
*/
|
12
|
+
size?: CSSUIObject["width"];
|
13
|
+
};
|
14
|
+
type CarouselSlideProps = HTMLUIProps<"div"> & UseCarouselSlideProps & CarouselSlideOptions;
|
15
|
+
declare const CarouselSlide: _yamada_ui_core.Component<"div", CarouselSlideProps>;
|
16
|
+
|
17
|
+
export { CarouselSlide, type CarouselSlideProps };
|
@@ -0,0 +1,106 @@
|
|
1
|
+
"use client"
|
2
|
+
"use strict";
|
3
|
+
var __create = Object.create;
|
4
|
+
var __defProp = Object.defineProperty;
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
9
|
+
var __export = (target, all) => {
|
10
|
+
for (var name in all)
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
12
|
+
};
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
15
|
+
for (let key of __getOwnPropNames(from))
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
18
|
+
}
|
19
|
+
return to;
|
20
|
+
};
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
27
|
+
mod
|
28
|
+
));
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
30
|
+
|
31
|
+
// src/carousel-slide.tsx
|
32
|
+
var carousel_slide_exports = {};
|
33
|
+
__export(carousel_slide_exports, {
|
34
|
+
CarouselSlide: () => CarouselSlide
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(carousel_slide_exports);
|
37
|
+
var import_core2 = require("@yamada-ui/core");
|
38
|
+
var import_utils2 = require("@yamada-ui/utils");
|
39
|
+
|
40
|
+
// src/use-carousel.ts
|
41
|
+
var import_core = require("@yamada-ui/core");
|
42
|
+
var import_use_controllable_state = require("@yamada-ui/use-controllable-state");
|
43
|
+
var import_utils = require("@yamada-ui/utils");
|
44
|
+
var import_embla_carousel_react = __toESM(require("embla-carousel-react"));
|
45
|
+
var import_react = require("react");
|
46
|
+
var [CarouselProvider, useCarouselContext] = (0, import_utils.createContext)({
|
47
|
+
name: "CarouselContext",
|
48
|
+
errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in "<Carousel />"`
|
49
|
+
});
|
50
|
+
var useCarouselSlide = ({ index }) => {
|
51
|
+
const { selectedIndex, slidesToScroll } = useCarouselContext();
|
52
|
+
index = Math.floor((index != null ? index : 0) / (slidesToScroll != null ? slidesToScroll : 1));
|
53
|
+
const isSelected = index === selectedIndex;
|
54
|
+
const getSlideProps = (0, import_react.useCallback)(
|
55
|
+
(props = {}) => ({
|
56
|
+
...props,
|
57
|
+
"data-index": index,
|
58
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected)
|
59
|
+
}),
|
60
|
+
[isSelected, index]
|
61
|
+
);
|
62
|
+
return { getSlideProps };
|
63
|
+
};
|
64
|
+
|
65
|
+
// src/carousel-slide.tsx
|
66
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
67
|
+
var CarouselSlide = (0, import_core2.forwardRef)(
|
68
|
+
({ className, size, ...rest }, ref) => {
|
69
|
+
const { slideSize, includeGapInSize, orientation, gap } = useCarouselContext();
|
70
|
+
const { getSlideProps } = useCarouselSlide(rest);
|
71
|
+
size != null ? size : size = slideSize;
|
72
|
+
const css = {
|
73
|
+
position: "relative",
|
74
|
+
flex: `0 0 ${size}`,
|
75
|
+
...includeGapInSize ? { [orientation === "vertical" ? "pb" : "pr"]: gap } : { [orientation === "vertical" ? "mb" : "mr"]: gap }
|
76
|
+
};
|
77
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
78
|
+
import_core2.ui.div,
|
79
|
+
{
|
80
|
+
className: (0, import_utils2.cx)("ui-carousel__slide", className),
|
81
|
+
__css: css,
|
82
|
+
...getSlideProps({}),
|
83
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CarouselSlideInner, { ref, ...rest })
|
84
|
+
}
|
85
|
+
);
|
86
|
+
}
|
87
|
+
);
|
88
|
+
var CarouselSlideInner = (0, import_core2.forwardRef)(
|
89
|
+
({ ...rest }, ref) => {
|
90
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
91
|
+
import_core2.ui.div,
|
92
|
+
{
|
93
|
+
ref,
|
94
|
+
className: "ui-carousel__slide__inner",
|
95
|
+
w: "100%",
|
96
|
+
h: "100%",
|
97
|
+
...rest
|
98
|
+
}
|
99
|
+
);
|
100
|
+
}
|
101
|
+
);
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
103
|
+
0 && (module.exports = {
|
104
|
+
CarouselSlide
|
105
|
+
});
|
106
|
+
//# sourceMappingURL=carousel-slide.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"sources":["../src/carousel-slide.tsx","../src/use-carousel.ts"],"sourcesContent":["import type { HTMLUIProps, CSSUIObject } from \"@yamada-ui/core\"\nimport { ui, forwardRef } from \"@yamada-ui/core\"\nimport { cx } from \"@yamada-ui/utils\"\nimport type { UseCarouselSlideProps } from \"./use-carousel\"\nimport { useCarouselContext, useCarouselSlide } from \"./use-carousel\"\n\ntype CarouselSlideOptions = {\n /**\n * The CSS `width` property.\n */\n size?: CSSUIObject[\"width\"]\n}\n\nexport type CarouselSlideProps = HTMLUIProps<\"div\"> &\n UseCarouselSlideProps &\n CarouselSlideOptions\n\nexport const CarouselSlide = forwardRef<CarouselSlideProps, \"div\">(\n ({ className, size, ...rest }, ref) => {\n const { slideSize, includeGapInSize, orientation, gap } =\n useCarouselContext()\n\n const { getSlideProps } = useCarouselSlide(rest)\n\n size ??= slideSize\n\n const css: CSSUIObject = {\n position: \"relative\",\n flex: `0 0 ${size}`,\n ...(includeGapInSize\n ? { [orientation === \"vertical\" ? \"pb\" : \"pr\"]: gap }\n : { [orientation === \"vertical\" ? \"mb\" : \"mr\"]: gap }),\n }\n\n return (\n <ui.div\n className={cx(\"ui-carousel__slide\", className)}\n __css={css}\n {...getSlideProps({})}\n >\n <CarouselSlideInner ref={ref} {...rest} />\n </ui.div>\n )\n },\n)\n\ntype CarouselSlideInnerProps = HTMLUIProps<\"div\">\n\nconst CarouselSlideInner = forwardRef<CarouselSlideInnerProps, \"div\">(\n ({ ...rest }, ref) => {\n return (\n <ui.div\n ref={ref}\n className=\"ui-carousel__slide__inner\"\n w=\"100%\"\n h=\"100%\"\n {...rest}\n />\n )\n },\n)\n","import type { IconButtonProps } from \"@yamada-ui/button\"\nimport type {\n CSSUIObject,\n HTMLUIProps,\n CSSUIProps,\n UIPropGetter,\n RequiredUIPropGetter,\n} from \"@yamada-ui/core\"\nimport { layoutStyleProperties } from \"@yamada-ui/core\"\nimport { useControllableState } from \"@yamada-ui/use-controllable-state\"\nimport {\n createContext,\n dataAttr,\n handlerAll,\n splitObject,\n useUpdateEffect,\n} from \"@yamada-ui/utils\"\nimport type { EmblaCarouselType } from \"embla-carousel-react\"\nimport useEmblaCarousel from \"embla-carousel-react\"\nimport type { MouseEvent } from \"react\"\nimport { Children, useCallback, useEffect, useRef, useState } from \"react\"\n\ntype CarouselContext = {\n carousel: EmblaCarouselType | undefined\n indexes: number[]\n selectedIndex: number\n orientation: \"vertical\" | \"horizontal\"\n includeGapInSize: boolean\n slidesToScroll: number\n slideSize: string | number\n gap: CSSUIProps[\"gap\"]\n styles: Record<string, CSSUIObject>\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 type UseCarouselProps = Omit<\n HTMLUIProps<\"div\">,\n \"onChange\" | \"draggable\" | \"gap\"\n> & {\n /**\n * The index of the carousel slide.\n */\n index?: number\n /**\n * The initial index of the carousel slide.\n *\n * @default 0\n */\n defaultIndex?: number\n /**\n * The callback invoked when carousel slide selected.\n */\n onChange?: (index: number) => void\n /**\n * The orientation of the carousel.\n *\n * @default 'horizontal'\n */\n orientation?: \"vertical\" | \"horizontal\"\n /**\n * The alignment of the carousel.\n *\n * @default 'center'\n */\n align?: \"start\" | \"center\" | \"end\" | number\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 ''\n */\n containScroll?: \"trimSnaps\" | \"keepSnaps\" | \"\"\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`, 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 * 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?: number\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 * 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 * Adjusts scroll speed when triggered by any of the methods.\n * Higher numbers enables faster scrolling.\n *\n * @default 10\n */\n speed?: number\n /**\n * The number for the autoplay interval of the carousel.\n *\n * @default 4000\n */\n delay?: number\n /**\n * If `true`, the carousel will be autoplay.\n *\n * @default false\n */\n autoplay?: boolean\n /**\n * If `true`, autoplay will pause when the mouse entries over.\n *\n * @default true\n */\n stopMouseEnterAutoplay?: boolean\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 CSS `gap` property.\n *\n * @default '4'\n */\n gap?: CSSUIProps[\"gap\"]\n /**\n * The carousel slide width.\n *\n * @default '100%'\n */\n slideSize?: string | number\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 index,\n defaultIndex = 0,\n onChange,\n align = \"center\",\n orientation = \"horizontal\",\n autoplay = false,\n stopMouseEnterAutoplay = true,\n loop = true,\n speed = 10,\n delay = 4000,\n gap = \"fallback(4, 1rem)\",\n slidesToScroll = 1,\n draggable = true,\n dragFree = false,\n inViewThreshold = 0,\n skipSnaps = false,\n containScroll = \"\",\n slideSize = \"100%\",\n includeGapInSize = true,\n onScrollProgress,\n children,\n ...rest\n}: UseCarouselProps) => {\n const computedProps = splitObject(rest, layoutStyleProperties)\n\n const [selectedIndex, setSelectedIndex] = useControllableState({\n value: index,\n defaultValue: defaultIndex,\n onChange,\n })\n\n const isVertical = orientation === \"vertical\"\n\n const [carouselRef, carousel] = useEmblaCarousel({\n axis: isVertical ? \"y\" : \"x\",\n startIndex: defaultIndex,\n loop,\n align,\n slidesToScroll,\n draggable,\n dragFree,\n speed,\n inViewThreshold,\n skipSnaps,\n containScroll,\n })\n\n const [indexes, setIndexes] = useState<number[]>([])\n const [isMouseEnter, setIsMouseEnter] = useState<boolean>(false)\n\n const timeoutId = useRef<any>(undefined)\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 isStop = isMouseEnter && stopMouseEnterAutoplay\n const isLast = !carousel?.canScrollNext()\n\n if (carousel && autoplay && !isStop && !isLast) {\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 isMouseEnter,\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 speed,\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 const getContainerProps: UIPropGetter = useCallback(\n (props = {}, ref = null) => ({\n ...computedProps[0],\n ...props,\n ref,\n onMouseEnter: handlerAll(props.onMouseEnter, () => {\n setIsMouseEnter(true)\n }),\n onMouseLeave: handlerAll(props.onMouseLeave, () => {\n setIsMouseEnter(false)\n }),\n }),\n [computedProps],\n )\n\n const getSlidesProps: UIPropGetter = useCallback(\n (props = {}) => ({\n ...computedProps[1],\n ...props,\n ref: carouselRef,\n }),\n [computedProps, carouselRef],\n )\n\n return {\n carousel,\n children,\n indexes,\n selectedIndex,\n orientation,\n slideSize,\n gap,\n slidesToScroll,\n includeGapInSize,\n getContainerProps,\n getSlidesProps,\n }\n}\n\nexport type UseCarouselReturn = ReturnType<typeof useCarousel>\n\nexport type UseCarouselSlideProps = {\n index?: number\n}\n\nexport const useCarouselSlide = ({ index }: UseCarouselSlideProps) => {\n const { selectedIndex, slidesToScroll } = useCarouselContext()\n\n index = Math.floor((index ?? 0) / (slidesToScroll ?? 1))\n\n const isSelected = index === selectedIndex\n\n const getSlideProps: UIPropGetter = useCallback(\n (props = {}) => ({\n ...props,\n \"data-index\": index,\n \"data-selected\": dataAttr(isSelected),\n }),\n [isSelected, index],\n )\n\n return { getSlideProps }\n}\n\nexport type UseCarouselSlideReturn = ReturnType<typeof useCarouselSlide>\n\nexport type UseCarouselControlProps = IconButtonProps & {\n operation: \"prev\" | \"next\"\n}\n\nexport const useCarouselControl = ({\n operation,\n ...rest\n}: UseCarouselControlProps) => {\n const { carousel } = useCarouselContext()\n\n const isPrev = operation === \"prev\"\n\n const disabled =\n rest.disabled ??\n rest.isDisabled ??\n (isPrev ? !carousel?.canScrollPrev() : !carousel?.canScrollNext())\n\n const onClick = useCallback(() => {\n if (!carousel) return\n\n if (isPrev) {\n carousel.scrollPrev()\n } else {\n carousel.scrollNext()\n }\n }, [carousel, isPrev])\n\n const getControlProps: UIPropGetter<\"button\"> = useCallback(\n (props = {}, ref = null) => ({\n ...props,\n ref,\n disabled,\n onClick: handlerAll(props.onClick, onClick),\n }),\n [disabled, onClick],\n )\n\n return { getControlProps }\n}\n\nexport type UseCarouselControlReturn = ReturnType<typeof useCarouselControl>\n\nexport const useCarouselIndicators = () => {\n const { selectedIndex, carousel, indexes } = useCarouselContext()\n\n const onClick = useCallback(\n (ev: MouseEvent, index: number) => {\n if (!carousel) return\n\n ev.stopPropagation()\n\n carousel.scrollTo(index)\n },\n [carousel],\n )\n\n const getIndicatorProps: RequiredUIPropGetter<\"button\", { index: number }> =\n useCallback(\n ({ index, ...props }) => {\n const isSelected = index === selectedIndex\n\n return {\n \"aria-label\": `Go to ${index + 1} slide`,\n ...props,\n key: index,\n \"data-index\": index,\n \"data-selected\": dataAttr(isSelected),\n onClick: handlerAll(props.onClick, (ev) => onClick(ev, index)),\n }\n },\n [onClick, selectedIndex],\n )\n\n return { indexes, getIndicatorProps }\n}\n\nexport type UseCarouselIndicatorsReturn = ReturnType<\n typeof useCarouselIndicators\n>\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,IAAAA,eAA+B;AAC/B,IAAAC,gBAAmB;;;ACMnB,kBAAsC;AACtC,oCAAqC;AACrC,mBAMO;AAEP,kCAA6B;AAE7B,mBAAmE;AAc5D,IAAM,CAAC,kBAAkB,kBAAkB,QAChD,4BAA+B;AAAA,EAC7B,MAAM;AAAA,EACN,cAAc;AAChB,CAAC;AA8TI,IAAM,mBAAmB,CAAC,EAAE,MAAM,MAA6B;AACpE,QAAM,EAAE,eAAe,eAAe,IAAI,mBAAmB;AAE7D,UAAQ,KAAK,OAAO,wBAAS,MAAM,0CAAkB,EAAE;AAEvD,QAAM,aAAa,UAAU;AAE7B,QAAM,oBAA8B;AAAA,IAClC,CAAC,QAAQ,CAAC,OAAO;AAAA,MACf,GAAG;AAAA,MACH,cAAc;AAAA,MACd,qBAAiB,uBAAS,UAAU;AAAA,IACtC;AAAA,IACA,CAAC,YAAY,KAAK;AAAA,EACpB;AAEA,SAAO,EAAE,cAAc;AACzB;;;AD7UQ;AAvBD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