@lumx/react 3.9.2-alpha.1 → 3.9.2-alpha.2

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/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/core": "^3.9.2-alpha.1",
10
- "@lumx/icons": "^3.9.2-alpha.1",
9
+ "@lumx/core": "^3.9.2-alpha.2",
10
+ "@lumx/icons": "^3.9.2-alpha.2",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -110,5 +110,5 @@
110
110
  "build:storybook": "storybook build"
111
111
  },
112
112
  "sideEffects": false,
113
- "version": "3.9.2-alpha.1"
113
+ "version": "3.9.2-alpha.2"
114
114
  }
@@ -1,10 +1,10 @@
1
1
  import React, { useEffect, useMemo, useState } from 'react';
2
- import { usePopper } from 'react-popper';
3
2
  import memoize from 'lodash/memoize';
4
3
  import { detectOverflow } from '@popperjs/core';
5
4
 
6
- import { DOCUMENT, IS_JSDOM_ENV, WINDOW } from '@lumx/react/constants';
5
+ import { DOCUMENT, WINDOW } from '@lumx/react/constants';
7
6
  import { PopoverProps } from '@lumx/react/components/popover/Popover';
7
+ import { usePopper } from '@lumx/react/hooks/usePopper';
8
8
  import { ARROW_SIZE, FitAnchorWidth, Placement } from './constants';
9
9
 
10
10
  /**
@@ -104,12 +104,6 @@ export function usePopoverStyle({
104
104
  }: Options): Output {
105
105
  const [popperElement, setPopperElement] = useState<null | HTMLElement>(null);
106
106
 
107
- if (IS_JSDOM_ENV) {
108
- // Skip all logic; we don't need popover positioning in jsdom.
109
- return { styles: {}, attributes: {}, isPositioned: true, popperElement, setPopperElement };
110
- }
111
-
112
- // eslint-disable-next-line react-hooks/rules-of-hooks
113
107
  const [arrowElement, setArrowElement] = useState<null | HTMLElement>(null);
114
108
 
115
109
  const actualOffset: [number, number] = [offset?.along ?? 0, (offset?.away ?? 0) + (hasArrow ? ARROW_SIZE : 0)];
@@ -142,16 +136,13 @@ export function usePopoverStyle({
142
136
  );
143
137
  }
144
138
 
145
- // eslint-disable-next-line react-hooks/rules-of-hooks
146
139
  const { styles, attributes, state, update } = usePopper(anchorRef.current, popperElement, { placement, modifiers });
147
- // eslint-disable-next-line react-hooks/rules-of-hooks
148
140
  useEffect(() => {
149
141
  update?.();
150
142
  }, [children, update]);
151
143
 
152
144
  const position = state?.placement ?? placement;
153
145
 
154
- // eslint-disable-next-line react-hooks/rules-of-hooks
155
146
  const popoverStyle = useMemo(() => {
156
147
  const newStyles = { ...style, ...styles.popper, zIndex };
157
148
 
@@ -1,11 +1,10 @@
1
1
  /* eslint-disable react-hooks/rules-of-hooks */
2
2
  import React, { forwardRef, ReactNode, useState } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
- import { usePopper } from 'react-popper';
5
4
 
6
5
  import classNames from 'classnames';
7
6
 
8
- import { DOCUMENT, IS_JSDOM_ENV } from '@lumx/react/constants';
7
+ import { DOCUMENT } from '@lumx/react/constants';
9
8
  import { Comp, GenericProps, HasCloseMode } from '@lumx/react/utils/type';
10
9
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
11
10
  import { useMergeRefs } from '@lumx/react/utils/mergeRefs';
@@ -15,6 +14,7 @@ import { useId } from '@lumx/react/hooks/useId';
15
14
 
16
15
  import { useInjectTooltipRef } from './useInjectTooltipRef';
17
16
  import { useTooltipOpen } from './useTooltipOpen';
17
+ import { usePopper } from '@lumx/react/hooks/usePopper';
18
18
 
19
19
  /** Position of the tooltip relative to the anchor element. */
