diff options
author | 2022-04-04 01:03:06 +0200 | |
---|---|---|
committer | 2022-04-04 01:03:06 +0200 | |
commit | e8594de7b45102b8bc1cfb82d0839e3722d9c4c2 (patch) | |
tree | c7cb6eb04784db0e1fcb64629dd112a7715d22fb /src/components | |
parent | bab92ef84f66372df40ce385c2949518ed158427 (diff) | |
download | it-tools-e8594de7b45102b8bc1cfb82d0839e3722d9c4c2.tar.gz it-tools-e8594de7b45102b8bc1cfb82d0839e3722d9c4c2.tar.zst it-tools-e8594de7b45102b8bc1cfb82d0839e3722d9c4c2.zip |
feat: search-bar
Diffstat (limited to 'src/components')
-rw-r--r-- | src/components/SearchBar.vue | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/components/SearchBar.vue b/src/components/SearchBar.vue new file mode 100644 index 0000000..78e18cf --- /dev/null +++ b/src/components/SearchBar.vue @@ -0,0 +1,57 @@ +<script lang="ts" setup> +import { SearchRound } from '@vicons/material' +import { computed, ref } from 'vue'; +import { deburr } from 'lodash' +import { tools } from '@/tools'; +import { useRouter } from 'vue-router'; + +const router = useRouter() +const queryString = ref('') + +const cleanString = (s: string) => deburr(s.trim().toLowerCase()) + +const searchableTools = tools.map(({ name, description, keywords, path }) => ({ + searchableText: [name, description, ...keywords].map(cleanString).join(' '), + path, + name +})) + +const options = computed(() => { + const query = cleanString(queryString.value) + + return searchableTools + .filter(({ searchableText }) => searchableText.includes(query)) + .map(({ name, path }) => ({ label: name, value: path })) +}) + +function onSelect(path: string) { + router.push(path) + queryString.value = '' +} + +</script> + +<template> + <div> + <n-auto-complete + placeholder="Search a tool..." + :options="options" + v-model:value="queryString" + :input-props="{ autocomplete: 'disabled' }" + :on-select="onSelect" + > + <template #prefix> + <n-icon> + <search-round /> + </n-icon> + </template> + </n-auto-complete> + </div> +</template> + + +<style lang="less" scoped> +// ::v-deep(.n-input__border) { +// border: none; +// } +</style>
\ No newline at end of file |