-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathLoading.js
58 lines (53 loc) · 1.27 KB
/
Loading.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
require('./Loading.css')
var classNames = require('classnames')
var Glyphicon = require('react-bootstrap/lib/Glyphicon')
var React = require('react')
var Loading = React.createClass({
propTypes: {
delay: React.PropTypes.oneOfType([
React.PropTypes.bool,
React.PropTypes.number
]),
inline: React.PropTypes.bool,
text: React.PropTypes.string
},
getDefaultProps() {
return {
delay: 500,
inline: false
}
},
getInitialState() {
return {
delaying: !!this.props.delay
}
},
componentDidMount() {
if (this.props.delay) {
this.timeout = setTimeout(this.handleDisplay, this.props.delay)
}
},
componentWillUnmount() {
if (this.timeout) {
clearTimeout(this.timeout)
}
},
handleDisplay() {
this.timeout = null
this.setState({delaying: false})
},
render() {
var {delay, inline, text} = this.props
var {delaying} = this.state
var className = classNames('Loading', {
'Loading--delaying': delaying,
'Loading--displaying': delay && !delaying,
'Loading--inline': inline
})
return <div className={className}>
<Glyphicon glyph="refresh"/>
{text && <div className="Loading__text">{text}…</div>}
</div>
}
})
module.exports = Loading