-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathindex.js
48 lines (42 loc) · 1.23 KB
/
index.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
import React from 'react';
import PropTypes from 'prop-types';
class Progress extends React.Component {
static propTypes = {
completed: (props, propName) => {
if (typeof props[propName] !== 'number')
return Progress.throwError('Invalid Props: "completed" should ∈ ℝ ');
if (props[propName] < 0 || props[propName] > 100) {
return Progress.throwError('Invalid Props: "completed" should be between 0 and 100');
}
},
color: PropTypes.string,
animation: PropTypes.number,
height: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
};
static defaultProps = {
completed: 0,
color: '#0BD318',
animation: 200,
height: 10,
};
static throwError() {
return new Error(...arguments);
}
render() {
const {color, completed, animation, height, className, children, ...rest} = this.props;
const style = {
backgroundColor: color,
width: completed + '%',
transition: `width ${animation}ms`,
height: height,
};
return (
<div className={className || 'progressbar-container'} {...rest}>
<div className="progressbar-progress" style={style}>
{children}
</div>
</div>
);
}
}
export default Progress;