@lumx/react 3.7.6-alpha.2 → 3.7.6-alpha.3
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
|
@@ -1404,6 +1404,7 @@ interface ImageLightboxProps extends HasClassName, ZoomProps, ImagesProps, Inher
|
|
|
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
|
@@ -8322,7 +8322,6 @@ const EMPTY_PROPS = {
|
|
|
8322
8322
|
images: [],
|
|
8323
8323
|
parentElement: /*#__PURE__*/React.createRef()
|
|
8324
8324
|
};
|
|
8325
|
-
|
|
8326
8325
|
/**
|
|
8327
8326
|
* Set up an ImageLightbox with images and triggers.
|
|
8328
8327
|
*
|
|
@@ -8377,21 +8376,23 @@ function useImageLightbox(initialProps) {
|
|
|
8377
8376
|
// Morph from the image in lightbox to the image in trigger
|
|
8378
8377
|
viewTransitionName: {
|
|
8379
8378
|
source: currentImageRef,
|
|
8380
|
-
//source: imageIsVisible ? currentImageRef : null,
|
|
8381
8379
|
target: triggerImageRefs[currentIndex],
|
|
8382
8380
|
name: CLASSNAME$v
|
|
8383
8381
|
}
|
|
8384
8382
|
});
|
|
8385
8383
|
}
|
|
8386
|
-
async function openLightbox(triggerElement
|
|
8384
|
+
async function openLightbox(triggerElement) {
|
|
8387
8385
|
var _triggerImageRefs;
|
|
8386
|
+
let {
|
|
8387
|
+
activeImageIndex
|
|
8388
|
+
} = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
8388
8389
|
// If we find an image inside the trigger, animate it in transition with the opening image
|
|
8389
|
-
const triggerImage = ((_triggerImageRefs = triggerImageRefs[
|
|
8390
|
+
const triggerImage = ((_triggerImageRefs = triggerImageRefs[activeImageIndex]) === null || _triggerImageRefs === void 0 ? void 0 : _triggerImageRefs.current) || findImage(triggerElement);
|
|
8390
8391
|
|
|
8391
8392
|
// Inject the trigger image size as a fallback for better loading state
|
|
8392
8393
|
const imagesWithFallbackSize = imagesPropsRef.current.map((image, idx) => {
|
|
8393
8394
|
var _image$imgProps, _image$imgProps2;
|
|
8394
|
-
if (triggerImage && idx ===
|
|
8395
|
+
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
8396
|
const imgProps = _objectSpread2(_objectSpread2({}, image.imgProps), {}, {
|
|
8396
8397
|
height: triggerImage.naturalHeight,
|
|
8397
8398
|
width: triggerImage.naturalWidth
|
|
@@ -8413,7 +8414,7 @@ function useImageLightbox(initialProps) {
|
|
|
8413
8414
|
isOpen: true,
|
|
8414
8415
|
onClose: closeLightbox,
|
|
8415
8416
|
images: imagesWithFallbackSize,
|
|
8416
|
-
activeImageIndex:
|
|
8417
|
+
activeImageIndex: activeImageIndex || 0
|
|
8417
8418
|
}));
|
|
8418
8419
|
},
|
|
8419
8420
|
// Morph from the image in trigger to the image in lightbox
|
|
@@ -8424,15 +8425,15 @@ function useImageLightbox(initialProps) {
|
|
|
8424
8425
|
}
|
|
8425
8426
|
});
|
|
8426
8427
|
}
|
|
8427
|
-
return memoize(
|
|
8428
|
+
return memoize(options => ({
|
|
8428
8429
|
ref(element) {
|
|
8429
8430
|
const triggerImage = findImage(element);
|
|
8430
|
-
if (
|
|
8431
|
+
if ((options === null || options === void 0 ? void 0 : options.activeImageIndex) !== undefined && triggerImage) triggerImageRefs[options.activeImageIndex] = {
|
|
8431
8432
|
current: triggerImage
|
|
8432
8433
|
};
|
|
8433
8434
|
},
|
|
8434
8435
|
onClick(e) {
|
|
8435
|
-
openLightbox(e.target,
|
|
8436
|
+
openLightbox(e.target, options);
|
|
8436
8437
|
}
|
|
8437
8438
|
}));
|
|
8438
8439
|
}, []);
|