/
LibraryEditField.vue
84 lines (81 loc) · 2.41 KB
/
LibraryEditField.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
<template>
<div>
<div class="text-field">
<!-- edit mode -->
<div v-if="isEditMode">
<b-form-textarea class="form-control" :value="text" rows="3" no-resize @change="updateValue" />
</div>
<!-- shrink long text -->
<div v-else-if="text.length > maxDescriptionLength && !isExpanded">
<!-- eslint-disable vue/no-v-html -->
<span
class="shrinked-description"
:title="text"
v-html="linkify(sanitize(text.substring(0, maxDescriptionLength)))">
</span>
<!-- eslint-enable vue/no-v-html -->
<span :title="text">...</span>
<a class="more-text-btn" href="javascript:void(0)" @click="toggleDescriptionExpand">(more) </a>
</div>
<!-- Regular -->
<div v-else>
<!-- eslint-disable-next-line vue/no-v-html -->
<div v-html="linkify(sanitize(text))"></div>
<!-- hide toggle expand if text is too short -->
<a
v-if="text.length > maxDescriptionLength"
class="more-text-btn"
href="javascript:void(0)"
@click="toggleDescriptionExpand"
>(less)
</a>
</div>
</div>
</div>
</template>
<script>
import { MAX_DESCRIPTION_LENGTH } from "components/Libraries/library-utils";
import BootstrapVue from "bootstrap-vue";
import Vue from "vue";
import linkifyHtml from "linkify-html";
import { sanitize } from "dompurify";
Vue.use(BootstrapVue);
export default {
props: {
text: {
type: String,
},
changedValue: {
type: String,
},
isEditMode: {
type: Boolean,
},
isExpanded: {
type: Boolean,
},
},
data() {
return {
maxDescriptionLength: MAX_DESCRIPTION_LENGTH,
};
},
methods: {
sanitize,
updateValue(value) {
this.$emit("update:changedValue", value);
},
toggleDescriptionExpand() {
this.$emit("toggleDescriptionExpand");
},
linkify(raw_text) {
return linkifyHtml(raw_text);
},
},
};
</script>
<style scoped>
.text-field {
min-width: 20rem;
}
</style>