📱 Navbar show/ hide functionality on mobile

This commit is contained in:
Alicia Sykes 2021-10-11 21:36:23 +01:00
parent 5fe79711bd
commit 987f904430
2 changed files with 69 additions and 29 deletions

View File

@ -0,0 +1 @@
<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="bars" class="svg-inline--fa fa-bars fa-w-14" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512"><path fill="currentColor" d="M16 132h416c8.837 0 16-7.163 16-16V76c0-8.837-7.163-16-16-16H16C7.163 60 0 67.163 0 76v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16zm0 160h416c8.837 0 16-7.163 16-16v-40c0-8.837-7.163-16-16-16H16c-8.837 0-16 7.163-16 16v40c0 8.837 7.163 16 16 16z"></path></svg>

After

Width:  |  Height:  |  Size: 569 B

View File

@ -1,5 +1,10 @@
<template> <template>
<nav id="nav"> <div class="nav-outer">
<IconBurger
:class="`burger ${!navVisible ? 'visible' : ''}`"
@click="navVisible = !navVisible"
/>
<nav id="nav" v-if="navVisible">
<router-link <router-link
v-for="(link, index) in links" v-for="(link, index) in links"
:key="index" :key="index"
@ -10,22 +15,43 @@
class="nav-item" class="nav-item"
>{{link.title}}</router-link> >{{link.title}}</router-link>
</nav> </nav>
</div>
</template> </template>
<script> <script>
import IconBurger from '@/assets/interface-icons/burger-menu.svg';
export default { export default {
name: 'Nav', name: 'Nav',
components: {
IconBurger,
},
props: { props: {
links: Array, links: Array,
}, },
data: () => ({
navVisible: true,
isMobile: false,
}),
created() {
this.navVisible = !this.detectMobile();
this.isMobile = this.detectMobile();
},
methods: { methods: {
detectMobile() {
const screenWidth = document.body.clientWidth;
return screenWidth && screenWidth < 600;
},
isUrl: (str) => new RegExp(/(http|https):\/\/(\S+)(:[0-9]+)?/).test(str), isUrl: (str) => new RegExp(/(http|https):\/\/(\S+)(:[0-9]+)?/).test(str),
}, },
}; };
</script> </script>
<style scoped lang="scss"> <style scoped lang="scss">
@import '@/styles/style-helpers.scss';
@import '@/styles/media-queries.scss';
.nav-outer {
nav { nav {
display: flex; display: flex;
align-items: center; align-items: center;
@ -51,4 +77,17 @@ nav {
} }
} }
} }
/* Mobile and Burger-Menu Styles */
@extend .svg-button;
@include phone {
width: 100%;
nav { flex-wrap: wrap; }
}
.burger {
display: none;
&.visible { display: block; }
@include phone { display: block; }
}
}
</style> </style>