@lumx/react 3.10.1-alpha.3 → 3.10.1-alpha.4

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 (45) hide show
  1. package/index.js +99 -92
  2. package/index.js.map +1 -1
  3. package/package.json +3 -3
  4. package/src/components/chip/Chip.tsx +1 -1
  5. package/src/components/date-picker/DatePickerControlled.tsx +1 -1
  6. package/src/components/expansion-panel/ExpansionPanel.test.tsx +2 -2
  7. package/src/components/image-lightbox/internal/ImageSlide.tsx +2 -2
  8. package/src/components/image-lightbox/internal/ImageSlideshow.tsx +4 -8
  9. package/src/components/image-lightbox/useImageLightbox.tsx +3 -4
  10. package/src/components/list/ListItem.tsx +1 -1
  11. package/src/components/popover/usePopoverStyle.tsx +3 -1
  12. package/src/components/popover/useRestoreFocusOnClose.tsx +1 -1
  13. package/src/components/popover-dialog/PopoverDialog.test.tsx +1 -1
  14. package/src/components/select/Select.test.tsx +2 -2
  15. package/src/components/slideshow/useSlideFocusManagement.tsx +1 -1
  16. package/src/components/text-field/TextField.test.tsx +2 -2
  17. package/src/components/tooltip/Tooltip.test.tsx +2 -2
  18. package/src/components/tooltip/useTooltipOpen.tsx +3 -3
  19. package/src/hooks/useCallbackOnEscape.ts +1 -1
  20. package/src/hooks/useFocusTrap.ts +1 -1
  21. package/src/hooks/useSizeOnWindowResize.ts +14 -10
  22. package/src/hooks/useTransitionVisibility.ts +2 -2
  23. package/src/utils/{DOM → browser/DOM}/startViewTransition.ts +3 -3
  24. package/src/utils/{focus → browser/focus}/getFirstAndLastFocusable.test.ts +1 -1
  25. package/src/utils/{focus → browser/focus}/getFocusableElements.test.ts +1 -1
  26. package/src/utils/{browserDoesNotSupportHover.test.js → browser/isHoverNotSupported.test.js} +5 -5
  27. package/src/utils/browser/isHoverNotSupported.ts +2 -0
  28. package/src/utils/browser/{getPrefersReducedMotion.ts → isReducedMotion.ts} +1 -1
  29. package/src/utils/className/getFontColorClassName.ts +9 -0
  30. package/src/utils/{className.ts → className/getRootClassName.ts} +1 -21
  31. package/src/utils/className/getTypographyClassName.ts +9 -0
  32. package/src/utils/className/index.ts +4 -0
  33. package/src/utils/function/memoize.test.ts +36 -0
  34. package/src/utils/function/memoize.ts +13 -0
  35. package/src/utils/partitionMulti.test.ts +27 -0
  36. package/src/utils/browserDoesNotSupportHover.ts +0 -2
  37. package/src/utils/isInternetExplorer.ts +0 -15
  38. package/src/utils/userHasReducedMotion.ts +0 -7
  39. package/src/utils/utils.test.ts +0 -21
  40. /package/src/utils/{DOM → browser/DOM}/findImage.tsx +0 -0
  41. /package/src/utils/{event.ts → browser/event.ts} +0 -0
  42. /package/src/utils/{focus → browser/focus}/constants.ts +0 -0
  43. /package/src/utils/{focus → browser/focus}/getFirstAndLastFocusable.ts +0 -0
  44. /package/src/utils/{focus → browser/focus}/getFocusableElements.ts +0 -0
  45. /package/src/utils/{isFocusVisible.ts → browser/isFocusVisible.ts} +0 -0
package/index.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import * as React from 'react';
2
2
  import React__default, { useState, useEffect, useMemo, useRef, Children, isValidElement, cloneElement, useLayoutEffect, useCallback, Fragment, createContext, useContext, useReducer } from 'react';
3
- import kebabCase from 'lodash/kebabCase';
4
3
  import isBoolean from 'lodash/isBoolean';
5
4
  import isEmpty from 'lodash/isEmpty';
5
+ import kebabCase from 'lodash/kebabCase';
6
6
  import ReactDOM, { createPortal } from 'react-dom';
7
7
  import get from 'lodash/get';
8
8
  import { C as ClickAwayProvider, i as isEmpty$1 } from './_internal/index.js';
9
- import memoize from 'lodash/memoize';
10
- import throttle from 'lodash/throttle';
11
9
 
