-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(home): move change language to navbar menu
- Loading branch information
Showing
7 changed files
with
105 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/modules/shared/components/nav-bar/nav-bar-language-menu.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<script setup lang="ts"> | ||
import { Icon } from '@iconify/vue' | ||
import Button from 'primevue/button' | ||
import Menu from 'primevue/menu' | ||
import type { MenuItem } from 'primevue/menuitem' | ||
import { ref } from 'vue' | ||
import { useColorMode } from '@vueuse/core' | ||
import { typesafeI18n } from '#i18n/i18n-vue' | ||
import { loadLocale } from '#i18n/i18n-util.sync' | ||
const { LL, locale, setLocale } = typesafeI18n() | ||
const menuTheme = ref<InstanceType<typeof Menu> | null>(null) | ||
const menuItemsTheme = ref<MenuItem[]>([ | ||
{ | ||
label: LL.value.common.language(), | ||
items: [ | ||
{ | ||
icon: 'flag:us-1x1', | ||
label: LL.value.common.english(), | ||
showEndIcon: locale.value === 'en', // FIXME: this is not reactive | ||
command: () => { | ||
// update dictionaries and update formatters | ||
loadLocale('en') | ||
// change locale store | ||
setLocale('en') | ||
}, | ||
}, | ||
{ | ||
icon: 'flag:id-1x1', | ||
label: 'Indonesia', | ||
showEndIcon: locale.value === 'id', | ||
command: () => { | ||
// update dictionaries and update formatters | ||
loadLocale('id') | ||
// change locale store | ||
setLocale('id') | ||
}, | ||
}, | ||
], | ||
}, | ||
]) | ||
</script> | ||
|
||
<template> | ||
<Button | ||
aria-haspopup="true" aria-controls="menu-theme" @click="(evt) => { | ||
menuTheme?.toggle(evt) | ||
}" | ||
> | ||
<template #icon> | ||
<Icon icon="lucide:globe" /> | ||
</template> | ||
</Button> | ||
|
||
<Menu id="menu-theme" ref="menuTheme" class="mt-2" :popup="true" :model="menuItemsTheme"> | ||
<template #item="{ item, props }"> | ||
<!-- IMPORTANT: wrapper needs to be an "a" tag for "command" to works --> | ||
<a v-ripple class="flex items-center" v-bind="props.action"> | ||
<Icon class="mr-2" :icon="item.icon as string" /> | ||
<span class="mr-auto">{{ item.label }}</span> | ||
<Icon v-if="item.showEndIcon" icon="lucide:check">{{ item.label }}</Icon> | ||
</a> | ||
</template> | ||
</Menu> | ||
</template> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters