it-tools/components/ColorInput.vue

58 lines
1.3 KiB
Vue
Raw Normal View History

2021-05-17 23:11:47 +02:00
<template>
<v-text-field
v-model="color"
hide-details
class="ma-0 pa-0"
outlined
:label="label"
@input="$emit('input', color)"
>
2021-05-22 00:45:00 +02:00
<template #append>
2021-05-17 23:11:47 +02:00
<v-menu v-model="menu" top nudge-bottom="101" nudge-left="16" :close-on-content-click="false">
2021-05-22 00:45:00 +02:00
<template #activator="{ on }">
2021-05-17 23:39:32 +02:00
<div :style="swatchStyle" v-on="on" />
2021-05-17 23:11:47 +02:00
</template>
<v-card>
<v-card-text class="pa-0">
2021-05-17 23:39:32 +02:00
<v-color-picker v-model="color" flat @input="$emit('input', color)" />
2021-05-17 23:11:47 +02:00
</v-card-text>
</v-card>
</v-menu>
</template>
</v-text-field>
</template>
<script lang="ts">
import {Component, Prop, Vue} from 'nuxt-property-decorator'
// Adapted from: https://codepen.io/JamieCurnow/pen/KKPjraK
@Component
export default class ColorInput extends Vue {
@Prop({default: '#ffffff'}) readonly value!: string;
@Prop() readonly label: string | undefined;
menu = false
color = ''
created() {
this.color = this.value
}
get swatchStyle() {
return {
backgroundColor: this.color,
cursor: 'pointer',
height: '30px',
width: '30px',
borderRadius: this.menu ? '50%' : '4px',
transition: 'border-radius 200ms ease-in-out'
}
}
}
</script>
<style scoped lang="less">
::v-deep .v-input__append-inner {
margin-top: 13px;
}
</style>