12
10
  function ownKeys(e, r) {
13
11
  var t = Object.keys(e);
@@ -319,57 +317,6 @@ var classNames = classnames.exports;
319
317
 
320
318
  const mdiAlert='M13 14h-2V9h2m0 9h-2v-2h2M1 21h22L12 2z';const mdiAlertCircle='M13 13h-2V7h2m0 10h-2v-2h2M12 2A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2';const mdiArrowDown='M11 4h2v12l5.5-5.5 1.42 1.42L12 19.84l-7.92-7.92L5.5 10.5 11 16z';const mdiArrowUp='M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z';const mdiCheck='M21 7 9 19l-5.5-5.5 1.41-1.41L9 16.17 19.59 5.59z';const mdiCheckCircle='M12 2C6.5 2 2 6.5 2 12s4.5 10 10 10 10-4.5 10-10S17.5 2 12 2m-2 15-5-5 1.41-1.41L10 14.17l7.59-7.59L19 8z';const mdiChevronDown='M7.41 8.58 12 13.17l4.59-4.59L18 10l-6 6-6-6z';const mdiChevronLeft='M15.41 16.58 10.83 12l4.58-4.59L14 6l-6 6 6 6z';const mdiChevronRight='M8.59 16.58 13.17 12 8.59 7.41 10 6l6 6-6 6z';const mdiChevronUp='M7.41 15.41 12 10.83l4.59 4.58L18 14l-6-6-6 6z';const mdiClose='M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z';const mdiCloseCircle='M12 2a10 10 0 1 1 0 20 10 10 0 1 1 0-20m3.59 5L12 10.59 8.41 7 7 8.41 10.59 12 7 15.59 8.41 17 12 13.41 15.59 17 17 15.59 13.41 12 17 8.41z';const mdiDragVertical='M9 3h2v2H9zm4 0h2v2h-2zM9 7h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2zm-4 4h2v2H9zm4 0h2v2h-2z';const mdiImageBroken='M19 3a2 2 0 0 1 2 2v6h-2v2h-2v2h-2v2h-2v2h-2v2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2zm2 12v4a2 2 0 0 1-2 2h-4v-2h2v-2h2v-2zm-2-6.5a.5.5 0 0 0-.5-.5h-13a.5.5 0 0 0-.5.5v7a.5.5 0 0 0 .5.5H11v-1h2v-2h2v-2h2V9h2z';const mdiInformation='M13 9h-2V7h2m0 10h-2v-6h2m-1-9A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2';const mdiMagnifyMinusOutline='M15.5 14h-.79l-.28-.27A6.5 6.5 0 0 0 16 9.5 6.5 6.5 0 0 0 9.5 3 6.5 6.5 0 0 0 3 9.5 6.5 6.5 0 0 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 5 1.5-1.5zm-6 0C7 14 5 12 5 9.5S7 5 9.5 5 14 7 14 9.5 12 14 9.5 14M7 9h5v1H7z';const mdiMagnifyPlusOutline='m15.5 14 5 5-1.5 1.5-5-5v-.79l-.27-.28A6.5 6.5 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3 6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.57 4.23l.28.27zm-6 0C12 14 14 12 14 9.5S12 5 9.5 5 5 7 5 9.5 7 14 9.5 14m2.5-4h-2v2H9v-2H7V9h2V7h1v2h2z';const mdiMenuDown='m7 10 5 5 5-5z';const mdiMinus='M19 13H5v-2h14z';const mdiPauseCircleOutline='M13 16V8h2v8zm-4 0V8h2v8zm3-14a10 10 0 0 1 10 10 10 10 0 0 1-10 10A10 10 0 0 1 2 12 10 10 0 0 1 12 2m0 2a8 8 0 0 0-8 8 8 8 0 0 0 8 8 8 8 0 0 0 8-8 8 8 0 0 0-8-8';const mdiPlayCircleOutline='M12 20a8.01 8.01 0 0 1 0-16 8.01 8.01 0 0 1 0 16m0-18A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2m-2 14.5 6-4.5-6-4.5z';const mdiRadioboxBlank='M12 20a8 8 0 0 1-8-8 8 8 0 0 1 8-8 8 8 0 0 1 8 8 8 8 0 0 1-8 8m0-18A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2';const mdiRadioboxMarked='M12 20a8 8 0 0 1-8-8 8 8 0 0 1 8-8 8 8 0 0 1 8 8 8 8 0 0 1-8 8m0-18A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2m0 5a5 5 0 0 0-5 5 5 5 0 0 0 5 5 5 5 0 0 0 5-5 5 5 0 0 0-5-5';
321
319
 
322
- /**
323
- * The prefix to use for the CSS classes.
324
- */
325
- const CSS_PREFIX = 'lumx';
326
-
327
- /**
328
- * Animation duration constants. Take into consideration that if you change one of these variables,
329
- * you need to update their scss counterpart as well
330
- */
331
- const DIALOG_TRANSITION_DURATION = 400;
332
- const EXPANSION_PANEL_TRANSITION_DURATION = 400;
333
- const NOTIFICATION_TRANSITION_DURATION = 200;
334
-
335
- /**
336
- * Delay on hover after which we open or close the tooltip.
337
- * Only applies to devices supporting pointer hover.
338
- */
339
- const TOOLTIP_HOVER_DELAY = {
340
- open: 500,
341
- close: 500
342
- };
343
-
344
- /**
345
- * Delay on long press after which we open or close the tooltip.
346
- * Only applies to devices not supporting pointer hover.
347
- */
348
- const TOOLTIP_LONG_PRESS_DELAY = {
349
- open: 250,
350
- close: 3000
351
- };
352
-
353
- /**
354
- * Optional global `window` instance (not defined when running SSR).
355
- */
356
- const WINDOW = typeof window !== 'undefined' ? window : undefined;
357
-
358
- /**
359
- * Optional global `document` instance (not defined when running SSR).
360
- */
361
- const DOCUMENT = typeof document !== 'undefined' ? document : undefined;
362
-
363
- /**
364
- * Check if we are running in a true browser
365
- */
366
- const IS_BROWSER = typeof navigator !== 'undefined' && !navigator.userAgent.includes('jsdom');
367
-
368
- /**
369
- * Visually hidden a11y utility class name
370
- */
371
- const VISUALLY_HIDDEN = 'visually-hidden';
372
-
373
320
  const _excluded$1t = ["prefix"];
374
321
 
375
322
  /**
@@ -567,6 +514,37 @@ function onButtonPressed(handler) {
567
514
  };
568
515
  }
569
516
 
517
+ /**
518
+ * The prefix to use for the CSS classes.
519
+ */
520
+ const CSS_PREFIX = 'lumx';
521
+
522
+ /**
523
+ * Animation duration constants. Take into consideration that if you change one of these variables,
524
+ * you need to update their scss counterpart as well
525
+ */
526
+ const DIALOG_TRANSITION_DURATION = 400;
527
+ const EXPANSION_PANEL_TRANSITION_DURATION = 400;
528
+ const NOTIFICATION_TRANSITION_DURATION = 200;
529
+
530
+ /**
531
+ * Delay on hover after which we open or close the tooltip.
532
+ * Only applies to devices supporting pointer hover.
533
+ */
534
+ const TOOLTIP_HOVER_DELAY = {
535
+ open: 500,
536
+ close: 500
537
+ };
538
+
539
+ /**
540
+ * Delay on long press after which we open or close the tooltip.
541
+ * Only applies to devices not supporting pointer hover.
542
+ */
543
+ const TOOLTIP_LONG_PRESS_DELAY = {
544
+ open: 250,
545
+ close: 3000
546
+ };
547
+
570
548
  // See https://regex101.com/r/YjS1uI/3
571
549
  const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
572
550
 
@@ -588,6 +566,14 @@ function getRootClassName(componentName, subComponent) {
588
566
  return formattedClassName;
589
567
  }
590
568
 
569
+ /**
570
+ * Returns the classname associated to the given typography.
571
+ * For example, for `Typography.title` it returns `lumx-typography-title`
572
+ */
573
+ const getTypographyClassName = typography => {
574
+ return `lumx-typography-${typography}`;
575
+ };
576
+
591
577
  /**
592
578
  * Returns the classname associated to the given color and variant.
593
579
  * For example, for 'dark' and 'L2' it returns `lumx-color-font-dark-l2`
@@ -597,14 +583,6 @@ const getFontColorClassName = function (color) {
597
583
  return `lumx-color-font-${color}-${colorVariant}`;
598
584
  };
599
585
 
600
- /**
601
- * Returns the classname associated to the given typography.
602
- * For example, for `Typography.title` it returns `lumx-typography-title`
603
- */
604
- const getTypographyClassName = typography => {
605
- return `lumx-typography-${typography}`;
606
- };
607
-
608
586
  let i = 0;
609
587
 
610
588
  /**
@@ -2069,6 +2047,26 @@ const List = Object.assign(InternalList, {
2069
2047
  useKeyboardListNavigation
2070
2048
  });
2071
2049
 
2050
+ /**
2051
+ * Optional global `window` instance (not defined when running SSR).
2052
+ */
2053
+ const WINDOW = typeof window !== 'undefined' ? window : undefined;
2054
+
2055
+ /**
2056
+ * Optional global `document` instance (not defined when running SSR).
2057
+ */
2058
+ const DOCUMENT = typeof document !== 'undefined' ? document : undefined;
2059
+
2060
+ /**
2061
+ * Check if we are running in a true browser
2062
+ */
2063
+ const IS_BROWSER = typeof navigator !== 'undefined' && !navigator.userAgent.includes('jsdom');
2064
+
2065
+ /**
2066
+ * Visually hidden a11y utility class name
2067
+ */
2068
+ const VISUALLY_HIDDEN = 'visually-hidden';
2069
+
2072
2070
  /** Pull an element from an array (inverse of array.push) */
2073
2071
  const pull = (array, element) => {
2074
2072
  const index = array.indexOf(element);
@@ -4436,6 +4434,21 @@ const useStubPopper = (_a, _p, _ref) => {
4436
4434
  /** Switch hook implementation between environment */
4437
4435
  const usePopper = IS_BROWSER ? usePopper$1 : useStubPopper;
4438
4436
 
4437
+ /** Memoize a function based on the serialization of its args */
4438
+ function memoize(fn) {
4439
+ const cache = new Map();
4440
+ return function () {
4441
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
4442
+ args[_key] = arguments[_key];
4443
+ }
4444
+ const serializedArgs = JSON.stringify(args);
4445
+ if (cache.has(serializedArgs)) return cache.get(serializedArgs);
4446
+ const value = fn(...args);
4447
+ cache.set(serializedArgs, value);
4448
+ return value;
4449
+ };
4450
+ }
4451
+
4439
4452
  /**
4440
4453
  * Different possible placements for the popover.
4441
4454
  */
@@ -6807,13 +6820,11 @@ const useDisableBodyScroll = modalElement => {
6807
6820
  }, [modalElement]);
6808
6821
  };
