mirror of
https://github.com/ArthurDanjou/ui.git
synced 2026-02-01 12:47:57 +01:00
feat(CommandPalette): implement group filter function
This commit is contained in:
@@ -31,6 +31,7 @@ export interface CommandPaletteGroup<T> {
|
|||||||
label?: string
|
label?: string
|
||||||
slot?: string
|
slot?: string
|
||||||
items?: T[]
|
items?: T[]
|
||||||
|
filter?: (searchTerm: string, items: T[]) => T[]
|
||||||
/** The icon displayed when an item is highlighted. */
|
/** The icon displayed when an item is highlighted. */
|
||||||
highlightedIcon?: string
|
highlightedIcon?: string
|
||||||
}
|
}
|
||||||
@@ -111,7 +112,13 @@ const items = computed(() => props.groups?.filter((group) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return true
|
return true
|
||||||
}).flatMap(group => group.items?.map(item => ({ ...item, group: group.id })) || []) || [])
|
}).flatMap((group) => {
|
||||||
|
let items = group.items || []
|
||||||
|
if (group.filter) {
|
||||||
|
items = group.filter(searchTerm.value, items)
|
||||||
|
}
|
||||||
|
return items?.map(item => ({ ...item, group: group.id })) || []
|
||||||
|
}) || [])
|
||||||
|
|
||||||
const { results: fuseResults } = useFuse<T>(searchTerm, items, fuse)
|
const { results: fuseResults } = useFuse<T>(searchTerm, items, fuse)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user