pleroma-fe/src/components/color_input/color_input.vue

111 lines
2.5 KiB
Vue
Raw Normal View History

2018-10-07 18:59:22 +02:00
<template>
2019-07-05 09:17:44 +02:00
<div
class="color-input style-control"
2019-07-05 09:17:44 +02:00
:class="{ disabled: !present || disabled }"
>
<label
:for="name"
class="label"
2018-10-07 18:59:22 +02:00
>
2019-07-05 09:17:44 +02:00
{{ label }}
</label>
<Checkbox
2019-12-28 14:55:42 +01:00
v-if="typeof fallback !== 'undefined' && showOptionalTickbox"
:checked="present"
:disabled="disabled"
@change="$emit('input', typeof value === 'undefined' ? fallback : undefined)"
class="opt"
2019-07-05 09:17:44 +02:00
/>
<div class="input color-input-field">
<input
:id="name + '-t'"
class="textColor unstyled"
type="text"
:value="value || fallback"
:disabled="!present || disabled"
@input="$emit('input', $event.target.value)"
>
<input
v-if="validColor"
:id="name"
class="nativeColor unstyled"
type="color"
:value="value || fallback"
:disabled="!present || disabled"
@input="$emit('input', $event.target.value)"
>
<div
v-if="transparentColor"
class="transparentIndicator"
/>
</div>
2019-07-05 09:17:44 +02:00
</div>
2018-10-07 18:59:22 +02:00
</template>
<style lang="scss" src="./color_input.scss"></style>
2018-10-07 18:59:22 +02:00
<script>
import Checkbox from '../checkbox/checkbox.vue'
import { hex2rgb } from '../../services/color_convert/color_convert.js'
2018-10-07 18:59:22 +02:00
export default {
2019-12-28 14:55:42 +01:00
props: {
// Name of color, used for identifying
name: {
required: true,
type: String
},
// Readable label
label: {
required: true,
type: String
},
// Color value, should be required but vue cannot tell the difference
// between "property missing" and "property set to undefined"
value: {
required: false,
type: String,
default: undefined
},
// Color fallback to use when value is not defeind
fallback: {
required: false,
type: String,
default: undefined
},
// Disable the control
disabled: {
required: false,
type: Boolean,
default: false
},
// Show "optional" tickbox, for when value might become mandatory
showOptionalTickbox: {
required: false,
type: Boolean,
default: true
}
},
components: {
Checkbox
},
2018-10-07 18:59:22 +02:00
computed: {
present () {
return typeof this.value !== 'undefined'
},
validColor () {
return hex2rgb(this.value || this.fallback)
},
transparentColor () {
return this.value === 'transparent'
2018-10-07 18:59:22 +02:00
}
}
}
</script>
<style lang="scss">
.color-control {
2018-11-20 20:14:49 +01:00
input.text-input {
2018-10-07 18:59:22 +02:00
max-width: 7em;
flex: 1;
}
}
</style>