2018-04-28 17:56:03 -04:00
|
|
|
<template lang="html">
|
2018-05-31 18:34:15 -04:00
|
|
|
<div class="ffz--color-widget">
|
|
|
|
<div v-if="showInput" class="tw-relative tw-full-width tw-mg-y-05">
|
|
|
|
<input
|
|
|
|
v-if="showInput"
|
|
|
|
ref="input"
|
|
|
|
v-model="color"
|
2019-06-20 15:15:54 -04:00
|
|
|
v-bind="$attrs"
|
2018-05-31 18:34:15 -04:00
|
|
|
type="text"
|
2021-02-11 19:40:12 -05:00
|
|
|
class="tw-block tw-border-radius-medium tw-font-size-6 tw-full-width ffz-input tw-pd-l-1 tw-pd-r-3 tw-pd-y-05 tw-mg-y-05"
|
2018-05-31 18:34:15 -04:00
|
|
|
autocapitalize="off"
|
|
|
|
autocorrect="off"
|
|
|
|
autocomplete="off"
|
|
|
|
@input="onChange"
|
|
|
|
>
|
|
|
|
|
|
|
|
<button
|
|
|
|
class="ffz-color-preview tw-absolute tw-top-0 tw-bottom-0 tw-right-0 tw-border-l tw-z-default"
|
|
|
|
@click="togglePicker"
|
|
|
|
>
|
|
|
|
<figure v-if="! valid" class="ffz-i-attention tw-c-text-alert" />
|
|
|
|
<figure v-else-if="color" :style="`background-color: ${color}`" />
|
|
|
|
<figure v-else class="ffz-i-eyedropper" />
|
|
|
|
</button>
|
2020-04-10 16:59:42 -04:00
|
|
|
<div
|
|
|
|
v-if="open"
|
|
|
|
v-on-clickaway="closePicker"
|
|
|
|
:class="{'ffz-bottom-100': openUp}"
|
|
|
|
class="tw-absolute tw-z-above tw-right-0"
|
|
|
|
>
|
2019-09-27 15:44:33 -04:00
|
|
|
<chrome-picker :disable-alpha="! alpha" :value="colors" @input="onPick" />
|
2018-05-31 18:34:15 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-05-03 15:33:03 -04:00
|
|
|
<div
|
|
|
|
v-else
|
2021-05-17 17:02:23 -04:00
|
|
|
:class="{'ffz-il-tooltip__container': hasTooltip}"
|
2021-05-03 15:33:03 -04:00
|
|
|
class="tw-relative"
|
|
|
|
>
|
2018-05-31 18:34:15 -04:00
|
|
|
<button
|
2019-08-09 14:24:26 -04:00
|
|
|
class="tw-button tw-button--text ffz-color-preview"
|
2018-05-31 18:34:15 -04:00
|
|
|
@click="togglePicker"
|
|
|
|
@contextmenu.prevent="maybeResetColor"
|
|
|
|
>
|
|
|
|
<figure v-if="! valid" class="ffz-i-attention tw-c-text-alert" />
|
|
|
|
<figure v-else-if="color" :style="`background-color: ${color}`">
|
|
|
|
|
|
|
|
</figure>
|
|
|
|
<figure v-else class="ffz-i-eyedropper" />
|
|
|
|
</button>
|
2018-06-27 14:13:59 -04:00
|
|
|
<div
|
|
|
|
v-if="open"
|
2019-06-20 15:15:54 -04:00
|
|
|
v-on-clickaway="closePicker"
|
2018-06-27 14:13:59 -04:00
|
|
|
:class="{'ffz-bottom-100': openUp}"
|
2021-05-17 17:02:23 -04:00
|
|
|
class="tw-absolute tw-z-above ffz-il-tooltip--down ffz-il-tooltip--align-right"
|
2018-06-27 14:13:59 -04:00
|
|
|
>
|
2019-09-27 15:44:33 -04:00
|
|
|
<chrome-picker :disable-alpha="! alpha" :value="colors" @input="onPick" />
|
2018-05-31 18:34:15 -04:00
|
|
|
</div>
|
2021-05-03 15:33:03 -04:00
|
|
|
<div
|
|
|
|
v-if="! open && hasTooltip"
|
2021-05-17 17:02:23 -04:00
|
|
|
class="ffz-il-tooltip ffz-il-tooltip--down ffz-il-tooltip--align-right"
|
2021-05-03 15:33:03 -04:00
|
|
|
>
|
|
|
|
{{ tooltip }}
|
|
|
|
<div v-if="nullable" class="tw-regular">
|
|
|
|
{{ t('setting.color.nullable', 'Right-Click to Reset') }}
|
|
|
|
</div>
|
|
|
|
</div>
|
2018-04-28 17:56:03 -04:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
|
|
|
import {Color} from 'utilities/color';
|
|
|
|
|
2018-05-31 18:34:15 -04:00
|
|
|
import {Sketch} from 'vue-color';
|
2018-04-28 17:56:03 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
components: {
|
2018-05-31 18:34:15 -04:00
|
|
|
'chrome-picker': Sketch
|
2018-04-28 17:56:03 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
props: {
|
|
|
|
value: String,
|
2019-09-27 15:44:33 -04:00
|
|
|
alpha: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
2018-04-28 17:56:03 -04:00
|
|
|
default: {
|
|
|
|
type: String,
|
|
|
|
default: '#000'
|
2018-04-29 01:28:19 -04:00
|
|
|
},
|
2018-05-31 18:34:15 -04:00
|
|
|
nullable: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
},
|
2018-04-29 01:28:19 -04:00
|
|
|
validate: {
|
|
|
|
type: Boolean,
|
|
|
|
default: true
|
2018-05-31 18:34:15 -04:00
|
|
|
},
|
|
|
|
showInput: {
|
2018-06-27 14:13:59 -04:00
|
|
|
type: Boolean,
|
|
|
|
default: true
|
|
|
|
},
|
2021-05-03 15:33:03 -04:00
|
|
|
tooltip: {
|
|
|
|
type: String,
|
|
|
|
default: null
|
|
|
|
},
|
2018-06-27 14:13:59 -04:00
|
|
|
openUp: {
|
2018-05-31 18:34:15 -04:00
|
|
|
type: Boolean,
|
|
|
|
default: false
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
color: '',
|
2018-04-29 01:28:19 -04:00
|
|
|
valid: false,
|
2018-04-28 17:56:03 -04:00
|
|
|
open: false
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2021-05-03 15:33:03 -04:00
|
|
|
hasTooltip() {
|
|
|
|
return this.tooltip?.length > 0 || this.nullable
|
|
|
|
},
|
|
|
|
|
2018-04-28 17:56:03 -04:00
|
|
|
colors() {
|
2018-04-29 01:28:19 -04:00
|
|
|
try {
|
|
|
|
return Color.RGBA.fromCSS(this.color || this.default)
|
|
|
|
} catch(err) {
|
|
|
|
return {
|
|
|
|
hex: this.default
|
|
|
|
}
|
|
|
|
}
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
value(val) {
|
|
|
|
this.color = val;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
mounted() {
|
|
|
|
this.color = this.value;
|
2018-04-29 01:28:19 -04:00
|
|
|
this._validate();
|
2018-04-28 17:56:03 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2018-05-31 18:34:15 -04:00
|
|
|
maybeResetColor() {
|
|
|
|
if ( this.open )
|
|
|
|
return this.open = false;
|
|
|
|
|
|
|
|
if ( this.nullable ) {
|
|
|
|
this.color = '';
|
|
|
|
this._validate();
|
|
|
|
this.emit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2018-04-28 17:56:03 -04:00
|
|
|
openPicker() {
|
|
|
|
this.open = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
closePicker() {
|
|
|
|
this.open = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
togglePicker() {
|
|
|
|
this.open = ! this.open;
|
|
|
|
},
|
|
|
|
|
|
|
|
onPick(color) {
|
|
|
|
const old_val = this.color;
|
|
|
|
|
|
|
|
if ( color.rgba.a == 1 )
|
|
|
|
this.color = color.hex;
|
|
|
|
else {
|
|
|
|
const c = color.rgba;
|
|
|
|
this.color = `rgba(${c.r}, ${c.g}, ${c.b}, ${c.a})`;
|
|
|
|
}
|
|
|
|
|
2018-04-29 01:28:19 -04:00
|
|
|
if ( old_val !== this.color ) {
|
|
|
|
this._validate();
|
|
|
|
this.emit();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
_validate() {
|
|
|
|
this.valid = true;
|
|
|
|
if ( ! this.color || ! this.color.length || ! this.validate )
|
|
|
|
return;
|
|
|
|
|
|
|
|
try {
|
|
|
|
Color.RGBA.fromCSS(this.color);
|
|
|
|
} catch(err) {
|
|
|
|
this.valid = false;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
emit() {
|
|
|
|
if ( this.valid )
|
2018-04-28 17:56:03 -04:00
|
|
|
this.$emit('input', this.color);
|
|
|
|
},
|
|
|
|
|
|
|
|
onChange() {
|
2018-04-29 01:28:19 -04:00
|
|
|
this._validate();
|
|
|
|
this.emit();
|
2018-04-28 17:56:03 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|