vikunja-frontend/src/components/input/colorPicker.vue

81 lines
1.3 KiB
Vue
Raw Normal View History

<template>
<div class="color-picker-container">
<verte
2020-11-01 14:59:47 +01:00
:showHistory="true"
:colorHistory="[
'#1973ff',
'#7F23FF',
'#ff4136',
'#ff851b',
'#ffeb10',
'#00db60',
]"
:enableAlpha="false"
:menuPosition="menuPosition"
:rgbSliders="true"
model="hex"
picker="square"
v-model="color"/>
2021-01-17 13:04:49 +01:00
<a @click="reset" class="button has-no-shadow is-small ml-2">
Reset Color
</a>
</div>
</template>
<script>
import verte from 'verte'
import 'verte/dist/verte.css'
export default {
name: 'colorPicker',
data() {
return {
color: '',
lastChangeTimeout: null,
}
},
components: {
verte,
},
props: {
value: {
required: true,
},
menuPosition: {
type: String,
default: 'top',
},
},
watch: {
value(newVal) {
this.color = newVal
},
color() {
this.update()
},
},
mounted() {
this.color = this.value
},
methods: {
update() {
if (this.lastChangeTimeout !== null) {
clearTimeout(this.lastChangeTimeout)
}
this.lastChangeTimeout = setTimeout(() => {
this.$emit('input', this.color)
this.$emit('change')
}, 500)
},
reset() {
// FIXME: I havn't found a way to make it clear to the user the color war reset.
// Not sure if verte is capable of this - it does not show the change when setting this.color = ''
this.color = ''
this.update()
},
},
}
</script>