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.
71 lines
1.7 KiB
71 lines
1.7 KiB
3 years ago
|
<template>
|
||
|
<div class="d-100 mb-5">
|
||
2 years ago
|
<div class="rounded pa-5 mb-2 d-100 text-center caption" :style="{ background: value }" @click="generateGradient">
|
||
3 years ago
|
Click to change gradient
|
||
|
</div>
|
||
3 years ago
|
|
||
2 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: {
|
||
2 years ago
|
value: [String],
|
||
3 years ago
|
},
|
||
|
data: () => ({
|
||
2 years ago
|
angle: 0,
|
||
3 years ago
|
}),
|
||
|
computed: {
|
||
|
color1: {
|
||
|
get() {
|
||
2 years ago
|
const val = this.value && this.value.split(',')[1].trim();
|
||
|
return val;
|
||
3 years ago
|
},
|
||
|
set(v) {
|
||
2 years ago
|
const gradient = 'linear-gradient(' + this.angle + 'deg, ' + v + ', ' + this.color2 + ')';
|
||
|
this.$emit('input', gradient);
|
||
|
},
|
||
3 years ago
|
},
|
||
|
color2: {
|
||
|
get() {
|
||
2 years ago
|
return this.value && this.value.split(',')[2].slice(0, -1).trim();
|
||
3 years ago
|
},
|
||
|
set(v) {
|
||
2 years ago
|
const gradient = 'linear-gradient(' + this.angle + 'deg, ' + this.color1 + ', ' + v + ')';
|
||
|
this.$emit('input', gradient);
|
||
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
3 years ago
|
created() {
|
||
|
if (!this.color1 && !this.color2) {
|
||
2 years ago
|
this.generateGradient();
|
||
3 years ago
|
}
|
||
|
},
|
||
3 years ago
|
methods: {
|
||
|
generateGradient() {
|
||
2 years ago
|
const hexValues = '0123456789abcde';
|
||
3 years ago
|
|
||
|
function populate(a) {
|
||
|
for (let i = 0; i < 6; i++) {
|
||
2 years ago
|
const x = Math.round(Math.random() * 14);
|
||
|
const y = hexValues[x];
|
||
|
a += y;
|
||
3 years ago
|
}
|
||
2 years ago
|
return a;
|
||
3 years ago
|
}
|
||
|
|
||
2 years ago
|
const newColor1 = populate('#');
|
||
|
const newColor2 = populate('#');
|
||
|
this.angle = Math.round(Math.random() * 360);
|
||
|
const gradient = 'linear-gradient(' + this.angle + 'deg, ' + newColor1 + ', ' + newColor2 + ')';
|
||
|
this.$emit('input', gradient);
|
||
|
},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
2 years ago
|
<style scoped></style>
|