Open source personal finance application
feat(CategoriesCommand): init
Ilya Komicheva7513cf963ea
diff --git a/app/app.config.ts b/app/app.config.tsindex 906f6354..49bb5c1a 100644--- a/app/app.config.ts+++ b/app/app.config.ts@@ -14,5 +14,13 @@ export default defineAppConfig({neutral: 'neutral',primary: 'black',},+ commandPalette: {+ slots: {+ group: 'p-0 py-1 first:pt-0',+ item: 'p-0',+ label: 'z-10 sticky top-0 bg-[var(--ui-bg)]',+ viewport: 'scrollerBlock',+ },+ },},})diff --git a/app/components/categories/CommandPalette.vue b/app/components/categories/CommandPalette.vuenew file mode 100644index 00000000..f6453bcb--- /dev/null+++ b/app/components/categories/CommandPalette.vue@@ -0,0 +1,84 @@+<script setup lang="ts">+import type { CategoryId, CategoryItemWithId } from '~/components/categories/types'++import { useCategoriesStore } from '~/components/categories/useCategoriesStore'++const props = defineProps<{+ activeItemId?: CategoryId+ hide?: () => null+}>()++const emit = defineEmits<{+ filter: [id: CategoryId]+ onClickParent: [id: CategoryId]+ onClose: []+ onSelected: [id: CategoryId]+}>()++const { t } = useI18n()+const categoriesStore = useCategoriesStore()++const cats = computed(() => categoriesStore.categoriesRootIds.map((id) => {+ const category = categoriesStore.items[id]!++ const items = category?.childIds?.length+ ? categoriesStore.getChildsIds(id).map(childId => ({+ id: childId,+ ...categoriesStore.items[childId],+ suffix: category.name,+ }))+ : [{+ id,+ ...category,+ suffix: category.name,+ }]++ return {+ ...category,+ childIds: undefined,+ id,+ items,+ slot: 'category',+ }+}))++function onSelect(item: CategoryItemWithId) {+ emit('onSelected', item.id)+ emit('onClose')+ if (props.hide)+ props.hide()+}+</script>++<template>+ <UCommandPalette+ :placeholder="t('categories.search.placeholder')"+ :groups="cats"+ labelKey="name"+ @update:modelValue="onSelect"+ >+ <template #category="{ item }">+ <UiElement+ :isActive="item.id === props.activeItemId"+ :lineWidth="1"+ class="w-full grow"+ insideClasses="min-h-[46px]"+ >+ <template #leftIcon>+ <UiIconBase+ :color="item.color"+ :name="item.icon"+ invert+ />+ </template>++ <div class="grid grow">+ <CategoriesName+ :alt="item.alt"+ :category="item"+ />+ </div>+ </UiElement>+ </template>+ </UCommandPalette>+</template>diff --git a/app/components/trnForm/SelectorCategory.vue b/app/components/trnForm/SelectorCategory.vueindex fc880c51..f67bcc40 100644--- a/app/components/trnForm/SelectorCategory.vue+++ b/app/components/trnForm/SelectorCategory.vue@@ -36,11 +36,12 @@ const isShow = ref(false)/></template>- <template #content="{ close }">- <CategoriesSelector+ <template #custom="{ close }">+ <CategoriesCommandPalette:hide="close"- class="min-w-72 md:px-2"- @onSelected="id => { emit('onSelected', id); close() }"+ :activeItemId="props.categoryId"+ class="min-w-72 -mt-2 bottomSheetContentInside"+ @onSelected="(id: CategoryId) => { emit('onSelected', id); close() }"/></template></BottomSheetOrDropdown>diff --git a/app/components/ui/Element.vue b/app/components/ui/Element.vueindex f36cf0ce..48209b17 100644--- a/app/components/ui/Element.vue+++ b/app/components/ui/Element.vue@@ -16,8 +16,8 @@ const emit = defineEmits<{const slots = useSlots()const classes = computed(() => cn(- getStyles('item', ['rounded', 'padding1', 'minh1', 'link']),- 'uiElement flex grow items-center gap-3 overflow-hidden -my-[1px] border border-transparent',+ getStyles('item', ['padding1', 'minh1', 'link']),+ 'uiElement flex grow items-center gap-3 overflow-hidden -my-[1px] border border-transparent rounded-(--ui-radius)',props.insideClasses,{ 'relative border-(--ui-primary)/60 z-10': props.isActive },))