Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions coffee/react-countdown-clock.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ CreateReactClass = require 'create-react-class'

ReactCountdownClock = CreateReactClass
_seconds: 0
_prevSeconds: 0
_radius: null
_fraction: null
_content: null
Expand Down Expand Up @@ -99,6 +100,7 @@ ReactCountdownClock = CreateReactClass
start = Date.now()
@_timeoutIds.push(setTimeout ( =>
duration = (Date.now() - start) / 1000
@_prevSeconds = Math.round(@_seconds)
@_seconds -= duration

if @_seconds <= 0
Expand All @@ -107,6 +109,10 @@ ReactCountdownClock = CreateReactClass
@_clearTimer()
else
@_updateCanvas()
if @props.onSecond
roundSeconds = Math.round(@_seconds)
if roundSeconds != @_prevSeconds
@props.onSecond(roundSeconds)
@_tick()
), @_tickPeriod)

Expand Down Expand Up @@ -201,6 +207,7 @@ ReactCountdownClock.propTypes =
timeFormat: PropTypes.string
onComplete: PropTypes.func
onClick: PropTypes.func
onSecond: PropTypes.func
showMilliseconds: PropTypes.bool
paused: PropTypes.bool
pausedText: PropTypes.string
Expand Down
34 changes: 21 additions & 13 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="utf-8" />
<title>react-countdown-clock</title>
<style>
body {
background-color: #CCC;
}
#parappa {

#parappa {
position: absolute;
top: 50%;
left: 50%;
Expand All @@ -17,6 +19,7 @@
}
</style>
</head>

<body>
<div id="parappa"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.2.0/umd/react.development.js"></script>
Expand All @@ -27,39 +30,42 @@
var MAX = 120;
var MIN = 10;

var randomAmountOfSeconds = function(){
return Math.floor( Math.random() * ( MAX - MIN + 1) + MIN )
var randomAmountOfSeconds = function () {
return Math.floor(Math.random() * (MAX - MIN + 1) + MIN)
}

var randomColor = function(){
return '#' + ( Math.random() * 0xFFFFFF << 0 ).toString(16);
var randomColor = function () {
return '#' + (Math.random() * 0xFFFFFF << 0).toString(16);
}

var Demo = createReactClass({
displayName: 'Demo',
getState: function(){
return {
getState: function () {
return {
seconds: randomAmountOfSeconds(),
color: randomColor(),
paused: false,
fontSize: 'auto'
}
},
getInitialState: function(){
getInitialState: function () {
return this.getState();
},
handleOnComplete: function(){
handleOnComplete: function () {
this.setState(this.getState());
},
handleOnClick: function(){
handleOnSecond: function (seconds) {
console.log('seconds: ' + seconds);
},
handleOnClick: function () {
wasPaused = this.state.paused
this.setState({
// color: randomColor(),
paused: (wasPaused) ? false : true,
fontSize: (wasPaused) ? 'auto' : '45px',
});
},
render: function(){
render: function () {
return (
React.createElement(ReactCountdownClock, {
seconds: this.state.seconds,
Expand All @@ -69,7 +75,8 @@
alpha: 0.9,
onComplete: this.handleOnComplete,
onClick: this.handleOnClick,
fontSize: this.state.fontSize
fontSize: this.state.fontSize,
onSecond: this.handleOnSecond
})
)
}
Expand All @@ -81,4 +88,5 @@
)
</script>
</body>
</html>

</html>