@lumx/react 3.8.2-alpha.0 → 3.8.2-alpha.2
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.js +12 -4
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/image-lightbox/ImageLightbox.test.tsx +10 -18
- package/src/components/image-lightbox/ImageLightbox.tsx +16 -3
- package/src/components/image-lightbox/internal/ImageSlide.tsx +2 -2
- package/src/hooks/{useElementSizeDependentOfWindowSize.ts → useSizeOnWindowResize.ts} +1 -3
- package/src/utils/unref.ts +0 -0
package/package.json
CHANGED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/core": "^3.8.2-alpha.
|
|
10
|
-
"@lumx/icons": "^3.8.2-alpha.
|
|
9
|
+
"@lumx/core": "^3.8.2-alpha.2",
|
|
10
|
+
"@lumx/icons": "^3.8.2-alpha.2",
|
|
11
11
|
"@popperjs/core": "^2.5.4",
|
|
12
12
|
"body-scroll-lock": "^3.1.5",
|
|
13
13
|
"classnames": "^2.3.2",
|
|
@@ -111,5 +111,5 @@
|
|
|
111
111
|
"build:storybook": "storybook build"
|
|
112
112
|
},
|
|
113
113
|
"sideEffects": false,
|
|
114
|
-
"version": "3.8.2-alpha.
|
|
114
|
+
"version": "3.8.2-alpha.2"
|
|
115
115
|
}
|
|
@@ -5,7 +5,7 @@ import { render, within, screen } from '@testing-library/react';
|
|
|
5
5
|
import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
|
|
6
6
|
import userEvent from '@testing-library/user-event';
|
|
7
7
|
import { useImageSize } from '@lumx/react/hooks/useImageSize';
|
|
8
|
-
import {
|
|
8
|
+
import { useSizeOnWindowResize } from '@lumx/react/hooks/useSizeOnWindowResize';
|
|
9
9
|
|
|
10
10
|
import { ImageLightbox } from './ImageLightbox';
|
|
11
11
|
import { ImageLightboxProps } from './types';
|
|
@@ -19,7 +19,7 @@ import Meta, {
|
|
|
19
19
|
} from './ImageLightbox.stories';
|
|
20
20
|
|
|
21
21
|
jest.mock('@lumx/react/hooks/useImageSize');
|
|
22
|
-
jest.mock('@lumx/react/hooks/
|
|
22
|
+
jest.mock('@lumx/react/hooks/useSizeOnWindowResize');
|
|
23
23
|
|
|
24
24
|
const CLASSNAME = ImageLightbox.className as string;
|
|
25
25
|
const baseProps = Meta.args;
|
|
@@ -56,7 +56,7 @@ const queries = {
|
|
|
56
56
|
describe(`<${ImageLightbox.displayName}>`, () => {
|
|
57
57
|
beforeEach(() => {
|
|
58
58
|
(useImageSize as any).mockReturnValue(null);
|
|
59
|
-
(
|
|
59
|
+
(useSizeOnWindowResize as any).mockReturnValue([null, jest.fn()]);
|
|
60
60
|
});
|
|
61
61
|
|
|
62
62
|
describe('render', () => {
|
|
@@ -189,7 +189,7 @@ describe(`<${ImageLightbox.displayName}>`, () => {
|
|
|
189
189
|
const scrollAreaSize = { width: 600, height: 600 };
|
|
190
190
|
beforeEach(() => {
|
|
191
191
|
(useImageSize as any).mockImplementation((_: any, getInitialSize: any) => getInitialSize?.() || null);
|
|
192
|
-
(
|
|
192
|
+
(useSizeOnWindowResize as any).mockReturnValue([scrollAreaSize, jest.fn()]);
|
|
193
193
|
});
|
|
194
194
|
|
|
195
195
|
it('should use the image initial size', () => {
|
|
@@ -207,23 +207,15 @@ describe(`<${ImageLightbox.displayName}>`, () => {
|
|
|
207
207
|
});
|
|
208
208
|
|
|
209
209
|
it('should zoom on zoom button pressed', async () => {
|
|
210
|
-
|
|
211
|
-
const imageLightbox = queries.getImageLightbox();
|
|
212
|
-
|
|
213
|
-
// Initial image style
|
|
214
|
-
const image = queries.queryImage(imageLightbox, 'Image 1');
|
|
215
|
-
|
|
216
|
-
expect(image).toHaveStyle({
|
|
217
|
-
maxHeight: `${scrollAreaSize.height}px`,
|
|
218
|
-
maxWidth: `${scrollAreaSize.width}px`,
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
// Update image size (simulate image loaded)
|
|
210
|
+
// Set image size (simulate image loaded)
|
|
222
211
|
const imageSize = { width: 500, height: 300 };
|
|
223
212
|
(useImageSize as any).mockReturnValue(imageSize);
|
|
224
|
-
rerender();
|
|
225
213
|
|
|
226
|
-
|
|
214
|
+
setup(SingleImageWithZoom.args);
|
|
215
|
+
const imageLightbox = queries.getImageLightbox();
|
|
216
|
+
|
|
217
|
+
// Image style
|
|
218
|
+
const image = queries.queryImage(imageLightbox, 'Image 1');
|
|
227
219
|
expect(image).toHaveStyle({ width: `${imageSize.width}px`, height: `${imageSize.height}px` });
|
|
228
220
|
|
|
229
221
|
// Scroll area is bigger than the image, it should not be focusable
|
|
@@ -4,7 +4,7 @@ import classNames from 'classnames';
|
|
|
4
4
|
import { Lightbox } from '@lumx/react';
|
|
5
5
|
import { ClickAwayProvider } from '@lumx/react/utils';
|
|
6
6
|
import type { Comp } from '@lumx/react/utils/type';
|
|
7
|
-
import {
|
|
7
|
+
import { useMergeRefs } from '@lumx/react/utils/mergeRefs';
|
|
8
8
|
|
|
9
9
|
import { ImageSlideshow } from './internal/ImageSlideshow';
|
|
10
10
|
import { useImageLightbox } from './useImageLightbox';
|
|
@@ -32,6 +32,19 @@ const Inner: Comp<ImageLightboxProps, HTMLDivElement> = forwardRef((props, ref)
|
|
|
32
32
|
const imageRef = React.useRef(null);
|
|
33
33
|
const clickAwayChildrenRefs = React.useRef([imageRef, footerRef]);
|
|
34
34
|
|
|
35
|
+
const onClickAway = React.useCallback(
|
|
36
|
+
(evt: Event) => {
|
|
37
|
+
const targetElement = evt.target;
|
|
38
|
+
if (!(targetElement instanceof HTMLElement) || !(evt instanceof MouseEvent)) return;
|
|
39
|
+
|
|
40
|
+
// Skip click away if clicking on the scrollbar
|
|
41
|
+
if (targetElement.clientWidth < evt.clientX || targetElement.clientHeight < evt.clientY) return;
|
|
42
|
+
|
|
43
|
+
onClose?.();
|
|
44
|
+
},
|
|
45
|
+
[onClose],
|
|
46
|
+
);
|
|
47
|
+
|
|
35
48
|
return (
|
|
36
49
|
<Lightbox
|
|
37
50
|
ref={ref}
|
|
@@ -43,7 +56,7 @@ const Inner: Comp<ImageLightboxProps, HTMLDivElement> = forwardRef((props, ref)
|
|
|
43
56
|
focusElement={currentPaginationItemRef}
|
|
44
57
|
{...forwardedProps}
|
|
45
58
|
>
|
|
46
|
-
<ClickAwayProvider childrenRefs={clickAwayChildrenRefs} callback={
|
|
59
|
+
<ClickAwayProvider childrenRefs={clickAwayChildrenRefs} callback={onClickAway}>
|
|
47
60
|
<ImageSlideshow
|
|
48
61
|
activeImageIndex={activeImageIndex}
|
|
49
62
|
slideGroupLabel={slideGroupLabel}
|
|
@@ -52,7 +65,7 @@ const Inner: Comp<ImageLightboxProps, HTMLDivElement> = forwardRef((props, ref)
|
|
|
52
65
|
zoomInButtonProps={zoomInButtonProps}
|
|
53
66
|
zoomOutButtonProps={zoomOutButtonProps}
|
|
54
67
|
footerRef={footerRef}
|
|
55
|
-
activeImageRef={
|
|
68
|
+
activeImageRef={useMergeRefs(propImageRef, imageRef)}
|
|
56
69
|
currentPaginationItemRef={currentPaginationItemRef}
|
|
57
70
|
/>
|
|
58
71
|
</ClickAwayProvider>
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
|
|
3
3
|
import { SlideshowItem, Thumbnail } from '@lumx/react';
|
|
4
4
|
import { useMergeRefs } from '@lumx/react/utils/mergeRefs';
|
|
5
|
-
import {
|
|
5
|
+
import { useSizeOnWindowResize } from '@lumx/react/hooks/useSizeOnWindowResize';
|
|
6
6
|
import { useImageSize } from '@lumx/react/hooks/useImageSize';
|
|
7
7
|
import { getPrefersReducedMotion } from '@lumx/react/utils/browser/getPrefersReducedMotion';
|
|
8
8
|
import { isEqual } from '@lumx/react/utils/object/isEqual';
|
|
@@ -30,7 +30,7 @@ export const ImageSlide = React.memo((props: ImageSlideProps) => {
|
|
|
30
30
|
|
|
31
31
|
// Get scroll area size
|
|
32
32
|
const scrollAreaRef = React.useRef<HTMLDivElement>(null);
|
|
33
|
-
const [scrollAreaSize, updateSize] =
|
|
33
|
+
const [scrollAreaSize, updateSize] = useSizeOnWindowResize(scrollAreaRef);
|
|
34
34
|
React.useEffect(() => {
|
|
35
35
|
// Update size when active
|
|
36
36
|
if (isActive) updateSize();
|
|
@@ -11,9 +11,7 @@ import { RectSize } from '@lumx/react/utils/type';
|
|
|
11
11
|
* @param elementRef Element to observe
|
|
12
12
|
* @return the size and a manual update callback
|
|
13
13
|
*/
|
|
14
|
-
export function
|
|
15
|
-
elementRef: React.RefObject<HTMLElement>,
|
|
16
|
-
): [RectSize | null, () => void] {
|
|
14
|
+
export function useSizeOnWindowResize(elementRef: React.RefObject<HTMLElement>): [RectSize | null, () => void] {
|
|
17
15
|
const [size, setSize] = React.useState<null | RectSize>(null);
|
|
18
16
|
const updateSize = React.useMemo(
|
|
19
17
|
() =>
|
package/src/utils/unref.ts
DELETED
|
File without changes
|