-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathimage.js
66 lines (57 loc) · 1.33 KB
/
image.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import Knocking from './knocking';
import React, { Component, PropTypes } from 'react';
class Image extends Component {
constructor(props) {
super(props);
this.onLoad = this.onLoad.bind(this);
this.state = {
isLoading: true
};
}
componentWillReceiveProps(nextProps) {
if (this.props.src !== nextProps.src) {
this.setState({
isLoading: true
});
}
}
onLoad() {
this.setState({
isLoading: false
});
}
render() {
const { isLoading } = this.state;
const { text, src, style, styleLoading, styleWrapper } = this.props;
return (
<div style={styleWrapper}>
{isLoading && <Knocking style={styleLoading} />}
<img
alt={text}
onLoad={this.onLoad}
src={src}
style={style}
title={text}
/>
</div>
);
}
}
Image.defaultProps = {
src: 'https://files.usepages.today/usepages.today/image-placeholder.svg',
style: {},
styleLoading: {
position: 'absolute'
},
styleWrapper: {},
text: 'Alternative text'
};
Image.description = "Add some text for when the image can't be displayed.";
Image.propTypes = {
src: PropTypes.string.isRequired,
style: PropTypes.object,
styleLoading: PropTypes.object,
styleWrapper: PropTypes.object,
text: PropTypes.string
};
export default Image;