This repository was archived by the owner on Jun 27, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 146
/
Copy pathTableSearchRows.vue
117 lines (104 loc) · 3.26 KB
/
TableSearchRows.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
<template>
<div
v-for="(searchInput, key) in searchInputs"
v-show="searchInput.value !== null || isForcedVisible(searchInput.key)"
:key="key"
class="px-4 sm:px-0"
>
<div class="flex rounded-md shadow-sm relative mt-3">
<label
:for="searchInput.key"
class="inline-flex items-center px-4 rounded-l-md border border-r-0 border-gray-300 bg-gray-50 text-gray-500 text-sm dark:text-gray-100 dark:bg-gray-600 dark:border-gray-500"
>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5 mr-2 text-gray-400"
viewBox="0 0 20 20"
fill="currentColor"
>
<path
fill-rule="evenodd"
d="M8 4a4 4 0 100 8 4 4 0 000-8zM2 8a6 6 0 1110.89 3.476l4.817 4.817a1 1 0 01-1.414 1.414l-4.816-4.816A6 6 0 012 8z"
clip-rule="evenodd"
/>
</svg>
<span>{{ searchInput.label }}</span></label>
<input
:id="searchInput.key"
:ref="skipUnwrap.el"
:key="searchInput.key"
:name="searchInput.key"
:value="searchInput.value"
type="text"
class="flex-1 min-w-0 block w-full px-3 py-2 rounded-none rounded-r-md focus:ring-indigo-500 focus:border-gray-500 text-sm border-gray-300 focus:ring-2 dark:bg-gray-700 dark:border-gray-500 dark:text-gray-100"
@input="onChange(searchInput.key, $event.target.value)"
>
<div
class="absolute inset-y-0 right-0 pr-3 flex items-center"
>
<button
class="rounded-md text-gray-400 hover:text-gray-500 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500"
:dusk="`remove-search-row-${searchInput.key}`"
@click.prevent="onRemove(searchInput.key)"
>
<span class="sr-only">Remove search</span>
<svg
xmlns="http://www.w3.org/2000/svg"
class="h-5 w-5"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
>
<path
stroke-linecap="round"
stroke-linejoin="round"
stroke-width="2"
d="M6 18L18 6M6 6l12 12"
/>
</svg>
</button>
</div>
</div>
</div>
</template>
<script setup>
import { computed, ref, watch, nextTick } from "vue";
import find from "lodash-es/find";
const skipUnwrap = { el: ref([]) };
let el = computed(() => skipUnwrap.el.value);
const props = defineProps({
searchInputs: {
type: Object,
required: true,
},
forcedVisibleSearchInputs: {
type: Array,
required: true,
},
onChange: {
type: Function,
required: true,
},
onRemove: {
type: Function,
required: true,
},
});
function isForcedVisible(key) {
return props.forcedVisibleSearchInputs.includes(key);
}
watch(props.forcedVisibleSearchInputs, (inputs) => {
const latestInput = inputs.length > 0 ? inputs[inputs.length -1] : null;
if(!latestInput) {
return;
}
nextTick().then(() => {
const inputElement = find(el.value, (el) => {
return el.__vnode.key === latestInput;
});
if(inputElement) {
inputElement.focus();
}
});
}, { immediate: true });
</script>