@lumx/react 3.0.4 → 3.0.5-alpha.1

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/index.js CHANGED
@@ -343,13 +343,6 @@ function uid(len) {
343
343
  */
344
344
  const CSS_PREFIX = 'lumx';
345
345
 
346
- /**
347
- * Animation duration constants. Take into consideration that if you change one of these variables,
348
- * you need to update their scss counterpart as well
349
- */
350
- const DIALOG_TRANSITION_DURATION = 400;
351
- const NOTIFICATION_TRANSITION_DURATION = 200;
352
-
353
346
  /**
354
347
  * Delay on hover after which we open or close the tooltip.
355
348
  * Only applies to devices supporting pointer hover.
@@ -2465,42 +2458,6 @@ function partitionMulti(elements, predicates) {
2465
2458
  return reduce(predicates, (partitioned, predicate) => concat(dropRight(partitioned), partition(last(partitioned), predicate)), [elements]);
2466
2459
  }
2467
2460
 
2468
- /**
2469
- * Returns true if the component is visible taking into account the component's
2470
- * own visibility and the animations delay
2471
- *
2472
- * @param isComponentVisible Whether the component intends to be visible or not.
2473
- * @param transitionDuration time in ms that the transition takes for the specific component.
2474
- * @param onVisibilityChange Callback called when the visibility changes.
2475
- * @return true if the component should be rendered
2476
- */
2477
- function useDelayedVisibility(isComponentVisible, transitionDuration, onVisibilityChange) {
2478
- // Delay visibility to account for the 400ms of CSS opacity animation.
2479
- const [isVisible, setVisible] = useState(isComponentVisible);
2480
- useEffect(() => {
2481
- if (isComponentVisible) {
2482
- setVisible(true);
2483
- } else {
2484
- setTimeout(() => setVisible(false), transitionDuration);
2485
- }
2486
- }, [isComponentVisible, transitionDuration]);
2487
-
2488
- /**
2489
- * Since we don't want onVisibiltyChange function to trigger itself if when it changes,
2490
- * we store the previous visibility and only trigger when visibility is different
2491
- * than previous value.
2492
- */
2493
-
2494
- const previousVisibility = useRef(isVisible);
2495
- useEffect(() => {
2496
- if (onVisibilityChange && previousVisibility.current !== isVisible) {
2497
- onVisibilityChange(isVisible);
2498
- previousVisibility.current = isVisible;
2499
- }
2500
- }, [isVisible, onVisibilityChange]);
2501
- return isComponentVisible || isVisible;
2502
- }
2503
-
2504
2461
  function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
2505
2462
 
2506
2463
  // Older browsers don't support event options, feature detect it.
@@ -2716,6 +2673,52 @@ const useDisableBodyScroll = modalElement => {
2716
2673
  }, [modalElement]);
2717
2674
  };
2718
2675
 
2676
+ /**
2677
+ * Returns true if the component is visible tracking the opacity transition.
2678
+ *
2679
+ * @param ref Element on which to listen the transition event.
2680
+ * @param isComponentVisible Whether the component intends to be visible or not.
2681
+ * @param onVisibilityChange Callback called when the visibility changes.
2682
+ * @return true if the component should be rendered
2683
+ */
2684
+ const useTransitionVisibility = (ref, isComponentVisible, onVisibilityChange) => {
2685
+ const [isVisible, setVisible] = useState(isComponentVisible);
2686
+ const previousVisibility = useRef(isVisible);
2687
+ useEffect(() => {
2688
+ if (isComponentVisible) {
2689
+ setVisible(true);
2690
+ } else if (!window.TransitionEvent) {
2691
+ // Transition event is not available so visibility is set to false directly.
2692
+ setVisible(false);
2693
+ }
2694
+ }, [isComponentVisible]);
2695
+ useEffect(() => {
2696
+ if (onVisibilityChange && previousVisibility.current !== isVisible) {
2697
+ onVisibilityChange(isVisible);
2698
+ previousVisibility.current = isVisible;
2699
+ }
2700
+ }, [isVisible, onVisibilityChange]);
2701
+ useEffect(() => {
2702
+ const {
2703
+ current: element
2704
+ } = ref;
2705
+ if (!element) {
2706
+ return undefined;
2707
+ }
2708
+
2709
+ // Listen opacity transition
2710
+ const onTransitionEnd = e => {
2711
+ if (e.target !== ref.current || e.propertyName !== 'opacity') return;
2712
+ setVisible(wasVisible => !wasVisible);
2713
+ };
2714
+ element.addEventListener('transitionend', onTransitionEnd);
2715
+ return () => {
2716
+ element.removeEventListener('transitionend', onTransitionEnd);
2717
+ };
2718
+ });
2719
+ return isVisible || isComponentVisible;
2720
+ };
2721
+
2719
2722
  const _excluded$h = ["children", "className", "header", "focusElement", "forceFooterDivider", "forceHeaderDivider", "footer", "isLoading", "isOpen", "onClose", "parentElement", "contentRef", "preventAutoClose", "size", "zIndex", "dialogProps", "onVisibilityChange"];
