@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.
Files changed (69) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +8 -2
  3. package/agent-rules.md +9 -2
  4. package/appica.css +2 -2
  5. package/dist/components/badge/badge.js +1 -1
  6. package/dist/components/badge/badge.js.map +1 -1
  7. package/dist/components/button/button-variants.js +1 -1
  8. package/dist/components/button/button-variants.js.map +1 -1
  9. package/dist/components/card/card.js +1 -1
  10. package/dist/components/card/card.js.map +1 -1
  11. package/dist/components/carousel/carousel.d.ts +24 -3
  12. package/dist/components/carousel/carousel.d.ts.map +1 -1
  13. package/dist/components/carousel/carousel.js +149 -31
  14. package/dist/components/carousel/carousel.js.map +1 -1
  15. package/dist/components/checkbox/checkbox.js +1 -1
  16. package/dist/components/checkbox/checkbox.js.map +1 -1
  17. package/dist/components/command-palette/command-palette.d.ts +91 -0
  18. package/dist/components/command-palette/command-palette.d.ts.map +1 -0
  19. package/dist/components/command-palette/command-palette.js +376 -0
  20. package/dist/components/command-palette/command-palette.js.map +1 -0
  21. package/dist/components/date-field/date-field.js +1 -1
  22. package/dist/components/date-field/date-field.js.map +1 -1
  23. package/dist/components/date-picker/date-picker.js +1 -1
  24. package/dist/components/date-picker/date-picker.js.map +1 -1
  25. package/dist/components/input/input-variants.js +2 -2
  26. package/dist/components/input/input-variants.js.map +1 -1
  27. package/dist/components/radio/radio.js +1 -1
  28. package/dist/components/radio/radio.js.map +1 -1
  29. package/dist/components/splitter/splitter.d.ts +57 -0
  30. package/dist/components/splitter/splitter.d.ts.map +1 -0
  31. package/dist/components/splitter/splitter.js +395 -0
  32. package/dist/components/splitter/splitter.js.map +1 -0
  33. package/dist/components/textarea/textarea.js +1 -1
  34. package/dist/components/textarea/textarea.js.map +1 -1
  35. package/dist/components/time-field/time-field.js +1 -1
  36. package/dist/components/time-field/time-field.js.map +1 -1
  37. package/dist/components/toc/toc.d.ts +6 -1
  38. package/dist/components/toc/toc.d.ts.map +1 -1
  39. package/dist/components/toc/toc.js +15 -7
  40. package/dist/components/toc/toc.js.map +1 -1
  41. package/dist/index.d.ts +2 -0
  42. package/dist/index.d.ts.map +1 -1
  43. package/dist/index.js +3 -1
  44. package/dist/index.js.map +1 -1
  45. package/package.json +24 -14
  46. package/src/components/badge/badge.tsx +1 -1
  47. package/src/components/button/button-variants.ts +1 -1
  48. package/src/components/card/card.tsx +1 -1
  49. package/src/components/carousel/carousel.test.tsx +559 -21
  50. package/src/components/carousel/carousel.tsx +195 -40
  51. package/src/components/checkbox/checkbox.tsx +1 -1
  52. package/src/components/command-palette/command-palette.test.tsx +280 -0
  53. package/src/components/command-palette/command-palette.tsx +544 -0
  54. package/src/components/compare-slider/compare-slider.test.tsx +8 -7
  55. package/src/components/date-field/date-field.tsx +1 -1
  56. package/src/components/date-picker/date-picker.tsx +1 -1
  57. package/src/components/input/input-variants.ts +2 -2
  58. package/src/components/radio/radio.tsx +1 -1
  59. package/src/components/rating/rating.test.tsx +10 -3
  60. package/src/components/splitter/splitter.test.tsx +415 -0
  61. package/src/components/splitter/splitter.tsx +555 -0
  62. package/src/components/textarea/textarea.tsx +1 -1
  63. package/src/components/time-field/time-field.tsx +1 -1
  64. package/src/components/toc/toc.test.tsx +15 -0
  65. package/src/components/toc/toc.tsx +22 -7
  66. package/src/index.ts +2 -0
  67. package/src/test/css.ts +9 -0
  68. package/src/test/setup.ts +13 -0
  69. package/styles.css +3 -0
