@fy-/fws-vue 0.3.22 → 0.3.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -3,7 +3,7 @@ import { LinkIcon } from "@heroicons/vue/24/solid";
|
|
|
3
3
|
import { computed, ref, toRef } from "vue";
|
|
4
4
|
import type { ErrorObject } from "@vuelidate/core";
|
|
5
5
|
import { useTranslation } from "../../composables/translations";
|
|
6
|
-
|
|
6
|
+
import DefaultTagInput from "./DefaultTagInput.vue";
|
|
7
7
|
type modelValueType = string | number | string[] | number[] | undefined;
|
|
8
8
|
|
|
9
9
|
type checkboxValueType = any[] | Set<any> | undefined | boolean;
|
|
@@ -25,6 +25,7 @@ const props = withDefaults(
|
|
|
25
25
|
options?: string[][];
|
|
26
26
|
help?: string;
|
|
27
27
|
error?: string;
|
|
28
|
+
color?: string;
|
|
28
29
|
errorVuelidate?: ErrorObject[];
|
|
29
30
|
disabled?: boolean;
|
|
30
31
|
}>(),
|
|
@@ -152,11 +153,21 @@ defineExpose({ focus, blur, getInputRef });
|
|
|
152
153
|
@blur="handleBlur"
|
|
153
154
|
/>
|
|
154
155
|
</div>
|
|
156
|
+
<div v-if="type == 'chips'">
|
|
157
|
+
<!-- @vue-skip -->
|
|
158
|
+
<DefaultTagInput
|
|
159
|
+
v-model="model"
|
|
160
|
+
:id="id"
|
|
161
|
+
:disabled="disabled"
|
|
162
|
+
:color="color"
|
|
163
|
+
/>
|
|
164
|
+
</div>
|
|
155
165
|
<div class="group relative" v-else-if="type == 'textarea'">
|
|
156
166
|
<label
|
|
167
|
+
v-if="label"
|
|
157
168
|
:for="id"
|
|
158
169
|
class="block mb-2 text-sm font-medium text-fv-neutral-900 dark:text-white"
|
|
159
|
-
>
|
|
170
|
+
>{{ label }}</label
|
|
160
171
|
>
|
|
161
172
|
<!-- @vue-skip -->
|
|
162
173
|
<textarea
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>
|
|
3
|
+
<label
|
|
4
|
+
:for="`tags_${id}`"
|
|
5
|
+
v-if="label"
|
|
6
|
+
class="block mb-2 text-sm font-medium text-fv-neutral-900 dark:text-white"
|
|
7
|
+
>{{ label }}</label
|
|
8
|
+
>
|
|
9
|
+
<div
|
|
10
|
+
class="tags-input"
|
|
11
|
+
@click="focusInput"
|
|
12
|
+
@keydown.delete.prevent="removeLastTag"
|
|
13
|
+
@keydown.enter.prevent="addTag"
|
|
14
|
+
>
|
|
15
|
+
<span v-for="(tag, index) in tags" :key="index" :class="`tag ${color}`">
|
|
16
|
+
{{ tag }}
|
|
17
|
+
<button @click.stop="removeTag(index)">
|
|
18
|
+
<svg
|
|
19
|
+
class="w-3 h-3"
|
|
20
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
21
|
+
fill="none"
|
|
22
|
+
viewBox="0 0 24 24"
|
|
23
|
+
stroke-width="1.5"
|
|
24
|
+
stroke="currentColor"
|
|
25
|
+
>
|
|
26
|
+
<path
|
|
27
|
+
stroke-linecap="round"
|
|
28
|
+
stroke-linejoin="round"
|
|
29
|
+
d="m9.75 9.75 4.5 4.5m0-4.5-4.5 4.5M21 12a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z"
|
|
30
|
+
/>
|
|
31
|
+
</svg>
|
|
32
|
+
</button>
|
|
33
|
+
</span>
|
|
34
|
+
<div
|
|
35
|
+
contenteditable
|
|
36
|
+
class="input"
|
|
37
|
+
:id="`tags_${id}`"
|
|
38
|
+
ref="textInput"
|
|
39
|
+
@input="handleInput"
|
|
40
|
+
@paste.prevent="handlePaste"
|
|
41
|
+
placeholder="Add a tag..."
|
|
42
|
+
></div>
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script setup lang="ts">
|
|
48
|
+
import { ref, watch, onMounted } from "vue";
|
|
49
|
+
type colorType = "blue" | "red" | "green" | "purple" | "orange" | "neutral";
|
|
50
|
+
|
|
51
|
+
const props = withDefaults(
|
|
52
|
+
defineProps<{
|
|
53
|
+
modelValue: string[];
|
|
54
|
+
color?: colorType;
|
|
55
|
+
label?: string;
|
|
56
|
+
id: string;
|
|
57
|
+
separators?: string[];
|
|
58
|
+
autofocus?: boolean;
|
|
59
|
+
}>(),
|
|
60
|
+
{
|
|
61
|
+
color: "blue",
|
|
62
|
+
label: "Tags",
|
|
63
|
+
separators: () => [","],
|
|
64
|
+
autofocus: false,
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const emit = defineEmits(["update:modelValue"]);
|
|
69
|
+
const tags = ref([...props.modelValue]);
|
|
70
|
+
const textInput = ref<HTMLElement>();
|
|
71
|
+
|
|
72
|
+
watch(
|
|
73
|
+
tags,
|
|
74
|
+
(newTags) => {
|
|
75
|
+
emit("update:modelValue", newTags);
|
|
76
|
+
},
|
|
77
|
+
{ deep: true },
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
onMounted(() => {
|
|
81
|
+
if (props.autofocus) {
|
|
82
|
+
focusInput();
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const handleInput = (event: any) => {
|
|
87
|
+
const separatorsRegex = new RegExp(props.separators.join("|"));
|
|
88
|
+
if (separatorsRegex.test(event.data)) {
|
|
89
|
+
addTag();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const addTag = () => {
|
|
94
|
+
if (!textInput.value) return;
|
|
95
|
+
|
|
96
|
+
const separatorsRegex = new RegExp(props.separators.join("|"));
|
|
97
|
+
const newTags = textInput.value.innerText
|
|
98
|
+
.split(separatorsRegex)
|
|
99
|
+
.map((tag: string) => tag.trim())
|
|
100
|
+
.filter((tag: string) => tag.length > 0);
|
|
101
|
+
tags.value.push(...newTags);
|
|
102
|
+
textInput.value.innerText = "";
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const removeTag = (index: number) => {
|
|
106
|
+
tags.value.splice(index, 1);
|
|
107
|
+
focusInput();
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const removeLastTag = () => {
|
|
111
|
+
if (!textInput.value) return;
|
|
112
|
+
|
|
113
|
+
if (textInput.value.innerText === "") {
|
|
114
|
+
tags.value.pop();
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const focusInput = () => {
|
|
119
|
+
if (!textInput.value) return;
|
|
120
|
+
|
|
121
|
+
textInput.value.focus();
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handlePaste = (e: any) => {
|
|
125
|
+
if (!textInput.value) return;
|
|
126
|
+
|
|
127
|
+
// @ts-ignore
|
|
128
|
+
const text = (e.clipboardData || window.clipboardData).getData("text");
|
|
129
|
+
const separatorsRegex = new RegExp(props.separators.join("|"), "g");
|
|
130
|
+
const pasteText = text.replace(separatorsRegex, ",");
|
|
131
|
+
textInput.value.innerText += pasteText;
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
addTag();
|
|
134
|
+
};
|
|
135
|
+
</script>
|
|
136
|
+
|
|
137
|
+
<style scoped>
|
|
138
|
+
.tags-input {
|
|
139
|
+
cursor: text;
|
|
140
|
+
@apply flex flex-wrap gap-2 items-center shadow-sm bg-fv-neutral-50 border border-fv-neutral-300 text-fv-neutral-900 text-sm rounded-sm focus:ring-fv-primary-500 focus:border-fv-primary-500 w-full p-2.5 dark:bg-fv-neutral-700 dark:border-fv-neutral-600 dark:placeholder-fv-neutral-400 dark:text-white dark:focus:ring-fv-primary-500 dark:focus:border-fv-primary-500;
|
|
141
|
+
}
|
|
142
|
+
.tag-label {
|
|
143
|
+
@apply block mb-2 text-sm font-medium text-fv-neutral-900 dark:text-white;
|
|
144
|
+
|
|
145
|
+
&.error {
|
|
146
|
+
@apply text-red-700 dark:text-red-500;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
.tag {
|
|
150
|
+
@apply inline-flex gap-1 font-medium px-2.5 py-0.5 rounded text-black dark:text-white;
|
|
151
|
+
&.blue {
|
|
152
|
+
@apply bg-blue-400 dark:bg-blue-900;
|
|
153
|
+
}
|
|
154
|
+
&.red {
|
|
155
|
+
@apply bg-red-400 dark:bg-red-900;
|
|
156
|
+
}
|
|
157
|
+
&.green {
|
|
158
|
+
@apply bg-green-400 dark:bg-green-900;
|
|
159
|
+
}
|
|
160
|
+
&.purple {
|
|
161
|
+
@apply bg-purple-400 dark:bg-purple-900;
|
|
162
|
+
}
|
|
163
|
+
&.orange {
|
|
164
|
+
@apply bg-orange-400 dark:bg-orange-900;
|
|
165
|
+
}
|
|
166
|
+
&.neutral {
|
|
167
|
+
@apply bg-fv-neutral-400 dark:bg-fv-neutral-900;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
.input {
|
|
172
|
+
flex-grow: 1;
|
|
173
|
+
min-width: 100px;
|
|
174
|
+
outline: none;
|
|
175
|
+
border: none;
|
|
176
|
+
}
|
|
177
|
+
</style>
|