2720
2723
 
2721
2724
  /**
@@ -2827,14 +2830,14 @@ const Dialog = /*#__PURE__*/forwardRef((props, ref) => {
2827
2830
  const footerChildProps = footerChild === null || footerChild === void 0 ? void 0 : footerChild.props;
2828
2831
  const footerChildContent = footerChildProps === null || footerChildProps === void 0 ? void 0 : footerChildProps.children;
2829
2832
 
2830
- // eslint-disable-next-line react-hooks/rules-of-hooks
2831
- const isVisible = useDelayedVisibility(Boolean(isOpen), DIALOG_TRANSITION_DURATION, onVisibilityChange);
2832
-
2833
2833
  // eslint-disable-next-line react-hooks/rules-of-hooks
2834
2834
  const clickAwayRefs = useRef([wrapperRef]);
2835
2835
 
2836
2836
  // eslint-disable-next-line react-hooks/rules-of-hooks
2837
2837
  const rootRef = useRef(null);
2838
+
2839
+ // eslint-disable-next-line react-hooks/rules-of-hooks
2840
+ const isVisible = useTransitionVisibility(rootRef, Boolean(isOpen), onVisibilityChange);
2838
2841
  return isOpen || isVisible ? /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement("div", _extends({
2839
2842
  ref: mergeRefs(rootRef, ref)
2840
2843
  }, forwardedProps, {
@@ -7266,7 +7269,6 @@ InputLabel.className = CLASSNAME$w;
7266
7269
  InputLabel.defaultProps = DEFAULT_PROPS$s;
7267
7270
 
7268
7271
  const _excluded$B = ["ariaLabel", "children", "className", "closeButtonProps", "isOpen", "onClose", "parentElement", "preventAutoClose", "theme", "zIndex"];
7269
- const LIGHTBOX_TRANSITION_DURATION = 400;
7270
7272
 
7271
7273
  /**
7272
7274
  * Defines the props of the component.
@@ -7318,7 +7320,7 @@ const Lightbox = /*#__PURE__*/forwardRef((props, ref) => {
7318
7320
  useDisableBodyScroll(isOpen && wrapperRef.current);
7319
7321
 
7320
7322
  // eslint-disable-next-line react-hooks/rules-of-hooks
7321
- const isVisible = useDelayedVisibility(!!isOpen, LIGHTBOX_TRANSITION_DURATION);
7323
+ const isVisible = useTransitionVisibility(wrapperRef, !!isOpen);
7322
7324
 
7323
7325
  // Handle focus trap.
7324
7326
  // eslint-disable-next-line react-hooks/rules-of-hooks
@@ -7906,7 +7908,8 @@ const Notification = /*#__PURE__*/forwardRef((props, ref) => {
7906
7908
  color,
7907
7909
  icon
7908
7910
  } = NOTIFICATION_CONFIGURATION[type] || {};
7909
- const isVisible = useDelayedVisibility(!!isOpen, NOTIFICATION_TRANSITION_DURATION);
7911
+ const rootRef = useRef(null);
7912
+ const isVisible = useTransitionVisibility(rootRef, !!isOpen);
7910
7913
  const hasAction = Boolean(onActionClick) && Boolean(actionLabel);
7911
7914
  const handleCallback = evt => {
7912
7915
  if (isFunction(onActionClick)) {
@@ -7918,7 +7921,7 @@ const Notification = /*#__PURE__*/forwardRef((props, ref) => {
7918
7921
  /*#__PURE__*/
7919
7922
  // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
7920
7923
  React.createElement("div", _extends({
7921
- ref: ref,
7924
+ ref: mergeRefs(ref, rootRef),
7922
7925
  role: "alert"
7923
7926
  }, forwardedProps, {
7924
7927
  className: classnames(className, handleBasicClasses({