misskey/packages/client/src/components/form/range.vue

140 lines
2.2 KiB
Vue
Raw Normal View History

<template>
2021-09-29 17:50:45 +02:00
<div class="timctyfi" :class="{ focused, disabled }">
<div class="icon"><slot name="icon"></slot></div>
<span class="label"><slot name="label"></slot></span>
<input
ref="input"
v-model="v"
2021-11-19 11:36:12 +01:00
type="range"
2021-09-29 17:50:45 +02:00
:disabled="disabled"
:min="min"
:max="max"
:step="step"
:autofocus="autofocus"
@focus="focused = true"
@blur="focused = false"
@input="$emit('update:value', $event.target.value)"
/>
</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
},
2021-09-29 17:50:45 +02:00
autofocus: {
type: Boolean,
required: false
}
},
data() {
return {
v: this.value,
focused: false
};
},
watch: {
value(v) {
this.v = parseFloat(v);
}
},
2021-09-29 17:50:45 +02:00
mounted() {
if (this.autofocus) {
this.$nextTick(() => {
this.$refs.input.focus();
});
}
}
});
</script>
<style lang="scss" scoped>
2021-09-29 17:50:45 +02:00
.timctyfi {
position: relative;
2021-09-29 17:50:45 +02:00
margin: 8px;
2021-09-29 17:50:45 +02:00
> .icon {
display: inline-block;
width: 24px;
text-align: center;
}
2021-09-29 17:50:45 +02:00
> .title {
pointer-events: none;
font-size: 16px;
color: var(--inputLabel);
overflow: hidden;
}
2021-09-29 17:50:45 +02:00
> input {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
background: var(--X10);
height: 7px;
margin: 0 8px;
outline: 0;
border: 0;
border-radius: 7px;
2021-09-29 17:50:45 +02:00
&.disabled {
opacity: 0.6;
cursor: not-allowed;
}
2021-09-29 17:50:45 +02:00
&::-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>