Added variable timer

This commit is contained in:
Jeroen De Meerleer 2021-04-20 13:30:23 +02:00
parent e311f63ae7
commit badbe330a3
3 changed files with 66 additions and 14 deletions

View File

@ -1,17 +1,31 @@
<template> <template>
<div id="app"> <div id="app">
<Timer time="10"/> <Settings v-if="time == 0" v-on:set-time="setTime"/>
<Timer v-if="time != 0" v-bind:time="time"/>
</div> </div>
</template> </template>
<script> <script>
import Settings from './components/Settings.vue'
import Timer from './components/Timer.vue' import Timer from './components/Timer.vue'
export default { export default {
name: 'App', name: 'App',
components: { components: {
Timer Timer,
Settings
},
data: function() {
return {
time: 0
}
},
methods: {
setTime(number) {
this.time = number;
}
} }
} }
</script> </script>

View File

@ -0,0 +1,33 @@
<template>
<div class="settings">
<div class="time">
<span class="time-choice" v-on:click="setTime(15)">15</span>
<span class="time-choice" v-on:click="setTime(30)">30</span>
<span class="time-choice" v-on:click="setTime(45)">45</span>
<span class="time-choice" v-on:click="setTime(60)">60</span>
<span class="time-choice" v-on:click="setTime(75)">75</span>
<span class="time-choice" v-on:click="setTime(90)">90</span>
</div>
</div>
</template>
<script>
export default {
name: "Settings",
props: {
time: {
type: Number,
default: 0
}
},
methods: {
setTime(number) {
this.$emit('set-time', number);
}
}
}
</script>
<style scoped>
</style>

View File

@ -1,16 +1,16 @@
<template> <template>
<div class="timer"> <div class="timer">
<p v-if="warning == false" class="timeleft reverse">{{ countDown.toString() }}</p> <p v-if="warning == false" class="timeleft reverse">{{ countDown.toString() }}</p>
<p v-if="warning == true" class="timeout reverse"> <p v-if="(warning == true) || (typeof warning == 'undefined')" class="timeout reverse">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
</p> </p>
<button v-on:click="restartTimer" class="timerBtn">Restart</button> <button v-on:click="restartTimer" class="timerBtn"><span class="timerBtn-inner"></span></button>
<p v-if="warning == false" class="timeleft">{{ countDown.toString() }}</p> <p v-if="warning == false" class="timeleft">{{ countDown.toString() }}</p>
<p v-if="warning == true" class="timeout"> <p v-if="warning == true || (typeof warning == 'undefined')" class="timeout">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
<img src="joker.png" alt="joker"> <img src="joker.png" alt="joker">
@ -26,17 +26,15 @@ export default {
name: "Timer", name: "Timer",
props: { props: {
time: Number, time: Number,
countDown: { },
type: Number, data: function() {
default: -2 return {
}, countDown: -2,
warning: { warning: true,
type: Boolean, }
default: true,
},
}, },
mounted: function() { mounted: function() {
}, },
methods: { methods: {
timeleft: function(){ timeleft: function(){
this.countDown--; this.countDown--;
@ -96,6 +94,13 @@ export default {
font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif; font-family: "HelveticaNeue", "Helvetica Neue", Helvetica, Arial, sans-serif;
} }
.timerBtn-inner {
display: inline-block;
height: 2rem;
width: 2rem;
background-color: #2c3e50;
}
.reverse { .reverse {
transform: scale(-1, -1); transform: scale(-1, -1);
} }