@lumx/react 3.7.6-alpha.13 → 3.7.6-alpha.15

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.13",
11
- "@lumx/icons": "^3.7.6-alpha.13",
10
+ "@lumx/core": "^3.7.6-alpha.15",
11
+ "@lumx/icons": "^3.7.6-alpha.15",
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.13"
115
+ "version": "3.7.6-alpha.15"
116
116
  }
@@ -21,13 +21,15 @@ describe(`<${Heading.displayName}>`, () => {
21
21
  const heading = screen.getByRole('heading', { level: 1, name: 'Some text' });
22
22
  expect(heading).toBeInTheDocument();
23
23
  expect(heading).toHaveClass(CLASSNAME);
24
+ expect(heading).toHaveClass('lumx-typography-display1');
24
25
  });
25
26
 
26
- it('should render with as', () => {
27
+ it('should render with as with the correct default typography', () => {
27
28
  setup({ children: 'Some text', as: 'h2' });
28
29
  const heading = screen.getByRole('heading', { level: 2, name: 'Some text' });
29
30
  expect(heading).toBeInTheDocument();
30
31
  expect(heading).toHaveClass(CLASSNAME);
32
+ expect(heading).toHaveClass('lumx-typography-headline');
31
33
  });
32
34
 
33
35
  it('should correctly render levels nested in HeadingLevel', () => {
@@ -40,6 +40,7 @@ export const Heading: Comp<HeadingProps> = forwardRef((props, ref) => {
40
40
  const { children, as, className, ...forwardedProps } = props;
41
41
  const { headingElement } = useHeadingLevel();
42
42
 
43
+ const computedHeadingElement = as || headingElement;
43
44
  return (
44
45
  <Text
45
46
  ref={ref}
@@ -49,8 +50,8 @@ export const Heading: Comp<HeadingProps> = forwardRef((props, ref) => {
49
50
  prefix: CLASSNAME,
50
51
  }),
51
52
  )}
52
- as={as || headingElement}
53
- typography={DEFAULT_TYPOGRAPHY_BY_LEVEL[headingElement]}
53
+ as={computedHeadingElement}
54
+ typography={DEFAULT_TYPOGRAPHY_BY_LEVEL[computedHeadingElement]}
54
55
  {...forwardedProps}
55
56
  >
56
57
  {children}
@@ -1,11 +1,11 @@
1
1
  import React from 'react';
2
2
 
3
- import isEqual from 'lodash/isEqual';
4
3
  import { SlideshowItem, Thumbnail } from '@lumx/react';
5
4
  import { mergeRefs } from '@lumx/react/utils/mergeRefs';
6
5
  import { useElementSizeDependentOfWindowSize } from '@lumx/react/hooks/useElementSizeDependentOfWindowSize';
7
6
  import { useImageSize } from '@lumx/react/hooks/useImageSize';
8
7
  import { getPrefersReducedMotion } from '@lumx/react/utils/getPrefersReducedMotion';
8
+ import { isEqual } from '@lumx/react/utils/object/isEqual';
9
9
 
10
10
  import { CLASSNAME } from '../constants';
11
11
  import { usePointerZoom } from './usePointerZoom';
@@ -1,5 +1,7 @@
1
1
  import React from 'react';
2
2
 
3
+ import uniqueId from 'lodash/uniqueId';
4
+
3
5
  import { mdiAbTesting } from '@lumx/icons';
4
6
  import {
5
7
  Alignment,
@@ -427,14 +429,16 @@ export const LoadingPlaceholderImage = () => {
427
429
  <FlexBox orientation="horizontal">
428
430
  <Thumbnail alt="Small image" imgRef={imgRef} image="https://picsum.photos/id/15/128/85" />
429
431
  {isShown && (
430
- <Thumbnail
431
- image="https://picsum.photos/id/15/2500/1667"
432
- alt="Large image"
433
- // Loading placeholder image
434
- loadingPlaceholderImageRef={imgRef}
435
- // Reserve space
436
- imgProps={{ width: 2500, height: 1667 }}
437
- />
432
+ <div style={{ maxHeight: 400 }}>
433
+ <Thumbnail
434
+ image={`https://picsum.photos/id/15/2500/1667?cacheBust${uniqueId()}`}
435
+ alt="Large image"
436
+ // Loading placeholder image
437
+ loadingPlaceholderImageRef={imgRef}
438
+ // Reserve space
439
+ imgProps={{ width: 2500, height: 1667 }}
440
+ />
441
+ </div>
438
442
  )}
439
443
  </FlexBox>
440
444
  </>
@@ -17,7 +17,7 @@ import { Comp, Falsy, GenericProps, HasTheme } from '@lumx/react/utils/type';
17
17
  import { getRootClassName, handleBasicClasses } from '@lumx/react/utils/className';
18
18
 
19
19
  import { mdiImageBroken } from '@lumx/icons';
20
- import { mergeRefs } from '@lumx/react/utils/mergeRefs';
20
+ import { useMergeRefs } from '@lumx/react/utils/mergeRefs';
21
21
  import { useImageLoad } from '@lumx/react/components/thumbnail/useImageLoad';
22
22
  import { useFocusPointStyle } from '@lumx/react/components/thumbnail/useFocusPointStyle';
23
23
  import { FocusPoint, ThumbnailSize, ThumbnailVariant } from './types';
@@ -199,16 +199,19 @@ export const Thumbnail: Comp<ThumbnailProps> = forwardRef((props, ref) => {
199
199
  >
200
200
  <span className={`${CLASSNAME}__background`}>
201
201
  <img
202
+ // Use placeholder image size
203
+ width={loadingPlaceholderImage?.naturalWidth}
204
+ height={loadingPlaceholderImage?.naturalHeight}
202
205
  {...imgProps}
203
- width={imgProps?.width || loadingPlaceholderImage?.naturalWidth}
204
- height={imgProps?.height || loadingPlaceholderImage?.naturalHeight}
205
206
  style={{
207
+ // Reserve space while loading (when possible)
208
+ width: isLoading ? imgProps?.width || loadingPlaceholderImage?.naturalWidth : undefined,
206
209
  ...imgProps?.style,
207
210
  ...imageErrorStyle,
208
211
  ...focusPointStyle,
209
212
  ...loadingStyle,
210
213
  }}
211
- ref={mergeRefs(setImgElement, propImgRef)}
214
+ ref={useMergeRefs(setImgElement, propImgRef)}
212
215
  className={classNames(
213
216
  handleBasicClasses({
214
217
  prefix: `${CLASSNAME}__image`,
@@ -0,0 +1,25 @@
1
+ import { isEqual } from './isEqual';
2
+
3
+ test(isEqual, () => {
4
+ expect(isEqual('', '')).toBe(true);
5
+ expect(isEqual(0, 0)).toBe(true);
6
+ expect(isEqual(Number.POSITIVE_INFINITY, Number.POSITIVE_INFINITY)).toBe(true);
7
+
8
+ expect(isEqual('', 0)).toBe(false);
9
+
10
+ expect(isEqual({}, {})).toBe(true);
11
+ expect(isEqual({ a: 1 }, { a: 1 })).toBe(true);
12
+ expect(isEqual({ a: { a: 1 } }, { a: { a: 1 } })).toBe(true);
13
+
14
+ expect(isEqual([], [])).toBe(true);
15
+
16
+ expect(isEqual([1], [2])).toBe(false);
17
+ expect(isEqual([1], [1, 2])).toBe(false);
18
+ expect(isEqual([1, 2], [2, 1])).toBe(false);
19
+
20
+ expect(isEqual({ a: 1 }, { a: 2 })).toBe(false);
21
+ expect(isEqual({ a: 1 }, {})).toBe(false);
22
+ expect(isEqual({}, { a: 1 })).toBe(false);
23
+ expect(isEqual({ a: { a: 1 } }, { a: { a: 2 } })).toBe(false);
24
+ expect(isEqual({ a: 1 }, { a: 1, b: 1 })).toBe(false);
25
+ });
@@ -0,0 +1,11 @@
1
+ /** Minimal recursive deep equal of JS values */
2
+ export function isEqual(obj1: any, obj2: any): boolean {
3
+ if (obj1 === obj2) return true;
4
+ if (typeof obj1 === 'object' && typeof obj2 === 'object') {
5
+ const keys1 = Object.keys(obj1);
6
+ const keys2 = Object.keys(obj2);
7
+ if (keys1.length !== keys2.length) return false;
8
+ return keys1.every((key1) => isEqual(obj1[key1], obj2[key1]));
9
+ }
10
+ return false;
11
+ }