@lumx/react 3.7.6-alpha.3 → 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 +7 -7
- package/index.js +17 -11
- package/index.js.map +1 -1
- package/package.json +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 +1 -1
- package/src/hooks/useElementSizeDependentOfWindowSize.ts +2 -2
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.4",
|
|
11
|
+
"@lumx/icons": "^3.7.6-alpha.4",
|
|
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.4"
|
|
116
116
|
}
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
+
import isEqual from 'lodash/isEqual';
|
|
3
4
|
import { SlideshowItem, Thumbnail } from '@lumx/react';
|
|
4
5
|
import { mergeRefs } from '@lumx/react/utils/mergeRefs';
|
|
5
6
|
import { useElementSizeDependentOfWindowSize } from '@lumx/react/hooks/useElementSizeDependentOfWindowSize';
|
|
6
7
|
import { useImageSize } from '@lumx/react/hooks/useImageSize';
|
|
7
|
-
|
|
8
8
|
import { getPrefersReducedMotion } from '@lumx/react/utils/getPrefersReducedMotion';
|
|
9
|
+
|
|
9
10
|
import { CLASSNAME } from '../constants';
|
|
10
11
|
import { usePointerZoom } from './usePointerZoom';
|
|
11
12
|
import { useAnimateScroll } from './useAnimateScroll';
|
|
12
|
-
import type {
|
|
13
|
+
import type { ImageProps } from '../types';
|
|
13
14
|
|
|
14
|
-
export interface ImageSlideProps
|
|
15
|
+
export interface ImageSlideProps {
|
|
16
|
+
image: ImageProps;
|
|
15
17
|
isActive?: boolean;
|
|
16
18
|
scale?: number;
|
|
17
19
|
onScaleChange?: (value: number) => void;
|
|
@@ -19,7 +21,12 @@ export interface ImageSlideProps extends InheritedThumbnailProps {
|
|
|
19
21
|
|
|
20
22
|
/** Internal image slide component for ImageLightbox */
|
|
21
23
|
export const ImageSlide = React.memo((props: ImageSlideProps) => {
|
|
22
|
-
const {
|
|
24
|
+
const {
|
|
25
|
+
isActive,
|
|
26
|
+
scale,
|
|
27
|
+
onScaleChange,
|
|
28
|
+
image: { image, imgRef: propImgRef, imgProps, alt },
|
|
29
|
+
} = props;
|
|
23
30
|
|
|
24
31
|
// Get scroll area size
|
|
25
32
|
const scrollAreaRef = React.useRef<HTMLDivElement>(null);
|
|
@@ -96,4 +103,4 @@ export const ImageSlide = React.memo((props: ImageSlideProps) => {
|
|
|
96
103
|
/>
|
|
97
104
|
</SlideshowItem>
|
|
98
105
|
);
|
|
99
|
-
});
|
|
106
|
+
}, isEqual);
|
|
@@ -4,12 +4,13 @@ import { mdiMagnifyMinusOutline, mdiMagnifyPlusOutline } from '@lumx/icons';
|
|
|
4
4
|
import { FlexBox, IconButton, Slides, SlideshowControls } from '@lumx/react';
|
|
5
5
|
import { mergeRefs } from '@lumx/react/utils/mergeRefs';
|
|
6
6
|
|
|
7
|
+
import memoize from 'lodash/memoize';
|
|
7
8
|
import { ImageCaption } from '../../image-block/ImageCaption';
|
|
8
9
|
import { CLASSNAME } from '../constants';
|
|
9
|
-
import type { ImagesProps, InheritedSlideShowProps,
|
|
10
|
+
import type { ImagesProps, InheritedSlideShowProps, ZoomButtonProps } from '../types';
|
|
10
11
|
import { ImageSlide } from './ImageSlide';
|
|
11
12
|
|
|
12
|
-
export interface ImageSlideshowProps extends InheritedSlideShowProps,
|
|
13
|
+
export interface ImageSlideshowProps extends InheritedSlideShowProps, ZoomButtonProps, ImagesProps {
|
|
13
14
|
currentPaginationItemRef?: React.Ref<HTMLButtonElement>;
|
|
14
15
|
footerRef?: React.Ref<HTMLDivElement>;
|
|
15
16
|
}
|
|
@@ -110,6 +111,14 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
|
|
|
110
111
|
</>
|
|
111
112
|
);
|
|
112
113
|
|
|
114
|
+
const getImgRef = React.useMemo(
|
|
115
|
+
() =>
|
|
116
|
+
memoize((index: number) =>
|
|
117
|
+
mergeRefs(images?.[index].imgRef, index === activeImageIndex ? activeImageRef : undefined),
|
|
118
|
+
),
|
|
119
|
+
[images, activeImageIndex, activeImageRef],
|
|
120
|
+
);
|
|
121
|
+
|
|
113
122
|
return (
|
|
114
123
|
<>
|
|
115
124
|
<Slides
|
|
@@ -122,15 +131,17 @@ export const ImageSlideshow: React.FC<ImageSlideshowProps> = ({
|
|
|
122
131
|
slidesId={slideshowSlidesId}
|
|
123
132
|
toggleAutoPlay={toggleAutoPlay}
|
|
124
133
|
>
|
|
125
|
-
{images.map(({ image, imgRef, ...
|
|
134
|
+
{images.map(({ image, imgRef, ...imageProps }, index) => {
|
|
126
135
|
const isActive = index === activeIndex;
|
|
127
136
|
return (
|
|
128
137
|
<ImageSlide
|
|
129
|
-
{...props}
|
|
130
138
|
isActive={isActive}
|
|
131
139
|
key={image}
|
|
132
|
-
|
|
133
|
-
|
|
140
|
+
image={{
|
|
141
|
+
...imageProps,
|
|
142
|
+
image,
|
|
143
|
+
imgRef: getImgRef(index),
|
|
144
|
+
}}
|
|
134
145
|
scale={isActive ? scale : undefined}
|
|
135
146
|
onScaleChange={onScaleChange}
|
|
136
147
|
/>
|
|
@@ -4,14 +4,12 @@ import type { IconButtonProps, LightboxProps, SlideshowProps, ThumbnailProps } f
|
|
|
4
4
|
import type { HasClassName } from '@lumx/react/utils/type';
|
|
5
5
|
import type { ImageCaptionMetadata } from '@lumx/react/components/image-block/ImageCaption';
|
|
6
6
|
|
|
7
|
-
export type InheritedSlideShowProps = Pick<
|
|
8
|
-
SlideshowProps,
|
|
9
|
-
'activeIndex' | 'slideshowControlsProps' | 'slideGroupLabel'
|
|
10
|
-
>;
|
|
7
|
+
export type InheritedSlideShowProps = Pick<SlideshowProps, 'slideshowControlsProps' | 'slideGroupLabel'>;
|
|
11
8
|
|
|
12
|
-
export interface
|
|
13
|
-
/** */
|
|
9
|
+
export interface ZoomButtonProps {
|
|
10
|
+
/** Zoom in button props */
|
|
14
11
|
zoomInButtonProps?: IconButtonProps;
|
|
12
|
+
/** Zoom out button props */
|
|
15
13
|
zoomOutButtonProps?: IconButtonProps;
|
|
16
14
|
}
|
|
17
15
|
|
|
@@ -30,9 +28,10 @@ export interface ImagesProps {
|
|
|
30
28
|
activeImageRef?: React.Ref<HTMLImageElement>;
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
export type InheritedLightboxProps = Pick<
|
|
34
|
-
|
|
35
|
-
|
|
31
|
+
export type InheritedLightboxProps = Pick<
|
|
32
|
+
LightboxProps,
|
|
33
|
+
'isOpen' | 'parentElement' | 'onClose' | 'closeButtonProps' | 'aria-label' | 'aria-labelledby'
|
|
34
|
+
>;
|
|
36
35
|
|
|
37
36
|
export type ForwardedProps = React.ComponentPropsWithoutRef<'div'>;
|
|
38
37
|
|
|
@@ -41,9 +40,8 @@ export type ForwardedProps = React.ComponentPropsWithoutRef<'div'>;
|
|
|
41
40
|
*/
|
|
42
41
|
export interface ImageLightboxProps
|
|
43
42
|
extends HasClassName,
|
|
44
|
-
|
|
43
|
+
ZoomButtonProps,
|
|
45
44
|
ImagesProps,
|
|
46
45
|
InheritedSlideShowProps,
|
|
47
46
|
InheritedLightboxProps,
|
|
48
|
-
InheritedAriaAttributes,
|
|
49
47
|
ForwardedProps {}
|
|
@@ -34,7 +34,7 @@ export function useImageLightbox<P extends Partial<ImageLightboxProps>>(
|
|
|
34
34
|
* Generates trigger props
|
|
35
35
|
* @param index Provide an index to choose which image to display when the image lightbox opens.
|
|
36
36
|
* */
|
|
37
|
-
getTriggerProps: (options
|
|
37
|
+
getTriggerProps: (options?: TriggerOptions) => { onClick: React.MouseEventHandler; ref: React.Ref<any> };
|
|
38
38
|
/** Props to forward to the ImageLightbox */
|
|
39
39
|
imageLightboxProps: P & ManagedProps;
|
|
40
40
|
} {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
|
|
3
|
-
import { RectSize } from '@lumx/react/utils/type';
|
|
4
3
|
import throttle from 'lodash/throttle';
|
|
4
|
+
import { RectSize } from '@lumx/react/utils/type';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Observe element size (only works if it's size depends on the window size).
|
|
@@ -18,7 +18,7 @@ export function useElementSizeDependentOfWindowSize(
|
|
|
18
18
|
const updateSize = React.useMemo(
|
|
19
19
|
() =>
|
|
20
20
|
throttle(() => {
|
|
21
|
-
const newSize = elementRef
|
|
21
|
+
const newSize = elementRef.current?.getBoundingClientRect();
|
|
22
22
|
if (newSize) setSize(newSize);
|
|
23
23
|
}, 10),
|
|
24
24
|
[elementRef],
|