@appica/ui-react 1.3.1 → 1.4.0
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/CHANGELOG.md +13 -0
- package/agent-rules.md +1 -0
- package/appica.css +1 -1
- package/dist/components/carousel/carousel.d.ts +24 -3
- package/dist/components/carousel/carousel.d.ts.map +1 -1
- package/dist/components/carousel/carousel.js +137 -27
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/src/components/carousel/carousel.test.tsx +425 -20
- package/src/components/carousel/carousel.tsx +182 -36
|
@@ -14,6 +14,16 @@ type CarouselOptions = EmblaOptionsType;
|
|
|
14
14
|
type CarouselPlugin = EmblaPluginType;
|
|
15
15
|
type CarouselAutoplayOptions = AutoplayOptionsType & {
|
|
16
16
|
resumeAfter?: number;
|
|
17
|
+
/**
|
|
18
|
+
* Pause while the pointer is over the carousel. Turn it off only beside a `CarouselPlayToggle`.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
pauseOnHover?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Pause while keyboard focus is inside the carousel. Turn it off only beside a `CarouselPlayToggle`.
|
|
24
|
+
* @default true
|
|
25
|
+
*/
|
|
26
|
+
pauseOnFocus?: boolean;
|
|
17
27
|
};
|
|
18
28
|
type CarouselAutoScrollOptions = AutoScrollOptionsType & {
|
|
19
29
|
resumeAfter?: number;
|
|
@@ -44,6 +54,12 @@ interface CarouselContextValue {
|
|
|
44
54
|
subscribeScrollProgress: (onChange: () => void) => () => void;
|
|
45
55
|
getScrollProgress: () => number;
|
|
46
56
|
autoplay: CarouselAutoplayState | null;
|
|
57
|
+
/** Whether Autoplay or Auto Scroll stays stopped until `play()`: paused by the user, or stopped for good by a drag. */
|
|
58
|
+
paused: boolean;
|
|
59
|
+
/** Stop Autoplay or Auto Scroll until `play()`. Hover, focus, `resumeAfter`, drags and the wheel don't restart it. */
|
|
60
|
+
pause: () => void;
|
|
61
|
+
/** Restart Autoplay or Auto Scroll on a fresh timer, even while hovered or focused. */
|
|
62
|
+
play: () => void;
|
|
47
63
|
scrollPrev: () => void;
|
|
48
64
|
scrollNext: () => void;
|
|
49
65
|
scrollTo: (index: number) => void;
|
|
@@ -93,7 +109,7 @@ interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onS
|
|
|
93
109
|
duration?: number;
|
|
94
110
|
/** Escape hatch: a raw Embla options object, merged last so it wins over the flat props. */
|
|
95
111
|
options?: CarouselOptions;
|
|
96
|
-
/** Enable the Autoplay plugin. It pauses while hovered or
|
|
112
|
+
/** Enable the Autoplay plugin. It pauses while hovered or while keyboard focus is inside, unless `pauseOnHover` or `pauseOnFocus` is `false`, and stays off under reduced motion. `resumeAfter` (ms) restarts the timer after user interaction. */
|
|
97
113
|
autoplay?: boolean | CarouselAutoplayOptions;
|
|
98
114
|
/** Enable continuous Auto Scroll. Mutually exclusive with `autoplay`; paused under reduced motion. */
|
|
99
115
|
autoScroll?: boolean | CarouselAutoScrollOptions;
|
|
@@ -172,6 +188,11 @@ interface CarouselNextProps extends useRender.ComponentProps<'button', CarouselB
|
|
|
172
188
|
disabled?: boolean;
|
|
173
189
|
}
|
|
174
190
|
declare function CarouselNext({ className, position, disabled: disabledProp, render, ...props }: CarouselNextProps): React.JSX.Element;
|
|
191
|
+
type CarouselPlayToggleState = {
|
|
192
|
+
paused: boolean;
|
|
193
|
+
};
|
|
194
|
+
type CarouselPlayToggleProps = useRender.ComponentProps<'button', CarouselPlayToggleState>;
|
|
195
|
+
declare function CarouselPlayToggle({ className, render, ...props }: CarouselPlayToggleProps): React.JSX.Element | null;
|
|
175
196
|
interface CarouselPaginationProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
176
197
|
/**
|
|
177
198
|
* Lay the bullets out in a row or a column.
|
|
@@ -215,6 +236,6 @@ declare function CarouselProgress({ source, variant, orientation, light: lightPr
|
|
|
215
236
|
* `setApi`); the effect re-runs once both resolve.
|
|
216
237
|
*/
|
|
217
238
|
declare function useLinkedCarousels(mainApi: CarouselApi | undefined, thumbsApi: CarouselApi | undefined): void;
|
|
218
|
-
export { Carousel, CarouselContent, CarouselSlide, CarouselThumbs, CarouselThumb, CarouselPrev, CarouselNext, CarouselPagination, CarouselProgress, useCarousel, useLinkedCarousels, };
|
|
219
|
-
export type { CarouselProps, CarouselContentProps, CarouselSlideProps, CarouselThumbsProps, CarouselThumbProps, CarouselPrevProps, CarouselNextProps, CarouselPaginationProps, CarouselProgressProps, CarouselApi, CarouselOptions, CarouselPlugin, CarouselAutoplayOptions, CarouselAutoScrollOptions, CarouselAutoHeightOptions, CarouselFadeOptions, CarouselClassNamesOptions, CarouselAccessibilityOptions, CarouselWheelGesturesOptions, };
|
|
239
|
+
export { Carousel, CarouselContent, CarouselSlide, CarouselThumbs, CarouselThumb, CarouselPrev, CarouselNext, CarouselPlayToggle, CarouselPagination, CarouselProgress, useCarousel, useLinkedCarousels, };
|
|
240
|
+
export type { CarouselProps, CarouselContentProps, CarouselSlideProps, CarouselThumbsProps, CarouselThumbProps, CarouselPrevProps, CarouselNextProps, CarouselPlayToggleProps, CarouselPaginationProps, CarouselProgressProps, CarouselApi, CarouselOptions, CarouselPlugin, CarouselAutoplayOptions, CarouselAutoScrollOptions, CarouselAutoHeightOptions, CarouselFadeOptions, CarouselClassNamesOptions, CarouselAccessibilityOptions, CarouselWheelGesturesOptions, };
|
|
220
241
|
//# sourceMappingURL=carousel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"carousel.d.ts","sourceRoot":"","sources":["../../../src/components/carousel/carousel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAG9B,OAAO,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAA;AACrD,OAAsB,EAAE,KAAK,wBAAwB,EAAE,MAAM,8BAA8B,CAAA;AAC3F,OAAiB,EAAE,KAAK,mBAAmB,EAAE,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T,WAA0B,EAC1B,KAAK,EAAE,SAAS,EAChB,GAAG,IAAI,EACR,EAAE,uBAAuB,4BA0DzB;AAiDD,UAAU,qBAAsB,SAAQ,KAAK,CAAC,wBAAwB,CAAC,KAAK,CAAC;IAC3E;;;OAGG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,UAAU,GAAG,QAAQ,CAAA;IACvC;;;OAGG;IACH,OAAO,CAAC,EAAE,KAAK,GAAG,UAAU,CAAA;IAC5B;;;OAGG;IACH,WAAW,CAAC,EAAE,mBAAmB,CAAA;IACjC;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAA;CAChB;AAQD,iBAAS,gBAAgB,CAAC,EACxB,MAAe,EACf,OAAe,EACf,WAA0B,EAC1B,KAAK,EAAE,SAAS,EAChB,SAAS,EACT,GAAG,IAAI,EACR,EAAE,qBAAqB,qBAkGvB;AAyDD;;;;;GAKG;AACH,iBAAS,kBAAkB,CAAC,OAAO,EAAE,WAAW,GAAG,SAAS,EAAE,SAAS,EAAE,WAAW,GAAG,SAAS,GAAG,IAAI,CAiBtG;AAED,OAAO,EACL,QAAQ,EACR,eAAe,EACf,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,GACnB,CAAA;AACD,YAAY,EACV,aAAa,EACb,oBAAoB,EACpB,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,iBAAiB,EACjB,iBAAiB,EACjB,uBAAuB,EACvB,uBAAuB,EACvB,qBAAqB,EACrB,WAAW,EACX,eAAe,EACf,cAAc,EACd,uBAAuB,EACvB,yBAAyB,EACzB,yBAAyB,EACzB,mBAAmB,EACnB,yBAAyB,EACzB,4BAA4B,EAC5B,4BAA4B,GAC7B,CAAA"}
|
|
@@ -17,6 +17,7 @@ import { useReducedMotion } from '../../hooks/use-reduced-motion.js';
|
|
|
17
17
|
import { useDirection } from '@base-ui/react/direction-provider';
|
|
18
18
|
|
|
19
19
|
const CarouselContext = React.createContext(null);
|
|
20
|
+
const CarouselRotationContext = React.createContext(false);
|
|
20
21
|
function useCarousel() {
|
|
21
22
|
const ctx = React.useContext(CarouselContext);
|
|
22
23
|
if (!ctx) {
|
|
@@ -29,6 +30,9 @@ const CAROUSEL_ACCESSIBILITY_VIEWPORT = {
|
|
|
29
30
|
carouselAriaLabel: "",
|
|
30
31
|
carouselAriaRoleDescription: ""
|
|
31
32
|
};
|
|
33
|
+
function hasKeyboardFocus(node) {
|
|
34
|
+
return node instanceof Element && node.matches(":focus-visible");
|
|
35
|
+
}
|
|
32
36
|
function getShownSlides(api) {
|
|
33
37
|
const { options, scrollSnapList } = api.internalEngine();
|
|
34
38
|
if (!options.active) return new Set(api.slideNodes().keys());
|
|
@@ -127,6 +131,8 @@ function Carousel({
|
|
|
127
131
|
}
|
|
128
132
|
}, [autoplayEnabled, autoScrollEnabled]);
|
|
129
133
|
const resumeAfterMs = typeof autoplay === "object" && typeof autoplay.resumeAfter === "number" && autoplay.resumeAfter || typeof autoScroll === "object" && typeof autoScroll.resumeAfter === "number" && autoScroll.resumeAfter || 0;
|
|
134
|
+
const pauseOnHover = typeof autoplay !== "object" || autoplay.pauseOnHover !== false;
|
|
135
|
+
const pauseOnFocus = typeof autoplay !== "object" || autoplay.pauseOnFocus !== false;
|
|
130
136
|
const plugins = React.useMemo(() => {
|
|
131
137
|
const list = [];
|
|
132
138
|
if (typeof accessibility === "object") {
|
|
@@ -137,7 +143,7 @@ function Carousel({
|
|
|
137
143
|
}
|
|
138
144
|
if (autoplay) {
|
|
139
145
|
const opts = typeof autoplay === "object" ? autoplay : void 0;
|
|
140
|
-
const { resumeAfter, ...emblaOpts } = opts ?? {};
|
|
146
|
+
const { resumeAfter, pauseOnHover: _pauseOnHover, pauseOnFocus: _pauseOnFocus, ...emblaOpts } = opts ?? {};
|
|
141
147
|
const autoResume = typeof resumeAfter === "number" && resumeAfter > 0;
|
|
142
148
|
list.push(Autoplay(autoResume ? { ...emblaOpts, defaultInteraction: false } : emblaOpts));
|
|
143
149
|
} else if (autoScroll && !reducedMotion) {
|
|
@@ -229,6 +235,21 @@ function Carousel({
|
|
|
229
235
|
canScrollNext: false
|
|
230
236
|
});
|
|
231
237
|
const [autoplayState, setAutoplayState] = React.useState(null);
|
|
238
|
+
const [paused, setPausedState] = React.useState(false);
|
|
239
|
+
const pausedRef = React.useRef(false);
|
|
240
|
+
const setPaused = React.useCallback((next) => {
|
|
241
|
+
pausedRef.current = next;
|
|
242
|
+
setPausedState(next);
|
|
243
|
+
}, []);
|
|
244
|
+
const rotationRef = React.useRef(null);
|
|
245
|
+
const pause = React.useCallback(() => {
|
|
246
|
+
setPaused(true);
|
|
247
|
+
rotationRef.current?.pause();
|
|
248
|
+
}, [setPaused]);
|
|
249
|
+
const play = React.useCallback(() => {
|
|
250
|
+
setPaused(false);
|
|
251
|
+
rotationRef.current?.play();
|
|
252
|
+
}, [setPaused]);
|
|
232
253
|
const scrollProgressRef = React.useRef(0);
|
|
233
254
|
const scrollListenersRef = React.useRef(/* @__PURE__ */ new Set());
|
|
234
255
|
const subscribeScrollProgress = React.useCallback((onChange) => {
|
|
@@ -297,12 +318,11 @@ function Carousel({
|
|
|
297
318
|
resumeTimer = void 0;
|
|
298
319
|
}
|
|
299
320
|
};
|
|
300
|
-
const scheduleResume = (
|
|
301
|
-
if (resumeAfter <= 0) return;
|
|
321
|
+
const scheduleResume = (restart) => {
|
|
302
322
|
clearResumeTimer();
|
|
303
323
|
resumeTimer = setTimeout(() => {
|
|
304
324
|
resumeTimer = void 0;
|
|
305
|
-
|
|
325
|
+
restart();
|
|
306
326
|
}, resumeAfter);
|
|
307
327
|
};
|
|
308
328
|
const root = rootRef.current;
|
|
@@ -310,13 +330,23 @@ function Carousel({
|
|
|
310
330
|
let focused = false;
|
|
311
331
|
let held = false;
|
|
312
332
|
const playAutoplay = () => {
|
|
333
|
+
if (pausedRef.current) return;
|
|
313
334
|
if (hovered || focused) held = true;
|
|
314
335
|
else emblaApi.plugins().autoplay?.play();
|
|
315
336
|
};
|
|
316
337
|
const interruptAutoplay = () => {
|
|
317
338
|
held = false;
|
|
318
339
|
emblaApi.plugins().autoplay?.stop();
|
|
319
|
-
scheduleResume(playAutoplay);
|
|
340
|
+
if (resumeAfter > 0) scheduleResume(playAutoplay);
|
|
341
|
+
else setPaused(true);
|
|
342
|
+
};
|
|
343
|
+
const playAutoScroll = () => {
|
|
344
|
+
if (!pausedRef.current) emblaApi.plugins().autoScroll?.play();
|
|
345
|
+
};
|
|
346
|
+
const interruptAutoScroll = () => {
|
|
347
|
+
emblaApi.plugins().autoScroll?.stop();
|
|
348
|
+
if (resumeAfter > 0) scheduleResume(playAutoScroll);
|
|
349
|
+
else setPaused(true);
|
|
320
350
|
};
|
|
321
351
|
let cleanupAutoplay;
|
|
322
352
|
if (autoplayPlugin) {
|
|
@@ -330,14 +360,17 @@ function Carousel({
|
|
|
330
360
|
const onPlay = () => {
|
|
331
361
|
held = false;
|
|
332
362
|
clearResumeTimer();
|
|
363
|
+
if (pausedRef.current) setPaused(false);
|
|
333
364
|
setAutoplayState((s) => s ? { ...s, isPlaying: true } : s);
|
|
334
365
|
};
|
|
335
366
|
const onStop = () => setAutoplayState((s) => s ? { ...s, isPlaying: false } : s);
|
|
336
367
|
const onTimerSet = () => setAutoplayState((s) => s ? { ...s, cycleId: s.cycleId + 1, isPlaying: true } : s);
|
|
337
368
|
const onTimerStopped = () => setAutoplayState((s) => s ? { ...s, isPlaying: false } : s);
|
|
338
369
|
const resetOnSelect = () => autoplayPlugin.reset();
|
|
370
|
+
const stopsOnPress = autoplayPlugin.options.defaultInteraction !== false;
|
|
339
371
|
const onUserStop = () => {
|
|
340
372
|
held = false;
|
|
373
|
+
if (stopsOnPress && !reducedMotion) setPaused(true);
|
|
341
374
|
};
|
|
342
375
|
const onInteraction = (_api, event) => {
|
|
343
376
|
if (event.detail.interaction === "pointerdown" || event.detail.interaction === "slidefocus") {
|
|
@@ -360,9 +393,10 @@ function Carousel({
|
|
|
360
393
|
hovered = false;
|
|
361
394
|
release();
|
|
362
395
|
};
|
|
363
|
-
const onFocusIn = () => {
|
|
364
|
-
focused =
|
|
365
|
-
hold();
|
|
396
|
+
const onFocusIn = (event) => {
|
|
397
|
+
focused = hasKeyboardFocus(event.target);
|
|
398
|
+
if (focused) hold();
|
|
399
|
+
else release();
|
|
366
400
|
};
|
|
367
401
|
const onFocusOut = (event) => {
|
|
368
402
|
if (event.relatedTarget instanceof Node && root?.contains(event.relatedTarget)) return;
|
|
@@ -377,17 +411,33 @@ function Carousel({
|
|
|
377
411
|
emblaApi.on("pointerdown", onUserStop);
|
|
378
412
|
emblaApi.on("slidefocus", onUserStop);
|
|
379
413
|
if (resumeAfter > 0) emblaApi.on("autoplay:interaction", onInteraction);
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
414
|
+
if (pauseOnHover) {
|
|
415
|
+
root?.addEventListener("pointerenter", onPointerEnter);
|
|
416
|
+
root?.addEventListener("pointerleave", onPointerLeave);
|
|
417
|
+
}
|
|
418
|
+
if (pauseOnFocus) {
|
|
419
|
+
root?.addEventListener("focusin", onFocusIn);
|
|
420
|
+
root?.addEventListener("focusout", onFocusOut);
|
|
421
|
+
}
|
|
384
422
|
if (autoplayEnabled && !reducedMotion) {
|
|
385
|
-
hovered = !!root?.matches(":hover");
|
|
386
|
-
focused = !!root?.contains(document.activeElement);
|
|
423
|
+
hovered = pauseOnHover && !!root?.matches(":hover");
|
|
424
|
+
focused = pauseOnFocus && !!root?.contains(document.activeElement) && hasKeyboardFocus(document.activeElement);
|
|
387
425
|
playAutoplay();
|
|
388
426
|
} else {
|
|
389
427
|
autoplayPlugin.stop();
|
|
390
428
|
}
|
|
429
|
+
rotationRef.current = {
|
|
430
|
+
pause: () => {
|
|
431
|
+
held = false;
|
|
432
|
+
clearResumeTimer();
|
|
433
|
+
emblaApi.plugins().autoplay?.stop();
|
|
434
|
+
},
|
|
435
|
+
play: () => {
|
|
436
|
+
held = false;
|
|
437
|
+
clearResumeTimer();
|
|
438
|
+
if (!reducedMotion) emblaApi.plugins().autoplay?.play();
|
|
439
|
+
}
|
|
440
|
+
};
|
|
391
441
|
cleanupAutoplay = () => {
|
|
392
442
|
emblaApi.off("autoplay:play", onPlay);
|
|
393
443
|
emblaApi.off("autoplay:stop", onStop);
|
|
@@ -407,17 +457,39 @@ function Carousel({
|
|
|
407
457
|
}
|
|
408
458
|
let cleanupAutoScroll;
|
|
409
459
|
if (autoScrollPlugin && autoScrollEnabled && !autoplayEnabled) {
|
|
410
|
-
|
|
460
|
+
playAutoScroll();
|
|
461
|
+
const onPlay = () => {
|
|
462
|
+
if (pausedRef.current) setPaused(false);
|
|
463
|
+
};
|
|
464
|
+
const stopsOnPress = autoScrollPlugin.options.defaultInteraction !== false;
|
|
465
|
+
const onUserStop = () => {
|
|
466
|
+
if (stopsOnPress) setPaused(true);
|
|
467
|
+
};
|
|
411
468
|
const onInteraction = (_api, event) => {
|
|
412
469
|
if (event.detail.interaction === "pointerdown" || event.detail.interaction === "slidefocus") {
|
|
413
|
-
|
|
414
|
-
scheduleResume(() => emblaApi.plugins().autoScroll?.play());
|
|
470
|
+
interruptAutoScroll();
|
|
415
471
|
}
|
|
416
472
|
};
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
473
|
+
emblaApi.on("autoscroll:play", onPlay);
|
|
474
|
+
emblaApi.on("pointerdown", onUserStop);
|
|
475
|
+
emblaApi.on("slidefocus", onUserStop);
|
|
476
|
+
if (resumeAfter > 0) emblaApi.on("autoscroll:interaction", onInteraction);
|
|
477
|
+
rotationRef.current = {
|
|
478
|
+
pause: () => {
|
|
479
|
+
clearResumeTimer();
|
|
480
|
+
emblaApi.plugins().autoScroll?.stop();
|
|
481
|
+
},
|
|
482
|
+
play: () => {
|
|
483
|
+
clearResumeTimer();
|
|
484
|
+
emblaApi.plugins().autoScroll?.play();
|
|
485
|
+
}
|
|
486
|
+
};
|
|
487
|
+
cleanupAutoScroll = () => {
|
|
488
|
+
emblaApi.off("autoscroll:play", onPlay);
|
|
489
|
+
emblaApi.off("pointerdown", onUserStop);
|
|
490
|
+
emblaApi.off("slidefocus", onUserStop);
|
|
491
|
+
if (resumeAfter > 0) emblaApi.off("autoscroll:interaction", onInteraction);
|
|
492
|
+
};
|
|
421
493
|
}
|
|
422
494
|
let cleanupWheel;
|
|
423
495
|
if (emblaApi.plugins().wheelGestures && (autoplayPlugin || autoScrollPlugin)) {
|
|
@@ -430,8 +502,7 @@ function Carousel({
|
|
|
430
502
|
if (autoplayPlugin?.isPlaying() || held) {
|
|
431
503
|
interruptAutoplay();
|
|
432
504
|
} else if (autoScrollPlugin?.isPlaying()) {
|
|
433
|
-
|
|
434
|
-
scheduleResume(() => emblaApi.plugins().autoScroll?.play());
|
|
505
|
+
interruptAutoScroll();
|
|
435
506
|
}
|
|
436
507
|
};
|
|
437
508
|
viewport.addEventListener("wheel", onWheel, { passive: true });
|
|
@@ -446,8 +517,18 @@ function Carousel({
|
|
|
446
517
|
cleanupAutoScroll?.();
|
|
447
518
|
cleanupWheel?.();
|
|
448
519
|
clearResumeTimer();
|
|
520
|
+
rotationRef.current = null;
|
|
449
521
|
};
|
|
450
|
-
}, [
|
|
522
|
+
}, [
|
|
523
|
+
emblaApi,
|
|
524
|
+
autoplayEnabled,
|
|
525
|
+
autoScrollEnabled,
|
|
526
|
+
resumeAfterMs,
|
|
527
|
+
reducedMotion,
|
|
528
|
+
pauseOnHover,
|
|
529
|
+
pauseOnFocus,
|
|
530
|
+
setPaused
|
|
531
|
+
]);
|
|
451
532
|
const scrollPrev = React.useCallback(() => emblaApi?.goToPrev(), [emblaApi]);
|
|
452
533
|
const scrollNext = React.useCallback(() => emblaApi?.goToNext(), [emblaApi]);
|
|
453
534
|
const scrollTo = React.useCallback((i) => emblaApi?.goTo(i), [emblaApi]);
|
|
@@ -469,6 +550,9 @@ function Carousel({
|
|
|
469
550
|
subscribeScrollProgress,
|
|
470
551
|
getScrollProgress,
|
|
471
552
|
autoplay: autoplayState,
|
|
553
|
+
paused,
|
|
554
|
+
pause,
|
|
555
|
+
play,
|
|
472
556
|
scrollPrev,
|
|
473
557
|
scrollNext,
|
|
474
558
|
scrollTo
|
|
@@ -486,12 +570,15 @@ function Carousel({
|
|
|
486
570
|
subscribeScrollProgress,
|
|
487
571
|
getScrollProgress,
|
|
488
572
|
autoplayState,
|
|
573
|
+
paused,
|
|
574
|
+
pause,
|
|
575
|
+
play,
|
|
489
576
|
scrollPrev,
|
|
490
577
|
scrollNext,
|
|
491
578
|
scrollTo
|
|
492
579
|
]
|
|
493
580
|
);
|
|
494
|
-
return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|
|
581
|
+
return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(CarouselRotationContext.Provider, { value: autoplayEnabled || autoScrollEnabled, children: /* @__PURE__ */ jsx(
|
|
495
582
|
"div",
|
|
496
583
|
{
|
|
497
584
|
"data-slot": "carousel",
|
|
@@ -503,7 +590,7 @@ function Carousel({
|
|
|
503
590
|
ref: composedRootRef,
|
|
504
591
|
children
|
|
505
592
|
}
|
|
506
|
-
) });
|
|
593
|
+
) }) });
|
|
507
594
|
}
|
|
508
595
|
function CarouselContent({ className, children, viewportProps, ...rest }) {
|
|
509
596
|
const { viewportRef, orientation, autoHeight } = useCarousel();
|
|
@@ -809,6 +896,29 @@ function CarouselNext({ className, position = "inside", disabled: disabledProp,
|
|
|
809
896
|
}
|
|
810
897
|
);
|
|
811
898
|
}
|
|
899
|
+
function CarouselPlayToggle({ className, render, ...props }) {
|
|
900
|
+
const { reducedMotion, paused, pause, play } = useCarousel();
|
|
901
|
+
const rotates = React.useContext(CarouselRotationContext);
|
|
902
|
+
const state = { paused };
|
|
903
|
+
const trigger = useRender({
|
|
904
|
+
defaultTagName: "button",
|
|
905
|
+
render,
|
|
906
|
+
state,
|
|
907
|
+
props: mergeProps(
|
|
908
|
+
{
|
|
909
|
+
type: "button",
|
|
910
|
+
"data-slot": "carousel-play-toggle",
|
|
911
|
+
"data-paused": paused || void 0,
|
|
912
|
+
"aria-pressed": paused,
|
|
913
|
+
"aria-label": "Pause slides",
|
|
914
|
+
onClick: paused ? play : pause
|
|
915
|
+
},
|
|
916
|
+
props
|
|
917
|
+
)
|
|
918
|
+
});
|
|
919
|
+
if (!rotates || reducedMotion) return null;
|
|
920
|
+
return /* @__PURE__ */ jsx("div", { "data-slot": "carousel-play-toggle-positioner", className: cn("motion-reduce:hidden", className), children: trigger });
|
|
921
|
+
}
|
|
812
922
|
function CarouselPagination({
|
|
813
923
|
className,
|
|
814
924
|
orientation = "horizontal",
|
|
@@ -1086,5 +1196,5 @@ function useLinkedCarousels(mainApi, thumbsApi) {
|
|
|
1086
1196
|
}, [mainApi, thumbsApi]);
|
|
1087
1197
|
}
|
|
1088
1198
|
|
|
1089
|
-
export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels };
|
|
1199
|
+
export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPlayToggle, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels };
|
|
1090
1200
|
//# sourceMappingURL=carousel.js.map
|