@lumx/react 3.7.6-alpha.3 → 3.7.6-alpha.5

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.d.ts CHANGED
@@ -1376,10 +1376,11 @@ interface ImageBlockProps extends GenericProps, HasTheme, ImageCaptionMetadata {
1376
1376
  */
1377
1377
  declare const ImageBlock: Comp<ImageBlockProps, HTMLDivElement>;
1378
1378
 
1379
- type InheritedSlideShowProps = Pick<SlideshowProps, 'activeIndex' | 'slideshowControlsProps' | 'slideGroupLabel'>;
1380
- interface ZoomProps {
1381
- /** */
1379
+ type InheritedSlideShowProps = Pick<SlideshowProps, 'slideshowControlsProps' | 'slideGroupLabel'>;
1380
+ interface ZoomButtonProps {
1381
+ /** Zoom in button props */
1382
1382
  zoomInButtonProps?: IconButtonProps;
1383
+ /** Zoom out button props */
1383
1384
  zoomOutButtonProps?: IconButtonProps;
1384
1385
  }
1385
1386
  type InheritedThumbnailProps = Pick<ThumbnailProps, 'image' | 'alt' | 'imgProps' | 'imgRef'>;
@@ -1393,13 +1394,12 @@ interface ImagesProps {
1393
1394
  /** Ref of the active image when the lightbox is open */
1394
1395
  activeImageRef?: React.Ref<HTMLImageElement>;
1395
1396
  }
1396
- type InheritedLightboxProps = Pick<LightboxProps, 'isOpen' | 'parentElement' | 'onClose' | 'closeButtonProps'>;
1397
- type InheritedAriaAttributes = Pick<React.AriaAttributes, 'aria-label' | 'aria-labelledby'>;
1397
+ type InheritedLightboxProps = Pick<LightboxProps, 'isOpen' | 'parentElement' | 'onClose' | 'closeButtonProps' | 'aria-label' | 'aria-labelledby'>;
1398
1398
  type ForwardedProps = React.ComponentPropsWithoutRef<'div'>;
1399
1399
  /**
1400
1400
  * ImageLightbox component props
1401
1401
  */
1402
- interface ImageLightboxProps extends HasClassName, ZoomProps, ImagesProps, InheritedSlideShowProps, InheritedLightboxProps, InheritedAriaAttributes, ForwardedProps {
1402
+ interface ImageLightboxProps extends HasClassName, ZoomButtonProps, ImagesProps, InheritedSlideShowProps, InheritedLightboxProps, ForwardedProps {
1403
1403
  }
1404
1404
 
1405
1405
  /** Subset of the ImageLightboxProps managed by the useImageLightbox hook */
@@ -1419,7 +1419,7 @@ declare function useImageLightbox<P extends Partial<ImageLightboxProps>>(initial
1419
1419
  * Generates trigger props
1420
1420
  * @param index Provide an index to choose which image to display when the image lightbox opens.
1421
1421
  * */
1422
- getTriggerProps: (options: TriggerOptions) => {
1422
+ getTriggerProps: (options?: TriggerOptions) => {
1423
1423
  onClick: React.MouseEventHandler;
1424
1424
  ref: React.Ref<any>;
1425
1425
  };
package/index.js CHANGED
@@ -17,6 +17,7 @@ import memoize from 'lodash/memoize';
17
17
  import castArray from 'lodash/castArray';
18
18
  import pick from 'lodash/pick';
19
19
  import isInteger from 'lodash/isInteger';
20
+ import isEqual from 'lodash/isEqual';
20
21
  import throttle from 'lodash/throttle';
21
22
  import take from 'lodash/take';
22
23
  import uniqueId from 'lodash/uniqueId';
@@ -7817,7 +7818,7 @@ function useElementSizeDependentOfWindowSize(elementRef) {
7817
7818
  const [size, setSize] = React.useState(null);
7818
7819
  const updateSize = React.useMemo(() => throttle(() => {
7819
7820
  var _elementRef$current;
7820
- const newSize = elementRef === null || elementRef === void 0 ? void 0 : (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.getBoundingClientRect();
7821
+ const newSize = (_elementRef$current = elementRef.current) === null || _elementRef$current === void 0 ? void 0 : _elementRef$current.getBoundingClientRect();
7821
7822
  if (newSize) setSize(newSize);
7822
7823
  }, 10), [elementRef]);
7823
7824
  React.useEffect(() => {
@@ -8054,10 +8055,12 @@ const ImageSlide = /*#__PURE__*/React.memo(props => {
8054
8055
  isActive,
8055
8056
  scale,
8056
8057
  onScaleChange,
8057
- image,
8058
- imgRef: propImgRef,
8059
- imgProps,
8060
- alt
8058
+ image: {
8059
+ image,
8060
+ imgRef: propImgRef,
8061
+ imgProps,
8062
+ alt
8063
+ }
8061
8064
  } = props;
8062
8065
 
8063
8066
  // Get scroll area size
@@ -8127,7 +8130,7 @@ const ImageSlide = /*#__PURE__*/React.memo(props => {
8127
8130
  })
8128
8131
  })
8129
8132
  }));
8130
- });
8133
+ }, isEqual);
8131
8134
 
8132
8135
  const _excluded$z = ["image", "imgRef"];
8133
8136
  /** Internal image slideshow component for ImageLightbox */
@@ -8222,6 +8225,16 @@ const ImageSlideshow = _ref => {
8222
8225
  icon: mdiMagnifyMinusOutline,
8223
8226
  onClick: zoomOut
8224
8227
  })));