20
20
  export type TooltipPlacement = Extract<Placement, 'top' | 'right' | 'bottom' | 'left'>;
@@ -58,9 +58,6 @@ const DEFAULT_PROPS: Partial<TooltipProps> = {
58
58
  */
59
59
  const ARROW_SIZE = 8;
60
60
 
61
- // Skip popper logic in jsdom env
62
- const usePopperHook: typeof usePopper = IS_JSDOM_ENV ? () => ({}) as any : usePopper;
63
-
64
61
  /**
65
62
  * Tooltip component.
66
63
  *
@@ -71,7 +68,7 @@ const usePopperHook: typeof usePopper = IS_JSDOM_ENV ? () => ({}) as any : usePo
71
68
  export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, ref) => {
72
69
  const { label, children, className, delay, placement, forceOpen, closeMode, ...forwardedProps } = props;
73
70
  // Disable in SSR.
74
- if (!DOCUMENT && closeMode === 'unmount') {
71
+ if (!DOCUMENT) {
75
72
  return <>{children}</>;
76
73
  }
77
74
 
@@ -79,7 +76,7 @@ export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, re
79
76
 
80
77
  const [popperElement, setPopperElement] = useState<null | HTMLElement>(null);
81
78
  const [anchorElement, setAnchorElement] = useState<null | HTMLElement>(null);
82
- const { styles = {}, attributes = {} } = usePopperHook(anchorElement, popperElement, {
79
+ const { styles, attributes } = usePopper(anchorElement, popperElement, {
83
80
  placement,
84
81
  modifiers: [
85
82
  {
@@ -1,6 +1,6 @@
1
1
  import { MutableRefObject, useEffect, useRef, useState } from 'react';
2
2
  import { browserDoesNotSupportHover } from '@lumx/react/utils/browserDoesNotSupportHover';
3
- import { IS_JSDOM_ENV, TOOLTIP_HOVER_DELAY, TOOLTIP_LONG_PRESS_DELAY } from '@lumx/react/constants';
3
+ import { IS_BROWSER, TOOLTIP_HOVER_DELAY, TOOLTIP_LONG_PRESS_DELAY } from '@lumx/react/constants';
4
4
  import { useCallbackOnEscape } from '@lumx/react/hooks/useCallbackOnEscape';
5
5
  import { isFocusVisible } from '@lumx/react/utils/isFocusVisible';
6
6
 
@@ -34,8 +34,8 @@ export function useTooltipOpen(delay: number | undefined, anchorElement: HTMLEle
34
34
  const update = () => {
35
35
  setIsOpen(!!shouldOpen);
36
36
  };
37
- // Skip timeout in jsdom env
38
- if (IS_JSDOM_ENV) update();
37
+ // Skip timeout in fake browsers
38
+ if (!IS_BROWSER) update();
39
39
  else timer = setTimeout(update, duration) as any;
40
40
  };
41
41
 
package/src/constants.ts CHANGED
@@ -17,6 +17,6 @@ export const WINDOW = typeof window !== 'undefined' ? window : undefined;
17
17
  export const DOCUMENT = typeof document !== 'undefined' ? document : undefined;
18
18
 
19
19
  /**
20
- * Check if we are running in the simulated DOM jsdom environment
20
+ * Check if we are running in a true browser
21
21
  */
22
- export const IS_JSDOM_ENV = typeof navigator !== 'undefined' && navigator.userAgent.includes('jsdom');
22
+ export const IS_BROWSER = typeof navigator !== 'undefined' && !navigator.userAgent.includes('jsdom');
@@ -0,0 +1,9 @@
1
+ import { usePopper as usePopperHook } from 'react-popper';
2
+ import { IS_BROWSER } from '@lumx/react/constants';
3
+
4
+ /** Stub usePopper for use outside of browsers */
5
+ const useStubPopper: typeof usePopperHook = (_a, _p, { placement }: any) =>
6
+ ({ attributes: { 'data-popper-placement': placement }, styles: {} }) as any;
7
+
8
+ /** Switch hook implementation between environment */
9
+ export const usePopper: typeof usePopperHook = IS_BROWSER ? usePopperHook : useStubPopper;