summaryrefslogtreecommitdiff
path: root/src/client/components/form/range.vue
blob: 65d665c70ade15fae5b49df2dac087afe55a01b5 (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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
<div class="ifitouly _formItem" :class="{ focused, disabled }">
	<div class="_formLabel"><slot name="label"></slot></div>
	<div class="_formPanel main">
		<input
			type="range"
			ref="input"
			v-model="v"
			:disabled="disabled"
			:min="min"
			:max="max"
			:step="step"
			@focus="focused = true"
			@blur="focused = false"
			@input="$emit('update:value', $event.target.value)"
		/>
	</div>
	<div class="_formCaption"><slot name="caption"></slot></div>
</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
	props: {
		value: {
			type: Number,
			required: false,
			default: 0
		},
		disabled: {
			type: Boolean,
			required: false,
			default: false
		},
		min: {
			type: Number,
			required: false,
			default: 0
		},
		max: {
			type: Number,
			required: false,
			default: 100
		},
		step: {
			type: Number,
			required: false,
			default: 1
		},
	},
	data() {
		return {
			v: this.value,
			focused: false
		};
	},
	watch: {
		value(v) {
			this.v = parseFloat(v);
		}
	},
});
</script>

<style lang="scss" scoped>
.ifitouly {
	position: relative;

	> .main {
		padding: 22px 16px;

		> input {
			display: block;
			-webkit-appearance: none;
			-moz-appearance: none;
			appearance: none;
			background: var(--X10);
			height: 4px;
			width: 100%;
			box-sizing: border-box;
			margin: 0;
			outline: 0;
			border: 0;
			border-radius: 7px;

			&.disabled {
				opacity: 0.6;
				cursor: not-allowed;
			}

			&::-webkit-slider-thumb {
				-webkit-appearance: none;
				appearance: none;
				cursor: pointer;
				width: 20px;
				height: 20px;
				display: block;
				border-radius: 50%;
				border: none;
				background: var(--accent);
				box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
				box-sizing: content-box;
			}

			&::-moz-range-thumb {
				-moz-appearance: none;
				appearance: none;
				cursor: pointer;
				width: 20px;
				height: 20px;
				display: block;
				border-radius: 50%;
				border: none;
				background: var(--accent);
				box-shadow: 0 0 6px rgba(0, 0, 0, 0.3);
			}
		}
	}
}
</style>