@lumx/react 3.9.2-alpha.6 → 3.9.2-alpha.7

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.6",
10
- "@lumx/icons": "^3.9.2-alpha.6",
9
+ "@lumx/core": "^3.9.2-alpha.7",
10
+ "@lumx/icons": "^3.9.2-alpha.7",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -57,7 +57,7 @@
57
57
  "jest-environment-jsdom": "29.1.2",
58
58
  "react": "^17.0.2",
59
59
  "react-dom": "^17.0.2",
60
- "rollup": "2.26.10",
60
+ "rollup": "2.79.2",
61
61
  "rollup-plugin-analyzer": "^3.3.0",
62
62
  "rollup-plugin-babel": "^4.4.0",
63
63
  "rollup-plugin-cleaner": "^1.0.0",
@@ -110,5 +110,5 @@
110
110
  "build:storybook": "storybook build"
111
111
  },
112
112
  "sideEffects": false,
113
- "version": "3.9.2-alpha.6"
113
+ "version": "3.9.2-alpha.7"
114
114
  }
@@ -145,11 +145,18 @@ describe(`<${ImageLightbox.displayName}>`, () => {
145
145
 
146
146
  // Focus moved to the close button
147
147
  const imageLightbox = queries.getImageLightbox();
148
- expect(queries.queryCloseButton(imageLightbox)).toHaveFocus();
148
+ const closeButton = queries.queryCloseButton(imageLightbox);
149
+ expect(closeButton).toHaveFocus();
150
+ const tooltip = screen.getByRole('tooltip', { name: 'Close' });
151
+ expect(tooltip).toBeInTheDocument();
149
152
 
150
153
  // Image lightbox opened on the correct image
151
154
  expect(queries.queryImage(imageLightbox, 'Image 2')).toBeInTheDocument();
152
155
 
156
+ // Close tooltip
157
+ await userEvent.keyboard('{escape}');
158
+ expect(tooltip).not.toBeInTheDocument();
159
+
153
160
  // Close on escape
154
161
  await userEvent.keyboard('{escape}');
155
162
  expect(imageLightbox).not.toBeInTheDocument();
@@ -41,13 +41,12 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
41
41
  const propsRef = React.useRef(props);
42
42
 
43
43
  React.useEffect(() => {
44
- const newProps = { ...props };
45
- if (newProps?.images) {
46
- newProps.images = newProps.images.map((image) => ({ imgRef: React.createRef(), ...image }));
47
- }
48
- propsRef.current = newProps;
44
+ propsRef.current = props;
49
45
  }, [props]);
50
46
 
47
+ // Keep reference for each image elements
48
+ const imageRefsRef = React.useRef<Array<React.RefObject<HTMLImageElement>>>([]);
49
+
51
50
  const currentImageRef = React.useRef<HTMLImageElement>(null);
52
51
  const [imageLightboxProps, setImageLightboxProps] = React.useState(
53
52
  () => ({ ...EMPTY_PROPS, ...props }) as ManagedProps & P,
@@ -61,8 +60,8 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
61
60
  if (!currentImage) {
62
61
  return;
63
62
  }
64
- const currentIndex = propsRef.current?.images?.findIndex(
65
- ({ imgRef }) => (imgRef as any)?.current === currentImage,
63
+ const currentIndex = imageRefsRef.current.findIndex(
64
+ (imageRef) => imageRef.current === currentImage,
66
65
  ) as number;
67
66
 
68
67
  await startViewTransition({
@@ -83,12 +82,20 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
83
82
  // If we find an image inside the trigger, animate it in transition with the opening image
84
83
  const triggerImage = triggerImageRefs[activeImageIndex as any]?.current || findImage(triggerElement);
85
84
 
86
- // Inject the trigger image as loading placeholder for better loading state
87
- const imagesWithFallbackSize = propsRef.current?.images?.map((image, idx) => {
88
- if (triggerImage && idx === activeImageIndex && !image.loadingPlaceholderImageRef) {
89
- return { ...image, loadingPlaceholderImageRef: { current: triggerImage } };
85
+ // Inject refs to improve transition and loading style
86
+ const images = propsRef.current?.images?.map((image, idx) => {
87
+ // Get or create image reference
88
+ let imgRef = imageRefsRef.current[idx];
89
+ if (!imgRef) {
90
+ imgRef = React.createRef();
91
+ imageRefsRef.current[idx] = imgRef;
90
92
  }
91
- return image;
93
+
94
+ // Try to use the trigger image as the loading placeholder
95
+ const loadingPlaceholderImageRef =
96
+ triggerImage && idx === activeImageIndex ? { current: triggerImage } : undefined;
97
+
98
+ return { loadingPlaceholderImageRef, ...image, imgRef };
92
99
  });
93
100
 
94
101
  await startViewTransition({
@@ -104,7 +111,7 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
104
111
  close();
105
112
  prevProps?.onClose?.();
106
113
  },
107
- images: imagesWithFallbackSize,
114
+ images,
108
115
  activeImageIndex: activeImageIndex || 0,
109
116
  }));
110
117
  },
@@ -2,8 +2,10 @@ import { Button, Dialog, Dropdown, Placement, Tooltip } from '@lumx/react';
2
2
  import React, { useState } from 'react';
3
3
  import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
4
4
  import { withChromaticForceScreenSize } from '@lumx/react/stories/decorators/withChromaticForceScreenSize';
5
+ import { ARIA_LINK_MODES } from '@lumx/react/components/tooltip/constants';
5
6
 
6
7
  const placements = [Placement.TOP, Placement.BOTTOM, Placement.RIGHT, Placement.LEFT];
8
+ const CLOSE_MODES = ['hide', 'unmount'];
7
9
 
8
10
  export default {
9
11
  title: 'LumX components/tooltip/Tooltip',
@@ -11,6 +13,9 @@ export default {
11
13
  args: Tooltip.defaultProps,
12
14
  argTypes: {
13
15
  placement: getSelectArgType(placements),
16
+ children: { control: false },
17
+ closeMode: { control: { type: 'inline-radio' }, options: CLOSE_MODES },
18
+ ariaLinkMode: { control: { type: 'inline-radio' }, options: ARIA_LINK_MODES },
14
19
  },
15
20
  decorators: [
16
21
  // Force minimum chromatic screen size to make sure the dialog appears in view.
@@ -13,6 +13,7 @@ import { TooltipContextProvider } from '@lumx/react/components/tooltip/context';
13
13
  import { useId } from '@lumx/react/hooks/useId';
14
14
  import { usePopper } from '@lumx/react/hooks/usePopper';
15
15
 
16
+ import { ARIA_LINK_MODES } from '@lumx/react/components/tooltip/constants';
16
17
  import { useInjectTooltipRef } from './useInjectTooltipRef';
17
18
  import { useTooltipOpen } from './useTooltipOpen';
18
19
 
@@ -34,7 +35,7 @@ export interface TooltipProps extends GenericProps, HasCloseMode {
34
35
  /** Placement of the tooltip relative to the anchor. */
35
36
  placement?: TooltipPlacement;
36
37
  /** Choose how the tooltip text should link to the anchor */
37
- ariaLinkMode?: 'aria-describedby' | 'aria-labelledby';
38
+ ariaLinkMode?: (typeof ARIA_LINK_MODES)[number];
38
39
  }
39
40
 
40
41
  /**
@@ -0,0 +1 @@
1
+ export const ARIA_LINK_MODES = ['aria-describedby', 'aria-labelledby'] as const;
@@ -1,4 +1,4 @@
1
- import React, { AriaAttributes, cloneElement, ReactNode, useMemo } from 'react';
1
+ import React, { cloneElement, ReactNode, useMemo } from 'react';
2
2
 
3
3
  import { mergeRefs } from '@lumx/react/utils/mergeRefs';
4
4
 
package/src/utils/type.ts CHANGED
@@ -59,7 +59,6 @@ export interface HasClassName {
59
59
  className?: string;
60
60
  }
61
61
 
62
-
63
62
  export interface HasCloseMode {
64
63
  /**
65
64
  * Choose how the children are hidden when closed