-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Refactor Add Item input * Refactor tag inputs
- Loading branch information
Showing
6 changed files
with
177 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<script setup> | ||
import { ref, computed } from 'vue' | ||
import { | ||
Combobox, | ||
ComboboxInput, | ||
ComboboxButton, | ||
ComboboxOptions, | ||
ComboboxOption, | ||
TransitionRoot, | ||
} from '@headlessui/vue'; | ||
const props = defineProps({ | ||
items: Array, | ||
modelValue: Object, | ||
}); | ||
defineEmits(['update:modelValue']); | ||
let query = ref('') | ||
let filteredItems = computed(() => { | ||
const items = query.value === '' | ||
? props.items | ||
: props.items.filter((item) => | ||
item.name | ||
.toLowerCase() | ||
.replace(/\s+/g, '') | ||
.includes(query.value.toLowerCase().replace(/\s+/g, '')) | ||
); | ||
return items.slice(0, 100) | ||
}) | ||
</script> | ||
|
||
<template> | ||
<Combobox | ||
:modelValue="modelValue" | ||
@update:modelValue="value => $emit('update:modelValue', value)" | ||
by="id" | ||
> | ||
<div class="relative"> | ||
<div | ||
class="relative w-full cursor-default overflow-hidden rounded-lg bg-white text-left shadow-md focus:outline-none focus-visible:ring-2 focus-visible:ring-white/75 focus-visible:ring-offset-2 focus-visible:ring-offset-teal-300 sm:text-sm" | ||
> | ||
<ComboboxInput | ||
class="w-full border-none py-2 pl-3 pr-10 text-sm leading-5 text-gray-900 focus:ring-0" | ||
:displayValue="(item) => item.name" | ||
@change="query = $event.target.value" | ||
/> | ||
<ComboboxButton | ||
class="absolute inset-y-0 right-0 flex items-center pr-2" | ||
> | ||
<svg class="h-5 w-5 text-gray-400" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"> | ||
<path fill-rule="evenodd" d="M10 3a.75.75 0 01.55.24l3.25 3.5a.75.75 0 11-1.1 1.02L10 4.852 7.3 7.76a.75.75 0 01-1.1-1.02l3.25-3.5A.75.75 0 0110 3zm-3.76 9.2a.75.75 0 011.06.04l2.7 2.908 2.7-2.908a.75.75 0 111.1 1.02l-3.25 3.5a.75.75 0 01-1.1 0l-3.25-3.5a.75.75 0 01.04-1.06z" clip-rule="evenodd" /> | ||
</svg> | ||
</ComboboxButton> | ||
</div> | ||
<TransitionRoot | ||
leave="transition ease-in duration-100" | ||
leaveFrom="opacity-100" | ||
leaveTo="opacity-0" | ||
@after-leave="query = ''" | ||
> | ||
<ComboboxOptions | ||
class="absolute z-10 mt-1 max-h-96 w-full md:w-96 right-0 overflow-auto rounded-md bg-white py-1 text-base shadow-lg ring-1 ring-black/5 focus:outline-none sm:text-sm" | ||
> | ||
<div | ||
v-if="filteredItems.length === 0 && query !== ''" | ||
class="relative cursor-default select-none px-4 py-2 text-gray-700" | ||
> | ||
Nothing found. | ||
</div> | ||
|
||
<ComboboxOption | ||
v-for="item in filteredItems" | ||
as="template" | ||
:key="item.id" | ||
:value="item" | ||
v-slot="{ selected, active }" | ||
> | ||
<li | ||
class="relative cursor-default select-none py-2 pl-10 pr-4" | ||
:class="{ | ||
'bg-indigo-600 text-white': active, | ||
'text-gray-900': !active, | ||
}" | ||
> | ||
<span | ||
class="block truncate" | ||
:class="{ 'font-medium': selected, 'font-normal': !selected }" | ||
> | ||
{{ item.name }} | ||
</span> | ||
<span | ||
v-if="selected" | ||
class="absolute inset-y-0 left-0 flex items-center pl-3" | ||
:class="{ 'text-white': active, 'text-indigo-600': !active }" | ||
> | ||
<svg class="h-5 w-5" viewBox="0 0 20 20" fill="currentColor" aria-hidden="true"> | ||
<path fill-rule="evenodd" d="M16.704 4.153a.75.75 0 01.143 1.052l-8 10.5a.75.75 0 01-1.127.075l-4.5-4.5a.75.75 0 011.06-1.06l3.894 3.893 7.48-9.817a.75.75 0 011.05-.143z" clip-rule="evenodd" /> | ||
</svg> | ||
</span> | ||
</li> | ||
</ComboboxOption> | ||
</ComboboxOptions> | ||
</TransitionRoot> | ||
</div> | ||
</Combobox> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters