mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.7 KiB
78 lines
1.7 KiB
3 years ago
|
<template>
|
||
|
<div class="d-100 mb-5">
|
||
|
<div
|
||
|
class="rounded pa-5 mb-2 d-100 text-center caption"
|
||
|
:style="{background:value}"
|
||
|
@click="generateGradient"
|
||
|
>
|
||
|
Click to change gradient
|
||
|
</div>
|
||
3 years ago
|
|
||
|
<input v-model="color1" type="color">
|
||
|
<input v-model="color2" type="color">
|
||
3 years ago
|
</div>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
|
export default {
|
||
|
name: 'GradientGenerator',
|
||
|
props: {
|
||
|
value: [String]
|
||
|
},
|
||
|
data: () => ({
|
||
|
angle: 0
|
||
|
}),
|
||
|
computed: {
|
||
|
color1: {
|
||
|
get() {
|
||
3 years ago
|
const val = this.value && this.value.split(',')[1].trim()
|
||
|
return val
|
||
3 years ago
|
},
|
||
|
set(v) {
|
||
|
const gradient = 'linear-gradient(' + this.angle + 'deg, ' + v + ', ' + this.color2 + ')'
|
||
|
this.$emit('input', gradient)
|
||
|
}
|
||
|
},
|
||
|
color2: {
|
||
|
get() {
|
||
3 years ago
|
return this.value && this.value.split(',')[2].slice(0, -1).trim()
|
||
3 years ago
|
},
|
||
|
set(v) {
|
||
|
const gradient = 'linear-gradient(' + this.angle + 'deg, ' + this.color1 + ', ' + v + ')'
|
||
|
this.$emit('input', gradient)
|
||
|
}
|
||
|
}
|
||
|
},
|
||
3 years ago
|
created() {
|
||
|
if (!this.color1 && !this.color2) {
|
||
|
this.generateGradient()
|
||
|
}
|
||
|
},
|
||
3 years ago
|
methods: {
|
||
|
|
||
|
generateGradient() {
|
||
|
const hexValues = '0123456789abcde'
|
||
|
|
||
|
function populate(a) {
|
||
|
for (let i = 0; i < 6; i++) {
|
||
|
const x = Math.round(Math.random() * 14)
|
||
|
const y = hexValues[x]
|
||
|
a += y
|
||
|
}
|
||
|
return a
|
||
|
}
|
||
|
|
||
|
const newColor1 = populate('#')
|
||
|
const newColor2 = populate('#')
|
||
|
this.angle = Math.round(Math.random() * 360)
|
||
3 years ago
|
const gradient = 'linear-gradient(' + this.angle + 'deg, ' + newColor1 + ', ' + newColor2 + ')'
|
||
|
this.$emit('input', gradient)
|
||
3 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
</script>
|
||
|
|
||
|
<style scoped>
|
||
|
|
||
|
</style>
|