@fy-/fws-vue 0.0.916 → 0.0.917

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.
@@ -0,0 +1,164 @@
1
+ <template>
2
+ <div>
3
+ <label class="tag-label" :for="`tags_${id}`">{{ label }}</label>
4
+ <div
5
+ class="tags-input"
6
+ @click="focusInput"
7
+ @keydown.enter.prevent="addTag"
8
+ @keydown.delete="removeLastTag"
9
+ >
10
+ <span v-for="(tag, index) in tags" :key="index" :class="`tag ${color}`">
11
+ {{ tag }}
12
+ <button @click.stop="removeTag(index)">
13
+ <svg
14
+ xmlns="http://www.w3.org/2000/svg"
15
+ fill="none"
16
+ viewBox="0 0 24 24"
17
+ stroke-width="1.5"
18
+ stroke="currentColor"
19
+ class="w-3 h-3 text-red-600"
20
+ >
21
+ <path
22
+ stroke-linecap="round"
23
+ stroke-linejoin="round"
24
+ d="M14.74 9l-.346 9m-4.788 0L9.26 9m9.968-3.21c.342.052.682.107 1.022.166m-1.022-.165L18.16 19.673a2.25 2.25 0 01-2.244 2.077H8.084a2.25 2.25 0 01-2.244-2.077L4.772 5.79m14.456 0a48.108 48.108 0 00-3.478-.397m-12 .562c.34-.059.68-.114 1.022-.165m0 0a48.11 48.11 0 013.478-.397m7.5 0v-.916c0-1.18-.91-2.164-2.09-2.201a51.964 51.964 0 00-3.32 0c-1.18.037-2.09 1.022-2.09 2.201v.916m7.5 0a48.667 48.667 0 00-7.5 0"
25
+ />
26
+ </svg>
27
+ </button>
28
+ </span>
29
+ <div
30
+ contenteditable
31
+ class="input"
32
+ :id="`tags_${id}`"
33
+ ref="textInput"
34
+ @input="updateInput"
35
+ @paste.prevent="handlePaste"
36
+ placeholder="Add a tag..."
37
+ ></div>
38
+ </div>
39
+ </div>
40
+ </template>
41
+
42
+ <script setup>
43
+ import { ref, watch, onMounted } from "vue";
44
+
45
+ const props = defineProps({
46
+ modelValue: {
47
+ type: Array,
48
+ default: () => [],
49
+ },
50
+ color: {
51
+ type: String,
52
+ default: "blue",
53
+ },
54
+ label: {
55
+ type: String,
56
+ default: "Tags",
57
+ },
58
+ id: {
59
+ type: String,
60
+ required: true,
61
+ },
62
+ autofocus: {
63
+ type: Boolean,
64
+ default: false,
65
+ },
66
+ });
67
+
68
+ const emit = defineEmits(["update:modelValue"]);
69
+ const tags = ref([...props.modelValue]);
70
+ const textInput = ref(null);
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 updateInput = (event) => {
87
+ const text = event.target.innerText;
88
+ if (text.includes(",")) {
89
+ addTag();
90
+ }
91
+ };
92
+
93
+ const addTag = () => {
94
+ const newTags = textInput.value.innerText
95
+ .split(",")
96
+ .map((tag) => tag.trim())
97
+ .filter((tag) => tag.length > 0);
98
+ tags.value.push(...newTags);
99
+ textInput.value.innerText = "";
100
+ };
101
+
102
+ const removeTag = (index) => {
103
+ tags.value.splice(index, 1);
104
+ focusInput();
105
+ };
106
+
107
+ const removeLastTag = () => {
108
+ if (textInput.value.innerText === "") {
109
+ tags.value.pop();
110
+ }
111
+ };
112
+
113
+ const focusInput = () => {
114
+ textInput.value.focus();
115
+ };
116
+
117
+ const handlePaste = (e) => {
118
+ const text = (e.clipboardData || window.clipboardData).getData("text");
119
+ textInput.value.innerText += text;
120
+ e.preventDefault();
121
+ };
122
+ </script>
123
+
124
+ <style scoped>
125
+ .tags-input {
126
+ cursor: text;
127
+ @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;
128
+ }
129
+ .tag-label {
130
+ @apply block mb-2 text-sm font-medium text-fv-neutral-900 dark:text-white;
131
+
132
+ &.error {
133
+ @apply text-red-700 dark:text-red-500;
134
+ }
135
+ }
136
+ .tag {
137
+ @apply inline-flex gap-1 font-medium px-2.5 py-0.5 rounded;
138
+ &.blue {
139
+ @apply bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-300;
140
+ }
141
+ &.purple {
142
+ @apply bg-purple-100 text-purple-800 dark:bg-purple-900 dark:text-purple-300;
143
+ }
144
+ &.red {
145
+ @apply bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-300;
146
+ }
147
+ &.orange {
148
+ @apply bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-300;
149
+ }
150
+ &.neutral {
151
+ @apply bg-fv-neutral-100 text-fv-neutral-800 dark:bg-fv-neutral-900 dark:text-fv-neutral-300;
152
+ }
153
+ &.green {
154
+ @apply bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-300;
155
+ }
156
+ }
157
+
158
+ .input {
159
+ flex-grow: 1;
160
+ min-width: 100px;
161
+ outline: none;
162
+ border: none;
163
+ }
164
+ </style>
package/index.ts CHANGED
@@ -38,7 +38,7 @@ import DefaultPaging from "./components/ui/DefaultPaging.vue";
38
38
  import DefaultBreadcrumb from "./components/ui/DefaultBreadcrumb.vue";
39
39
  import DefaultLoader from "./components/ui/DefaultLoader.vue";
40
40
  import DefaultSidebar from "./components/ui/DefaultSidebar.vue";
41
-
41
+ import DefaultTagInput from "./components/ui/DefaultTagInput.vue";
42
42
  // Components/FWS
43
43
  import UserFlow from "./components/fws/UserFlow.vue";
44
44
  import DataTable from "./components/fws/DataTable.vue";
@@ -119,6 +119,7 @@ export {
119
119
  DefaultBreadcrumb,
120
120
  DefaultLoader,
121
121
  DefaultSidebar,
122
+ DefaultTagInput,
122
123
 
123
124
  // FWS
124
125
  UserFlow,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fy-/fws-vue",
3
- "version": "0.0.916",
3
+ "version": "0.0.917",
4
4
  "author": "Florian 'Fy' Gasquez <m@fy.to>",
5
5
  "license": "MIT",
6
6
  "repository": {