Skip to content

Commit 18b98b4

Browse files
committed
Merge branch 'master' into gh-pages
2 parents 7f9e906 + 0878204 commit 18b98b4

File tree

8 files changed

+105
-30
lines changed

8 files changed

+105
-30
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# Changelog
22

3+
## 1.0.8 - Aug 8, 2016
4+
5+
* Updated React version in peerDependencies
6+
* Added new props for fontSize, font, timeFormat and showMilliseconds
7+
* Added ability to render minutes and hours
8+
* Fixed long countdowns having a tick period longer than 1 second
9+
310
## 1.0.7 - Aug 7, 2016
411

512
* Weight of circle can now be configured. Thanks @rutan.

README.md

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# React Countdown Clock
22

3-
A HTML 5 canvas countdown clock as a React component
3+
A HTML 5 canvas countdown clock as a React component.
44

55
![Screenshot](http://pughpugh.github.io/react-countdown-clock/screenshot.png?=0)
66

@@ -26,13 +26,26 @@ npm install react-countdown-clock
2626

2727
## Props
2828

29-
* `seconds` to count down
30-
* `color` you'd like it to be as a hex/css colour code
31-
* `alpha` transparency for component
32-
* `size` for height and width of canvas element, in pixels.
33-
* `weight` for weight of circle, in pixels.
34-
* `onComplete` callback when timer 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 |
3541

36-
## Bugs
42+
## Bugs & Contributions
43+
44+
Bugs, features and pull requests always welcome.
3745

3846
[github.com/pughpugh/react-countdown-clock/issues](https://github.com/pughpugh/react-countdown-clock/issues)
47+
48+
Also, it's always just nice to hear how people are using it. Feel free to get in touch.
49+
50+
* Email: [hugh@hcgallagher.co.uk](mailto:hugh@hcgallagher.co.uk)
51+
* Web: [www.hughgallagher.co.uk](http://www.hughgallagher.co.uk/)

RELEASE_PROCESS.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1-
Just to remind myself of my own release process for this repo
1+
Just to remind myself of my own release process for this repo.
22

33
1. Make some changes / merge PR
44
2. Bump version in `package.json`
55
3. Update `README.md` if needed
66
4. Update `CHANGELOG.md`
77
5. Webpack build
8-
```
8+
99
webpack -p
10-
```
10+
1111
6. Test it all works
12-
```
12+
1313
serve
1414
open index.html -a 'Google Chrome'
15-
```
15+
1616
7. Tag and push the release
17-
```
17+
1818
git tag 1.0.x
1919
git push
2020
git push --tags
21-
```
21+
2222
8. Publish on NPM
23-
```
23+
2424
npm publish
25-
```
25+
26+
9. Update Githup Pages
27+
28+
git checkout gh-pages
29+
git merge master
30+
git push
31+
2632
9. Cup of tea

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: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,22 @@ module.exports = React.createClass
1515
size: React.PropTypes.number
1616
weight: React.PropTypes.number
1717
color: React.PropTypes.string
18+
fontSize: React.PropTypes.string
19+
font: React.PropTypes.string
1820
alpha: React.PropTypes.number
21+
timeFormat: React.PropTypes.string
1922
onComplete: React.PropTypes.func
23+
showMilliseconds: React.PropTypes.boolean
2024

2125
getDefaultProps: ->
26+
seconds: 60
2227
size: 300
2328
color: '#000'
2429
alpha: 1
30+
timeFormat: 'hms'
31+
fontSize: 'auto'
32+
font: 'Arial'
33+
showMilliseconds: true
2534

2635
componentWillReceiveProps: (props) ->
2736
@_seconds = props.seconds
@@ -47,19 +56,25 @@ module.exports = React.createClass
4756
_setScale: ->
4857
@_radius = @props.size / 2
4958
@_fraction = 2 / @_seconds
50-
@_tickPeriod = @_seconds * 1.8
59+
@_tickPeriod = @_calculateTick()
5160
@_innerRadius =
5261
if @props.weight
5362
@_radius - @props.weight
5463
else
5564
@_radius / 1.8
5665

66+
_calculateTick: ->
67+
# Tick period (milleseconds) needs to be fast for smaller time periods and slower
68+
# for longer ones. This provides smoother rendering. It should never exceed 1 second.
69+
tickScale = 1.8
70+
tick = @_seconds * tickScale
71+
if tick > 1000 then 1000 else tick
72+
5773
_setupCanvas: ->
5874
@_canvas = @refs.canvas
5975
@_context = @_canvas.getContext '2d'
6076
@_context.textAlign = 'center'
6177
@_context.textBaseline = 'middle'
62-
@_context.font = "bold #{@_radius/2}px Arial"
6378

6479
_startTimer: ->
6580
# Give it a moment to collect it's thoughts for smoother render
@@ -99,12 +114,45 @@ module.exports = React.createClass
99114
@_context.arc @_radius, @_radius, @_innerRadius, Math.PI * 2, 0, true
100115
@_context.fill()
101116

117+
_formattedTime: ->
118+
decimals = (@_seconds <= 9.9 && @props.showMilliseconds) ? 1 : 0
119+
120+
if @props.timeFormat == 'hms'
121+
hours = parseInt( @_seconds / 3600 ) % 24
122+
minutes = parseInt( @_seconds / 60 ) % 60
123+
seconds = (@_seconds % 60).toFixed(decimals)
124+
125+
hours = "0#{hours}" if hours < 10
126+
minutes = "0#{minutes}" if minutes < 10
127+
seconds = "0#{seconds}" if seconds < 10 && minutes >= 1
128+
129+
timeParts = []
130+
timeParts.push hours if hours > 0
131+
timeParts.push minutes if minutes > 0
132+
timeParts.push seconds
133+
134+
timeParts.join ':'
135+
else
136+
return @_seconds.toFixed(decimals)
137+
138+
_fontSize: (timeString) ->
139+
if @props.fontSize == 'auto'
140+
scale = switch timeString.length
141+
when 8 then 4 # hh:mm:ss
142+
when 5 then 3 # mm:ss
143+
else 2 # ss or ss.s
144+
size = @_radius / scale
145+
"#{size}px"
146+
else
147+
@props.fontSize
148+
102149
_drawTimer: ->
103150
percent = @_fraction * @_seconds + 1.5
104-
decimals = (@_seconds <= 9.9) ? 1 : 0
151+
formattedTime = @_formattedTime()
105152
@_context.globalAlpha = @props.alpha
106153
@_context.fillStyle = @props.color
107-
@_context.fillText @_seconds.toFixed(decimals), @_radius, @_radius
154+
@_context.font = "bold #{@_fontSize(formattedTime)} #{@props.font}"
155+
@_context.fillText formattedTime, @_radius, @_radius
108156
@_context.beginPath()
109157
@_context.arc @_radius, @_radius, @_radius, Math.PI * 1.5, Math.PI * percent, false
110158
@_context.arc @_radius, @_radius, @_innerRadius, Math.PI * percent, Math.PI * 1.5, true

index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@
1919
</head>
2020
<body>
2121
<div id="parappa"></div>
22-
<script src="http://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react.js"></script>
23-
<script src="http://cdnjs.cloudflare.com/ajax/libs/react/0.14.3/react-dom.js"></script>
22+
<script src="http://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react.js"></script>
23+
<script src="http://cdnjs.cloudflare.com/ajax/libs/react/15.3.0/react-dom.js"></script>
2424
<script src="./build/react-countdown-clock.js"></script>
2525
<script>
26-
var MAX = 30;
27-
var MIN = 5;
26+
var MAX = 120;
27+
var MIN = 30;
2828

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

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-countdown-clock",
3-
"version": "1.0.7",
3+
"version": "1.0.8",
44
"description": "HTML5 canvas countdown clock React component",
55
"main": "build/react-countdown-clock.js",
66
"repository": {
@@ -24,9 +24,10 @@
2424
"cjsx-loader": "^2.1.0",
2525
"coffee-loader": "^0.7.2",
2626
"coffee-script": "^1.8.0",
27-
"webpack": "^1.4.15"
27+
"webpack": "^1.13.1",
28+
"react": "15.*"
2829
},
2930
"peerDependencies": {
30-
"react": "^0.14.3"
31+
"react": "15.*"
3132
}
3233
}

0 commit comments

Comments
 (0)