2020-06-15 11:46:52 +02:00
|
|
|
<template>
|
|
|
|
<div class="color-picker-container">
|
|
|
|
<verte
|
2020-09-05 22:35:52 +02:00
|
|
|
:enableAlpha="false"
|
|
|
|
:menuPosition="menuPosition"
|
|
|
|
:rgbSliders="true"
|
|
|
|
model="hex"
|
|
|
|
picker="square"
|
|
|
|
v-model="color"/>
|
2020-06-15 11:46:52 +02:00
|
|
|
<a @click="reset" class="reset">
|
|
|
|
Reset Color
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-09-05 22:35:52 +02:00
|
|
|
import verte from 'verte'
|
|
|
|
import 'verte/dist/verte.css'
|
2020-06-15 11:46:52 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
export default {
|
|
|
|
name: 'colorPicker',
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
color: '',
|
|
|
|
lastChangeTimeout: null,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
verte,
|
|
|
|
},
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
required: true,
|
2020-06-15 11:46:52 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
menuPosition: {
|
|
|
|
type: String,
|
|
|
|
default: 'top',
|
2020-06-15 11:46:52 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
watch: {
|
|
|
|
value(newVal) {
|
|
|
|
this.color = newVal
|
2020-06-15 11:46:52 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
color() {
|
|
|
|
this.update()
|
2020-06-15 11:46:52 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
mounted() {
|
|
|
|
this.color = this.value
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
update() {
|
2020-06-21 20:27:39 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
if (this.lastChangeTimeout !== null) {
|
|
|
|
clearTimeout(this.lastChangeTimeout)
|
|
|
|
}
|
2020-06-21 20:27:39 +02:00
|
|
|
|
2020-09-05 22:35:52 +02:00
|
|
|
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()
|
2020-06-15 11:46:52 +02:00
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
},
|
|
|
|
}
|
2020-06-15 11:46:52 +02:00
|
|
|
</script>
|