vue-counter/src/components/Counter.vue

115 lines
2.2 KiB
Vue

<template>
<div class="counter">
<div class="count-top">
<label class="upper-label" for="limit">Limit</label>
<input class="upper-input" id="limit" type="number" v-model="countBound" placeholder="10"/>
</div>
<div @click="bumpCount" :style="countStyle" class="count-bottom">
<div class="value">{{ countCurrent }}</div>
</div>
</div>
</template>
<script>
export default {
name: 'counter',
data () {
return {
msg: 'Welcome to Your Counter PWA',
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.limitReached = (this.countCurrent >= this.countBound)
if (this.limitReached) {
this.countStyle.backgroundColor = '#e53232'
} else {
this.countStyle.backgroundColor = '#179e63'
}
}
}
}
</script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style>
.counter {
margin: 0;
width: 100%;
height: 100%;
}
.count-top {
display: table;
width:100%;
min-height:30%;
font-size: 3em;
}
.upper-label {
display: table-cell;
width: 1px;
min-height: 50%;
padding-left: 0.2em;
padding-right: 0.2em;
}
.upper-input {
display: table-cell;
min-width: 97%;
min-height: 80%;
font-size: 1em;
}
.count-bottom {
width:100%;
min-height:70%;
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;
}
.value {
font-family: -apple-system-tall-body, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
flex: 0 0 auto;
font-size: 10em;
}
h1, h2 {
font-weight: normal;
}
ul {
list-style-type: none;
padding: 0;
}
li {
display: inline-block;
margin: 0 10px;
}
a {
color: #35495E;
}
</style>