@yamada-ui/carousel 2.0.7-next-20241005220055 → 2.0.7-next-20241008193728

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. package/dist/carousel-control.js +2 -2
  2. package/dist/carousel-control.js.map +1 -1
  3. package/dist/carousel-control.mjs +2 -2
  4. package/dist/carousel-indicators.js +5 -5
  5. package/dist/carousel-indicators.js.map +1 -1
  6. package/dist/carousel-indicators.mjs +2 -2
  7. package/dist/carousel-slide.js +4 -4
  8. package/dist/carousel-slide.js.map +1 -1
  9. package/dist/carousel-slide.mjs +2 -2
  10. package/dist/carousel.d.mts +47 -47
  11. package/dist/carousel.d.ts +47 -47
  12. package/dist/carousel.js +60 -55
  13. package/dist/carousel.js.map +1 -1
  14. package/dist/carousel.mjs +5 -5
  15. package/dist/{chunk-OQNU22B2.mjs → chunk-GUS42GBZ.mjs} +6 -6
  16. package/dist/chunk-GUS42GBZ.mjs.map +1 -0
  17. package/dist/{chunk-W6XPFRNI.mjs → chunk-LZCAOPIG.mjs} +7 -7
  18. package/dist/chunk-LZCAOPIG.mjs.map +1 -0
  19. package/dist/{chunk-LRO4RIBJ.mjs → chunk-MRBEMM2G.mjs} +32 -27
  20. package/dist/chunk-MRBEMM2G.mjs.map +1 -0
  21. package/dist/{chunk-LV5JHVV6.mjs → chunk-MVAYW6S5.mjs} +28 -28
  22. package/dist/chunk-MVAYW6S5.mjs.map +1 -0
  23. package/dist/{chunk-T3LMURPY.mjs → chunk-UGZPN7LD.mjs} +4 -4
  24. package/dist/{chunk-T3LMURPY.mjs.map → chunk-UGZPN7LD.mjs.map} +1 -1
  25. package/dist/index.d.mts +1 -1
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.js +60 -55
  28. package/dist/index.js.map +1 -1
  29. package/dist/index.mjs +5 -5
  30. package/dist/use-carousel.d.mts +98 -98
  31. package/dist/use-carousel.d.ts +98 -98
  32. package/dist/use-carousel.js +31 -26
  33. package/dist/use-carousel.js.map +1 -1
  34. package/dist/use-carousel.mjs +1 -1
  35. package/package.json +8 -8
  36. package/dist/chunk-LRO4RIBJ.mjs.map +0 -1
  37. package/dist/chunk-LV5JHVV6.mjs.map +0 -1
  38. package/dist/chunk-OQNU22B2.mjs.map +0 -1
  39. package/dist/chunk-W6XPFRNI.mjs.map +0 -1
@@ -8,18 +8,18 @@ import 'react';
8
8
  import 'embla-carousel';
9
9
 
