This repository was archived by the owner on Apr 23, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +68
-0
lines changed
Expand file tree Collapse file tree 1 file changed +68
-0
lines changed Original file line number Diff line number Diff line change 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+ } ;
You can’t perform that action at this time.
0 commit comments