8228
+ const getImgRef = React.useMemo(() => memoize((index, isActive) => {
8229
+ return mergeRefs(images === null || images === void 0 ? void 0 : images[index].imgRef, isActive ? activeImageRef : undefined);
8230
+ },
8231
+ // memoize based on both arguments
8232
+ function () {
8233
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
8234
+ args[_key] = arguments[_key];
8235
+ }
8236
+ return args.join();
8237
+ }), [images, activeImageRef]);
8225
8238
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Slides, {
8226
8239
  activeIndex: activeIndex,
8227
8240
  theme: "dark",
@@ -8236,16 +8249,18 @@ const ImageSlideshow = _ref => {
8236
8249
  image,
8237
8250
  imgRef
8238
8251
  } = _ref2,
8239
- props = _objectWithoutProperties(_ref2, _excluded$z);
8252
+ imageProps = _objectWithoutProperties(_ref2, _excluded$z);
8240
8253
  const isActive = index === activeIndex;
8241
- return /*#__PURE__*/React.createElement(ImageSlide, _extends({}, props, {
8254
+ return /*#__PURE__*/React.createElement(ImageSlide, {
8242
8255
  isActive: isActive,
8243
8256
  key: image,
8244
- imgRef: mergeRefs(imgRef, isActive ? activeImageRef : undefined),
8245
- image: image,
8257
+ image: _objectSpread2(_objectSpread2({}, imageProps), {}, {
8258
+ image,
8259
+ imgRef: getImgRef(index, isActive)
8260
+ }),
8246
8261
  scale: isActive ? scale : undefined,
8247
8262
  onScaleChange: onScaleChange
8248
- }));
8263
+ });
8249
8264
  })), (metadata || slideShowControls || zoomControls) && /*#__PURE__*/React.createElement(FlexBox, {
8250
8265
  ref: footerRef,
8251
8266
  className: `${CLASSNAME$v}__footer`,
@@ -8311,7 +8326,7 @@ async function startViewTransition(_ref) {
8311
8326
  }
8312
8327
 
8313
8328
  /** Find image in element including the element */
8314
- const findImage = element => element !== null && element !== void 0 && element.matches('img') ? element : element === null || element === void 0 ? void 0 : element.querySelector('img');
8329
+ const findImage = element => element !== null && element !== void 0 && element.matches('img') ? element : (element === null || element === void 0 ? void 0 : element.querySelector('img')) || null;
8315
8330
 
8316
8331
  const _excluded$A = ["images"];
8317
8332
 
@@ -8427,10 +8442,12 @@ function useImageLightbox(initialProps) {
8427
8442
  }
8428
8443
  return memoize(options => ({
8429
8444
  ref(element) {
8430
- const triggerImage = findImage(element);
8431
- if ((options === null || options === void 0 ? void 0 : options.activeImageIndex) !== undefined && triggerImage) triggerImageRefs[options.activeImageIndex] = {
8432
- current: triggerImage
8433
- };
8445
+ // Track trigger image ref if any
8446
+ if ((options === null || options === void 0 ? void 0 : options.activeImageIndex) !== undefined && element) {
8447
+ triggerImageRefs[options.activeImageIndex] = {
8448
+ current: findImage(element)
8449
+ };
8450
+ }
8434
8451
  },
8435
8452
  onClick(e) {
8436
8453
  openLightbox(e.target, options);