@appica/ui-react 1.3.1 → 1.5.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 +33 -0
- package/README.md +8 -2
- package/agent-rules.md +9 -2
- package/appica.css +2 -2
- package/dist/components/badge/badge.js +1 -1
- package/dist/components/badge/badge.js.map +1 -1
- package/dist/components/button/button-variants.js +1 -1
- package/dist/components/button/button-variants.js.map +1 -1
- package/dist/components/card/card.js +1 -1
- package/dist/components/card/card.js.map +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 +149 -31
- package/dist/components/carousel/carousel.js.map +1 -1
- package/dist/components/checkbox/checkbox.js +1 -1
- package/dist/components/checkbox/checkbox.js.map +1 -1
- package/dist/components/command-palette/command-palette.d.ts +91 -0
- package/dist/components/command-palette/command-palette.d.ts.map +1 -0
- package/dist/components/command-palette/command-palette.js +376 -0
- package/dist/components/command-palette/command-palette.js.map +1 -0
- package/dist/components/date-field/date-field.js +1 -1
- package/dist/components/date-field/date-field.js.map +1 -1
- package/dist/components/date-picker/date-picker.js +1 -1
- package/dist/components/date-picker/date-picker.js.map +1 -1
- package/dist/components/input/input-variants.js +2 -2
- package/dist/components/input/input-variants.js.map +1 -1
- package/dist/components/radio/radio.js +1 -1
- package/dist/components/radio/radio.js.map +1 -1
- package/dist/components/splitter/splitter.d.ts +57 -0
- package/dist/components/splitter/splitter.d.ts.map +1 -0
- package/dist/components/splitter/splitter.js +395 -0
- package/dist/components/splitter/splitter.js.map +1 -0
- package/dist/components/textarea/textarea.js +1 -1
- package/dist/components/textarea/textarea.js.map +1 -1
- package/dist/components/time-field/time-field.js +1 -1
- package/dist/components/time-field/time-field.js.map +1 -1
- package/dist/components/toc/toc.d.ts +6 -1
- package/dist/components/toc/toc.d.ts.map +1 -1
- package/dist/components/toc/toc.js +15 -7
- package/dist/components/toc/toc.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/package.json +24 -14
- package/src/components/badge/badge.tsx +1 -1
- package/src/components/button/button-variants.ts +1 -1
- package/src/components/card/card.tsx +1 -1
- package/src/components/carousel/carousel.test.tsx +559 -21
- package/src/components/carousel/carousel.tsx +195 -40
- package/src/components/checkbox/checkbox.tsx +1 -1
- package/src/components/command-palette/command-palette.test.tsx +280 -0
- package/src/components/command-palette/command-palette.tsx +544 -0
- package/src/components/compare-slider/compare-slider.test.tsx +8 -7
- package/src/components/date-field/date-field.tsx +1 -1
- package/src/components/date-picker/date-picker.tsx +1 -1
- package/src/components/input/input-variants.ts +2 -2
- package/src/components/radio/radio.tsx +1 -1
- package/src/components/rating/rating.test.tsx +10 -3
- package/src/components/splitter/splitter.test.tsx +415 -0
- package/src/components/splitter/splitter.tsx +555 -0
- package/src/components/textarea/textarea.tsx +1 -1
- package/src/components/time-field/time-field.tsx +1 -1
- package/src/components/toc/toc.test.tsx +15 -0
- package/src/components/toc/toc.tsx +22 -7
- package/src/index.ts +2 -0
- package/src/test/css.ts +9 -0
- package/src/test/setup.ts +13 -0
- package/styles.css +3 -0
|
@@ -22,7 +22,19 @@ type CarouselApi = EmblaCarouselType
|
|
|
22
22
|
type CarouselOptions = EmblaOptionsType
|
|
23
23
|
type CarouselPlugin = EmblaPluginType
|
|
24
24
|
|
|
25
|
-
type CarouselAutoplayOptions = AutoplayOptionsType & {
|
|
25
|
+
type CarouselAutoplayOptions = AutoplayOptionsType & {
|
|
26
|
+
resumeAfter?: number
|
|
27
|
+
/**
|
|
28
|
+
* Pause while the pointer is over the carousel. Turn it off only beside a `CarouselPlayToggle`.
|
|
29
|
+
* @default true
|
|
30
|
+
*/
|
|
31
|
+
pauseOnHover?: boolean
|
|
32
|
+
/**
|
|
33
|
+
* Pause while keyboard focus is inside the carousel. Turn it off only beside a `CarouselPlayToggle`.
|
|
34
|
+
* @default true
|
|
35
|
+
*/
|
|
36
|
+
pauseOnFocus?: boolean
|
|
37
|
+
}
|
|
26
38
|
type CarouselAutoScrollOptions = AutoScrollOptionsType & { resumeAfter?: number }
|
|
27
39
|
type CarouselAutoHeightOptions = AutoHeightOptionsType
|
|
28
40
|
type CarouselFadeOptions = FadeOptionsType
|
|
@@ -52,12 +64,19 @@ interface CarouselContextValue {
|
|
|
52
64
|
subscribeScrollProgress: (onChange: () => void) => () => void
|
|
53
65
|
getScrollProgress: () => number
|
|
54
66
|
autoplay: CarouselAutoplayState | null
|
|
67
|
+
/** Whether Autoplay or Auto Scroll stays stopped until `play()`: paused by the user, or stopped for good by a drag. */
|
|
68
|
+
paused: boolean
|
|
69
|
+
/** Stop Autoplay or Auto Scroll until `play()`. Hover, focus, `resumeAfter`, drags and the wheel don't restart it. */
|
|
70
|
+
pause: () => void
|
|
71
|
+
/** Restart Autoplay or Auto Scroll on a fresh timer, even while hovered or focused. */
|
|
72
|
+
play: () => void
|
|
55
73
|
scrollPrev: () => void
|
|
56
74
|
scrollNext: () => void
|
|
57
75
|
scrollTo: (index: number) => void
|
|
58
76
|
}
|
|
59
77
|
|
|
60
78
|
const CarouselContext = React.createContext<CarouselContextValue | null>(null)
|
|
79
|
+
const CarouselRotationContext = React.createContext(false)
|
|
61
80
|
|
|
62
81
|
function useCarousel(): CarouselContextValue {
|
|
63
82
|
const ctx = React.useContext(CarouselContext)
|
|
@@ -75,6 +94,11 @@ const CAROUSEL_ACCESSIBILITY_VIEWPORT: CarouselAccessibilityOptions = {
|
|
|
75
94
|
carouselAriaRoleDescription: '',
|
|
76
95
|
}
|
|
77
96
|
|
|
97
|
+
// Browsers match :focus-visible for keyboard focus, not for focus from a mouse or touch press.
|
|
98
|
+
function hasKeyboardFocus(node: EventTarget | null): boolean {
|
|
99
|
+
return node instanceof Element && node.matches(':focus-visible')
|
|
100
|
+
}
|
|
101
|
+
|
|
78
102
|
function getShownSlides(api: CarouselApi): Set<number> {
|
|
79
103
|
const { options, scrollSnapList } = api.internalEngine()
|
|
80
104
|
if (!options.active) return new Set(api.slideNodes().keys())
|
|
@@ -185,7 +209,7 @@ interface CarouselProps extends Omit<React.ComponentPropsWithoutRef<'div'>, 'onS
|
|
|
185
209
|
duration?: number
|
|
186
210
|
/** Escape hatch: a raw Embla options object, merged last so it wins over the flat props. */
|
|
187
211
|
options?: CarouselOptions
|
|
188
|
-
/** Enable the Autoplay plugin. It pauses while hovered or
|
|
212
|
+
/** 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. */
|
|
189
213
|
autoplay?: boolean | CarouselAutoplayOptions
|
|
190
214
|
/** Enable continuous Auto Scroll. Mutually exclusive with `autoplay`; paused under reduced motion. */
|
|
191
215
|
autoScroll?: boolean | CarouselAutoScrollOptions
|
|
@@ -278,6 +302,8 @@ function Carousel({
|
|
|
278
302
|
(typeof autoplay === 'object' && typeof autoplay.resumeAfter === 'number' && autoplay.resumeAfter) ||
|
|
279
303
|
(typeof autoScroll === 'object' && typeof autoScroll.resumeAfter === 'number' && autoScroll.resumeAfter) ||
|
|
280
304
|
0
|
|
305
|
+
const pauseOnHover = typeof autoplay !== 'object' || autoplay.pauseOnHover !== false
|
|
306
|
+
const pauseOnFocus = typeof autoplay !== 'object' || autoplay.pauseOnFocus !== false
|
|
281
307
|
|
|
282
308
|
const plugins = React.useMemo<CarouselPlugin[]>(() => {
|
|
283
309
|
const list: CarouselPlugin[] = []
|
|
@@ -289,7 +315,7 @@ function Carousel({
|
|
|
289
315
|
}
|
|
290
316
|
if (autoplay) {
|
|
291
317
|
const opts = typeof autoplay === 'object' ? autoplay : undefined
|
|
292
|
-
const { resumeAfter, ...emblaOpts } = opts ?? {}
|
|
318
|
+
const { resumeAfter, pauseOnHover: _pauseOnHover, pauseOnFocus: _pauseOnFocus, ...emblaOpts } = opts ?? {}
|
|
293
319
|
const autoResume = typeof resumeAfter === 'number' && resumeAfter > 0
|
|
294
320
|
list.push(Autoplay(autoResume ? { ...emblaOpts, defaultInteraction: false } : emblaOpts))
|
|
295
321
|
} else if (autoScroll && !reducedMotion) {
|
|
@@ -387,6 +413,21 @@ function Carousel({
|
|
|
387
413
|
canScrollNext: false,
|
|
388
414
|
})
|
|
389
415
|
const [autoplayState, setAutoplayState] = React.useState<CarouselAutoplayState | null>(null)
|
|
416
|
+
const [paused, setPausedState] = React.useState(false)
|
|
417
|
+
const pausedRef = React.useRef(false)
|
|
418
|
+
const setPaused = React.useCallback((next: boolean) => {
|
|
419
|
+
pausedRef.current = next
|
|
420
|
+
setPausedState(next)
|
|
421
|
+
}, [])
|
|
422
|
+
const rotationRef = React.useRef<{ pause: () => void; play: () => void } | null>(null)
|
|
423
|
+
const pause = React.useCallback(() => {
|
|
424
|
+
setPaused(true)
|
|
425
|
+
rotationRef.current?.pause()
|
|
426
|
+
}, [setPaused])
|
|
427
|
+
const play = React.useCallback(() => {
|
|
428
|
+
setPaused(false)
|
|
429
|
+
rotationRef.current?.play()
|
|
430
|
+
}, [setPaused])
|
|
390
431
|
|
|
391
432
|
const scrollProgressRef = React.useRef(0)
|
|
392
433
|
const scrollListenersRef = React.useRef<Set<() => void>>(new Set())
|
|
@@ -431,12 +472,8 @@ function Carousel({
|
|
|
431
472
|
onReInitRef.current?.(emblaApi)
|
|
432
473
|
|
|
433
474
|
const handleReInit = () => {
|
|
434
|
-
const autoplayWasPlaying = emblaApi.plugins().autoplay?.isPlaying()
|
|
435
|
-
const autoScrollWasPlaying = emblaApi.plugins().autoScroll?.isPlaying()
|
|
436
475
|
syncFull()
|
|
437
476
|
onReInitRef.current?.(emblaApi)
|
|
438
|
-
if (autoplayEnabled && autoplayWasPlaying) emblaApi.plugins().autoplay?.play()
|
|
439
|
-
else if (autoScrollEnabled && autoScrollWasPlaying) emblaApi.plugins().autoScroll?.play()
|
|
440
477
|
}
|
|
441
478
|
const handleSelect = () => {
|
|
442
479
|
syncSelection()
|
|
@@ -464,12 +501,11 @@ function Carousel({
|
|
|
464
501
|
resumeTimer = undefined
|
|
465
502
|
}
|
|
466
503
|
}
|
|
467
|
-
const scheduleResume = (
|
|
468
|
-
if (resumeAfter <= 0) return
|
|
504
|
+
const scheduleResume = (restart: () => void) => {
|
|
469
505
|
clearResumeTimer()
|
|
470
506
|
resumeTimer = setTimeout(() => {
|
|
471
507
|
resumeTimer = undefined
|
|
472
|
-
|
|
508
|
+
restart()
|
|
473
509
|
}, resumeAfter)
|
|
474
510
|
}
|
|
475
511
|
|
|
@@ -479,13 +515,23 @@ function Carousel({
|
|
|
479
515
|
// Rotation that hover or focus stopped, owed a restart once both have left.
|
|
480
516
|
let held = false
|
|
481
517
|
const playAutoplay = () => {
|
|
518
|
+
if (pausedRef.current) return
|
|
482
519
|
if (hovered || focused) held = true
|
|
483
520
|
else emblaApi.plugins().autoplay?.play()
|
|
484
521
|
}
|
|
485
522
|
const interruptAutoplay = () => {
|
|
486
523
|
held = false
|
|
487
524
|
emblaApi.plugins().autoplay?.stop()
|
|
488
|
-
scheduleResume(playAutoplay)
|
|
525
|
+
if (resumeAfter > 0) scheduleResume(playAutoplay)
|
|
526
|
+
else setPaused(true)
|
|
527
|
+
}
|
|
528
|
+
const playAutoScroll = () => {
|
|
529
|
+
if (!pausedRef.current) emblaApi.plugins().autoScroll?.play()
|
|
530
|
+
}
|
|
531
|
+
const interruptAutoScroll = () => {
|
|
532
|
+
emblaApi.plugins().autoScroll?.stop()
|
|
533
|
+
if (resumeAfter > 0) scheduleResume(playAutoScroll)
|
|
534
|
+
else setPaused(true)
|
|
489
535
|
}
|
|
490
536
|
|
|
491
537
|
let cleanupAutoplay: (() => void) | undefined
|
|
@@ -500,14 +546,17 @@ function Carousel({
|
|
|
500
546
|
const onPlay = () => {
|
|
501
547
|
held = false
|
|
502
548
|
clearResumeTimer()
|
|
549
|
+
if (pausedRef.current) setPaused(false)
|
|
503
550
|
setAutoplayState((s) => (s ? { ...s, isPlaying: true } : s))
|
|
504
551
|
}
|
|
505
552
|
const onStop = () => setAutoplayState((s) => (s ? { ...s, isPlaying: false } : s))
|
|
506
553
|
const onTimerSet = () => setAutoplayState((s) => (s ? { ...s, cycleId: s.cycleId + 1, isPlaying: true } : s))
|
|
507
554
|
const onTimerStopped = () => setAutoplayState((s) => (s ? { ...s, isPlaying: false } : s))
|
|
508
555
|
const resetOnSelect = () => autoplayPlugin.reset()
|
|
556
|
+
const stopsOnPress = autoplayPlugin.options.defaultInteraction !== false
|
|
509
557
|
const onUserStop = () => {
|
|
510
558
|
held = false
|
|
559
|
+
if (stopsOnPress && !reducedMotion) setPaused(true)
|
|
511
560
|
}
|
|
512
561
|
const onInteraction = (_api: CarouselApi, event: { detail: { interaction: string } }) => {
|
|
513
562
|
if (event.detail.interaction === 'pointerdown' || event.detail.interaction === 'slidefocus') {
|
|
@@ -522,6 +571,12 @@ function Carousel({
|
|
|
522
571
|
const release = () => {
|
|
523
572
|
if (held) playAutoplay()
|
|
524
573
|
}
|
|
574
|
+
// A re-init destroys the plugin, which stops it, so restart from the carousel's own state.
|
|
575
|
+
const onReInit = () => {
|
|
576
|
+
if (!autoplayEnabled || reducedMotion || resumeTimer !== undefined) return
|
|
577
|
+
if (emblaApi.plugins().autoplay?.options.stopOnLastSnap && !emblaApi.canGoToNext()) return
|
|
578
|
+
playAutoplay()
|
|
579
|
+
}
|
|
525
580
|
const onPointerEnter = () => {
|
|
526
581
|
hovered = true
|
|
527
582
|
hold()
|
|
@@ -530,9 +585,10 @@ function Carousel({
|
|
|
530
585
|
hovered = false
|
|
531
586
|
release()
|
|
532
587
|
}
|
|
533
|
-
const onFocusIn = () => {
|
|
534
|
-
focused =
|
|
535
|
-
hold()
|
|
588
|
+
const onFocusIn = (event: FocusEvent) => {
|
|
589
|
+
focused = hasKeyboardFocus(event.target)
|
|
590
|
+
if (focused) hold()
|
|
591
|
+
else release()
|
|
536
592
|
}
|
|
537
593
|
const onFocusOut = (event: FocusEvent) => {
|
|
538
594
|
if (event.relatedTarget instanceof Node && root?.contains(event.relatedTarget)) return
|
|
@@ -546,18 +602,35 @@ function Carousel({
|
|
|
546
602
|
emblaApi.on('select', resetOnSelect)
|
|
547
603
|
emblaApi.on('pointerdown', onUserStop)
|
|
548
604
|
emblaApi.on('slidefocus', onUserStop)
|
|
605
|
+
emblaApi.on('reinit', onReInit)
|
|
549
606
|
if (resumeAfter > 0) emblaApi.on('autoplay:interaction', onInteraction)
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
607
|
+
if (pauseOnHover) {
|
|
608
|
+
root?.addEventListener('pointerenter', onPointerEnter)
|
|
609
|
+
root?.addEventListener('pointerleave', onPointerLeave)
|
|
610
|
+
}
|
|
611
|
+
if (pauseOnFocus) {
|
|
612
|
+
root?.addEventListener('focusin', onFocusIn)
|
|
613
|
+
root?.addEventListener('focusout', onFocusOut)
|
|
614
|
+
}
|
|
554
615
|
if (autoplayEnabled && !reducedMotion) {
|
|
555
|
-
hovered = !!root?.matches(':hover')
|
|
556
|
-
focused = !!root?.contains(document.activeElement)
|
|
616
|
+
hovered = pauseOnHover && !!root?.matches(':hover')
|
|
617
|
+
focused = pauseOnFocus && !!root?.contains(document.activeElement) && hasKeyboardFocus(document.activeElement)
|
|
557
618
|
playAutoplay()
|
|
558
619
|
} else {
|
|
559
620
|
autoplayPlugin.stop()
|
|
560
621
|
}
|
|
622
|
+
rotationRef.current = {
|
|
623
|
+
pause: () => {
|
|
624
|
+
held = false
|
|
625
|
+
clearResumeTimer()
|
|
626
|
+
emblaApi.plugins().autoplay?.stop()
|
|
627
|
+
},
|
|
628
|
+
play: () => {
|
|
629
|
+
held = false
|
|
630
|
+
clearResumeTimer()
|
|
631
|
+
if (!reducedMotion) emblaApi.plugins().autoplay?.play()
|
|
632
|
+
},
|
|
633
|
+
}
|
|
561
634
|
cleanupAutoplay = () => {
|
|
562
635
|
emblaApi.off('autoplay:play', onPlay)
|
|
563
636
|
emblaApi.off('autoplay:stop', onStop)
|
|
@@ -566,6 +639,7 @@ function Carousel({
|
|
|
566
639
|
emblaApi.off('select', resetOnSelect)
|
|
567
640
|
emblaApi.off('pointerdown', onUserStop)
|
|
568
641
|
emblaApi.off('slidefocus', onUserStop)
|
|
642
|
+
emblaApi.off('reinit', onReInit)
|
|
569
643
|
if (resumeAfter > 0) emblaApi.off('autoplay:interaction', onInteraction)
|
|
570
644
|
root?.removeEventListener('pointerenter', onPointerEnter)
|
|
571
645
|
root?.removeEventListener('pointerleave', onPointerLeave)
|
|
@@ -578,16 +652,43 @@ function Carousel({
|
|
|
578
652
|
|
|
579
653
|
let cleanupAutoScroll: (() => void) | undefined
|
|
580
654
|
if (autoScrollPlugin && autoScrollEnabled && !autoplayEnabled) {
|
|
581
|
-
|
|
655
|
+
playAutoScroll()
|
|
656
|
+
const onPlay = () => {
|
|
657
|
+
if (pausedRef.current) setPaused(false)
|
|
658
|
+
}
|
|
659
|
+
const stopsOnPress = autoScrollPlugin.options.defaultInteraction !== false
|
|
660
|
+
const onUserStop = () => {
|
|
661
|
+
if (stopsOnPress) setPaused(true)
|
|
662
|
+
}
|
|
582
663
|
const onInteraction = (_api: CarouselApi, event: { detail: { interaction: string } }) => {
|
|
583
664
|
if (event.detail.interaction === 'pointerdown' || event.detail.interaction === 'slidefocus') {
|
|
584
|
-
|
|
585
|
-
scheduleResume(() => emblaApi.plugins().autoScroll?.play())
|
|
665
|
+
interruptAutoScroll()
|
|
586
666
|
}
|
|
587
667
|
}
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
668
|
+
const onReInit = () => {
|
|
669
|
+
if (resumeTimer === undefined) playAutoScroll()
|
|
670
|
+
}
|
|
671
|
+
emblaApi.on('autoscroll:play', onPlay)
|
|
672
|
+
emblaApi.on('pointerdown', onUserStop)
|
|
673
|
+
emblaApi.on('slidefocus', onUserStop)
|
|
674
|
+
emblaApi.on('reinit', onReInit)
|
|
675
|
+
if (resumeAfter > 0) emblaApi.on('autoscroll:interaction', onInteraction)
|
|
676
|
+
rotationRef.current = {
|
|
677
|
+
pause: () => {
|
|
678
|
+
clearResumeTimer()
|
|
679
|
+
emblaApi.plugins().autoScroll?.stop()
|
|
680
|
+
},
|
|
681
|
+
play: () => {
|
|
682
|
+
clearResumeTimer()
|
|
683
|
+
emblaApi.plugins().autoScroll?.play()
|
|
684
|
+
},
|
|
685
|
+
}
|
|
686
|
+
cleanupAutoScroll = () => {
|
|
687
|
+
emblaApi.off('autoscroll:play', onPlay)
|
|
688
|
+
emblaApi.off('pointerdown', onUserStop)
|
|
689
|
+
emblaApi.off('slidefocus', onUserStop)
|
|
690
|
+
emblaApi.off('reinit', onReInit)
|
|
691
|
+
if (resumeAfter > 0) emblaApi.off('autoscroll:interaction', onInteraction)
|
|
591
692
|
}
|
|
592
693
|
}
|
|
593
694
|
|
|
@@ -602,8 +703,7 @@ function Carousel({
|
|
|
602
703
|
if (autoplayPlugin?.isPlaying() || held) {
|
|
603
704
|
interruptAutoplay()
|
|
604
705
|
} else if (autoScrollPlugin?.isPlaying()) {
|
|
605
|
-
|
|
606
|
-
scheduleResume(() => emblaApi.plugins().autoScroll?.play())
|
|
706
|
+
interruptAutoScroll()
|
|
607
707
|
}
|
|
608
708
|
}
|
|
609
709
|
viewport.addEventListener('wheel', onWheel, { passive: true })
|
|
@@ -619,8 +719,18 @@ function Carousel({
|
|
|
619
719
|
cleanupAutoScroll?.()
|
|
620
720
|
cleanupWheel?.()
|
|
621
721
|
clearResumeTimer()
|
|
722
|
+
rotationRef.current = null
|
|
622
723
|
}
|
|
623
|
-
}, [
|
|
724
|
+
}, [
|
|
725
|
+
emblaApi,
|
|
726
|
+
autoplayEnabled,
|
|
727
|
+
autoScrollEnabled,
|
|
728
|
+
resumeAfterMs,
|
|
729
|
+
reducedMotion,
|
|
730
|
+
pauseOnHover,
|
|
731
|
+
pauseOnFocus,
|
|
732
|
+
setPaused,
|
|
733
|
+
])
|
|
624
734
|
|
|
625
735
|
const scrollPrev = React.useCallback(() => emblaApi?.goToPrev(), [emblaApi])
|
|
626
736
|
const scrollNext = React.useCallback(() => emblaApi?.goToNext(), [emblaApi])
|
|
@@ -644,6 +754,9 @@ function Carousel({
|
|
|
644
754
|
subscribeScrollProgress,
|
|
645
755
|
getScrollProgress,
|
|
646
756
|
autoplay: autoplayState,
|
|
757
|
+
paused,
|
|
758
|
+
pause,
|
|
759
|
+
play,
|
|
647
760
|
scrollPrev,
|
|
648
761
|
scrollNext,
|
|
649
762
|
scrollTo,
|
|
@@ -661,6 +774,9 @@ function Carousel({
|
|
|
661
774
|
subscribeScrollProgress,
|
|
662
775
|
getScrollProgress,
|
|
663
776
|
autoplayState,
|
|
777
|
+
paused,
|
|
778
|
+
pause,
|
|
779
|
+
play,
|
|
664
780
|
scrollPrev,
|
|
665
781
|
scrollNext,
|
|
666
782
|
scrollTo,
|
|
@@ -669,17 +785,19 @@ function Carousel({
|
|
|
669
785
|
|
|
670
786
|
return (
|
|
671
787
|
<CarouselContext.Provider value={contextValue}>
|
|
672
|
-
<
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
788
|
+
<CarouselRotationContext.Provider value={autoplayEnabled || autoScrollEnabled}>
|
|
789
|
+
<div
|
|
790
|
+
data-slot="carousel"
|
|
791
|
+
data-orientation={orientation}
|
|
792
|
+
role={rootProps['aria-label'] || rootProps['aria-labelledby'] ? 'region' : 'group'}
|
|
793
|
+
aria-roledescription="carousel"
|
|
794
|
+
className={cn('relative', className)}
|
|
795
|
+
{...rootProps}
|
|
796
|
+
ref={composedRootRef}
|
|
797
|
+
>
|
|
798
|
+
{children}
|
|
799
|
+
</div>
|
|
800
|
+
</CarouselRotationContext.Provider>
|
|
683
801
|
</CarouselContext.Provider>
|
|
684
802
|
)
|
|
685
803
|
}
|
|
@@ -1080,6 +1198,41 @@ function CarouselNext({ className, position = 'inside', disabled: disabledProp,
|
|
|
1080
1198
|
)
|
|
1081
1199
|
}
|
|
1082
1200
|
|
|
1201
|
+
type CarouselPlayToggleState = { paused: boolean }
|
|
1202
|
+
|
|
1203
|
+
type CarouselPlayToggleProps = useRender.ComponentProps<'button', CarouselPlayToggleState>
|
|
1204
|
+
|
|
1205
|
+
function CarouselPlayToggle({ className, render, ...props }: CarouselPlayToggleProps) {
|
|
1206
|
+
const { reducedMotion, paused, pause, play } = useCarousel()
|
|
1207
|
+
const rotates = React.useContext(CarouselRotationContext)
|
|
1208
|
+
const state: CarouselPlayToggleState = { paused }
|
|
1209
|
+
|
|
1210
|
+
const trigger = useRender({
|
|
1211
|
+
defaultTagName: 'button',
|
|
1212
|
+
render,
|
|
1213
|
+
state,
|
|
1214
|
+
props: mergeProps<'button'>(
|
|
1215
|
+
{
|
|
1216
|
+
type: 'button',
|
|
1217
|
+
'data-slot': 'carousel-play-toggle',
|
|
1218
|
+
'data-paused': paused || undefined,
|
|
1219
|
+
'aria-pressed': paused,
|
|
1220
|
+
'aria-label': 'Pause slides',
|
|
1221
|
+
onClick: paused ? play : pause,
|
|
1222
|
+
} as unknown as React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
1223
|
+
props,
|
|
1224
|
+
),
|
|
1225
|
+
})
|
|
1226
|
+
|
|
1227
|
+
if (!rotates || reducedMotion) return null
|
|
1228
|
+
|
|
1229
|
+
return (
|
|
1230
|
+
<div data-slot="carousel-play-toggle-positioner" className={cn('motion-reduce:hidden', className)}>
|
|
1231
|
+
{trigger}
|
|
1232
|
+
</div>
|
|
1233
|
+
)
|
|
1234
|
+
}
|
|
1235
|
+
|
|
1083
1236
|
interface CarouselPaginationProps extends React.ComponentPropsWithoutRef<'div'> {
|
|
1084
1237
|
/**
|
|
1085
1238
|
* Lay the bullets out in a row or a column.
|
|
@@ -1429,6 +1582,7 @@ export {
|
|
|
1429
1582
|
CarouselThumb,
|
|
1430
1583
|
CarouselPrev,
|
|
1431
1584
|
CarouselNext,
|
|
1585
|
+
CarouselPlayToggle,
|
|
1432
1586
|
CarouselPagination,
|
|
1433
1587
|
CarouselProgress,
|
|
1434
1588
|
useCarousel,
|
|
@@ -1442,6 +1596,7 @@ export type {
|
|
|
1442
1596
|
CarouselThumbProps,
|
|
1443
1597
|
CarouselPrevProps,
|
|
1444
1598
|
CarouselNextProps,
|
|
1599
|
+
CarouselPlayToggleProps,
|
|
1445
1600
|
CarouselPaginationProps,
|
|
1446
1601
|
CarouselProgressProps,
|
|
1447
1602
|
CarouselApi,
|
|
@@ -140,7 +140,7 @@ function Checkbox({ className, ...props }: CheckboxProps) {
|
|
|
140
140
|
'focus-visible:border-transparent!',
|
|
141
141
|
'data-checked:bg-primary data-checked:outline-ring-primary data-checked:border-transparent',
|
|
142
142
|
'data-indeterminate:bg-primary data-indeterminate:outline-ring-primary data-indeterminate:border-transparent',
|
|
143
|
-
'data-disabled:not-data-checked:not-data-indeterminate:bg-background-subtle data-disabled:data-checked:opacity-disabled data-disabled:data-indeterminate:opacity-disabled data-disabled:cursor-not-allowed data-disabled:not-data-checked:not-data-indeterminate:border-dashed',
|
|
143
|
+
'data-disabled:not-data-checked:not-data-indeterminate:bg-background-subtle data-disabled:data-checked:opacity-disabled data-disabled:data-indeterminate:opacity-disabled data-disabled:cursor-not-allowed data-disabled:not-data-checked:not-data-indeterminate:border-dashed data-disabled:not-data-checked:not-data-indeterminate:backdrop-blur-md',
|
|
144
144
|
'data-invalid:border-error data-invalid:not-data-checked:not-data-indeterminate:bg-error-subtle data-invalid:outline-ring-error',
|
|
145
145
|
className,
|
|
146
146
|
)}
|