aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/RangeInput.vue
blob: 650c750d52af9cb2469039500b94af8f144594cc (plain)
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
<template>
    <div class="formpart range_input">
        <input type="range"
               :name="name"
               :min="min"
               :max="max"
               :step="step"
               :aria-valuemin="min"
               :aria-valuemax="max"
               :aria-valuenow="myValue"
               v-bind="$attrs"
               v-on="$listeners"
               v-model="myValue">
        <output for="fader"><translate :translate-params="{myValue: myValue || '1', max: max}">%{myValue} von %{max}</translate></output>
    </div>
</template>

<script>
export default {
    name: 'range-input',
    props: {
        name: {
            type: String,
            required: true
        },
        value: {
            required: false,
            default: 1
        },
        min: {
            type: Number,
            required: false,
            default: 1
        },
        max: {
            type: Number,
            required: false,
            default: 10
        },
        step: {
            type: Number,
            required: false,
            default: 1
        }
    },
    data () {
        return {
            myValue: 1
        };
    },
    mounted () {
        this.myValue = this.value > this.min ? this.value : this.min;
        if (this.myValue > this.max) {
            this.myValue = this.max;
        }
    },
    inheritAttrs: false,
    watch: {
        myValue: {
            handler(newValue, oldValue) {
                this.$emit('input', newValue);
            },
            deep: true
        }
    }
}
</script>