@@ -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) => {
@@ -268,12 +289,8 @@ function Carousel({
268
289
  setApiRef.current?.(emblaApi);
269
290
  onReInitRef.current?.(emblaApi);
270
291
  const handleReInit = () => {
271
- const autoplayWasPlaying = emblaApi.plugins().autoplay?.isPlaying();
272
- const autoScrollWasPlaying = emblaApi.plugins().autoScroll?.isPlaying();
273
292
  syncFull();
274
293
  onReInitRef.current?.(emblaApi);
275
- if (autoplayEnabled && autoplayWasPlaying) emblaApi.plugins().autoplay?.play();
276
- else if (autoScrollEnabled && autoScrollWasPlaying) emblaApi.plugins().autoScroll?.play();
277
294
  };
278
295
  const handleSelect = () => {
279
296
  syncSelection();
@@ -297,12 +314,11 @@ function Carousel({
297
314
  resumeTimer = void 0;
298
315
  }
299
316
  };
300
- const scheduleResume = (play) => {
301
- if (resumeAfter <= 0) return;
317
+ const scheduleResume = (restart) => {
302
318
  clearResumeTimer();
303
319
  resumeTimer = setTimeout(() => {
304
320
  resumeTimer = void 0;
305
- play();
321
+ restart();
306
322
  }, resumeAfter);
307
323
  };
308
324
  const root = rootRef.current;
@@ -310,13 +326,23 @@ function Carousel({
310
326
  let focused = false;
311
327
  let held = false;
312
328
  const playAutoplay = () => {
329
+ if (pausedRef.current) return;
313
330
  if (hovered || focused) held = true;
314
331
  else emblaApi.plugins().autoplay?.play();
315
332
  };
316
333
  const interruptAutoplay = () => {
317
334
  held = false;
318
335
  emblaApi.plugins().autoplay?.stop();
319
- scheduleResume(playAutoplay);
336
+ if (resumeAfter > 0) scheduleResume(playAutoplay);
337
+ else setPaused(true);
338
+ };
339
+ const playAutoScroll = () => {
340
+ if (!pausedRef.current) emblaApi.plugins().autoScroll?.play();
341
+ };
342
+ const interruptAutoScroll = () => {
343
+ emblaApi.plugins().autoScroll?.stop();
344
+ if (resumeAfter > 0) scheduleResume(playAutoScroll);
345
+ else setPaused(true);
320
346
  };
321
347
  let cleanupAutoplay;
322
348
  if (autoplayPlugin) {
@@ -330,14 +356,17 @@ function Carousel({
330
356
  const onPlay = () => {
331
357
  held = false;
332
358
  clearResumeTimer();
359
+ if (pausedRef.current) setPaused(false);
333
360
  setAutoplayState((s) => s ? { ...s, isPlaying: true } : s);
334
361
  };
335
362
  const onStop = () => setAutoplayState((s) => s ? { ...s, isPlaying: false } : s);
336
363
  const onTimerSet = () => setAutoplayState((s) => s ? { ...s, cycleId: s.cycleId + 1, isPlaying: true } : s);
337
364
  const onTimerStopped = () => setAutoplayState((s) => s ? { ...s, isPlaying: false } : s);
338
365
  const resetOnSelect = () => autoplayPlugin.reset();
366
+ const stopsOnPress = autoplayPlugin.options.defaultInteraction !== false;
339
367
  const onUserStop = () => {
340
368
  held = false;
369
+ if (stopsOnPress && !reducedMotion) setPaused(true);
341
370
  };
342
371
  const onInteraction = (_api, event) => {
343
372
  if (event.detail.interaction === "pointerdown" || event.detail.interaction === "slidefocus") {
@@ -352,6 +381,11 @@ function Carousel({
352
381
  const release = () => {
353
382
  if (held) playAutoplay();
354
383
  };
384
+ const onReInit2 = () => {
385
+ if (!autoplayEnabled || reducedMotion || resumeTimer !== void 0) return;
386
+ if (emblaApi.plugins().autoplay?.options.stopOnLastSnap && !emblaApi.canGoToNext()) return;
387
+ playAutoplay();
388
+ };
355
389
  const onPointerEnter = () => {
356
390
  hovered = true;
357
391
  hold();
@@ -360,9 +394,10 @@ function Carousel({
360
394
  hovered = false;
361
395
  release();
362
396
  };
363
- const onFocusIn = () => {
364
- focused = true;
365
- hold();
397
+ const onFocusIn = (event) => {
398
+ focused = hasKeyboardFocus(event.target);
399
+ if (focused) hold();
400
+ else release();
366
401
  };
367
402
  const onFocusOut = (event) => {
368
403
  if (event.relatedTarget instanceof Node && root?.contains(event.relatedTarget)) return;
@@ -376,18 +411,35 @@ function Carousel({
376
411
  emblaApi.on("select", resetOnSelect);
377
412
  emblaApi.on("pointerdown", onUserStop);
378
413
  emblaApi.on("slidefocus", onUserStop);
414
+ emblaApi.on("reinit", onReInit2);
379
415
  if (resumeAfter > 0) emblaApi.on("autoplay:interaction", onInteraction);
380
- root?.addEventListener("pointerenter", onPointerEnter);
381
- root?.addEventListener("pointerleave", onPointerLeave);
382
- root?.addEventListener("focusin", onFocusIn);
383
- root?.addEventListener("focusout", onFocusOut);
416
+ if (pauseOnHover) {
417
+ root?.addEventListener("pointerenter", onPointerEnter);
418
+ root?.addEventListener("pointerleave", onPointerLeave);
419
+ }
420
+ if (pauseOnFocus) {
421
+ root?.addEventListener("focusin", onFocusIn);
422
+ root?.addEventListener("focusout", onFocusOut);
423
+ }
384
424
  if (autoplayEnabled && !reducedMotion) {
385
- hovered = !!root?.matches(":hover");
386
- focused = !!root?.contains(document.activeElement);
425
+ hovered = pauseOnHover && !!root?.matches(":hover");
426
+ focused = pauseOnFocus && !!root?.contains(document.activeElement) && hasKeyboardFocus(document.activeElement);
387
427
  playAutoplay();
388
428
  } else {
389
429
  autoplayPlugin.stop();
390
430
  }
431
+ rotationRef.current = {
432
+ pause: () => {
433
+ held = false;
434
+ clearResumeTimer();
435
+ emblaApi.plugins().autoplay?.stop();
436
+ },
437
+ play: () => {
438
+ held = false;
439
+ clearResumeTimer();
440
+ if (!reducedMotion) emblaApi.plugins().autoplay?.play();
441
+ }
442
+ };
391
443
  cleanupAutoplay = () => {
392
444
  emblaApi.off("autoplay:play", onPlay);
393
445
  emblaApi.off("autoplay:stop", onStop);
@@ -396,6 +448,7 @@ function Carousel({
396
448
  emblaApi.off("select", resetOnSelect);
397
449
  emblaApi.off("pointerdown", onUserStop);
398
450
  emblaApi.off("slidefocus", onUserStop);
451
+ emblaApi.off("reinit", onReInit2);
399
452
  if (resumeAfter > 0) emblaApi.off("autoplay:interaction", onInteraction);
400
453
  root?.removeEventListener("pointerenter", onPointerEnter);
401
454
  root?.removeEventListener("pointerleave", onPointerLeave);
@@ -407,17 +460,44 @@ function Carousel({
407
460
  }
408
461
  let cleanupAutoScroll;
409
462
  if (autoScrollPlugin && autoScrollEnabled && !autoplayEnabled) {
410
- autoScrollPlugin.play();
463
+ playAutoScroll();
464
+ const onPlay = () => {
465
+ if (pausedRef.current) setPaused(false);
466
+ };
467
+ const stopsOnPress = autoScrollPlugin.options.defaultInteraction !== false;
468
+ const onUserStop = () => {
469
+ if (stopsOnPress) setPaused(true);
470
+ };
411
471
  const onInteraction = (_api, event) => {
412
472
  if (event.detail.interaction === "pointerdown" || event.detail.interaction === "slidefocus") {
413
- autoScrollPlugin.stop();
414
- scheduleResume(() => emblaApi.plugins().autoScroll?.play());
473
+ interruptAutoScroll();
415
474
  }
416
475
  };
417
- if (resumeAfter > 0) {
418
- emblaApi.on("autoscroll:interaction", onInteraction);
419
- cleanupAutoScroll = () => emblaApi.off("autoscroll:interaction", onInteraction);
420
- }
476
+ const onReInit2 = () => {
477
+ if (resumeTimer === void 0) playAutoScroll();
478
+ };
479
+ emblaApi.on("autoscroll:play", onPlay);
480
+ emblaApi.on("pointerdown", onUserStop);
481
+ emblaApi.on("slidefocus", onUserStop);
482
+ emblaApi.on("reinit", onReInit2);
483
+ if (resumeAfter > 0) emblaApi.on("autoscroll:interaction", onInteraction);
484
+ rotationRef.current = {
485
+ pause: () => {
486
+ clearResumeTimer();
487
+ emblaApi.plugins().autoScroll?.stop();
488
+ },
489
+ play: () => {
490
+ clearResumeTimer();
491
+ emblaApi.plugins().autoScroll?.play();
492
+ }
493
+ };
494
+ cleanupAutoScroll = () => {
495
+ emblaApi.off("autoscroll:play", onPlay);
496
+ emblaApi.off("pointerdown", onUserStop);
497
+ emblaApi.off("slidefocus", onUserStop);
498
+ emblaApi.off("reinit", onReInit2);
499
+ if (resumeAfter > 0) emblaApi.off("autoscroll:interaction", onInteraction);
500
+ };
421
501
  }
422
502
  let cleanupWheel;
423
503
  if (emblaApi.plugins().wheelGestures && (autoplayPlugin || autoScrollPlugin)) {
@@ -430,8 +510,7 @@ function Carousel({
430
510
  if (autoplayPlugin?.isPlaying() || held) {
431
511
  interruptAutoplay();
432
512
  } else if (autoScrollPlugin?.isPlaying()) {
433
- autoScrollPlugin.stop();
434
- scheduleResume(() => emblaApi.plugins().autoScroll?.play());
513
+ interruptAutoScroll();
435
514
  }
436
515
  };
437
516
  viewport.addEventListener("wheel", onWheel, { passive: true });
@@ -446,8 +525,18 @@ function Carousel({
446
525
  cleanupAutoScroll?.();
447
526
  cleanupWheel?.();
448
527
  clearResumeTimer();
528
+ rotationRef.current = null;
449
529
  };
450
- }, [emblaApi, autoplayEnabled, autoScrollEnabled, resumeAfterMs, reducedMotion]);
530
+ }, [
531
+ emblaApi,
532
+ autoplayEnabled,
533
+ autoScrollEnabled,
534
+ resumeAfterMs,
535
+ reducedMotion,
536
+ pauseOnHover,
537
+ pauseOnFocus,
538
+ setPaused
539
+ ]);
451
540
  const scrollPrev = React.useCallback(() => emblaApi?.goToPrev(), [emblaApi]);
452
541
  const scrollNext = React.useCallback(() => emblaApi?.goToNext(), [emblaApi]);
453
542
  const scrollTo = React.useCallback((i) => emblaApi?.goTo(i), [emblaApi]);
@@ -469,6 +558,9 @@ function Carousel({
469
558
  subscribeScrollProgress,
470
559
  getScrollProgress,
471
560
  autoplay: autoplayState,
561
+ paused,
562
+ pause,
563
+ play,
472
564
  scrollPrev,
473
565
  scrollNext,
474
566
  scrollTo
@@ -486,12 +578,15 @@ function Carousel({
486
578
  subscribeScrollProgress,
487
579
  getScrollProgress,
488
580
  autoplayState,
581
+ paused,
582
+ pause,
583
+ play,
489
584
  scrollPrev,
490
585
  scrollNext,
491
586
  scrollTo
492
587
  ]
493
588
  );
494
- return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
589
+ return /* @__PURE__ */ jsx(CarouselContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(CarouselRotationContext.Provider, { value: autoplayEnabled || autoScrollEnabled, children: /* @__PURE__ */ jsx(
495
590
  "div",
496
591
  {
497
592
  "data-slot": "carousel",
@@ -503,7 +598,7 @@ function Carousel({
503
598
  ref: composedRootRef,
504
599
  children
505
600
  }
506
- ) });
601
+ ) }) });
507
602
  }
508
603
  function CarouselContent({ className, children, viewportProps, ...rest }) {
509
604
  const { viewportRef, orientation, autoHeight } = useCarousel();
@@ -809,6 +904,29 @@ function CarouselNext({ className, position = "inside", disabled: disabledProp,
809
904
  }
810
905
  );
811
906
  }
907
+ function CarouselPlayToggle({ className, render, ...props }) {
908
+ const { reducedMotion, paused, pause, play } = useCarousel();
909
+ const rotates = React.useContext(CarouselRotationContext);
910
+ const state = { paused };
911
+ const trigger = useRender({
912
+ defaultTagName: "button",
913
+ render,
914
+ state,
915
+ props: mergeProps(
916
+ {
917
+ type: "button",
918
+ "data-slot": "carousel-play-toggle",
919
+ "data-paused": paused || void 0,
920
+ "aria-pressed": paused,
921
+ "aria-label": "Pause slides",
922
+ onClick: paused ? play : pause
923
+ },
924
+ props
925
+ )
926
+ });
927
+ if (!rotates || reducedMotion) return null;
928
+ return /* @__PURE__ */ jsx("div", { "data-slot": "carousel-play-toggle-positioner", className: cn("motion-reduce:hidden", className), children: trigger });
929
+ }
812
930
  function CarouselPagination({
813
931
  className,
814
932
  orientation = "horizontal",
@@ -1086,5 +1204,5 @@ function useLinkedCarousels(mainApi, thumbsApi) {
1086
1204
  }, [mainApi, thumbsApi]);
1087
1205
  }
1088
1206
 
1089
- export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels };
1207
+ export { Carousel, CarouselContent, CarouselNext, CarouselPagination, CarouselPlayToggle, CarouselPrev, CarouselProgress, CarouselSlide, CarouselThumb, CarouselThumbs, useCarousel, useLinkedCarousels };
1090
1208
  //# sourceMappingURL=carousel.js.map