10
10
  interface CarouselOptions {
11
- /**
12
- * The orientation of the carousel.
13
- *
14
- * @default 'horizontal'
15
- */
16
- orientation?: Token<"vertical" | "horizontal">;
17
11
  /**
18
12
  * The alignment of the carousel.
19
13
  *
20
14
  * @default 'center'
21
15
  */
22
16
  align?: Token<AlignmentOptionType>;
17
+ /**
18
+ * If `true`, the carousel will be autoplay.
19
+ *
20
+ * @default false
21
+ */
22
+ autoplay?: Token<boolean>;
23
23
  /**
24
24
  * Clear leading and trailing empty space that causes excessive scrolling.
25
25
  * Use trimSnaps to only use snap points that trigger scrolling or keepSnaps to keep them.
@@ -28,11 +28,11 @@ interface CarouselOptions {
28
28
  */
29
29
  containScroll?: Token<ScrollContainOptionType>;
30
30
  /**
31
- * The number of slides that should be scrolled with next or previous buttons.
31
+ * The number for the autoplay interval of the carousel.
32
32
  *
33
- * @default 1
33
+ * @default 4000
34
34
  */
35
- slidesToScroll?: Token<number>;
35
+ delay?: Token<number>;
36
36
  /**
37
37
  * If `true`, momentum scrolling will be enabled.
38
38
  *
@@ -45,6 +45,20 @@ interface CarouselOptions {
45
45
  * @default true
46
46
  */
47
47
  draggable?: Token<boolean>;
48
+ /**
49
+ * Set scroll duration when triggered by any of the API methods.
50
+ * Higher numbers enables slower scrolling.
51
+ * Drag interactions are not affected because duration is then determined by the drag force.
52
+ *
53
+ * @default 25
54
+ */
55
+ duration?: Token<number>;
56
+ /**
57
+ * If `true`, gap will be treated as part of the carousel slide size.
58
+ *
59
+ * @default true
60
+ */
61
+ includeGapInSize?: Token<boolean>;
48
62
  /**
49
63
  * Choose a fraction representing the percentage portion of a slide that needs to be visible in order to be considered in view.
50
64
  *
@@ -58,6 +72,12 @@ interface CarouselOptions {
58
72
  * @default true
59
73
  */
60
74
  loop?: Token<boolean>;
75
+ /**
76
+ * The orientation of the carousel.
77
+ *
78
+ * @default 'horizontal'
79
+ */
80
+ orientation?: Token<"horizontal" | "vertical">;
61
81
  /**
62
82
  * If `true`, allow the carousel to skip scroll snaps if it's dragged vigorously.
63
83
  * Note that this option will be ignored if the dragFree option is set to true.
@@ -66,25 +86,15 @@ interface CarouselOptions {
66
86
  */
67
87
  skipSnaps?: Token<boolean>;
68
88
  /**
69
- * Set scroll duration when triggered by any of the API methods.
70
- * Higher numbers enables slower scrolling.
71
- * Drag interactions are not affected because duration is then determined by the drag force.
72
- *
73
- * @default 25
74
- */
75
- duration?: Token<number>;
76
- /**
77
- * The number for the autoplay interval of the carousel.
78
- *
79
- * @default 4000
89
+ * The CSS `width` property.
80
90
  */
81
- delay?: Token<number>;
91
+ slideSize?: CSSUIProps["width"];
82
92
  /**
83
- * If `true`, the carousel will be autoplay.
93
+ * The number of slides that should be scrolled with next or previous buttons.
84
94
  *
85
- * @default false
95
+ * @default 1
86
96
  */
87
- autoplay?: Token<boolean>;
97
+ slidesToScroll?: Token<number>;
88
98
  /**
89
99
  * If `true`, autoplay will pause when the mouse entries over.
90
100
  *
@@ -92,49 +102,39 @@ interface CarouselOptions {
92
102
  */
93
103
  stopMouseEnterAutoplay?: Token<boolean>;
94
104
  /**
95
- * If `true`, gap will be treated as part of the carousel slide size.
105
+ * If `true`, display the carousel control buttons.
96
106
  *
97
107
  * @default true
98
108
  */
99
- includeGapInSize?: Token<boolean>;
100
- /**
101
- * The CSS `width` property.
102
- */
103
- slideSize?: CSSUIProps["width"];
104
- /**
105
- * Props for carousel inner element.
106
- */
107
- innerProps?: HTMLUIProps;
109
+ withControls?: Token<boolean>;
108
110
  /**
109
- * If `true`, display the carousel control buttons.
111
+ * If `true`, display the carousel indicator buttons.
110
112
  *
111
113
  * @default true
112
114
  */
113
- withControls?: Token<boolean>;
115
+ withIndicators?: Token<boolean>;
114
116
  /**
115
- * Props for carousel control element.
117
+ * Props for next of the carousel control element.
116
118
  */
117
- controlProps?: CarouselControlProps;
119
+ controlNextProps?: CarouselControlProps;
118
120
  /**
119
121
  * Props for previous of the carousel control element.
120
122
  */
121
123
  controlPrevProps?: CarouselControlProps;
122
124
  /**
123
- * Props for next of the carousel control element.
124
- */
125
- controlNextProps?: CarouselControlProps;
126
- /**
127
- * If `true`, display the carousel indicator buttons.
128
- *
129
- * @default true
125
+ * Props for carousel control element.
130
126
  */
131
- withIndicators?: Token<boolean>;
127
+ controlProps?: CarouselControlProps;
132
128
  /**
133
129
  * Props for carousel indicators element.
134
130
  */
135
131
  indicatorsProps?: CarouselIndicatorsProps;
132
+ /**
133
+ * Props for carousel inner element.
134
+ */
135
+ innerProps?: HTMLUIProps;
136
136
  }
