@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/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.
|
|
11
|
-
"@lumx/icons": "^3.7.6-alpha.
|
|
10
|
+
"@lumx/core": "^3.7.6-alpha.3",
|
|
11
|
+
"@lumx/icons": "^3.7.6-alpha.3",
|
|
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.
|
|
115
|
+
"version": "3.7.6-alpha.3"
|
|
116
116
|
}
|
|
@@ -128,8 +128,8 @@ export const WithButtonTrigger = {
|
|
|
128
128
|
return (
|
|
129
129
|
<>
|
|
130
130
|
<Story args={{ ...args, ...imageLightboxProps }} />
|
|
131
|
-
<Button {...(getTriggerProps(0) as any)}>Image 1</Button>
|
|
132
|
-
<Button {...(getTriggerProps(1) as any)}>Image 2</Button>
|
|
131
|
+
<Button {...(getTriggerProps({ activeImageIndex: 0 }) as any)}>Image 1</Button>
|
|
132
|
+
<Button {...(getTriggerProps({ activeImageIndex: 1 }) as any)}>Image 2</Button>
|
|
133
133
|
</>
|
|
134
134
|
);
|
|
135
135
|
},
|
|
@@ -152,7 +152,7 @@ export const WithMosaicTrigger = {
|
|
|
152
152
|
<Mosaic
|
|
153
153
|
thumbnails={MULTIPLE_IMAGES.map((image, index) => ({
|
|
154
154
|
...image,
|
|
155
|
-
...getTriggerProps(index),
|
|
155
|
+
...getTriggerProps({ activeImageIndex: index }),
|
|
156
156
|
}))}
|
|
157
157
|
/>
|
|
158
158
|
</>
|
|
@@ -16,6 +16,8 @@ type ManagedProps = Pick<
|
|
|
16
16
|
|
|
17
17
|
const EMPTY_PROPS: ManagedProps = { isOpen: false, images: [], parentElement: React.createRef() };
|
|
18
18
|
|
|
19
|
+
type TriggerOptions = Pick<ImageLightboxProps, 'activeImageIndex'>;
|
|
20
|
+
|
|
19
21
|
/**
|
|
20
22
|
* Set up an ImageLightbox with images and triggers.
|
|
21
23
|
*
|
|
@@ -32,7 +34,7 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
32
34
|
* Generates trigger props
|
|
33
35
|
* @param index Provide an index to choose which image to display when the image lightbox opens.
|
|
34
36
|
* */
|
|
35
|
-
getTriggerProps: (
|
|
37
|
+
getTriggerProps: (options: TriggerOptions) => { onClick: React.MouseEventHandler; ref: React.Ref<any> };
|
|
36
38
|
/** Props to forward to the ImageLightbox */
|
|
37
39
|
imageLightboxProps: P & ManagedProps;
|
|
38
40
|
} {
|
|
@@ -71,20 +73,19 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
71
73
|
// Morph from the image in lightbox to the image in trigger
|
|
72
74
|
viewTransitionName: {
|
|
73
75
|
source: currentImageRef,
|
|
74
|
-
//source: imageIsVisible ? currentImageRef : null,
|
|
75
76
|
target: triggerImageRefs[currentIndex],
|
|
76
77
|
name: CLASSNAME,
|
|
77
78
|
},
|
|
78
79
|
});
|
|
79
80
|
}
|
|
80
81
|
|
|
81
|
-
async function openLightbox(triggerElement: HTMLElement,
|
|
82
|
+
async function openLightbox(triggerElement: HTMLElement, { activeImageIndex }: TriggerOptions = {}) {
|
|
82
83
|
// If we find an image inside the trigger, animate it in transition with the opening image
|
|
83
|
-
const triggerImage = triggerImageRefs[
|
|
84
|
+
const triggerImage = triggerImageRefs[activeImageIndex as any]?.current || findImage(triggerElement);
|
|
84
85
|
|
|
85
86
|
// Inject the trigger image size as a fallback for better loading state
|
|
86
87
|
const imagesWithFallbackSize = imagesPropsRef.current.map((image, idx) => {
|
|
87
|
-
if (triggerImage && idx ===
|
|
88
|
+
if (triggerImage && idx === activeImageIndex && !image.imgProps?.width && !image.imgProps?.height) {
|
|
88
89
|
const imgProps = {
|
|
89
90
|
...image.imgProps,
|
|
90
91
|
height: triggerImage.naturalHeight,
|
|
@@ -105,7 +106,7 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
105
106
|
isOpen: true,
|
|
106
107
|
onClose: closeLightbox,
|
|
107
108
|
images: imagesWithFallbackSize,
|
|
108
|
-
activeImageIndex:
|
|
109
|
+
activeImageIndex: activeImageIndex || 0,
|
|
109
110
|
});
|
|
110
111
|
},
|
|
111
112
|
// Morph from the image in trigger to the image in lightbox
|
|
@@ -117,13 +118,14 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
117
118
|
});
|
|
118
119
|
}
|
|
119
120
|
|
|
120
|
-
return memoize((
|
|
121
|
+
return memoize((options?: TriggerOptions) => ({
|
|
121
122
|
ref(element: HTMLElement | null) {
|
|
122
123
|
const triggerImage = findImage(element);
|
|
123
|
-
if (
|
|
124
|
+
if (options?.activeImageIndex !== undefined && triggerImage)
|
|
125
|
+
triggerImageRefs[options.activeImageIndex] = { current: triggerImage };
|
|
124
126
|
},
|
|
125
127
|
onClick(e: React.MouseEvent) {
|
|
126
|
-
openLightbox(e.target as HTMLElement,
|
|
128
|
+
openLightbox(e.target as HTMLElement, options);
|
|
127
129
|
},
|
|
128
130
|
}));
|
|
129
131
|
}, []);
|