@lumx/react 3.7.6-alpha.4 → 3.7.6-alpha.6

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
@@ -7,8 +7,8 @@
7
7
  },
8
8
  "dependencies": {
9
9
  "@juggle/resize-observer": "^3.2.0",
10
- "@lumx/core": "^3.7.6-alpha.4",
11
- "@lumx/icons": "^3.7.6-alpha.4",
10
+ "@lumx/core": "^3.7.6-alpha.6",
11
+ "@lumx/icons": "^3.7.6-alpha.6",
12
12
  "@popperjs/core": "^2.5.4",
13
13
  "body-scroll-lock": "^3.1.5",
14
14
  "classnames": "^2.3.2",
@@ -112,5 +112,5 @@
112
112
  "build:storybook": "storybook build"
113
113
  },
114
114
  "sideEffects": false,
115
- "version": "3.7.6-alpha.4"
115
+ "version": "3.7.6-alpha.6"
116
116
  }
@@ -113,10 +113,14 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
113
113
 
114
114
  const getImgRef = React.useMemo(
115
115
  () =>
116
- memoize((index: number) =>
117
- mergeRefs(images?.[index].imgRef, index === activeImageIndex ? activeImageRef : undefined),
116
+ memoize(
117
+ (index: number, isActive: boolean) => {
118
+ return mergeRefs(images?.[index].imgRef, isActive ? activeImageRef : undefined);
119
+ },
120
+ // memoize based on both arguments
121
+ (...args) => args.join(),
118
122
  ),
119
- [images, activeImageIndex, activeImageRef],
123
+ [images, activeImageRef],
120
124
  );
121
125
 
122
126
  return (
@@ -140,7 +144,7 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
140
144
  image={{
141
145
  ...imageProps,
142
146
  image,
143
- imgRef: getImgRef(index),
147
+ imgRef: getImgRef(index, isActive),
144
148
  }}
145
149
  scale={isActive ? scale : undefined}
146
150
  onScaleChange={onScaleChange}
@@ -120,9 +120,10 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
120
120
 
121
121
  return memoize((options?: TriggerOptions) => ({
122
122
  ref(element: HTMLElement | null) {
123
- const triggerImage = findImage(element);
124
- if (options?.activeImageIndex !== undefined && triggerImage)
125
- triggerImageRefs[options.activeImageIndex] = { current: triggerImage };
123
+ // Track trigger image ref if any
124
+ if (options?.activeImageIndex !== undefined && element) {
125
+ triggerImageRefs[options.activeImageIndex] = { current: findImage(element) };
126
+ }
126
127
  },
127
128
  onClick(e: React.MouseEvent) {
128
129
  openLightbox(e.target as HTMLElement, options);
@@ -1,3 +1,3 @@
1
1
  /** Find image in element including the element */
2
- export const findImage = (element: HTMLElement | null) =>
3
- element?.matches('img') ? (element as HTMLImageElement) : element?.querySelector('img');
2
+ export const findImage = (element: HTMLElement | null): HTMLImageElement | null =>
3
+ element?.matches('img') ? (element as HTMLImageElement) : element?.querySelector('img') || null;