137
- interface CarouselProps extends ThemeProps<"Carousel">, Omit<HTMLUIProps, "onChange" | "draggable">, Pick<UseCarouselProps, "index" | "defaultIndex" | "onChange" | "onScrollProgress" | "watchDrag" | "watchResize" | "watchSlides" | "controlRef">, CarouselOptions {
137
+ interface CarouselProps extends ThemeProps<"Carousel">, Omit<HTMLUIProps, "draggable" | "onChange">, Pick<UseCarouselProps, "controlRef" | "defaultIndex" | "index" | "onChange" | "onScrollProgress" | "watchDrag" | "watchResize" | "watchSlides">, CarouselOptions {
138
138
  }
139
139
  /**
140
140
  * `Carousel` is a component that displays multiple elements like a slideshow.
package/dist/carousel.js CHANGED
@@ -57,51 +57,51 @@ var [CarouselProvider, useCarouselContext] = (0, import_utils.createContext)({
57
57
  errorMessage: `useCarouselContext returned is 'undefined'. Seems you forgot to wrap the components in "<Carousel />"`
58
58
  });
59
59
  var useCarousel = ({
60
- index,
61
- defaultIndex = 0,
62
- onChange,
63
60
  align = "center",
64
- orientation = "horizontal",
65
61
  autoplay = false,
66
- stopMouseEnterAutoplay = true,
67
- loop = true,
68
- duration = 25,
62
+ children,
63
+ containScroll = false,
64
+ controlRef,
65
+ defaultIndex = 0,
69
66
  delay = 4e3,
70
- slidesToScroll = 1,
71
- draggable = true,
72
67
  dragFree = false,
68
+ draggable = true,
69
+ duration = 25,
70
+ includeGapInSize = true,
71
+ index,
73
72
  inViewThreshold = 0,
73
+ loop = true,
74
+ orientation = "horizontal",
74
75
  skipSnaps = false,
75
- containScroll = false,
76
76
  slideSize = "100%",
77
- includeGapInSize = true,
78
- onScrollProgress,
77
+ slidesToScroll = 1,
78
+ stopMouseEnterAutoplay = true,
79
79
  watchDrag = draggable,
80
80
  watchResize = true,
81
81
  watchSlides = true,
82
- controlRef,
83
- children,
82
+ onChange,
83
+ onScrollProgress,
84
84
  ...rest
85
85
  }) => {
86
86
  const [{ gap = "fallback(4, 1rem)", ...containerProps }, slidesProps] = (0, import_utils.splitObject)(rest, import_core.layoutStyleProperties);
87
87
  const [selectedIndex, setSelectedIndex] = (0, import_use_controllable_state.useControllableState)({
88
- value: index,
89
88
  defaultValue: defaultIndex,
89
+ value: index,
90
90
  onChange
91
91
  });
92
92
  const isVertical = orientation === "vertical";
93
93
  const [carouselRef, carousel] = (0, import_embla_carousel_react.default)(
94
94
  {
95
- axis: isVertical ? "y" : "x",
96
- startIndex: defaultIndex,
97
- loop,
98
95
  align,
99
- slidesToScroll,
100
- duration,
96
+ axis: isVertical ? "y" : "x",
97
+ containScroll,
101
98
  dragFree,
99
+ duration,
102
100
  inViewThreshold,
101
+ loop,
103
102
  skipSnaps,
104
- containScroll,
103
+ slidesToScroll,
104
+ startIndex: defaultIndex,
105
105
  watchDrag,
106
106
  watchResize,
107
107
  watchSlides
@@ -186,6 +186,11 @@ var useCarousel = ({
186
186
  };
187
187
  }
188
188
  }, [carousel, onScroll]);
189
+ (0, import_utils.useUpdateEffect)(() => {
190
+ if (!carousel) return;
191
+ if (index === void 0) return;
192
+ carousel.scrollTo(index);
193
+ }, [index]);
189
194
  const getContainerProps = (0, import_react.useCallback)(
190
195
  (props = {}, ref = null) => ({
191
196
  ...containerProps,
@@ -211,20 +216,20 @@ var useCarousel = ({
211
216
  return {
212
217
  carousel,
213
218
  children,
219
+ gap,
220
+ includeGapInSize,
214
221
  indexes,
215
- selectedIndex,
216
222
  orientation,
223
+ selectedIndex,
217
224
  slideSize,
218
- gap,
219
225
  slidesToScroll,
220
- includeGapInSize,
221
226
  getContainerProps,
222
227
  getSlidesProps
223
228
  };
224
229
  };
225
230
  var useCarouselSlide = ({ index }) => {
226
231
  const { selectedIndex, slidesToScroll } = useCarouselContext();
227
- index = Math.floor((index != null ? index : 0) / (slidesToScroll != null ? slidesToScroll : 1));
232
+ index = Math.floor((index != null ? index : 0) / slidesToScroll);
228
233
  const isSelected = index === selectedIndex;
229
234
  const getSlideProps = (0, import_react.useCallback)(
230
235
  (props = {}) => ({
@@ -264,7 +269,7 @@ var useCarouselControl = ({
264
269
  return { getControlProps };
265
270
  };
266
271
  var useCarouselIndicators = () => {
267
- const { selectedIndex, carousel, indexes } = useCarouselContext();
272
+ const { carousel, indexes, selectedIndex } = useCarouselContext();
268
273
  const onClick = (0, import_react.useCallback)(
269
274
  (ev, index) => {
270
275
  if (!carousel) return;
@@ -299,7 +304,6 @@ var CarouselControlPrev = (0, import_core2.forwardRef)(
299
304
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
300
305
  CarouselControl,
301
306
  {
302
- operation: "prev",
303
307
  className: (0, import_utils2.cx)("ui-carousel__control--prev", className),
304
308
  "aria-label": "Go to previous slide",
305
309
  icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -311,6 +315,7 @@ var CarouselControlPrev = (0, import_core2.forwardRef)(
311
315
  }
312
316
  }
313
317
  ),
318
+ operation: "prev",
314
319
  ...getControlProps(rest, ref)
315
320
  }
316
321
  );
@@ -325,7 +330,6 @@ var CarouselControlNext = (0, import_core2.forwardRef)(
325
330
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
326
331
  CarouselControl,
327
332
  {
328
- operation: "next",
329
333
  className: (0, import_utils2.cx)("ui-carousel__control--next", className),
330
334
  "aria-label": "Go to next slide",
331
335
  icon: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
@@ -337,6 +341,7 @@ var CarouselControlNext = (0, import_core2.forwardRef)(
337
341
  }
338
342
  }
339
343
  ),
344
+ operation: "next",
340
345
  ...getControlProps(rest, ref)
341
346
  }
342
347
  );
@@ -374,13 +379,13 @@ var import_react2 = require("react");
374
379
  var import_jsx_runtime2 = require("react/jsx-runtime");
375
380
  var CarouselIndicators = (0, import_core3.forwardRef)(
376
381
  ({ className, component, ...rest }, ref) => {
377
- const { selectedIndex, orientation, styles } = useCarouselContext();
382
+ const { orientation, selectedIndex, styles } = useCarouselContext();
378
383
  const { indexes, getIndicatorProps } = useCarouselIndicators();
379
384
  const css = {
380
- position: "absolute",
381
- zIndex: "fallback(kurillin, 9)",
382
385
  display: "flex",
383
386
  justifyContent: "center",
387
+ position: "absolute",
388
+ zIndex: "fallback(kurillin, 9)",
384
389
  ...styles.indicators,
385
390
  ...orientation === "vertical" ? { flexDirection: "column" } : { flexDirection: "row" }
386
391
  };
@@ -422,8 +427,8 @@ var CarouselIndicator = ({
422
427
  import_core3.ui.button,
423
428
  {
424
429
  type: "button",
425
- tabIndex: -1,
426
430
  className: (0, import_utils3.cx)("ui-carousel__indicators__indicator", className),
431
+ tabIndex: -1,
427
432
  __css: css,
428
433
  ...rest
429
434
  }
@@ -438,12 +443,12 @@ var import_utils4 = require("@yamada-ui/utils");
438
443
  var import_jsx_runtime3 = require("react/jsx-runtime");
439
444
  var CarouselSlide = (0, import_core4.forwardRef)(
440
445
  ({ className, size, ...rest }, ref) => {
441
- const { slideSize, includeGapInSize, orientation, gap } = useCarouselContext();
446
+ const { gap, includeGapInSize, orientation, slideSize } = useCarouselContext();
442
447
  const { getSlideProps } = useCarouselSlide(rest);
443
448
  size != null ? size : size = slideSize;
444
449
  const css = {
445
- position: "relative",
446
450
  flex: `0 0 ${size}`,
451
+ position: "relative",
447
452
  ...includeGapInSize ? { [orientation === "vertical" ? "pb" : "pr"]: gap } : { [orientation === "vertical" ? "mb" : "mr"]: gap }
448
453
  };
449
454
  return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
@@ -466,8 +471,8 @@ var CarouselSlideInner = (0, import_core4.forwardRef)(
466
471
  {
467
472
  ref,
468
473
  className: "ui-carousel__slide__inner",
469
- w: "100%",
470
474
  h: "100%",
475
+ w: "100%",
471
476
  ...rest
472
477
  }
473
478
  );
@@ -501,37 +506,37 @@ var Carousel = (0, import_core5.forwardRef)(
501
506
  const slideSize = (_b = (0, import_use_token.useToken)("sizes", _slideSize)) != null ? _b : _slideSize;
502
507
  const [styles, mergedProps] = (0, import_core5.useComponentMultiStyle)("Carousel", {
503
508
  ...props,
504
- orientation,
505
509
  align,
506
510
  autoplay,
507
- stopMouseEnterAutoplay,
508
- loop,
509
- duration,
511
+ containScroll,
510
512
  delay,
511
- slidesToScroll,
512
- draggable,
513
513
  dragFree,
514
+ draggable,
515
+ duration,
516
+ gap,
517
+ includeGapInSize,
514
518
  inViewThreshold,
519
+ loop,
520
+ orientation,
515
521
  skipSnaps,
516
- containScroll,
517
- includeGapInSize,
518
- gap,
519
- slideSize
522
+ slideSize,
523
+ slidesToScroll,
524
+ stopMouseEnterAutoplay
520
525
  });
521
526
  const {
522
527
  className,
523
- innerProps,
524
528
  withControls = true,
525
- controlProps,
526
- controlPrevProps,
527
- controlNextProps,
528
529
  withIndicators = true,
530
+ controlNextProps,
531
+ controlPrevProps,
532
+ controlProps,
529
533
  indicatorsProps,
534
+ innerProps,
530
535
  ...computedProps
531
536
  } = (0, import_core5.omitThemeProps)(mergedProps);
532
537
  const computedWithControls = (0, import_use_value.useValue)(withControls);
533
538
  const computedWithIndicators = (0, import_use_value.useValue)(withIndicators);
534
- const { getContainerProps, getSlidesProps, children, ...rest } = useCarousel({
539
+ const { children, getContainerProps, getSlidesProps, ...rest } = useCarousel({
535
540
  ...computedProps
536
541
  });
537
542
  const validChildren = (0, import_utils5.getValidChildren)(children);
@@ -565,8 +570,8 @@ var Carousel = (0, import_core5.forwardRef)(
565
570
  {
566
571
  className: (0, import_utils5.cx)("ui-carousel", className),
567
572
  __css: {
568
- position: "relative",
569
573
  h: "fit-content",
574
+ position: "relative",
570
575
  ...styles.container
571
576
  },
572
577
  ...getContainerProps({}, ref),
@@ -594,21 +599,21 @@ Carousel.displayName = "Carousel";
594
599
  Carousel.__ui__ = "Carousel";
595
600
  var CarouselSlides = (0, import_core5.forwardRef)(
596
601
  ({ ...rest }, ref) => {
597
- const css = { w: "100%", h: "fit-content", overflow: "hidden" };
602
+ const css = { h: "fit-content", overflow: "hidden", w: "100%" };
598
603
  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 }) });
599
604
  }
600
605
  );
601
606
  CarouselSlides.displayName = "CarouselSlides";
602
607
  CarouselSlides.__ui__ = "CarouselSlides";
603
608
  var CarouselSlidesInner = ({ ...rest }) => {
604
- const { orientation, includeGapInSize, gap, styles } = useCarouselContext();
609
+ const { gap, includeGapInSize, orientation, styles } = useCarouselContext();
605
610
  const css = {
606
611
  display: "flex",
607
612
  flexDirection: orientation === "vertical" ? "column" : "row",
608
613
  ...styles.inner,
609
614
  ...includeGapInSize ? {
610
- vars: [{ name: "gap", token: "spaces", value: gap }],
611
- [orientation === "vertical" ? "mb" : "mr"]: "calc($gap * -1)"
615
+ [orientation === "vertical" ? "mb" : "mr"]: "calc($gap * -1)",
616
+ vars: [{ name: "gap", token: "spaces", value: gap }]
612
617
  } : {}
613
618
  };
614
619
  return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_core5.ui.div, { className: "ui-carousel__sliders__inner", __css: css, ...rest });