aboutsummaryrefslogtreecommitdiff
path: root/resources/vue/components/RangeInput.vue
blob: f28b091f2300798bf7de0c0685f6b41b83772f9d (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
68
69
<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-model="myValue">
        <output for="fader">
            {{ $gettext('%{myValue} von %{max}', {myValue: myValue || '1', max: max}) }}
        </output>
    </div>
</template>

<script>
export default {
    name: 'range-input',
    emits: ['update:modelValue'],
    props: {
        name: {
            type: String,
            required: true
        },
        modelValue: {
            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.modelValue > this.min ? this.modelValue : this.min;
        if (this.myValue > this.max) {
            this.myValue = this.max;
        }
    },
    inheritAttrs: false,
    watch: {
        myValue: {
            handler(newValue) {
                this.$emit('update:modelValue', newValue);
            },
            deep: true
        }
    }
}
</script>