@yamada-ui/carousel 1.0.28 → 2.0.0-next-20240513035416
Sign up to get free protection for your applications and to get access to all the features.
- 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-DDY7Q2IV.mjs +87 -0
- package/dist/chunk-DDY7Q2IV.mjs.map +1 -0
- package/dist/chunk-IKJXFLRJ.mjs +72 -0
- package/dist/chunk-IKJXFLRJ.mjs.map +1 -0
- package/dist/chunk-QQ2HS4J4.mjs +260 -0
- package/dist/chunk-QQ2HS4J4.mjs.map +1 -0
- package/dist/chunk-VQX7S5CU.mjs +50 -0
- package/dist/chunk-VQX7S5CU.mjs.map +1 -0
- package/dist/chunk-YDLJHKEU.mjs +171 -0
- package/dist/chunk-YDLJHKEU.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 +1 -1
package/dist/carousel.js
ADDED
@@ -0,0 +1,599 @@
|
|
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.tsx
|
32
|
+
var carousel_exports = {};
|
33
|
+
__export(carousel_exports, {
|
34
|
+
Carousel: () => Carousel
|
35
|
+
});
|
36
|
+
module.exports = __toCommonJS(carousel_exports);
|
37
|
+
var import_core5 = require("@yamada-ui/core");
|
38
|
+
var import_use_token = require("@yamada-ui/use-token");
|
39
|
+
var import_use_value = require("@yamada-ui/use-value");
|
40
|
+
var import_utils5 = require("@yamada-ui/utils");
|
41
|
+
var import_react3 = require("react");
|
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 useCarousel = ({
|
54
|
+
index,
|
55
|
+
defaultIndex = 0,
|
56
|
+
onChange,
|
57
|
+
align = "center",
|
58
|
+
orientation = "horizontal",
|
59
|
+
autoplay = false,
|
60
|
+
stopMouseEnterAutoplay = true,
|
61
|
+
loop = true,
|
62
|
+
speed = 10,
|
63
|
+
delay = 4e3,
|
64
|
+
gap = "fallback(4, 1rem)",
|
65
|
+
slidesToScroll = 1,
|
66
|
+
draggable = true,
|
67
|
+
dragFree = false,
|
68
|
+
inViewThreshold = 0,
|
69
|
+
skipSnaps = false,
|
70
|
+
containScroll = "",
|
71
|
+
slideSize = "100%",
|
72
|
+
includeGapInSize = true,
|
73
|
+
onScrollProgress,
|
74
|
+
children,
|
75
|
+
...rest
|
76
|
+
}) => {
|
77
|
+
const computedProps = (0, import_utils.splitObject)(rest, import_core.layoutStyleProperties);
|
78
|
+
const [selectedIndex, setSelectedIndex] = (0, import_use_controllable_state.useControllableState)({
|
79
|
+
value: index,
|
80
|
+
defaultValue: defaultIndex,
|
81
|
+
onChange
|
82
|
+
});
|
83
|
+
const isVertical = orientation === "vertical";
|
84
|
+
const [carouselRef, carousel] = (0, import_embla_carousel_react.default)({
|
85
|
+
axis: isVertical ? "y" : "x",
|
86
|
+
startIndex: defaultIndex,
|
87
|
+
loop,
|
88
|
+
align,
|
89
|
+
slidesToScroll,
|
90
|
+
draggable,
|
91
|
+
dragFree,
|
92
|
+
speed,
|
93
|
+
inViewThreshold,
|
94
|
+
skipSnaps,
|
95
|
+
containScroll
|
96
|
+
});
|
97
|
+
const [indexes, setIndexes] = (0, import_react.useState)([]);
|
98
|
+
const [isMouseEnter, setIsMouseEnter] = (0, import_react.useState)(false);
|
99
|
+
const timeoutId = (0, import_react.useRef)(void 0);
|
100
|
+
const onScroll = (0, import_react.useCallback)(() => {
|
101
|
+
if (!carousel)
|
102
|
+
return;
|
103
|
+
const progress = Math.round(
|
104
|
+
Math.max(0, Math.min(1, carousel.scrollProgress())) * 100
|
105
|
+
);
|
106
|
+
onScrollProgress == null ? void 0 : onScrollProgress(progress);
|
107
|
+
}, [carousel, onScrollProgress]);
|
108
|
+
const onSelect = (0, import_react.useCallback)(() => {
|
109
|
+
if (!carousel)
|
110
|
+
return;
|
111
|
+
const index2 = carousel.selectedScrollSnap();
|
112
|
+
setSelectedIndex(index2);
|
113
|
+
}, [carousel, setSelectedIndex]);
|
114
|
+
(0, import_react.useEffect)(() => {
|
115
|
+
const isStop = isMouseEnter && stopMouseEnterAutoplay;
|
116
|
+
const isLast = !(carousel == null ? void 0 : carousel.canScrollNext());
|
117
|
+
if (carousel && autoplay && !isStop && !isLast) {
|
118
|
+
timeoutId.current = setInterval(() => {
|
119
|
+
carousel.scrollNext();
|
120
|
+
}, delay);
|
121
|
+
} else {
|
122
|
+
if (timeoutId.current)
|
123
|
+
clearInterval(timeoutId.current);
|
124
|
+
timeoutId.current = void 0;
|
125
|
+
}
|
126
|
+
return () => {
|
127
|
+
if (timeoutId.current)
|
128
|
+
clearInterval(timeoutId.current);
|
129
|
+
};
|
130
|
+
}, [
|
131
|
+
autoplay,
|
132
|
+
delay,
|
133
|
+
stopMouseEnterAutoplay,
|
134
|
+
carousel,
|
135
|
+
isMouseEnter,
|
136
|
+
loop,
|
137
|
+
selectedIndex
|
138
|
+
]);
|
139
|
+
(0, import_utils.useUpdateEffect)(() => {
|
140
|
+
if (!carousel)
|
141
|
+
return;
|
142
|
+
carousel.reInit();
|
143
|
+
const snapList = carousel.scrollSnapList();
|
144
|
+
const indexes2 = snapList.map((_, i) => i);
|
145
|
+
setIndexes(indexes2);
|
146
|
+
}, [
|
147
|
+
import_react.Children.toArray(children).length,
|
148
|
+
align,
|
149
|
+
orientation,
|
150
|
+
loop,
|
151
|
+
speed,
|
152
|
+
gap,
|
153
|
+
slidesToScroll,
|
154
|
+
draggable,
|
155
|
+
dragFree,
|
156
|
+
inViewThreshold,
|
157
|
+
skipSnaps,
|
158
|
+
containScroll,
|
159
|
+
slideSize,
|
160
|
+
includeGapInSize
|
161
|
+
]);
|
162
|
+
(0, import_utils.useUpdateEffect)(() => {
|
163
|
+
if (!carousel)
|
164
|
+
return;
|
165
|
+
const snapList = carousel.scrollSnapList();
|
166
|
+
const indexes2 = snapList.map((_, i) => i);
|
167
|
+
setIndexes(indexes2);
|
168
|
+
}, [carousel]);
|
169
|
+
(0, import_utils.useUpdateEffect)(() => {
|
170
|
+
if (carousel) {
|
171
|
+
carousel.on("select", onSelect);
|
172
|
+
carousel.on("scroll", onScroll);
|
173
|
+
onScroll();
|
174
|
+
return () => {
|
175
|
+
carousel.off("select", onSelect);
|
176
|
+
carousel.off("scroll", onScroll);
|
177
|
+
};
|
178
|
+
}
|
179
|
+
}, [carousel, onScroll]);
|
180
|
+
const getContainerProps = (0, import_react.useCallback)(
|
181
|
+
(props = {}, ref = null) => ({
|
182
|
+
...computedProps[0],
|
183
|
+
...props,
|
184
|
+
ref,
|
185
|
+
onMouseEnter: (0, import_utils.handlerAll)(props.onMouseEnter, () => {
|
186
|
+
setIsMouseEnter(true);
|
187
|
+
}),
|
188
|
+
onMouseLeave: (0, import_utils.handlerAll)(props.onMouseLeave, () => {
|
189
|
+
setIsMouseEnter(false);
|
190
|
+
})
|
191
|
+
}),
|
192
|
+
[computedProps]
|
193
|
+
);
|
194
|
+
const getSlidesProps = (0, import_react.useCallback)(
|
195
|
+
(props = {}) => ({
|
196
|
+
...computedProps[1],
|
197
|
+
...props,
|
198
|
+
ref: carouselRef
|
199
|
+
}),
|
200
|
+
[computedProps, carouselRef]
|
201
|
+
);
|
202
|
+
return {
|
203
|
+
carousel,
|
204
|
+
children,
|
205
|
+
indexes,
|
206
|
+
selectedIndex,
|
207
|
+
orientation,
|
208
|
+
slideSize,
|
209
|
+
gap,
|
210
|
+
slidesToScroll,
|
211
|
+
includeGapInSize,
|
212
|
+
getContainerProps,
|
213
|
+
getSlidesProps
|
214
|
+
};
|
215
|
+
};
|
216
|
+
var useCarouselSlide = ({ index }) => {
|
217
|
+
const { selectedIndex, slidesToScroll } = useCarouselContext();
|
218
|
+
index = Math.floor((index != null ? index : 0) / (slidesToScroll != null ? slidesToScroll : 1));
|
219
|
+
const isSelected = index === selectedIndex;
|
220
|
+
const getSlideProps = (0, import_react.useCallback)(
|
221
|
+
(props = {}) => ({
|
222
|
+
...props,
|
223
|
+
"data-index": index,
|
224
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected)
|
225
|
+
}),
|
226
|
+
[isSelected, index]
|
227
|
+
);
|
228
|
+
return { getSlideProps };
|
229
|
+
};
|
230
|
+
var useCarouselControl = ({
|
231
|
+
operation,
|
232
|
+
...rest
|
233
|
+
}) => {
|
234
|
+
var _a, _b;
|
235
|
+
const { carousel } = useCarouselContext();
|
236
|
+
const isPrev = operation === "prev";
|
237
|
+
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());
|
238
|
+
const onClick = (0, import_react.useCallback)(() => {
|
239
|
+
if (!carousel)
|
240
|
+
return;
|
241
|
+
if (isPrev) {
|
242
|
+
carousel.scrollPrev();
|
243
|
+
} else {
|
244
|
+
carousel.scrollNext();
|
245
|
+
}
|
246
|
+
}, [carousel, isPrev]);
|
247
|
+
const getControlProps = (0, import_react.useCallback)(
|
248
|
+
(props = {}, ref = null) => ({
|
249
|
+
...props,
|
250
|
+
ref,
|
251
|
+
disabled,
|
252
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, onClick)
|
253
|
+
}),
|
254
|
+
[disabled, onClick]
|
255
|
+
);
|
256
|
+
return { getControlProps };
|
257
|
+
};
|
258
|
+
var useCarouselIndicators = () => {
|
259
|
+
const { selectedIndex, carousel, indexes } = useCarouselContext();
|
260
|
+
const onClick = (0, import_react.useCallback)(
|
261
|
+
(ev, index) => {
|
262
|
+
if (!carousel)
|
263
|
+
return;
|
264
|
+
ev.stopPropagation();
|
265
|
+
carousel.scrollTo(index);
|
266
|
+
},
|
267
|
+
[carousel]
|
268
|
+
);
|
269
|
+
const getIndicatorProps = (0, import_react.useCallback)(
|
270
|
+
({ index, ...props }) => {
|
271
|
+
const isSelected = index === selectedIndex;
|
272
|
+
return {
|
273
|
+
"aria-label": `Go to ${index + 1} slide`,
|
274
|
+
...props,
|
275
|
+
key: index,
|
276
|
+
"data-index": index,
|
277
|
+
"data-selected": (0, import_utils.dataAttr)(isSelected),
|
278
|
+
onClick: (0, import_utils.handlerAll)(props.onClick, (ev) => onClick(ev, index))
|
279
|
+
};
|
280
|
+
},
|
281
|
+
[onClick, selectedIndex]
|
282
|
+
);
|
283
|
+
return { indexes, getIndicatorProps };
|
284
|
+
};
|
285
|
+
|
286
|
+
// src/carousel-slide.tsx
|
287
|
+
var import_core2 = require("@yamada-ui/core");
|
288
|
+
var import_utils2 = require("@yamada-ui/utils");
|
289
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
290
|
+
var CarouselSlide = (0, import_core2.forwardRef)(
|
291
|
+
({ className, size, ...rest }, ref) => {
|
292
|
+
const { slideSize, includeGapInSize, orientation, gap } = useCarouselContext();
|
293
|
+
const { getSlideProps } = useCarouselSlide(rest);
|
294
|
+
size != null ? size : size = slideSize;
|
295
|
+
const css = {
|
296
|
+
position: "relative",
|
297
|
+
flex: `0 0 ${size}`,
|
298
|
+
...includeGapInSize ? { [orientation === "vertical" ? "pb" : "pr"]: gap } : { [orientation === "vertical" ? "mb" : "mr"]: gap }
|
299
|
+
};
|
300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
301
|
+
import_core2.ui.div,
|
302
|
+
{
|
303
|
+
className: (0, import_utils2.cx)("ui-carousel__slide", className),
|
304
|
+
__css: css,
|
305
|
+
...getSlideProps({}),
|
306
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CarouselSlideInner, { ref, ...rest })
|
307
|
+
}
|
308
|
+
);
|
309
|
+
}
|
310
|
+
);
|
311
|
+
var CarouselSlideInner = (0, import_core2.forwardRef)(
|
312
|
+
({ ...rest }, ref) => {
|
313
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
314
|
+
import_core2.ui.div,
|
315
|
+
{
|
316
|
+
ref,
|
317
|
+
className: "ui-carousel__slide__inner",
|
318
|
+
w: "100%",
|
319
|
+
h: "100%",
|
320
|
+
...rest
|
321
|
+
}
|
322
|
+
);
|
323
|
+
}
|
324
|
+
);
|
325
|
+
|
326
|
+
// src/carousel-control.tsx
|
327
|
+
var import_button = require("@yamada-ui/button");
|
328
|
+
var import_core3 = require("@yamada-ui/core");
|
329
|
+
var import_icon = require("@yamada-ui/icon");
|
330
|
+
var import_utils3 = require("@yamada-ui/utils");
|
331
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
332
|
+
var CarouselControlPrev = (0, import_core3.forwardRef)(
|
333
|
+
({ className, ...rest }, ref) => {
|
334
|
+
const { orientation } = useCarouselContext();
|
335
|
+
const { getControlProps } = useCarouselControl({ operation: "prev" });
|
336
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
337
|
+
CarouselControl,
|
338
|
+
{
|
339
|
+
operation: "prev",
|
340
|
+
className: (0, import_utils3.cx)("ui-carousel__control--prev", className),
|
341
|
+
"aria-label": "Go to previous slide",
|
342
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
343
|
+
import_icon.ChevronIcon,
|
344
|
+
{
|
345
|
+
__css: {
|
346
|
+
fontSize: "1.5em",
|
347
|
+
transform: orientation === "vertical" ? "rotate(180deg)" : "rotate(90deg)"
|
348
|
+
}
|
349
|
+
}
|
350
|
+
),
|
351
|
+
...getControlProps(rest, ref)
|
352
|
+
}
|
353
|
+
);
|
354
|
+
}
|
355
|
+
);
|
356
|
+
var CarouselControlNext = (0, import_core3.forwardRef)(
|
357
|
+
({ className, ...rest }, ref) => {
|
358
|
+
const { orientation } = useCarouselContext();
|
359
|
+
const { getControlProps } = useCarouselControl({ operation: "next" });
|
360
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
361
|
+
CarouselControl,
|
362
|
+
{
|
363
|
+
operation: "next",
|
364
|
+
className: (0, import_utils3.cx)("ui-carousel__control--next", className),
|
365
|
+
"aria-label": "Go to next slide",
|
366
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
367
|
+
import_icon.ChevronIcon,
|
368
|
+
{
|
369
|
+
__css: {
|
370
|
+
fontSize: "1.5em",
|
371
|
+
transform: orientation === "vertical" ? "rotate(0deg)" : "rotate(-90deg)"
|
372
|
+
}
|
373
|
+
}
|
374
|
+
),
|
375
|
+
...getControlProps(rest, ref)
|
376
|
+
}
|
377
|
+
);
|
378
|
+
}
|
379
|
+
);
|
380
|
+
var CarouselControl = (0, import_core3.forwardRef)(({ className, operation, ...rest }, ref) => {
|
381
|
+
const { styles } = useCarouselContext();
|
382
|
+
const colorScheme = (0, import_core3.useColorModeValue)("whiteAlpha", "blackAlpha");
|
383
|
+
const css = {
|
384
|
+
position: "absolute",
|
385
|
+
zIndex: "fallback(kurillin, 9)",
|
386
|
+
...styles.control,
|
387
|
+
...styles[operation]
|
388
|
+
};
|
389
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
390
|
+
import_button.IconButton,
|
391
|
+
{
|
392
|
+
ref,
|
393
|
+
className: (0, import_utils3.cx)("ui-carousel__control", className),
|
394
|
+
colorScheme,
|
395
|
+
isRounded: true,
|
396
|
+
__css: css,
|
397
|
+
...rest
|
398
|
+
}
|
399
|
+
);
|
400
|
+
});
|
401
|
+
|
402
|
+
// src/carousel-indicators.tsx
|
403
|
+
var import_core4 = require("@yamada-ui/core");
|
404
|
+
var import_utils4 = require("@yamada-ui/utils");
|
405
|
+
var import_react2 = require("react");
|
406
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
407
|
+
var CarouselIndicators = (0, import_core4.forwardRef)(
|
408
|
+
({ className, component, ...rest }, ref) => {
|
409
|
+
const { selectedIndex, orientation, styles } = useCarouselContext();
|
410
|
+
const { indexes, getIndicatorProps } = useCarouselIndicators();
|
411
|
+
const css = {
|
412
|
+
position: "absolute",
|
413
|
+
zIndex: "fallback(kurillin, 9)",
|
414
|
+
display: "flex",
|
415
|
+
justifyContent: "center",
|
416
|
+
...styles.indicators,
|
417
|
+
...orientation === "vertical" ? { flexDirection: "column" } : { flexDirection: "row" }
|
418
|
+
};
|
419
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
420
|
+
import_core4.ui.div,
|
421
|
+
{
|
422
|
+
ref,
|
423
|
+
className: (0, import_utils4.cx)("ui-carousel__indicators", className),
|
424
|
+
__css: css,
|
425
|
+
...rest,
|
426
|
+
children: indexes.map((index) => {
|
427
|
+
const isSelected = index === selectedIndex;
|
428
|
+
if (typeof component === "function") {
|
429
|
+
const child = component({
|
430
|
+
index,
|
431
|
+
isSelected
|
432
|
+
});
|
433
|
+
if (!child)
|
434
|
+
return null;
|
435
|
+
const props = getIndicatorProps({ ...child.props, index });
|
436
|
+
return (0, import_react2.cloneElement)(child, props);
|
437
|
+
} else {
|
438
|
+
const { key, ...props } = getIndicatorProps({ index });
|
439
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CarouselIndicator, { ...props }, key);
|
440
|
+
}
|
441
|
+
})
|
442
|
+
}
|
443
|
+
);
|
444
|
+
}
|
445
|
+
);
|
446
|
+
var CarouselIndicator = ({
|
447
|
+
className,
|
448
|
+
...rest
|
449
|
+
}) => {
|
450
|
+
const { styles } = useCarouselContext();
|
451
|
+
const css = { ...styles.indicator };
|
452
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
453
|
+
import_core4.ui.button,
|
454
|
+
{
|
455
|
+
type: "button",
|
456
|
+
tabIndex: -1,
|
457
|
+
className: (0, import_utils4.cx)("ui-carousel__indicator", className),
|
458
|
+
__css: css,
|
459
|
+
...rest
|
460
|
+
}
|
461
|
+
);
|
462
|
+
};
|
463
|
+
|
464
|
+
// src/carousel.tsx
|
465
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
466
|
+
var Carousel = (0, import_core5.forwardRef)(
|
467
|
+
({ h, height, minH, minHeight, ...props }, ref) => {
|
468
|
+
var _a, _b;
|
469
|
+
const orientation = (0, import_use_value.useValue)(props.orientation);
|
470
|
+
const align = (0, import_use_value.useValue)(props.align);
|
471
|
+
const autoplay = (0, import_use_value.useValue)(props.autoplay);
|
472
|
+
const stopMouseEnterAutoplay = (0, import_use_value.useValue)(props.stopMouseEnterAutoplay);
|
473
|
+
const loop = (0, import_use_value.useValue)(props.loop);
|
474
|
+
const speed = (0, import_use_value.useValue)(props.speed);
|
475
|
+
const delay = (0, import_use_value.useValue)(props.delay);
|
476
|
+
const slidesToScroll = (0, import_use_value.useValue)(props.slidesToScroll);
|
477
|
+
const draggable = (0, import_use_value.useValue)(props.draggable);
|
478
|
+
const dragFree = (0, import_use_value.useValue)(props.dragFree);
|
479
|
+
const inViewThreshold = (0, import_use_value.useValue)(props.inViewThreshold);
|
480
|
+
const skipSnaps = (0, import_use_value.useValue)(props.skipSnaps);
|
481
|
+
const containScroll = (0, import_use_value.useValue)(props.containScroll);
|
482
|
+
const includeGapInSize = (0, import_use_value.useValue)(props.includeGapInSize);
|
483
|
+
const gap = (_a = (0, import_use_token.useToken)("spaces", (0, import_use_value.useValue)(props.gap))) != null ? _a : (0, import_use_value.useValue)(props.gap);
|
484
|
+
const slideSize = (_b = (0, import_use_token.useToken)("sizes", (0, import_use_value.useValue)(props.slideSize))) != null ? _b : (0, import_use_value.useValue)(props.slideSize);
|
485
|
+
const [styles, mergedProps] = (0, import_core5.useMultiComponentStyle)("Carousel", {
|
486
|
+
...props,
|
487
|
+
orientation,
|
488
|
+
align,
|
489
|
+
autoplay,
|
490
|
+
stopMouseEnterAutoplay,
|
491
|
+
loop,
|
492
|
+
speed,
|
493
|
+
delay,
|
494
|
+
slidesToScroll,
|
495
|
+
draggable,
|
496
|
+
dragFree,
|
497
|
+
inViewThreshold,
|
498
|
+
skipSnaps,
|
499
|
+
containScroll,
|
500
|
+
includeGapInSize,
|
501
|
+
gap,
|
502
|
+
slideSize
|
503
|
+
});
|
504
|
+
const {
|
505
|
+
className,
|
506
|
+
innerProps,
|
507
|
+
withControls = true,
|
508
|
+
controlProps,
|
509
|
+
controlPrevProps,
|
510
|
+
controlNextProps,
|
511
|
+
withIndicators = true,
|
512
|
+
indicatorsProps,
|
513
|
+
...computedProps
|
514
|
+
} = (0, import_core5.omitThemeProps)(mergedProps);
|
515
|
+
const computedWithControls = (0, import_use_value.useValue)(withControls);
|
516
|
+
const computedWithIndicators = (0, import_use_value.useValue)(withIndicators);
|
517
|
+
const { getContainerProps, getSlidesProps, children, ...rest } = useCarousel({
|
518
|
+
...computedProps
|
519
|
+
});
|
520
|
+
const validChildren = (0, import_utils5.getValidChildren)(children);
|
521
|
+
const [customCarouselControlPrev] = (0, import_utils5.findChildren)(
|
522
|
+
validChildren,
|
523
|
+
CarouselControlPrev
|
524
|
+
);
|
525
|
+
const [customCarouselControlNext] = (0, import_utils5.findChildren)(
|
526
|
+
validChildren,
|
527
|
+
CarouselControlNext
|
528
|
+
);
|
529
|
+
const [customCarouselIndicators] = (0, import_utils5.findChildren)(
|
530
|
+
validChildren,
|
531
|
+
CarouselIndicators
|
532
|
+
);
|
533
|
+
const slideChildren = (0, import_utils5.pickChildren)(validChildren, CarouselSlide);
|
534
|
+
const otherChildren = (0, import_utils5.omitChildren)(
|
535
|
+
validChildren,
|
536
|
+
CarouselControlPrev,
|
537
|
+
CarouselControlNext,
|
538
|
+
CarouselIndicators,
|
539
|
+
CarouselSlide
|
540
|
+
);
|
541
|
+
const cloneSlideChildren = slideChildren.map(
|
542
|
+
(child, index) => (0, import_react3.cloneElement)(child, { index })
|
543
|
+
);
|
544
|
+
h != null ? h : h = height;
|
545
|
+
minH != null ? minH : minH = minHeight;
|
546
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CarouselProvider, { value: { styles, ...rest }, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsxs)(
|
547
|
+
import_core5.ui.div,
|
548
|
+
{
|
549
|
+
className: (0, import_utils5.cx)("ui-carousel", className),
|
550
|
+
__css: {
|
551
|
+
position: "relative",
|
552
|
+
h: "fit-content",
|
553
|
+
...styles.container
|
554
|
+
},
|
555
|
+
...getContainerProps({}, ref),
|
556
|
+
children: [
|
557
|
+
customCarouselControlPrev != null ? customCarouselControlPrev : computedWithControls ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CarouselControlPrev, { ...controlProps, ...controlPrevProps }) : null,
|
558
|
+
customCarouselControlNext != null ? customCarouselControlNext : computedWithControls ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CarouselControlNext, { ...controlProps, ...controlNextProps }) : null,
|
559
|
+
/* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
|
560
|
+
CarouselSlides,
|
561
|
+
{
|
562
|
+
...getSlidesProps({
|
563
|
+
...(0, import_utils5.filterUndefined)({ h, minH }),
|
564
|
+
...innerProps
|
565
|
+
}),
|
566
|
+
children: cloneSlideChildren
|
567
|
+
}
|
568
|
+
),
|
569
|
+
customCarouselIndicators != null ? customCarouselIndicators : computedWithIndicators ? /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CarouselIndicators, { ...indicatorsProps }) : null,
|
570
|
+
otherChildren
|
571
|
+
]
|
572
|
+
}
|
573
|
+
) });
|
574
|
+
}
|
575
|
+
);
|
576
|
+
var CarouselSlides = (0, import_core5.forwardRef)(
|
577
|
+
({ ...rest }, ref) => {
|
578
|
+
const css = { w: "100%", h: "fit-content", overflow: "hidden" };
|
579
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core5.ui.div, { ref, className: "ui-carousel__sliders", __css: css, children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(CarouselSlidesInner, { ...rest }) });
|
580
|
+
}
|
581
|
+
);
|
582
|
+
var CarouselSlidesInner = ({ ...rest }) => {
|
583
|
+
const { orientation, includeGapInSize, gap, styles } = useCarouselContext();
|
584
|
+
const css = {
|
585
|
+
display: "flex",
|
586
|
+
flexDirection: orientation === "vertical" ? "column" : "row",
|
587
|
+
...styles.inner,
|
588
|
+
...includeGapInSize ? {
|
589
|
+
var: [{ __prefix: "ui", name: "gap", token: "spaces", value: gap }],
|
590
|
+
[orientation === "vertical" ? "mb" : "mr"]: import_utils5.calc.negate("var(--ui-gap)")
|
591
|
+
} : {}
|
592
|
+
};
|
593
|
+
return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core5.ui.div, { className: "ui-carousel__sliders__inner", __css: css, ...rest });
|
594
|
+
};
|
595
|
+
// Annotate the CommonJS export names for ESM import in node:
|
596
|
+
0 && (module.exports = {
|
597
|
+
Carousel
|
598
|
+
});
|
599
|
+
//# sourceMappingURL=carousel.js.map
|