Skip to content

Commit e840bad

Browse files
authored
Udpdate dist folder to include all items, update default wrapper styl… (#4)
Udpdate dist folder to include all items, update default wrapper style, update usecallback deps
1 parent 9f0ba5e commit e840bad

File tree

4 files changed

+69
-14
lines changed

4 files changed

+69
-14
lines changed

example/src/modules/ImageCrush.js

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { memo, useCallback, useEffect, useState } from "react";
1+
import React, { useCallback, useEffect, useState } from "react";
22
import { ErrorRender } from "./ErrorRender/ErrorRender";
33
import { getKey } from "./key";
44
import { Spinner } from "./Spinner/Spinner";
@@ -19,6 +19,7 @@ const ImageCrush = ({
1919
width,
2020
height,
2121
acEnv = "production",
22+
alt = '',
2223
...props
2324
}) => {
2425
const [image, setImage] = useState("");
@@ -29,7 +30,7 @@ const ImageCrush = ({
2930
onError(e);
3031
setIsError(true);
3132
},
32-
[setIsError]
33+
[onError, setIsError]
3334
);
3435

3536
const fetchImage = useCallback(() => {
@@ -58,7 +59,7 @@ const ImageCrush = ({
5859
})
5960
.then(() => onLoad(headers))
6061
.catch(handleError);
61-
}, [setIsError]);
62+
}, [acEnv, handleError, height, onLoad, url, width, setIsError, setImage]);
6263

6364

6465
const handleRetry = useCallback(() => {
@@ -68,9 +69,10 @@ const ImageCrush = ({
6869
useEffect(() => {
6970
if (!url) return;
7071
fetchImage();
72+
// eslint-disable-next-line react-hooks/exhaustive-deps
7173
}, [url, width, height]);
7274

73-
if (isError)
75+
if (isError) {
7476
return (
7577
<ErrorRender
7678
width={width}
@@ -80,12 +82,22 @@ const ImageCrush = ({
8082
handleRetry={handleRetry}
8183
/>
8284
);
83-
if (!image)
85+
}
86+
87+
if (!image) {
8488
return (
8589
<>{!hideSpinner && <Spinner icon={spinnerIcon} color={spinnerColor} />}</>
8690
);
91+
}
8792

88-
return <img className={animated && "assetcrush-fade-in-Image"} src={image} {...props} />;
93+
return (
94+
<img
95+
className={animated && "assetcrush-fade-in-Image"}
96+
src={image}
97+
alt={alt}
98+
{...props}
99+
/>
100+
);
89101
};
90102

91-
export default memo(ImageCrush);
103+
export default React.memo(ImageCrush);

example/src/modules/ImageCrushAdoptive.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
import React, {
2-
memo,
32
useCallback,
4-
useEffect,
53
useLayoutEffect,
64
useRef,
75
useState,
86
} from "react";
97
import ImageCrush from "./ImageCrush";
108

119
const styles = (backgroundColor) => ({
12-
wrapperStyle: { height: "inherit", width: "inherit", background: backgroundColor, display:'flex', alignItems:'center', justifyContent: 'center' }
10+
wrapperStyle: {
11+
background: backgroundColor,
12+
width: '100%',
13+
height: '100%',
14+
display:'flex',
15+
alignItems:'center',
16+
justifyContent: 'center'
17+
}
1318
})
1419

1520
const ImageCrushAdoptive = ({ backgroundColor = '#f9f9f9', url, debounce = 100, wrapperStyle, ...restProps }) => {
@@ -28,12 +33,13 @@ const ImageCrushAdoptive = ({ backgroundColor = '#f9f9f9', url, debounce = 100,
2833
setWidth(_width);
2934
setHeight(_height);
3035
}
31-
}, [setWidth,setHeight, setCurrentHeight])
36+
}, [setWidth,setHeight, setCurrentHeight, width, height])
3237

3338
useLayoutEffect(() => {
3439
const handler = setTimeout(onLayout, debounce);
3540

3641
return () => clearTimeout(handler);
42+
// eslint-disable-next-line react-hooks/exhaustive-deps
3743
}, []);
3844

3945

@@ -46,4 +52,4 @@ const ImageCrushAdoptive = ({ backgroundColor = '#f9f9f9', url, debounce = 100,
4652
);
4753
};
4854

49-
export default memo(ImageCrushAdoptive);
55+
export default React.memo(ImageCrushAdoptive);

index.d.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import React from 'react';
2+
3+
export interface ImageCrushProps {
4+
animated?: boolean,
5+
reloadIconColor?: string,
6+
reloadIcon?: React.ReactNode,
7+
spinnerIcon?: React.ReactNode,
8+
spinnerColor?: string,
9+
hideSpinner?: boolean,
10+
onError?: function,
11+
onLoad?: function,
12+
url: string,
13+
width?: number,
14+
height?: number,
15+
acEnv?: string,
16+
alt?: string,
17+
className?: string,
18+
style?: React.CSSProperties
19+
}
20+
21+
declare const ImageCrush: React.FC<ImageCrushProps>;
22+
23+
export interface ImageCrushAdoptiveProps extends ImageCrushProps {
24+
backgroundColor?: string,
25+
debounce?: number,
26+
wrapperStyle?: React.CSSProperties
27+
}
28+
29+
declare const ImageCrushAdoptive: React.FC<ImageCrushAdoptiveProps>;
30+
31+
declare const setKey: (key: string) => void;
32+
33+
export {
34+
ImageCrush,
35+
ImageCrushAdoptive,
36+
setKey
37+
};

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "@assetcrush/reactjs-sdk",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"description": "A simple reactjs library to resize image on fly",
55
"main": "dist/index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
8-
"build": "babel example/src/modules/** -d ./dist"
8+
"build": "babel example/src/modules/ -d ./dist --copy-files"
99
},
1010
"repository": {
1111
"type": "git",

0 commit comments

Comments
 (0)