Skip to content

Commit 23efba5

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 17ae499 + ff2bc53 commit 23efba5

File tree

5 files changed

+47
-23
lines changed

5 files changed

+47
-23
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,20 @@ npm install react-countdown-clock
2626

2727
## Props
2828

29-
| prop | type | default | description |
30-
|------------------|----------------|---------|------------------------------------------------|
31-
| seconds | integer | 60 | Seconds to countdown |
32-
| color | string | #000 | Colour of counter |
33-
| alpha | float | 1.0 | Alpha transparency of counter |
34-
| size | integer | 300 | Width & height of canvas element |
35-
| weight | integer | | Weight of circle, in pixels |
36-
| fontSize | integer/string | auto | px size of font. `auto` for dynamic sizing. |
37-
| font | string | Arial | Font of counter |
38-
| timeFormat | string | seconds | Counter style; `seconds` or `hms` |
39-
| showMilliseconds | boolean | true | Show milliseconds for last 10 seconds |
40-
| onComplete | func | | Callback when time completes |
29+
| prop | type | default | description |
30+
|------------------|----------------|---------|-----------------------------------------------------------|
31+
| seconds | integer | 60 | Seconds to countdown |
32+
| color | string | #000 | Colour of counter |
33+
| alpha | float | 1.0 | Alpha transparency of counter |
34+
| size | integer | 300 | Width & height of canvas element |
35+
| weight | integer | | Weight of circle, in pixels |
36+
| fontSize | integer/string | auto | px size of font. `auto` for dynamic sizing. |
37+
| font | string | Arial | Font of counter |
38+
| timeFormat | string | seconds | Counter style; `seconds` or `hms` |
39+
| showMilliseconds | boolean | true | Show milliseconds for last 10 seconds |
40+
| onComplete | func | | Callback when time completes |
41+
| paused | boolean | false | Pause countdown of the timer |
42+
| pausedText | string | | Text to display when paused, defaults to the current time |
4143

4244
## Bugs & Contributions
4345

build/react-countdown-clock.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/react-countdown-clock.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coffee/react-countdown-clock.coffee

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ module.exports = React.createClass
2222
onComplete: React.PropTypes.func
2323
onClick: React.PropTypes.func
2424
showMilliseconds: React.PropTypes.bool
25+
paused: React.PropTypes.bool
26+
pausedText: React.PropTypes.string
2527

2628
getDefaultProps: ->
2729
seconds: 60
@@ -32,6 +34,7 @@ module.exports = React.createClass
3234
fontSize: 'auto'
3335
font: 'Arial'
3436
showMilliseconds: true
37+
paused: false
3538

3639
componentDidUpdate: (props) ->
3740
if props.seconds != @props.seconds
@@ -43,6 +46,10 @@ module.exports = React.createClass
4346
@_drawBackground()
4447
@_updateCanvas()
4548

49+
if props.paused != @props.paused
50+
@_startTimer() if !@props.paused
51+
@_pauseTimer() if @props.paused
52+
4653
componentDidMount: ->
4754
@_seconds = @props.seconds
4855
@_setupTimer()
@@ -55,7 +62,7 @@ module.exports = React.createClass
5562
@_setupCanvases()
5663
@_drawBackground()
5764
@_drawTimer()
58-
@_startTimer()
65+
@_startTimer() unless @props.paused
5966

6067
_updateCanvas: ->
6168
@_clearTimer()
@@ -90,10 +97,17 @@ module.exports = React.createClass
9097
# Give it a moment to collect it's thoughts for smoother render
9198
@_timeoutIds.push(setTimeout ( => @_tick() ), 200)
9299

93-
_cancelTimer: ->
100+
_pauseTimer: ->
101+
@_stopTimer()
102+
@_updateCanvas()
103+
104+
_stopTimer: ->
94105
for timeout in @_timeoutIds
95106
clearTimeout timeout
96107

108+
_cancelTimer: ->
109+
@_stopTimer()
110+
97111
if @props.onClick?
98112
@refs.component.removeEventListener 'click', @props.onClick
99113

@@ -166,15 +180,16 @@ module.exports = React.createClass
166180
_drawTimer: ->
167181
percent = @_fraction * @_seconds + 1.5
168182
formattedTime = @_formattedTime()
183+
text = if (@props.paused && @props.pausedText?) then @props.pausedText else formattedTime
169184

170185
# Timer
171186
@_timer.globalAlpha = @props.alpha
172187
@_timer.fillStyle = @props.color
173188
@_timer.font = "bold #{@_fontSize(formattedTime)} #{@props.font}"
174-
@_timer.fillText formattedTime, @_radius, @_radius
189+
@_timer.fillText text, @_radius, @_radius
175190
@_timer.beginPath()
176-
@_timer.arc @_radius, @_radius, @_radius, Math.PI * 1.5, Math.PI * percent, false
177-
@_timer.arc @_radius, @_radius, @_innerRadius, Math.PI * percent, Math.PI * 1.5, true
191+
@_timer.arc @_radius, @_radius, @_radius, Math.PI * 1.5, Math.PI * percent, false
192+
@_timer.arc @_radius, @_radius, @_innerRadius, Math.PI * percent, Math.PI * 1.5, true
178193
@_timer.closePath()
179194
@_timer.fill()
180195

index.html

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@
3939
getState: function(){
4040
return {
4141
seconds: randomAmountOfSeconds(),
42-
color: randomColor()
42+
color: randomColor(),
43+
paused: false,
44+
fontSize: 'auto'
4345
}
4446
},
4547
getInitialState: function(){
@@ -49,19 +51,24 @@
4951
this.setState(this.getState());
5052
},
5153
handleOnClick: function(){
52-
console.log("CLICK")
54+
wasPaused = this.state.paused
5355
this.setState({
54-
color: randomColor()
56+
// color: randomColor(),
57+
paused: (wasPaused) ? false : true,
58+
fontSize: (wasPaused) ? 'auto' : '45px',
5559
});
5660
},
5761
render: function(){
5862
return (
5963
React.createElement(ReactCountdownClock, {
6064
seconds: this.state.seconds,
6165
color: this.state.color,
66+
paused: this.state.paused,
67+
pausedText: "▐▐ ",
6268
alpha: 0.9,
6369
onComplete: this.handleOnComplete,
64-
onClick: this.handleOnClick
70+
onClick: this.handleOnClick,
71+
fontSize: this.state.fontSize
6572
})
6673
)
6774
}

0 commit comments

Comments
 (0)