-
Notifications
You must be signed in to change notification settings - Fork 1
/
AnNumber.vue
100 lines (92 loc) · 1.93 KB
/
AnNumber.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<template>
<div class="an-number">
<button
class="an-number__button--minus hide-print"
aria-label="weniger"
@click="calc(false)"
>
<IconMinus />
</button>
<input
:id="field_id"
v-model.number="field_data"
type="number"
:required="field_required"
/>
<button
class="an-number__button--plus hide-print"
aria-label="mehr"
@click="calc(true)"
>
<IconPlus />
</button>
</div>
</template>
<script>
import IconMinus from '@/assets/icons/minus.svg?inline';
import IconPlus from '@/assets/icons/plus.svg?inline';
import field from '@/mixins/field.js';
export default {
name: 'AnNumber',
components: {
IconMinus,
IconPlus
},
mixins: [field],
methods: {
validate(value) {
this.$emit(
'update:field_valid',
value !== '' && !Number.isNaN(Number(value))
);
},
calc(increment) {
if (this.field_data !== undefined && this.field_data > 0) {
if (increment) {
this.field_data++;
} else if (this.field_data > 1) {
this.field_data--;
}
} else {
this.field_data = 1;
}
}
}
};
</script>
<style lang="scss" scoped>
.an-number {
display: inline-flex;
background-color: $color-theme-lightgrey;
border-radius: $border-radius;
input {
appearance: textfield;
border-radius: 0;
max-width: 10ch;
border: none;
@media screen {
border-top: 2px solid $color-theme-lightgrey;
border-bottom: 2px solid $color-theme-lightgrey;
padding: $spacer;
}
&::-webkit-inner-spin-button {
display: none;
}
}
button {
background-repeat: no-repeat;
background-size: cover;
padding: $spacer;
width: 2.5rem;
height: 2.5rem;
cursor: pointer;
border: none;
background-color: transparent;
}
svg {
height: 100%;
width: 100%;
fill: $color-theme-darkgrey;
}
}
</style>