Skip to content

Commit ebfc77d

Browse files
Anwar HussainAnwar Hussain
authored andcommitted
Init commit
0 parents commit ebfc77d

File tree

5 files changed

+153
-0
lines changed

5 files changed

+153
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules/

Countdown.vue

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
<template>
2+
<ul class="vue-countdown">
3+
<li>
4+
<p class="digit">{{ days | twoDigits }}</p>
5+
<p class="text">days</p>
6+
</li>
7+
8+
<li>
9+
<p class="digit">{{ hours | twoDigits }}</p>
10+
<p class="text">hours</p>
11+
</li>
12+
13+
<li>
14+
<p class="digit">{{ minutes | twoDigits }}</p>
15+
<p class="text">Min</p>
16+
</li>
17+
18+
<li>
19+
<p class="digit">{{ seconds | twoDigits }}</p>
20+
<p class="text">Sec</p>
21+
</li>
22+
</ul>
23+
</template>
24+
25+
<script>
26+
import Vue from 'vue'
27+
28+
Vue.filter('twoDigits', (value) => {
29+
if ( value.toString().length <= 1 ) {
30+
return '0'+value.toString()
31+
}
32+
return value.toString()
33+
})
34+
35+
export default {
36+
props: ['deadline'],
37+
38+
data() {
39+
return {
40+
now: Math.trunc((new Date()).getTime() / 1000),
41+
date: null
42+
}
43+
},
44+
45+
mounted() {
46+
this.date = Math.trunc(Date.parse(this.deadline) / 1000)
47+
48+
setInterval(() => {
49+
this.now = Math.trunc((new Date()).getTime() / 1000)
50+
}, 1000)
51+
},
52+
53+
computed: {
54+
seconds() {
55+
return Math.trunc(this.date - this.now) % 60
56+
},
57+
58+
minutes() {
59+
return Math.trunc((this.date - this.now) / 60) % 60
60+
},
61+
62+
hours() {
63+
return Math.trunc((this.date - this.now) / 60 / 60) % 24
64+
},
65+
66+
days() {
67+
return Math.trunc((this.date - this.now) / 60 / 60 / 24)
68+
}
69+
}
70+
}
71+
</script>
72+
<style lang="sass" rel="stylesheet/sass">
73+
.vue-countdown
74+
padding: 0
75+
margin: 0
76+
77+
li
78+
display: inline-block
79+
margin: 0 8px
80+
text-align: center
81+
position: relative
82+
83+
&:after
84+
content: ':'
85+
position: absolute
86+
top: 0
87+
right: -13px
88+
font-size: 32px
89+
90+
&:first-of-type
91+
margin-left: 0
92+
93+
&:last-of-type
94+
margin-right: 0
95+
96+
&:after
97+
content: ''
98+
99+
.digit
100+
font-size: 32px
101+
font-weight: 600
102+
line-height: 1.4
103+
margin-bottom: 0
104+
105+
.text
106+
text-transform: uppercase
107+
margin-bottom: 0
108+
font-size: 10px
109+
110+
</style>

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 getanwar
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# vue-countdown
2+
A simple countdown timer component for vue js 2.0
3+
4+
## Installation
5+
`npm i vuejs-countdown --save`

package.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "vuejs-countdown",
3+
"version": "0.0.1",
4+
"description": "A simple countdown timer component for vue js 2.0",
5+
"main": "Countdown.vue",
6+
"scripts": {
7+
8+
},
9+
"keywords": [
10+
"Countdown",
11+
"timer",
12+
"vue countdown"
13+
],
14+
"author": "Anwar H.",
15+
"license": "MIT"
16+
}

0 commit comments

Comments
 (0)