-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMobileMenu.vue
57 lines (54 loc) · 1.61 KB
/
MobileMenu.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<script setup lang="ts">
import siteConfig from '~/site.config'
const { t } = useI18n()
const showMobileMenu = ref(false)
const onToggleMobileMenu = () => (showMobileMenu.value = !showMobileMenu.value)
useServerHead({
bodyAttrs: {
style: computed(() => showMobileMenu.value ? 'overflow: hidden' : 'overflow: auto').value,
},
})
</script>
<template>
<div class="md:hidden">
<button
type="button"
class="w-8 h-8 py-1 ml-1 mr-1 rounded-sm"
:aria-label="t('button.toggle_mobile_menu')"
@click="onToggleMobileMenu"
>
<Icon
:icon="showMobileMenu ? 'bi:x' : 'bi:list'"
width="32"
height="32"
class="text-gray-900 dark:text-gray-100"
/>
</button>
<div
class="fixed w-full h-full top-24 right-0 bg-white dark:bg-gray-900 z-10 transform ease-in-out duration-300" :class="[showMobileMenu ? 'translate-x-0' : 'translate-x-full']"
>
<button
type="button"
aria-label="toggle modal"
class="fixed w-full h-full cursor-auto focus:outline-hidden"
@click="onToggleMobileMenu"
/>
<nav class="fixed h-full mt-8">
<div
v-for="hnItem in siteConfig.headerNavigationItems"
:key="hnItem.title"
class="px-12 py-4"
>
<Link
class="text-2xl font-bold tracking-widest text-gray-900 dark:text-gray-100"
:href="hnItem.href"
:disable-router-link="hnItem.disableRouterLink"
@click="onToggleMobileMenu"
>
{{ hnItem.title }}
</Link>
</div>
</nav>
</div>
</div>
</template>