6809
6822
 
6810
- const userHasReducedMotion = () => {
6811
- try {
6812
- return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
6813
- } catch (e) {
6814
- return false;
6815
- }
6816
- };
6823
+ /** Check if user prefers reduced motion */
6824
+ function isReducedMotion() {
6825
+ var _WINDOW$matchMedia;
6826
+ return WINDOW === null || WINDOW === void 0 ? void 0 : (_WINDOW$matchMedia = WINDOW.matchMedia) === null || _WINDOW$matchMedia === void 0 ? void 0 : _WINDOW$matchMedia.call(WINDOW, '(prefers-reduced-motion: reduce)').matches;
6827
+ }
6817
6828
 
6818
6829
  /**
6819
6830
  * Returns true if the component is visible tracking the opacity transition.
@@ -6839,7 +6850,7 @@ const useTransitionVisibility = (ref, isComponentVisible, timeout, onVisibilityC
6839
6850
 
6840
6851
  // Transition event is not supported or the user prefers reduced motion.
6841
6852
  // => Skip and set visibility to false directly.
6842
- if (!element || !window.TransitionEvent || userHasReducedMotion()) {
6853
+ if (!element || !window.TransitionEvent || isReducedMotion()) {
6843
6854
  setVisible(false);
6844
6855
  return undefined;
6845
6856
  }
@@ -8140,11 +8151,20 @@ const CLASSNAME$O = getRootClassName(COMPONENT_NAME$O);
8140
8151
  */
