Skip to content
This repository was archived by the owner on Aug 19, 2022. It is now read-only.

Commit 3acce81

Browse files
committed
Add delay prop and prettier config
1 parent 6146776 commit 3acce81

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

demo/app.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ const textContainerStyle = {
3131
position: 'absolute',
3232
right: 0,
3333
top: 0
34-
}
34+
};
3535

3636
const textStyle = {
3737
color: '#fff',
3838
fontFamily: 'sans-serif',
3939
fontSize: '2.5em',
40-
textTransform: 'uppercase',
40+
textTransform: 'uppercase'
4141
};
4242

4343
class App extends React.Component {
@@ -51,20 +51,20 @@ class App extends React.Component {
5151
Image
5252
</h1>
5353
</div>
54-
<ProgressiveImage
55-
src={MD}
56-
placeholder={inline}
54+
<ProgressiveImage
55+
src={MD}
56+
placeholder={inline}
5757
srcSetData={{
5858
srcSet: `${SM} 320w, ${MD} 700w, ${LG} 2000w`,
59-
sizes: "(max-width: 2000px) 100vw, 2000px"
59+
sizes: '(max-width: 2000px) 100vw, 2000px'
6060
}}
6161
>
6262
{(image, loading, srcSetData) => {
6363
return (
64-
<img
65-
style={imageStyle}
66-
src={image}
67-
srcSet={srcSetData.srcSet}
64+
<img
65+
style={imageStyle}
66+
src={image}
67+
srcSet={srcSetData.srcSet}
6868
sizes={srcSetData.sizes}
6969
/>
7070
);

prettier.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
singleQuote: true,
3+
trailingComma: "none"
4+
};

src/index.js

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// @flow
22

3-
import * as React from "react";
3+
import * as React from 'react';
44

55
type SrcSetData = {
66
srcSet: string,
@@ -9,6 +9,7 @@ type SrcSetData = {
99

1010
type Props = {
1111
children: (string, boolean, SrcSetData) => React.Node,
12+
delay?: number,
1213
onError?: (errorEvent: Event) => void,
1314
placeholder: string,
1415
src: string,
@@ -28,7 +29,7 @@ export default class ProgressiveImage extends React.Component<Props, State> {
2829
this.state = {
2930
image: props.placeholder,
3031
loading: true,
31-
srcSetData: { srcSet: "", sizes: "" }
32+
srcSetData: { srcSet: '', sizes: '' }
3233
};
3334
}
3435

@@ -78,14 +79,16 @@ export default class ProgressiveImage extends React.Component<Props, State> {
7879
// avoid the possibility of props being updated and the
7980
// new image loading before the new props are available as
8081
// this.props.
81-
this.setState({
82-
image: this.image.src,
83-
loading: false,
84-
srcSetData: {
85-
srcSet: this.image.srcset || "",
86-
sizes: this.image.sizes || ""
87-
}
88-
});
82+
setTimeout(() => {
83+
this.setState({
84+
image: this.image.src,
85+
loading: false,
86+
srcSetData: {
87+
srcSet: this.image.srcset || '',
88+
sizes: this.image.sizes || ''
89+
}
90+
});
91+
}, this.props.delay || 0);
8992
};
9093

9194
onError = (errorEvent: Event) => {
@@ -99,7 +102,7 @@ export default class ProgressiveImage extends React.Component<Props, State> {
99102
const { image, loading, srcSetData } = this.state;
100103
const { children } = this.props;
101104

102-
if (!children || typeof children !== "function") {
105+
if (!children || typeof children !== 'function') {
103106
throw new Error(`ProgressiveImage requires a function as its only child`);
104107
}
105108

0 commit comments

Comments
 (0)