Skip to content

Commit 73fcd85

Browse files
authored
fix(component): Minor improvements
Improvements
2 parents 3cc0ad6 + 3adf789 commit 73fcd85

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,9 @@
22
Progressively load images using a blur effect.
33

44
[![CircleCI](https://circleci.com/gh/wcandillon/react-progressive-image-loading.svg?style=svg)](https://circleci.com/gh/wcandillon/react-progressive-image-loading)
5+
6+
## Installation
7+
8+
```bash
9+
$ npm install react-progressive-image-loading --save
10+
```

src/index.tsx

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export interface ProgressiveImageProps {
88
preview: string;
99
src: string;
1010
background?: boolean;
11+
transitionTime?: number;
12+
timingFunction?: string;
1113
}
1214

1315
export interface ProgressiveImageState {
@@ -19,11 +21,19 @@ export class ProgressiveImage extends React.Component<ProgressiveImageProps & Di
1921

2022
private clonedProps: React.HTMLProps<HTMLDivElement | HTMLImageElement> = {};
2123

24+
static defaultProps = {
25+
transitionTime: 500,
26+
timingFunction: "ease"
27+
};
28+
2229
componentWillMount() {
2330
const {src, preview} = this.props;
24-
this.setState({ src: preview, blur: 10 });
31+
this.setState({ src: "", blur: 10 });
2532
this.cloneProps();
26-
fetch(src).then(() => this.setState({ src, blur: 0 }));
33+
fetch(preview)
34+
.then(() => this.setState({ src: preview, blur: 10 }))
35+
.then(() => fetch(src))
36+
.then(() => this.setState({ src, blur: 0 }));
2737
}
2838

2939
render() {
@@ -42,19 +52,19 @@ export class ProgressiveImage extends React.Component<ProgressiveImageProps & Di
4252
}
4353

4454
private getStyle() {
55+
const {transitionTime, timingFunction} = this.props;
4556
const {blur} = this.state;
4657
return {
4758
filter: `blur(${blur}px)`,
48-
transition: "filter 500ms ease"
59+
transition: `filter ${transitionTime}ms ${timingFunction}`
4960
};
5061
}
5162

5263
private getBackgroundStyle() {
53-
const {src, blur} = this.state;
54-
return {
55-
backgroundImage: `url(${src})`,
56-
filter: `blur(${blur}px)`,
57-
transition: "filter 500ms ease"
64+
const {src} = this.state;
65+
const style = {
66+
backgroundImage: `url(${src})`
5867
};
68+
return assign(style, this.getStyle());
5969
}
6070
}

0 commit comments

Comments
 (0)