8141
8152
  function useSizeOnWindowResize(elementRef) {
8142
8153
  const [size, setSize] = React__default.useState(null);
8143
- const updateSize = React__default.useMemo(() => throttle(() => {
8144
- var _elementRef$current;
8145
- const newSize = (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.getBoundingClientRect();
8146
- if (newSize) setSize(newSize);
8147
- }, 10), [elementRef]);
8154
+ const updateSize = React__default.useMemo(() => {
8155
+ let prevTimeout;
8156
+ function update() {
8157
+ var _elementRef$current;
8158
+ const newSize = (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.getBoundingClientRect();
8159
+ if (newSize) setSize(newSize);
8160
+ prevTimeout = undefined;
8161
+ }
8162
+ return () => {
8163
+ if (!prevTimeout) {
8164
+ prevTimeout = setTimeout(update, 10);
8165
+ }
8166
+ };
8167
+ }, [elementRef]);
8148
8168
  React__default.useEffect(() => {
8149
8169
  updateSize();
8150
8170
  window.addEventListener('resize', updateSize);
@@ -8173,12 +8193,6 @@ function useImageSize(imgRef, getInitialSize) {
8173
8193
  return imageSize;
8174
8194
  }
8175
8195
 
8176
- /** Check if user prefers reduced motion */
8177
- function getPrefersReducedMotion() {
8178
- var _WINDOW$matchMedia;
8179
- return WINDOW === null || WINDOW === void 0 ? void 0 : (_WINDOW$matchMedia = WINDOW.matchMedia) === null || _WINDOW$matchMedia === void 0 ? void 0 : _WINDOW$matchMedia.call(WINDOW, '(prefers-reduced-motion: reduce)').matches;
8180
- }
8181
-
8182
8196
  /** Minimal recursive deep equal of JS values */
8183
8197
  function isEqual(obj1, obj2) {
8184
8198
  if (obj1 === obj2) return true;
@@ -8464,7 +8478,7 @@ const ImageSlide = /*#__PURE__*/React__default.memo(props => {
8464
8478
  maxWidth: scrollAreaSize === null || scrollAreaSize === void 0 ? void 0 : scrollAreaSize.width
8465
8479
  }), {}, {
8466
8480
  // Only animate when scale is set, and we are not pointer zooming and the user does not prefer reduced motion
8467
- transition: scale && !isPointerZooming && !getPrefersReducedMotion() ? 'all 250ms' : undefined
8481
+ transition: scale && !isPointerZooming && !isReducedMotion() ? 'all 250ms' : undefined
8468
8482
  })
8469
8483
  }),
8470
8484
  loadingPlaceholderImageRef: loadingPlaceholderImageRef
@@ -8566,13 +8580,6 @@ const ImageSlideshow = _ref => {
8566
8580
  })));
