Created
November 22, 2016 17:14
-
-
Save hyukkwonepic/6bf60ce5d76da00d924a78ce8d6ba884 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 Clock = React.createClass({ | |
propTypes: { | |
totalSeconds: React.PropTypes.number | |
}, | |
getDefaultProps: function () { | |
totalSeconds: 0 | |
}, | |
formatSeconds: function (totalSeconds) { | |
var seconds = totalSeconds % 60; | |
var minutes = Math.floor(totalSeconds / 60); | |
if (seconds < 10) { | |
seconds = '0' + seconds; | |
} | |
if (minutes < 10) { | |
minutes = '0' + minutes; | |
} | |
return minutes + ":" + seconds; | |
}, | |
render: function () { | |
var {totalSeconds} = this.props; | |
return ( | |
<div className="clock"> | |
<span className="clock-text"> | |
{this.formatSeconds(totalSeconds)} | |
</span> | |
</div> | |
); | |
} | |
}); | |
module.exports = Clock; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment