Added filtering of categories
This commit is contained in:
@@ -2,23 +2,13 @@
|
|||||||
import { PhCaretDown } from '@phosphor-icons/vue';
|
import { PhCaretDown } from '@phosphor-icons/vue';
|
||||||
import type { Category } from '~/models/Category';
|
import type { Category } from '~/models/Category';
|
||||||
|
|
||||||
|
const isPopoverOpen = ref<boolean>(false)
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
placeholder?: string
|
placeholder?: string
|
||||||
multiple?: boolean
|
multiple?: boolean
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const model = defineModel<Category[] | Category>()
|
|
||||||
|
|
||||||
const { categories: availableCategories } = useCalendarEvents()
|
|
||||||
|
|
||||||
const isPopoverOpen = ref<boolean>(false)
|
|
||||||
|
|
||||||
function handleCatSelect() {
|
|
||||||
if (!props.multiple) {
|
|
||||||
isPopoverOpen.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const computedTextValue = computed(() => {
|
const computedTextValue = computed(() => {
|
||||||
if (model.value) {
|
if (model.value) {
|
||||||
if ("name" in model.value) {
|
if ("name" in model.value) {
|
||||||
@@ -30,6 +20,26 @@ const computedTextValue = computed(() => {
|
|||||||
return props.placeholder
|
return props.placeholder
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const model = defineModel<Category[] | Category>()
|
||||||
|
|
||||||
|
const { categories: availableCategories } = useCalendarEvents()
|
||||||
|
|
||||||
|
const searchTerm = ref<string>('')
|
||||||
|
|
||||||
|
function handleCatSelect() {
|
||||||
|
if (!props.multiple) {
|
||||||
|
isPopoverOpen.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const filteredCategories = computed(() =>
|
||||||
|
searchTerm.value === ''
|
||||||
|
? availableCategories
|
||||||
|
: availableCategories.filter((category) => {
|
||||||
|
return category.name.toLowerCase().includes(searchTerm.value.toLowerCase())
|
||||||
|
})
|
||||||
|
)
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@@ -51,15 +61,16 @@ const computedTextValue = computed(() => {
|
|||||||
:collision-padding="50"
|
:collision-padding="50"
|
||||||
class="w-fit h-[33vh] p-0"
|
class="w-fit h-[33vh] p-0"
|
||||||
>
|
>
|
||||||
<UiCommand v-model="model" :multiple>
|
<UiCommand v-model="model" v-model:searchTerm="searchTerm" :multiple>
|
||||||
<UiCommandInput placeholder="Rechercher les catégories" />
|
<UiCommandInput placeholder="Rechercher les catégories" />
|
||||||
<UiCommandEmpty>Aucune catégorie trouvée.</UiCommandEmpty>
|
<UiCommandEmpty>Aucune catégorie trouvée.</UiCommandEmpty>
|
||||||
<UiCommandList>
|
<UiCommandList>
|
||||||
<UiCommandGroup>
|
<UiCommandGroup>
|
||||||
<UiCommandItem
|
<UiCommandItem
|
||||||
v-for="category in availableCategories"
|
v-for="category in filteredCategories"
|
||||||
:key="category.id"
|
:key="category.id"
|
||||||
:value="category"
|
:value="category"
|
||||||
|
class="cursor-pointer"
|
||||||
@select="handleCatSelect"
|
@select="handleCatSelect"
|
||||||
>
|
>
|
||||||
{{ category.name }}
|
{{ category.name }}
|
||||||
|
|||||||
Reference in New Issue
Block a user