Skip to content
This repository was archived by the owner on Apr 23, 2021. It is now read-only.

Commit cf8ca77

Browse files
Add initial incomplete implementation
1 parent 83764b4 commit cf8ca77

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed

react-progressbar.js

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import React from 'react';
2+
import uniqueId from 'lodash.uniqueid';
3+
import ProgressBar from 'progressbar.js';
4+
5+
class Shape extends React.Component {
6+
constructor(props) {
7+
super(props);
8+
9+
this.state = {
10+
id: uniqueId('progressbar'),
11+
shape: null
12+
};
13+
}
14+
15+
render() {
16+
const style = {
17+
width: '300px',
18+
height: '300px'
19+
};
20+
21+
return <div style={style} id={this.state.id}></div>;
22+
}
23+
24+
componentWillReceiveProps(nextProps) {
25+
this._setProgess(nextProps.progress);
26+
this._setText(nextProps.text);
27+
}
28+
29+
componentDidMount() {
30+
//console.log(this.props)
31+
// setState function is not used to prevent a new render cycle
32+
// This handling happens outside of React component's lifecycle
33+
var containerId = '#' + this.state.id;
34+
this.state.shape = new this.props.Shape(containerId, this.props.options);
35+
this._setProgress(this.props.progress);
36+
}
37+
38+
componentWillUnmount() {
39+
if (this.state.shape) {
40+
this.state.shape.destroy();
41+
}
42+
}
43+
44+
_setProgress(progress) {
45+
this.state.shape.animate(progress);
46+
}
47+
48+
_setText(text) {
49+
if (text) {
50+
this.state.shape.setText(text);
51+
}
52+
}
53+
}
54+
Shape.defaultProps = {
55+
Shape: null,
56+
options: {},
57+
progress: 0,
58+
text: null
59+
};
60+
61+
class Circle extends Shape {}
62+
Circle.defaultProps = {
63+
Shape: ProgressBar.Circle
64+
};
65+
66+
export {
67+
Circle
68+
};

0 commit comments

Comments
 (0)