@lumx/react 3.9.0 → 3.9.1-alpha.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.
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.0",
10
- "@lumx/icons": "^3.9.0",
9
+ "@lumx/core": "^3.9.1-alpha.0",
10
+ "@lumx/icons": "^3.9.1-alpha.0",
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.0"
113
+ "version": "3.9.1-alpha.0"
114
114
  }
@@ -89,7 +89,7 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
89
89
  const zoomOut = React.useCallback(() => onScaleChange?.(0.5), [onScaleChange]);
90
90
  React.useEffect(() => {
91
91
  // Reset scale on slide change
92
- if (activeIndex) setScale(undefined);
92
+ if (typeof activeIndex === 'number') setScale(undefined);
93
93
  }, [activeIndex]);
94
94
  const zoomControls = zoomEnabled && (
95
95
  <>
@@ -25,10 +25,10 @@ type TriggerOptions = Pick<ImageLightboxProps, 'activeImageIndex'>;
25
25
  * - Associate a trigger with an image to display on open
26
26
  * - Automatically provide a view transition between an image trigger and the displayed image on open & close
27
27
  *
28
- * @param initialProps Images to display in the image lightbox
28
+ * @param props Images to display in the image lightbox
29
29
  */
30
30
  export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
31
- initialProps: P,
31
+ props: P,
32
32
  ): {
33
33
  /**
34
34
  * Generates trigger props
@@ -38,16 +38,19 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
38
38
  /** Props to forward to the ImageLightbox */
39
39
  imageLightboxProps: ManagedProps & P;
40
40
  } {
41
- const { images = [], ...otherProps } = initialProps;
41
+ const propsRef = React.useRef(props);
42
42
 
43
- const imagesPropsRef = React.useRef(images);
44
43
  React.useEffect(() => {
45
- imagesPropsRef.current = images.map((props) => ({ imgRef: React.createRef(), ...props }));
46
- }, [images]);
44
+ const newProps = { ...props };
45
+ if (newProps?.images) {
46
+ newProps.images = newProps.images.map((image) => ({ imgRef: React.createRef(), ...image }));
47
+ }
48
+ propsRef.current = newProps;
49
+ }, [props]);
47
50
 
48
51
  const currentImageRef = React.useRef<HTMLImageElement>(null);
49
52
  const [imageLightboxProps, setImageLightboxProps] = React.useState(
50
- () => ({ ...EMPTY_PROPS, ...otherProps }) as ManagedProps & P,
53
+ () => ({ ...EMPTY_PROPS, ...props }) as ManagedProps & P,
51
54
  );
52
55
 
53
56
  const getTriggerProps = React.useMemo(() => {
@@ -58,9 +61,9 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
58
61
  if (!currentImage) {
59
62
  return;
60
63
  }
61
- const currentIndex = imagesPropsRef.current.findIndex(
64
+ const currentIndex = propsRef.current?.images?.findIndex(
62
65
  ({ imgRef }) => (imgRef as any)?.current === currentImage,
63
- );
66
+ ) as number;
64
67
 
65
68
  await startViewTransition({
66
69
  changes() {
@@ -81,7 +84,7 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
81
84
  const triggerImage = triggerImageRefs[activeImageIndex as any]?.current || findImage(triggerElement);
82
85
 
83
86
  // Inject the trigger image as loading placeholder for better loading state
84
- const imagesWithFallbackSize = imagesPropsRef.current.map((image, idx) => {
87
+ const imagesWithFallbackSize = propsRef.current?.images?.map((image, idx) => {
85
88
  if (triggerImage && idx === activeImageIndex && !image.loadingPlaceholderImageRef) {
86
89
  return { ...image, loadingPlaceholderImageRef: { current: triggerImage } };
87
90
  }
@@ -93,6 +96,7 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
93
96
  // Open lightbox with setup props
94
97
  setImageLightboxProps((prevProps) => ({
95
98
  ...prevProps,
99
+ ...propsRef.current,
96
100
  activeImageRef: currentImageRef,
97
101
  parentElement: { current: triggerElement },
98
102
  isOpen: true,
@@ -66,9 +66,9 @@ const ARROW_SIZE = 8;
66
66
  */
67
67
  export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, ref) => {
68
68
  const { label, children, className, delay, placement, forceOpen, ...forwardedProps } = props;
69
- // Disable in SSR or without a label.
70
- if (!DOCUMENT || !label) {
71
- return <TooltipContextProvider>{children}</TooltipContextProvider>;
69
+ // Disable in SSR.
70
+ if (!DOCUMENT) {
71
+ return <>{children}</>;
72
72
  }
73
73
 
74
74
  const id = useId();
@@ -87,7 +87,7 @@ export const Tooltip: Comp<TooltipProps, HTMLDivElement> = forwardRef((props, re
87
87
 
88
88
  const position = attributes?.popper?.['data-popper-placement'] ?? placement;
89
89
  const { isOpen: isActivated, onPopperMount } = useTooltipOpen(delay, anchorElement);
90
- const isOpen = isActivated || forceOpen;
90
+ const isOpen = (isActivated || forceOpen) && !!label;
91
91
  const wrappedChildren = useInjectTooltipRef(children, setAnchorElement, isOpen, id, label);
92
92
 
93
93
  return (
@@ -19,12 +19,14 @@ export const useInjectTooltipRef = (
19
19
  setAnchorElement: (e: HTMLDivElement) => void,
20
20
  isOpen: boolean | undefined,
21
21
  id: string,
22
- label: string,
22
+ label?: string | null | false,
23
23
  ): ReactNode => {
24
24
  // Only add description when open
25
25
  const describedBy = isOpen ? id : undefined;
26
26
 
27
27
  return useMemo(() => {
28
+ if (!label) return children;
29
+
28
30
  // Non-disabled element
29
31
  if (React.isValidElement(children) && children.props.disabled !== true && children.props.isDisabled !== true) {
30
32
  const ref = mergeRefs((children as any).ref, setAnchorElement);