Skip to content

Commit 7a3f70c

Browse files
hamburgermenu component
1 parent 324e945 commit 7a3f70c

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

src/components/ui/HamburgerMenu.vue

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<template>
2+
<div ref="menu">
3+
<button @click.stop="toggleMenu" class="w-[30px] md:hidden block">
4+
<svg className="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
5+
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M4 6h16M4 12h16m-7 6h7" />
6+
</svg>
7+
</button>
8+
<div :class="['flex flex-col items-start bg-[#252424] absolute left-0 w-full py-2 z-1', isOpen ? 'top-[80px]' : 'top-[-200px] opacity-0', 'transition-all']">
9+
<a class="cursor-pointer w-full hover:bg-grey-400 py-2 px-5" v-for="item, i in navItems" :key="i" href="item.link" target="_blank">
10+
<span class="px-1">{{item.title}}</span>
11+
</a>
12+
<a class="cursor-pointer w-full hover:bg-grey-400 py-2 px-5">
13+
<span class="px-1">Connect Wallet</span>
14+
</a>
15+
</div>
16+
</div>
17+
</template>
18+
19+
<script setup lang="ts">
20+
import { NavItem } from '@/types';
21+
import { defineProps, ref, onMounted, onBeforeUnmount } from 'vue';
22+
const isOpen = ref<boolean>(false)
23+
24+
const toggleMenu = () => {
25+
isOpen.value = !isOpen.value;
26+
}
27+
const menu = ref<HTMLElement | null>(null);
28+
29+
const handleClickOutside = (event: MouseEvent) => {
30+
if (
31+
menu.value &&
32+
!menu.value.contains(event.target as Node)
33+
) {
34+
console.log(isOpen.value)
35+
isOpen.value = false;
36+
}
37+
};
38+
39+
onMounted(() => {
40+
document.addEventListener('click', handleClickOutside);
41+
});
42+
43+
onBeforeUnmount(() => {
44+
document.removeEventListener('click', handleClickOutside);
45+
});
46+
47+
const props = defineProps<{
48+
navItems: NavItem[]
49+
}>();
50+
51+
</script>

0 commit comments

Comments
 (0)