Skip to content

Commit 1e2f253

Browse files
author
Minh Tran
committed
Build
1 parent 2661f3e commit 1e2f253

File tree

3 files changed

+156
-17
lines changed

3 files changed

+156
-17
lines changed

lib/Component.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

lib/ProgressBar.js

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
'use strict';
2+
3+
var React = require('react');
4+
5+
var ProgressBar = React.createClass({
6+
displayName: 'ProgressBar',
7+
8+
propTypes: {
9+
percent: React.PropTypes.number.isRequired,
10+
onTop: React.PropTypes.bool,
11+
autoIncrement: React.PropTypes.bool,
12+
intervalTime: React.PropTypes.number
13+
},
14+
getDefaultProps: function getDefaultProps() {
15+
return {
16+
percent: -1,
17+
onTop: false,
18+
autoIncrement: false,
19+
intervalTime: 200
20+
};
21+
},
22+
getInitialState: function getInitialState() {
23+
return {
24+
percent: this.props.percent
25+
};
26+
},
27+
increment: function increment() {
28+
var percent = this.state.percent + (Math.random() + 1 - Math.random());
29+
percent = percent < 99 ? percent : 99;
30+
this.setState({
31+
percent: percent
32+
});
33+
},
34+
componentWillUnmount: function componentWillUnmount() {
35+
if (this.interval) {
36+
clearInterval(this.interval);
37+
}
38+
},
39+
componentWillReceiveProps: function componentWillReceiveProps(nextProps) {
40+
if (this.interval) {
41+
clearInterval(this.interval);
42+
}
43+
44+
if (nextProps.autoIncrement && nextProps.percent >= 0 && nextProps.percent < 99) {
45+
this.interval = setInterval(this.increment, nextProps.intervalTime);
46+
}
47+
48+
if (nextProps.percent >= 100) {
49+
this.setState({
50+
percent: 99.9
51+
}, function () {
52+
setTimeout((function () {
53+
this.setState({
54+
percent: 100
55+
});
56+
}).bind(this), 400);
57+
});
58+
} else {
59+
this.setState({
60+
percent: nextProps.percent
61+
});
62+
}
63+
},
64+
render: function render() {
65+
var className = 'react-progress-bar' + (this.props.onTop ? ' react-progress-bar-on-top' : '');
66+
if (this.state.percent < 0 || this.state.percent >= 100) {
67+
className += ' react-progress-bar-hide';
68+
}
69+
var style = { width: this.state.percent + '%' };
70+
return React.createElement(
71+
'div',
72+
{ className: className },
73+
React.createElement('div', { className: 'react-progress-bar-percent', style: style }),
74+
React.createElement(
75+
'div',
76+
{ className: 'react-progress-bar-spinner' },
77+
React.createElement('div', { className: 'react-progress-bar-spinner-icon' })
78+
)
79+
);
80+
}
81+
});
82+
83+
module.exports = ProgressBar;

lib/progress-bar.css

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
@-webkit-keyframes react-progress-spinner {
2+
0% {
3+
-webkit-transform: rotate(0deg);
4+
}
5+
100% {
6+
-webkit-transform: rotate(360deg);
7+
}
8+
}
9+
10+
@keyframes react-progress-spinner {
11+
0% {
12+
-webkit-transform: rotate(0deg);
13+
transform: rotate(0deg);
14+
}
15+
100% {
16+
-webkit-transform: rotate(360deg);
17+
transform: rotate(360deg);
18+
}
19+
}
20+
21+
.react-progress-bar {
22+
position: fixed;
23+
top: 0;
24+
left: 0;
25+
width: 100%;
26+
visibility: visible;
27+
opacity: 1;
28+
-webkit-transition: all 400ms;
29+
transition: all 400ms;
30+
z-index: 9999999;
31+
}
32+
33+
.react-progress-bar.react-progress-bar-on-top {
34+
height: 100%;
35+
}
36+
37+
.react-progress-bar.react-progress-bar-hide {
38+
opacity: 0;
39+
visibility: hidden;
40+
z-index: -10;
41+
}
42+
43+
.react-progress-bar.react-progress-bar-hide .react-progress-bar-percent {
44+
width: 0;
45+
}
46+
47+
.react-progress-bar-percent {
48+
height: 2px;
49+
background: #29D;
50+
box-shadow: 0 0 10px #29D, 0 0 5px #29D;
51+
-webkit-transition: all 200ms ease;
52+
transition: all 200ms ease;
53+
width: 5px;
54+
}
55+
56+
.react-progress-bar-spinner {
57+
display: block;
58+
position: fixed;
59+
top: 15px;
60+
left: 15px;
61+
}
62+
63+
.react-progress-bar-spinner-icon {
64+
width: 18px;
65+
height: 18px;
66+
box-sizing: border-box;
67+
border: solid 2px transparent;
68+
border-top-color: #29d;
69+
border-left-color: #29d;
70+
border-radius: 50%;
71+
-webkit-animation: react-progress-spinner 400ms linear infinite;
72+
animation: react-progress-spinner 400ms linear infinite;
73+
}

0 commit comments

Comments
 (0)