8567
8581
  const getImgRef = React__default.useMemo(() => memoize((index, isActive) => {
8568
8582
  return mergeRefs(images === null || images === void 0 ? void 0 : images[index].imgRef, isActive ? activeImageRef : undefined);
8569
- },
8570
- // memoize based on both arguments
8571
- function () {
8572
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
8573
- args[_key] = arguments[_key];
8574
- }
8575
- return args.join();
8576
8583
  }), [images, activeImageRef]);
8577
8584
  return /*#__PURE__*/React__default.createElement(React__default.Fragment, null, /*#__PURE__*/React__default.createElement(Slides, {
8578
8585
  activeIndex: activeIndex,
@@ -8650,7 +8657,7 @@ async function startViewTransition(_ref) {
8650
8657
  viewTransitionName
8651
8658
  } = _ref;
8652
8659
  const start = (_document = document) === null || _document === void 0 ? void 0 : (_document$startViewTr = _document.startViewTransition) === null || _document$startViewTr === void 0 ? void 0 : _document$startViewTr.bind(document);
8653
- const prefersReducedMotion = getPrefersReducedMotion();
8660
+ const prefersReducedMotion = isReducedMotion();
8654
8661
  const {
8655
8662
  flushSync
8656
8663
  } = ReactDOM;
@@ -14043,7 +14050,7 @@ const useInjectTooltipRef = options => {
14043
14050
  };
14044
14051
 
14045
14052
  /** Return true if the browser does not support pointer hover */
14046
- const browserDoesNotSupportHover = () => {
14053
+ const isHoverNotSupported = () => {
14047
14054
  var _window$matchMedia, _window;
14048
14055
  return !!((_window$matchMedia = (_window = window).matchMedia) !== null && _window$matchMedia !== void 0 && _window$matchMedia.call(_window, '(hover: none)').matches);
14049
14056
  };
@@ -14090,7 +14097,7 @@ function useTooltipOpen(delay, anchorElement) {
14090
14097
  // Skip timeout in fake browsers
14091
14098
  if (!IS_BROWSER) update();else timer = setTimeout(update, duration);
14092
14099
  };
14093
- const hoverNotSupported = browserDoesNotSupportHover();
14100
+ const hoverNotSupported = isHoverNotSupported();
14094
14101
  const hasTouch = ('ontouchstart' in window);
14095
14102
 
14096
14103
  // Adapt open/close delay