2020-06-15 11:46:52 +02:00
|
|
|
<template>
|
|
|
|
<div class="color-picker-container">
|
|
|
|
<verte
|
2020-11-01 14:59:47 +01:00
|
|
|
:showHistory="true"
|
|
|
|
:colorHistory="[
|
|
|
|
'#1973ff',
|
|
|
|
'#7F23FF',
|
|
|
|
'#ff4136',
|
|
|
|
'#ff851b',
|
|
|
|
'#ffeb10',
|
|
|
|
'#00db60',
|
|
|
|
]"
|
2020-09-05 22:35:52 +02:00
|
|
|
:enableAlpha="false"
|
|
|
|
:menuPosition="menuPosition"
|
|
|
|
:rgbSliders="true"
|
|
|
|
model="hex"
|
|
|
|
picker="square"
|
2021-01-23 18:41:13 +01:00
|
|
|
v-model="color"
|
|
|
|
:class="{'is-empty': empty}"
|
|
|
|
/>
|
2021-01-17 18:57:57 +01:00
|
|
|
<x-button @click="reset" class="is-small ml-2" :shadow="false" type="secondary">
|
2020-06-15 11:46:52 +02:00
|
|
|
Reset Color
|
2021-01-17 18:57:57 +01:00
|
|
|
</x-button>
|
2020-06-15 11:46:52 +02:00
|
|
|
</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
|
|
|
|
},
|
2021-01-23 18:41:13 +01:00
|
|
|
computed: {
|
|
|
|
empty() {
|
|
|
|
return this.color === '#000000' || this.color === ''
|
|
|
|
},
|
|
|
|
},
|
2020-09-05 22:35:52 +02:00
|
|
|
methods: {
|
2021-01-31 12:19:34 +01:00
|
|
|
update(force = false) {
|
2020-06-21 20:27:39 +02:00
|
|
|
|
2021-01-31 12:19:34 +01:00
|
|
|
if(this.empty && !force) {
|
2021-01-23 18:41:13 +01:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
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 = ''
|
2021-01-31 12:19:34 +01:00
|
|
|
this.update(true)
|
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>
|
2021-01-23 18:41:13 +01:00
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.verte.is-empty {
|
|
|
|
.verte__icon {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
.verte__guide {
|
|
|
|
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAAGklEQVQYlWM4c+bMf3TMgA0MBYWDzDkUKQQAlHCpV9ycHeMAAAAASUVORK5CYII=);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|