-
Notifications
You must be signed in to change notification settings - Fork 399
/
Copy pathDatasetConfigurationLabels.vue
118 lines (114 loc) · 2.48 KB
/
DatasetConfigurationLabels.vue
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<template>
<div>
<div
:class="{ '--error': errors.length }"
class="dataset-config-label__input-container"
>
<input
type="text"
:value="optionsJoinedByCommas"
@input="onInput($event.target.value)"
@focus.stop="onFocus"
@blur="onBlur"
:placeholder="placeholder"
class="dataset-config-label__input"
/>
</div>
<Validation v-if="errors.length" :validations="translatedValidations" />
<label
v-else
class="dataset-config-label__label"
v-text="`Use coma to separate labels`"
/>
</div>
</template>
<script>
export default {
data() {
return {
errors: [],
isDirty: false,
};
},
props: {
question: {
type: Object,
required: true,
},
placeholder: {
type: String,
default: "",
},
},
computed: {
optionsJoinedByCommas() {
return this.question.options.map((item) => item.text).join(",");
},
translatedValidations() {
return this.errors.map((validation) => {
return this.$t(validation);
});
},
},
methods: {
validateOptions() {
this.errors = this.question.validate();
},
onFocus() {
this.$emit("is-focused", true);
},
onBlur() {
this.isDirty = true;
this.validateOptions();
this.$emit("is-focused", false);
},
onInput(inputValue) {
const optionsArray = inputValue.split(",");
const trimmedOptionsArray = optionsArray.map((text) => ({
value: text.trim(),
id: text.trim(),
text: text,
}));
this.question.settings.options = trimmedOptionsArray;
if (this.isDirty) {
this.validateOptions();
}
},
},
};
</script>
<style lang="scss" scoped>
$error-color: hsl(3, 100%, 69%);
.dataset-config-label {
&__input-container {
width: 100%;
padding: 0 $base-space;
border-radius: $border-radius;
border: 1px solid var(--bg-opacity-10);
background: var(--bg-accent-grey-1);
&.--error {
border-color: $error-color;
}
&:focus-within {
border-color: var(--fg-cuaternary);
}
}
&__input {
height: calc($base-space * 4 - 2px);
padding: 0;
border: none;
background: none;
width: 100%;
outline: none;
color: var(--fg-secondary);
@include font-size(12px);
@include input-placeholder {
color: var(--fg-tertiary);
}
}
&__label {
color: var(--fg-secondary);
@include font-size(12px);
}
}
</style>