Created
November 22, 2016 16:36
-
-
Save hyukkwonepic/cf017ceb1fb4f03cce942f75cdbb17c9 to your computer and use it in GitHub Desktop.
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 React = require('react'); | |
var Controls = React.createClass({ | |
PropTypes: { | |
countdownStatus: React.PropTypes.string.isRequired, | |
onStatusChange: React.PropTypes.func.isRequired | |
}, | |
onStatusChange: function (newStatus) { | |
return () => { | |
this.props.onStatusChange(newStatus); | |
} | |
}, | |
render: function () { | |
var {countdownStatus} = this.props; | |
var renderStartStopButton = () => { | |
if (countdownStatus === 'started') { | |
return ( | |
<button className="button secondary" onClick={this.onStatusChange('paused')}>Pause</button> | |
) | |
} else if (countdownStatus === 'paused') { | |
return ( | |
<button className="button primary" onClick={this.onStatusChange('started')}>Start</button> | |
) | |
} | |
} | |
return ( | |
<div className="controls"> | |
{renderStartStopButton()} | |
<button className="button alert hollow" onClick={this.onStatusChange('stopped')}>Clear</button> | |
</div> | |
) | |
} | |
}); | |
module.exports = Controls; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment