Skip to content

Open source personal finance application

feat: add theme switcher component and improve form select functionality

Ilya Komichev26edf4bb9c75
diff --git a/app/components/app/theme/SwitcherSelect.vue b/app/components/app/theme/SwitcherSelect.vue
new file mode 100644
index 00000000..8d868e53
--- /dev/null
+++ b/app/components/app/theme/SwitcherSelect.vue
@@ -0,0 +1,68 @@
+<script setup lang="ts">
+const props = defineProps<{
+ isShowTitle?: boolean
+}>()
+
+const colorMode = useColorMode()
+const { t } = useI18n()
+
+type Theme = 'system' | 'light' | 'dark' | 'pink'
+
+const locales: {
+ label: string
+ value: Theme
+}[] = [{
+ label: t('theme.system'),
+ value: 'system',
+}, {
+ label: t('theme.light'),
+ value: 'light',
+}, {
+ label: t('theme.dark'),
+ value: 'dark',
+}, {
+ label: t('theme.pink'),
+ value: 'pink',
+}] as const
+
+function setTheme(theme: Theme) {
+ colorMode.preference = theme
+}
+</script>
+
+<template>
+ <div>
+ <UiTitle3
+ v-if="props.isShowTitle"
+ class="pb-2"
+ >
+ {{ t('theme.select') }}
+ </UiTitle3>
+
+ <FormSelect
+ :options="locales"
+ :value="colorMode.preference"
+ @change="(theme: Theme) => setTheme(theme)"
+ />
+ </div>
+</template>
+
+<i18n lang="yaml">
+en:
+ theme:
+ change: 'Change theme'
+ dark: 'Dark'
+ light: 'Light'
+ pink: 'Pink'
+ select: 'Select theme'
+ system: 'System'
+
+ru:
+ theme:
+ change: 'Сменить тему'
+ dark: 'Темная'
+ light: 'Светлая'
+ pink: 'Розовая'
+ select: 'Выберите тему'
+ system: 'Авто'
+</i18n>
diff --git a/app/components/categories/page/id/Index.vue b/app/components/categories/page/id/Index.vue
index b961af51..86fbc651 100644
--- a/app/components/categories/page/id/Index.vue
+++ b/app/components/categories/page/id/Index.vue
@@ -99,7 +99,7 @@ useHead({ title: category.value?.name })
>
<UiHeaderLink
icon="mdi:pencil-outline"
- @click="() => onEditClick(close)"
+ @click="onEditClick(close)"
>
{{ t('base.edit') }}
</UiHeaderLink>
diff --git a/app/components/form/Select.vue b/app/components/form/Select.vue
new file mode 100644
index 00000000..21abaca1
--- /dev/null
+++ b/app/components/form/Select.vue
@@ -0,0 +1,39 @@
+<script lang="ts" setup>
+const props = defineProps<{
+ options: {
+ label: string
+ value: string
+ }[]
+ value: string
+}>()
+
+const emit = defineEmits<{
+ change: [value: string]
+}>()
+</script>
+
+<template>
+ <select
+ :value="props.value"
+ @change="emit('change', $event.target.value)"
+ >
+ <option
+ v-for="option in props.options"
+ :key="option.value"
+ :value="option.value"
+ >
+ {{ option.label }}
+ </option>
+ </select>
+</template>
+
+<style lang="css" scoped>
+select {
+ appearance: none;
+ background-image: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSIyMCIgaGVpZ2h0PSIyMCIgdmlld0JveD0iMCAwIDI0IDI0IiBmaWxsPSJub25lIiBzdHJva2U9IiM4MDgwODAiIHN0cm9rZS13aWR0aD0iMS41IiBzdHJva2UtbGluZWNhcD0icm91bmQiIHN0cm9rZS1saW5lam9pbj0icm91bmQiIGNsYXNzPSJsdWNpZGUgbHVjaWRlLWNoZXZyb25zLXVwLWRvd24iPjxwYXRoIGQ9Im03IDE1IDUgNSA1LTUiLz48cGF0aCBkPSJtNyA5IDUtNSA1IDUiLz48L3N2Zz4=');
+ background-position: right 0.7rem center;
+ background-repeat: no-repeat;
+ background-size: 1.25em 1.25em;
+ @apply hocus:bg-item-hover bg-item-4 focus:outline-none border border-transparent focus:border-accent-1 -my-px block min-h-[42px] w-full max-w-lg grow items-center gap-0 gap-x-2 overflow-hidden rounded-md px-4 pr-10 py-2 ring-0;
+}
+</style>
diff --git a/app/components/layout/MenuBottomModal.vue b/app/components/layout/MenuBottomModal.vue
index b622282f..89abbdfb 100644
--- a/app/components/layout/MenuBottomModal.vue
+++ b/app/components/layout/MenuBottomModal.vue
@@ -21,24 +21,19 @@ const { isDemo } = useDemo()
<BottomSheetClose @onClick="close" />
</template>
- <div class="grid gap-3 bg-foreground-1 px-1 py-3">
+ <div class="bg-foreground-1 grid gap-3 px-1 py-3">
+ <LayoutSidebarMenu />
+
+ <div class="pl-2 pt-2">
+ <AppThemeSwitcherSelect isShowTitle />
+ </div>
+
<!-- User -->
<div
- v-if="userStore.user"
- class="px-4 pb-2"
+ v-if="!isDemo"
+ class="border-item-6 border-t px-2 pt-3"
>
- <div class="font-primary text-xl font-semibold">
- {{ userStore.user?.displayName }}
- </div>
- <div class="text-sm">
- {{ userStore.user?.email }}
- </div>
- </div>
-
- <LayoutSidebarMenu />
-
- <div class="pl-2">
- <AppThemeSwitcher isShowSystem isShowPink />
+ <UserViewLogout />
</div>
<div
diff --git a/app/components/ui/FormInput.vue b/app/components/ui/FormInput.vue
index ee5071d5..f603012f 100644
--- a/app/components/ui/FormInput.vue
+++ b/app/components/ui/FormInput.vue
@@ -16,9 +16,9 @@ const emit = defineEmits<{
<input
:placeholder="props.placeholder"
:value="props.value"
- :class="getStyles('item', ['link'])"
+ :class="getStyles('item', ['link', 'rounded'])"
:type="props.type ?? 'text'"
- class="m-0 w-full rounded-lg border border-solid border-item-3 bg-item-4 px-4 py-2.5 text-base font-normal placeholder:text-item-2 focus:border-accent-2 focus:bg-item-hover focus:text-item-1 focus:outline-none"
+ class="border-item-6 bg-item-4 placeholder:text-item-2 focus:border-accent-2 focus:bg-item-hover focus:text-item-1 m-0 w-full border border-solid px-3 py-2 text-base font-normal focus:outline-none"
@input="(event: HTMLInputEvent) => emit('updateValue', event.target.value)"
>
</template>
diff --git a/app/components/wallets/Delete.vue b/app/components/wallets/Delete.vue
index b8f873a1..efd21866 100644
--- a/app/components/wallets/Delete.vue
+++ b/app/components/wallets/Delete.vue
@@ -11,6 +11,10 @@ const props = defineProps<{
walletId: WalletId
}>()
+const emit = defineEmits<{
+ close: []
+}>()
+
const router = useRouter()
const trnsStore = useTrnsStore()
const walletStore = useWalletsStore()
@@ -34,6 +38,8 @@ function onClickDelete() {
}
async function onDeleteConfirm() {
+ emit('close')
+
const trnsIdsS: TrnId[] = JSON.parse(JSON.stringify(trnsIds.value))
router.push('/wallets')
await walletStore.deleteWallet(JSON.parse(JSON.stringify(props.walletId)), trnsIdsS)
diff --git a/app/components/wallets/Form.vue b/app/components/wallets/Form.vue
index 228e0349..273a2e83 100644
--- a/app/components/wallets/Form.vue
+++ b/app/components/wallets/Form.vue
@@ -162,17 +162,11 @@ async function onSave() {
{{ t('money.type') }}
</UiTitle3>
- <div class="px-1">
- <USelect
- :options="walletType"
- :value="props.walletForm.type"
- color="blue"
- optionAttribute="label"
- size="lg"
- variant="outline"
- @change="(value: WalletType) => emit('updateValue', 'type', value)"
- />
- </div>
+ <FormSelect
+ :options="walletType"
+ :value="props.walletForm.type ?? 'cash'"
+ @change="(value: WalletType) => emit('updateValue', 'type', value)"
+ />
</div>
<!-- Credit Limit -->
diff --git a/app/components/wallets/page/id/Index.vue b/app/components/wallets/page/id/Index.vue
index c4f5cba9..d9a8179a 100644
--- a/app/components/wallets/page/id/Index.vue
+++ b/app/components/wallets/page/id/Index.vue
@@ -62,8 +62,9 @@ onMounted(() => {
const total = computed(() => walletsStore.itemsComputed[walletId.value]?.amount ?? 0)
-function onEditClick() {
+function onEditClick(close: () => void) {
router.push(`/wallets/${walletId.value}/edit`)
+ close()
}
useHead({ title: wallet.value?.name })
@@ -88,15 +89,15 @@ useHead({ title: wallet.value?.name })
</UiHeaderTitle>
</template>
- <template #popover>
+ <template #popover="{ close }">
<UiHeaderLink
icon="mdi:pencil-outline"
- @click="onEditClick"
+ @click="onEditClick(close)"
>
{{ t('base.edit') }}
</UiHeaderLink>
- <WalletsDelete :walletId />
+ <WalletsDelete :walletId @close="close" />
</template>
<template #summary>
diff --git a/app/pages/components.vue b/app/pages/components.vue
new file mode 100644
index 00000000..20d71ce6
--- /dev/null
+++ b/app/pages/components.vue
@@ -0,0 +1,46 @@
+<script lang="ts" setup>
+
+</script>
+
+<template>
+ <UiPage>
+ <div class="grid gap-8 p-3">
+ <!-- UiTitle -->
+ <div>
+ <h1 class="border-item-6 mb-4 border-b pb-2">
+ UiTitle
+ </h1>
+
+ <div class="grid gap-4">
+ <UiTitle6>
+ UiTitle6
+ </UiTitle6>
+
+ <UiTitle8>
+ UiTitle8
+ </UiTitle8>
+
+ <UiTitle3>
+ UiTitle3
+ </UiTitle3>
+ </div>
+ </div>
+
+ <div>
+ <h1 class="border-item-6 mb-4 border-b pb-2">
+ UiText
+ </h1>
+
+ <div class="grid gap-4">
+ <UiTextSm1>
+ UiTextSm1
+ </UiTextSm1>
+
+ <UiTextSm2>
+ UiTextSm2
+ </UiTextSm2>
+ </div>
+ </div>
+ </div>
+ </UiPage>
+</template>
diff --git a/app/pages/login.vue b/app/pages/login.vue
index 3e604939..af443dc6 100644
--- a/app/pages/login.vue
+++ b/app/pages/login.vue
@@ -66,10 +66,10 @@ async function openDemo() {
</script>
<template>
- <div class="mx-auto grid size-full max-w-xl grid-rows-[auto,1fr,auto] p-2 py-4 md:p-6">
- <div class="flex flex-wrap items-start justify-between gap-2">
+ <div class="mx-auto grid size-full max-w-xl grid-rows-[auto,1fr,auto] px-2 py-3 md:p-6">
+ <div class="flex flex-wrap items-center justify-between gap-2">
<AppLocaleSwitcher />
- <AppThemeSwitcher class="justify-end" />
+ <AppThemeSwitcherSelect class="justify-end" />
</div>
<div