@lumx/react 3.7.6-alpha.2 → 3.7.6-alpha.4
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 +8 -7
- package/index.js +27 -20
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/image-lightbox/ImageLightbox.stories.tsx +3 -3
- package/src/components/image-lightbox/internal/ImageSlide.tsx +12 -5
- package/src/components/image-lightbox/internal/ImageSlideshow.tsx +17 -6
- package/src/components/image-lightbox/types.ts +9 -11
- package/src/components/image-lightbox/useImageLightbox.tsx +11 -9
- package/src/hooks/useElementSizeDependentOfWindowSize.ts +2 -2
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, '
|
|
1380
|
-
interface
|
|
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,17 +1394,17 @@ 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,
|
|
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 */
|
|
1406
1406
|
type ManagedProps = Pick<ImageLightboxProps, 'isOpen' | 'images' | 'parentElement' | 'activeImageRef' | 'onClose' | 'activeImageIndex'>;
|
|
1407
|
+
type TriggerOptions = Pick<ImageLightboxProps, 'activeImageIndex'>;
|
|
1407
1408
|
/**
|
|
1408
1409
|
* Set up an ImageLightbox with images and triggers.
|
|
1409
1410
|
*
|
|
@@ -1418,7 +1419,7 @@ declare function useImageLightbox<P extends Partial<ImageLightboxProps>>(initial
|
|
|
1418
1419
|
* Generates trigger props
|
|
1419
1420
|
* @param index Provide an index to choose which image to display when the image lightbox opens.
|
|
1420
1421
|
* */
|
|
1421
|
-
getTriggerProps: (
|
|
1422
|
+
getTriggerProps: (options?: TriggerOptions) => {
|
|
1422
1423
|
onClick: React.MouseEventHandler;
|
|
1423
1424
|
ref: React.Ref<any>;
|
|
1424
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 =
|
|
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
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
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,7 @@ const ImageSlideshow = _ref => {
|
|
|
8222
8225
|
icon: mdiMagnifyMinusOutline,
|
|
8223
8226
|
onClick: zoomOut
|
|
8224
8227
|
})));
|
|
8228
|
+
const getImgRef = React.useMemo(() => memoize(index => mergeRefs(images === null || images === void 0 ? void 0 : images[index].imgRef, index === activeImageIndex ? activeImageRef : undefined)), [images, activeImageIndex, activeImageRef]);
|
|
8225
8229
|
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Slides, {
|
|
8226
8230
|
activeIndex: activeIndex,
|
|
8227
8231
|
theme: "dark",
|
|
@@ -8236,16 +8240,18 @@ const ImageSlideshow = _ref => {
|
|
|
8236
8240
|
image,
|
|
8237
8241
|
imgRef
|
|
8238
8242
|
} = _ref2,
|
|
8239
|
-
|
|
8243
|
+
imageProps = _objectWithoutProperties(_ref2, _excluded$z);
|
|
8240
8244
|
const isActive = index === activeIndex;
|
|
8241
|
-
return /*#__PURE__*/React.createElement(ImageSlide,
|
|
8245
|
+
return /*#__PURE__*/React.createElement(ImageSlide, {
|
|
8242
8246
|
isActive: isActive,
|
|
8243
8247
|
key: image,
|
|
8244
|
-
|
|
8245
|
-
|
|
8248
|
+
image: _objectSpread2(_objectSpread2({}, imageProps), {}, {
|
|
8249
|
+
image,
|
|
8250
|
+
imgRef: getImgRef(index)
|
|
8251
|
+
}),
|
|
8246
8252
|
scale: isActive ? scale : undefined,
|
|
8247
8253
|
onScaleChange: onScaleChange
|
|
8248
|
-
})
|
|
8254
|
+
});
|
|
8249
8255
|
})), (metadata || slideShowControls || zoomControls) && /*#__PURE__*/React.createElement(FlexBox, {
|
|
8250
8256
|
ref: footerRef,
|
|
8251
8257
|
className: `${CLASSNAME$v}__footer`,
|
|
@@ -8322,7 +8328,6 @@ const EMPTY_PROPS = {
|
|
|
8322
8328
|
images: [],
|
|
8323
8329
|
parentElement: /*#__PURE__*/React.createRef()
|
|
8324
8330
|
};
|
|
8325
|
-
|
|
8326
8331
|
/**
|
|
8327
8332
|
* Set up an ImageLightbox with images and triggers.
|
|
8328
8333
|
*
|
|
@@ -8377,21 +8382,23 @@ function useImageLightbox(initialProps) {
|
|
|
8377
8382
|
// Morph from the image in lightbox to the image in trigger
|
|
8378
8383
|
viewTransitionName: {
|
|
8379
8384
|
source: currentImageRef,
|
|
8380
|
-
//source: imageIsVisible ? currentImageRef : null,
|
|
8381
8385
|
target: triggerImageRefs[currentIndex],
|
|
8382
8386
|
name: CLASSNAME$v
|
|
8383
8387
|
}
|
|
8384
8388
|
});
|
|
8385
8389
|
}
|
|
8386
|
-
async function openLightbox(triggerElement
|
|
8390
|
+
async function openLightbox(triggerElement) {
|
|
8387
8391
|
var _triggerImageRefs;
|
|
8392
|
+
let {
|
|
8393
|
+
activeImageIndex
|
|
8394
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8388
8395
|
// If we find an image inside the trigger, animate it in transition with the opening image
|
|
8389
|
-
const triggerImage = ((_triggerImageRefs = triggerImageRefs[
|
|
8396
|
+
const triggerImage = ((_triggerImageRefs = triggerImageRefs[activeImageIndex]) === null || _triggerImageRefs === void 0 ? void 0 : _triggerImageRefs.current) || findImage(triggerElement);
|
|
8390
8397
|
|
|
8391
8398
|
// Inject the trigger image size as a fallback for better loading state
|
|
8392
8399
|
const imagesWithFallbackSize = imagesPropsRef.current.map((image, idx) => {
|
|
8393
8400
|
var _image$imgProps, _image$imgProps2;
|
|
8394
|
-
if (triggerImage && idx ===
|
|
8401
|
+
if (triggerImage && idx === activeImageIndex && !((_image$imgProps = image.imgProps) !== null && _image$imgProps !== void 0 && _image$imgProps.width) && !((_image$imgProps2 = image.imgProps) !== null && _image$imgProps2 !== void 0 && _image$imgProps2.height)) {
|
|
8395
8402
|
const imgProps = _objectSpread2(_objectSpread2({}, image.imgProps), {}, {
|
|
8396
8403
|
height: triggerImage.naturalHeight,
|
|
8397
8404
|
width: triggerImage.naturalWidth
|
|
@@ -8413,7 +8420,7 @@ function useImageLightbox(initialProps) {
|
|
|
8413
8420
|
isOpen: true,
|
|
8414
8421
|
onClose: closeLightbox,
|
|
8415
8422
|
images: imagesWithFallbackSize,
|
|
8416
|
-
activeImageIndex:
|
|
8423
|
+
activeImageIndex: activeImageIndex || 0
|
|
8417
8424
|
}));
|
|
8418
8425
|
},
|
|
8419
8426
|
// Morph from the image in trigger to the image in lightbox
|
|
@@ -8424,15 +8431,15 @@ function useImageLightbox(initialProps) {
|
|
|
8424
8431
|
}
|
|
8425
8432
|
});
|
|
8426
8433
|
}
|
|
8427
|
-
return memoize(
|
|
8434
|
+
return memoize(options => ({
|
|
8428
8435
|
ref(element) {
|
|
8429
8436
|
const triggerImage = findImage(element);
|
|
8430
|
-
if (
|
|
8437
|
+
if ((options === null || options === void 0 ? void 0 : options.activeImageIndex) !== undefined && triggerImage) triggerImageRefs[options.activeImageIndex] = {
|
|
8431
8438
|
current: triggerImage
|
|
8432
8439
|
};
|
|
8433
8440
|
},
|
|
8434
8441
|
onClick(e) {
|
|
8435
|
-
openLightbox(e.target,
|
|
8442
|
+
openLightbox(e.target, options);
|
|
8436
8443
|
}
|
|
8437
8444
|
}));
|
|
8438
8445
|
}, []);
|