-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (35 loc) · 1.11 KB
/
index.js
File metadata and controls
40 lines (35 loc) · 1.11 KB
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
var React = require('react');
var SuperPreview = require('super-preview');
var superPreview = new SuperPreview();
module.exports = React.createClass({
getInitialState: function() {
return {
loading: true
};
},
propTypes: {
url: React.PropTypes.string.isRequired,
compressed: React.PropTypes.string
},
handleLoadEvent: function(e) {
this.setState({
loading: false
});
},
render: function render() {
var imageData = superPreview.assemble(this.props.compressed);
return React.createElement('div', {
onLoad: this.handleLoadEvent,
className: 'super-preview ' + (this.state.loading ? "super-preview--loading" : '' ),
style: {
paddingBottom: ((this.props.height / this.props.width) * 100) + '%'
}
}, React.createElement('img', {
className: 'super-preview__image',
src: this.props.url,
style: {
backgroundImage: 'url(data:image/jpeg;base64,' + imageData.base64 + ')'
}
}));
}
})