@wonderflow/react-components 14.2.3 → 14.2.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"product-card-media.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-media/product-card-media.tsx"],"names":[],"mappings":";AA6BA,oBAAY,qBAAqB,GAAG,cAAc,CAAC;IACjD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CAAA;AAEF,oBAAY,yBAAyB,GAAG,KAAK,CAAC,yBAAyB,CAAC,qBAAqB,CAAC,CAAA;AAQ9F,eAAO,MAAM,gBAAgB,
|
|
1
|
+
{"version":3,"file":"product-card-media.d.ts","sourceRoot":"","sources":["../../../../src/components/product-card/product-card-media/product-card-media.tsx"],"names":[],"mappings":";AA6BA,oBAAY,qBAAqB,GAAG,cAAc,CAAC;IACjD;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC,CAAA;AAEF,oBAAY,yBAAyB,GAAG,KAAK,CAAC,yBAAyB,CAAC,qBAAqB,CAAC,CAAA;AAQ9F,eAAO,MAAM,gBAAgB,2BAsFE,CAAC"}
|
|
@@ -19,38 +19,36 @@ import { AspectRatio, Grid, Skeleton, } from '../../..';
|
|
|
19
19
|
import * as styles from './product-card-media.module.css';
|
|
20
20
|
export const ProductCardMedia = forwardRef(({ source = [], ratio = '1', isLoading = false, className, style, ...otherProps }, forwardedRef) => {
|
|
21
21
|
const [imgs, setImgs] = useState([]);
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
setImgs([]);
|
|
47
|
-
}
|
|
48
|
-
};
|
|
49
|
-
void preloadImages();
|
|
50
|
-
return () => {
|
|
22
|
+
const preloadImage = async (url) => new Promise((resolve) => {
|
|
23
|
+
const img = new Image();
|
|
24
|
+
const placeholder = 'https://wonderimages.gumlet.io/placeholders/image-placeholder.png';
|
|
25
|
+
img.src = url;
|
|
26
|
+
img.onload = () => resolve(url);
|
|
27
|
+
img.onerror = () => resolve(placeholder);
|
|
28
|
+
img.onabort = () => resolve(placeholder);
|
|
29
|
+
});
|
|
30
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
31
|
+
const preloadImages = async (source) => {
|
|
32
|
+
const images = source.slice(0, 4).map(async (s) => preloadImage(s));
|
|
33
|
+
try {
|
|
34
|
+
const urls = await Promise.all(images);
|
|
35
|
+
const t = urls.map((el, i) => ({
|
|
36
|
+
row: i < 2 ? '1' : '2',
|
|
37
|
+
col: i % 2 === 0 ? '1' : '2',
|
|
38
|
+
val: el,
|
|
39
|
+
}));
|
|
40
|
+
if (t.length === 3)
|
|
41
|
+
t[1].row = '1 / 3';
|
|
42
|
+
setImgs(t);
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
44
|
+
}
|
|
45
|
+
catch (err) {
|
|
51
46
|
setImgs([]);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
void preloadImages(source);
|
|
51
|
+
}, [preloadImages, source]);
|
|
54
52
|
if (source.length === 0)
|
|
55
53
|
return null;
|
|
56
54
|
return (_jsx("div", { ref: forwardedRef, className: className, style: { ...style }, ...otherProps, children: _jsx(AspectRatio, { ratio: ratio, children: isLoading
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wonderflow/react-components",
|
|
3
|
-
"version": "14.2.
|
|
3
|
+
"version": "14.2.4",
|
|
4
4
|
"description": "UI components from Wonderflow's Wanda design system",
|
|
5
5
|
"author": "Wonderflow",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -82,9 +82,9 @@
|
|
|
82
82
|
"@types/react-dom": "17.0.14",
|
|
83
83
|
"@types/react-table": "7.7.20",
|
|
84
84
|
"@types/react-test-renderer": "18.0.7",
|
|
85
|
-
"@wonderflow/config": "14.2.
|
|
86
|
-
"@wonderflow/tokens": "14.2.
|
|
87
|
-
"@wonderflow/charts": "14.2.
|
|
85
|
+
"@wonderflow/config": "14.2.4",
|
|
86
|
+
"@wonderflow/tokens": "14.2.4",
|
|
87
|
+
"@wonderflow/charts": "14.2.4",
|
|
88
88
|
"@types/uuid": "9.0.8",
|
|
89
89
|
"babel-loader": "8.2.5",
|
|
90
90
|
"cpy-cli": "3.1.1",
|