116 lines
2.5 KiB
Vue
116 lines
2.5 KiB
Vue
<template>
|
|
<div class="counter">
|
|
<div class="count-top">
|
|
<label class="upper-label" for="limit" @click="reset">Limit</label>
|
|
<input class="upper-input" name="limit" type="number" pattern="[0-9]*" v-model="countBound" placeholder="10"/>
|
|
</div>
|
|
<div @click="bumpCount" :style="countStyle" class="count-bottom">
|
|
<div class="value">{{ countCurrent }}</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
navigator.vibrate = navigator.vibrate || navigator.webkitVibrate || navigator.mozVibrate || navigator.msVibrate
|
|
|
|
export default {
|
|
name: 'counter',
|
|
data () {
|
|
return {
|
|
countBound: 15,
|
|
countCurrent: 0,
|
|
limitReached: false,
|
|
countStyle: {
|
|
backgroundColor: '#179e63',
|
|
color: '#FFFFFF'
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
bumpCount () {
|
|
if (this.limitReached) {
|
|
this.countCurrent = 0
|
|
this.limitReached = false
|
|
} else {
|
|
this.countCurrent = this.countCurrent + 1
|
|
}
|
|
|
|
this.checkLimit()
|
|
},
|
|
reset () {
|
|
this.countCurrent = 0
|
|
this.limitReached = false
|
|
},
|
|
checkLimit () {
|
|
this.limitReached = (this.countCurrent >= this.countBound)
|
|
|
|
if (this.limitReached) {
|
|
this.countStyle.backgroundColor = '#e53232'
|
|
window.navigator.vibrate([200, 100, 200])
|
|
} else {
|
|
this.countStyle.backgroundColor = '#179e63'
|
|
}
|
|
}
|
|
},
|
|
watch: {
|
|
countBound: function () { this.checkLimit() }
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<!-- Add "scoped" attribute to limit CSS to this component only -->
|
|
<style>
|
|
|
|
.counter {
|
|
margin: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
display: flex;
|
|
flex-direction: column;
|
|
}
|
|
|
|
.count-top {
|
|
width:100%;
|
|
height: 2em;
|
|
font-size: 3em;
|
|
display: flex;
|
|
flex-direction: row;
|
|
justify-content: flex-start;
|
|
vertical-align: bottom;
|
|
}
|
|
.upper-label {
|
|
flex: 0 0 auto;
|
|
vertical-align: middle;
|
|
align-self: flex-end;
|
|
margin: auto;
|
|
padding-right: 10px;
|
|
}
|
|
.upper-input {
|
|
font-size: 1em;
|
|
width: 2em;
|
|
flex: 1 1 auto;
|
|
margin: auto;
|
|
vertical-align: text-bottom;
|
|
}
|
|
.count-bottom {
|
|
width:100%;
|
|
height:100%;
|
|
display: flex;
|
|
justify-content: center;
|
|
align-items: center;
|
|
-webkit-touch-callout: none;
|
|
-webkit-user-select: none;
|
|
-khtml-user-select: none;
|
|
-moz-user-select: none;
|
|
-ms-user-select: none;
|
|
user-select: none;
|
|
margin: auto;
|
|
}
|
|
.value {
|
|
font-family: -apple-system-tall-body, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
|
|
flex: auto;
|
|
font-size: 10em;
|
|
}
|
|
|
|
</style>
|