Created
February 26, 2016 13:39
-
-
Save rahmanusta/f6a93a1a369f045b2349 to your computer and use it in GitHub Desktop.
React Zurb ProgressBar State Gist
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ProgressBar = React.createClass({ | |
getInitialState: function () { | |
return { | |
position: 0 | |
}; | |
}, | |
proceed: function () { | |
this.setState(function (currentState) { | |
if (currentState.position >= 100) { | |
currentState.position = 0; | |
return; | |
} | |
return { | |
position: currentState.position + this.props.step | |
}; | |
}); | |
}, | |
render: function () { | |
var color = this.props.color; | |
var position = this.state.position; | |
return ( | |
<div> | |
<div className={classNames("progress", color)} role="progressbar"> | |
<div className="progress-meter" style={{width: position + '%'}}></div> | |
</div> | |
<button onClick={this.proceed} type="button" className="success button">Proceed.. {position} %</button> | |
</div> | |
); | |
} | |
}); | |
var container = document.querySelectorAll(".placeholder"); | |
ReactDOM.render(<ProgressBar color="alert" step={10}/>, container[0]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment