/
FontWeight.vue
80 lines (77 loc) · 1.82 KB
/
FontWeight.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
<template>
<k-select-field class="k-fontweight-field"
:help="help"
:label="label"
:when="when"
:default="this.default"
:disabled="disabled"
:options="options"
:required="required"
v-model="value"
@input="onInput"/>
</template>
<script>
export default {
props: {
help: String,
label: String,
when: String,
watchField: String,
default: String,
disabled: Boolean,
value: String,
required: { type: Boolean, default: true },
},
data() {
return {
options: [],
loading: false,
}
},
created() {
this.syncContent(
this.$store.getters["content/values"]()[this.watchField]
)
},
watch: {
fontFamily() {
this.syncContent(
this.fontFamily
)
}
},
computed: {
hasChanges() {
return this.$store.getters["content/hasChanges"]()
},
fontFamily() {
return this.$store.getters["content/values"]()[this.watchField]
},
},
methods: {
onInput(value) {
this.$emit("input", value);
},
syncContent(family) {
if (family === undefined || family.length === 0) {
this.options = []
this.onInput('') // needs to be a string not null
return
}
this.$api.get('fontselector/family/' + encodeURIComponent(family))
.then(response => {
this.options = response.weight ? response.weight : []
if (this.options.some((item) => item.value === this.value) === false) {
this.onInput('') // needs to be a string not null
}
this.loading = false
})
.catch(error => {
this.loading = false
})
}
},
};
</script>
<style>
</style>