Skip to content

Commit

Permalink
chore: create account appearance form
Browse files Browse the repository at this point in the history
  • Loading branch information
hywax committed Aug 5, 2024
1 parent 28ae719 commit 836ffeb
Show file tree
Hide file tree
Showing 9 changed files with 164 additions and 7 deletions.
2 changes: 2 additions & 0 deletions apps/web/app/app.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export default defineAppConfig({
icons: {
account: {
settings: 'i-heroicons-cog',
appearance: 'i-heroicons-paint-brush',
security: 'i-heroicons-finger-print',
signOut: 'i-heroicons-arrow-left-on-rectangle',
},
Expand All @@ -27,6 +28,7 @@ export default defineAppConfig({
github: 'i-simple-icons-github',
},
colorMode: {
system: 'i-heroicons-computer-desktop-20-solid',
dark: 'i-heroicons-moon-20-solid',
light: 'i-heroicons-sun-20-solid',
},
Expand Down
15 changes: 15 additions & 0 deletions apps/web/app/components/account/AppearanceForm.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<template>
<UPageCard
:title="$t('account.appearance.title')"
:description="$t('account.appearance.description')"
>
<div class="space-y-4">
<UFormGroup :label="$t('account.appearance.form.theme.label')">
<UColorModeSelect />
</UFormGroup>
<UFormGroup :label="$t('account.appearance.form.i18n.label')">
<ULocaleSelect />
</UFormGroup>
</div>
</UPageCard>
</template>
50 changes: 50 additions & 0 deletions apps/web/app/components/ui/color-mode/ColorModeSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<ClientOnly v-if="!colorMode.forced">
<USelectMenu
v-bind="$attrs"
v-model="preference"
:options="options"
:leading-icon="preference?.icon"
/>

<template #fallback>
<USkeleton class="h-8 w-full" />
</template>
</ClientOnly>
</template>

<script setup lang="ts">
defineOptions({
inheritAttrs: false,
})
const { icons } = useAppConfig()
const colorMode = useColorMode()
const options = computed(() => [
{
label: $t('app.colorMode.system'),
value: 'system',
icon: icons.colorMode.system,
},
{
label: $t('app.colorMode.light'),
value: 'light',
icon: icons.colorMode.light,
},
{
label: $t('app.colorMode.dark'),
value: 'dark',
icon: icons.colorMode.dark,
},
])
const preference = computed({
get() {
return options.value.find((option) => option.value === colorMode.preference) || options.value[0]
},
set(option) {
colorMode.preference = option!.value
},
})
</script>
2 changes: 1 addition & 1 deletion apps/web/app/components/ui/color-mode/ColorModeToggle.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ const isDark = computed({
},
})
const areaLabel = computed(() => isDark.value ? t('app.colorMode.light') : t('app.colorMode.dark'))
const areaLabel = computed(() => isDark.value ? t('app.colorMode.switch.light') : t('app.colorMode.switch.dark'))
</script>
34 changes: 34 additions & 0 deletions apps/web/app/components/ui/i18n/LocaleSelect.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<template>
<ClientOnly>
<USelectMenu
v-bind="$attrs"
v-model="locale"
:options="options"
:leading-icon="currentLocale.icon"
/>

<template #fallback>
<USkeleton class="h-8 w-full" />
</template>
</ClientOnly>
</template>

<script setup lang="ts">
defineOptions({
inheritAttrs: false,
})
const { localesDictionary, currentLocale } = useI18nUtils()
const { setLocale } = useI18n()
const options = computed(() => Object.values(localesDictionary.value))
const locale = computed({
get() {
return currentLocale.value || options.value[0]
},
set(option) {
setLocale(option.code)
},
})
</script>
23 changes: 21 additions & 2 deletions apps/web/app/locales/en-US.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,15 @@ export default {
},
colorMode: {
title: 'Theme',
light: 'Switch to Light Mode',
dark: 'Switch to Dark Mode',
select: 'Select your theme',
system: 'System',
light: 'Light',
dark: 'Dark',
switch: {
system: 'Switch to System Theme',
light: 'Switch to Light Mode',
dark: 'Switch to Dark Mode',
},
},
footer: {
copyright: '© {year} Shorter by {author} {version}',
Expand Down Expand Up @@ -49,6 +56,18 @@ export default {
settings: 'Settings',
signOut: 'Sign Out',
},
appearance: {
title: 'Appearance',
description: 'Customize your experience with these settings.',
form: {
theme: {
label: 'Theme',
},
i18n: {
label: 'Language',
},
},
},
changePassword: {
title: 'Change Password',
description: 'Update your password to keep your account secure.',
Expand Down
25 changes: 22 additions & 3 deletions apps/web/app/locales/ru-RU.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ export default {
app: {
i18n: {
title: 'Язык',
select: 'Выбрать язык интерфейса',
select: 'Выберите язык интерфейса',
},
colorMode: {
title: 'Тема',
light: 'Переключиться на светлый режим',
dark: 'Переключиться на темный режим',
select: 'Выберите тему интерфейса',
system: 'Системная',
light: 'Светлая',
dark: 'Темная',
switch: {
system: 'Переключиться на системную тему',
light: 'Переключиться на светлый режим',
dark: 'Переключиться на темный режим',
},
},
footer: {
copyright: '© {year} Shorter, от {author} {version}',
Expand Down Expand Up @@ -49,6 +56,18 @@ export default {
settings: 'Настройки',
signOut: 'Выйти',
},
appearance: {
title: 'Внешний вид',
description: 'Настройте ваш опыт использования с помощью этих настроек.',
form: {
theme: {
label: 'Тема',
},
i18n: {
label: 'Язык',
},
},
},
changePassword: {
title: 'Изменить пароль',
description: 'Обновите свой пароль, чтобы обеспечить безопасность вашего аккаунта.',
Expand Down
7 changes: 6 additions & 1 deletion apps/web/app/pages/account.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
variant="ghost"
color="gray"
size="lg"
active-class="bg-gray-50 dark:bg-gray-800"
active-class="bg-gray-100 dark:bg-gray-800"
:to="link.to"
:exact="link.exact"
:label="link.label"
Expand Down Expand Up @@ -45,6 +45,11 @@ const links = [
to: '/account',
exact: true,
},
{
label: $t('account.appearance.title'),
icon: icons.account.appearance,
to: '/account/appearance',
},
{
label: $t('account.security'),
icon: icons.account.security,
Expand Down
13 changes: 13 additions & 0 deletions apps/web/app/pages/account/appearance.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<template>
<AccountAppearanceForm />
</template>

<script setup lang="ts">
definePageMeta({
middleware: ['auth'],
})
useHead({
title: () => $t('account.appearance.title'),
})
</script>

0 comments on commit 836ffeb

Please sign in to comment.