1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
<script>
import { GlFormInput, GlLink, GlTooltipDirective } from '@gitlab/ui';
export default {
components: {
GlFormInput,
GlLink,
},
directives: {
GlTooltip: GlTooltipDirective,
},
props: {
value: {
type: String,
required: false,
default: '',
},
},
computed: {
suggestedColors() {
const colorsMap = gon.suggested_label_colors;
return Object.keys(colorsMap).map((color) => ({ [color]: colorsMap[color] }));
},
selectedColor: {
get() {
return this.value;
},
set(color) {
this.handleColorClick(color);
},
},
},
methods: {
handleColorClick(color) {
this.$emit('input', color);
},
getColorCode(color) {
return Object.keys(color).pop();
},
getColorName(color) {
return Object.values(color).pop();
},
},
};
</script>
<template>
<div class="dropdown-content gl-px-3">
<div class="suggest-colors suggest-colors-dropdown gl-mt-0!">
<gl-link
v-for="(color, index) in suggestedColors"
:key="index"
v-gl-tooltip:tooltipcontainer
:style="{ backgroundColor: getColorCode(color) }"
:title="getColorName(color)"
@click.prevent="handleColorClick(getColorCode(color))"
/>
</div>
<div class="color-input-container gl-display-flex">
<gl-form-input
v-model.trim="selectedColor"
class="gl-rounded-top-right-none gl-rounded-bottom-right-none gl-mr-n1 gl-mb-2 gl-w-8"
type="color"
:value="selectedColor"
:placeholder="__('Select color')"
data-testid="selected-color"
/>
<gl-form-input
v-model.trim="selectedColor"
class="gl-rounded-top-left-none gl-rounded-bottom-left-none gl-mb-2"
:placeholder="__('Use custom color #FF0000')"
data-testid="selected-color-text"
/>
</div>
</div>
</template>
|