mirror of
https://github.com/KevinMidboe/planetposen.git
synced 2025-10-29 17:50:32 +00:00
Separated cart nav item to separate component.
Includes a badge that shows number of items, connected with store and links to /cart page. Always visible on mobile.
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
<template>
|
||||
<header :class="{ dark: showDarkText }">
|
||||
<div class="main col-wrap max-width">
|
||||
|
||||
<!-- Desktop menu -->
|
||||
<div class="main-content" v-if="!isMobile">
|
||||
<div class="logo">
|
||||
<router-link to="/">
|
||||
@@ -16,13 +18,16 @@
|
||||
|
||||
<ul class="secondary-nav-items">
|
||||
<li v-for="item in rightNavItems">
|
||||
<router-link :to="item.link" class="">
|
||||
<i v-if="item.icon" :class="'icon ' + item.icon"></i>
|
||||
<span v-else>{{ item.name }}</span>
|
||||
<router-link :to="item.link">
|
||||
<span>{{ item.name }}</span>
|
||||
</router-link>
|
||||
</li>
|
||||
|
||||
<cart :isDark="showDarkText" />
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<!-- Mobile menu -->
|
||||
<div class="main-content" v-else>
|
||||
<div>
|
||||
<router-link to="/">
|
||||
@@ -31,6 +36,8 @@
|
||||
</div>
|
||||
|
||||
<div class="menu">
|
||||
<cart :isDark="showDarkText" />
|
||||
|
||||
<div class="menu-toggle" :class="{ active: showMenu }" @click="showMenu = !showMenu">
|
||||
<span v-if="!showMenu">Menu</span>
|
||||
<span v-else>Close menu</span>
|
||||
@@ -55,10 +62,11 @@
|
||||
|
||||
<script>
|
||||
import logo from '@/components/ui/logo';
|
||||
import cart from '@/components/ui/cart';
|
||||
|
||||
export default {
|
||||
name: 'Navigation',
|
||||
components: { logo },
|
||||
components: { logo, cart },
|
||||
data() {
|
||||
return {
|
||||
showDarkText: false,
|
||||
@@ -78,10 +86,6 @@ export default {
|
||||
rightNavItems: [{
|
||||
name: 'Admin',
|
||||
link: '/admin'
|
||||
},{
|
||||
name: 'Cart',
|
||||
link: '/cart',
|
||||
icon: 'icon--basket-outline'
|
||||
}]
|
||||
}
|
||||
},
|
||||
@@ -163,10 +167,6 @@ a, span {
|
||||
}
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 1.5rem;
|
||||
}
|
||||
|
||||
.main-nav-items, .secondary-nav-items {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
@@ -180,11 +180,12 @@ a, span {
|
||||
|
||||
|
||||
.menu {
|
||||
&-toggle {
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
|
||||
&-toggle {
|
||||
position: relative;
|
||||
z-index: 2;
|
||||
margin-left: 1rem;
|
||||
|
||||
&.active span {
|
||||
border-bottom: 2px solid white;
|
||||
|
||||
67
frontend/components/ui/cart.vue
Normal file
67
frontend/components/ui/cart.vue
Normal file
@@ -0,0 +1,67 @@
|
||||
|
||||
<template>
|
||||
<router-link to="/cart" class="cart" :class="{ dark: isDark }">
|
||||
<div class="cart-counter">
|
||||
{{ cartInventory.length }}
|
||||
</div>
|
||||
<i class="icon icon--cart-outline"></i>
|
||||
</router-link>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import store from '@/store'
|
||||
export default {
|
||||
props: {
|
||||
isDark: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
required: false
|
||||
}
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
cartItems: [0,0,0,0]
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
cartInventory() {
|
||||
return store.getters['cartModule/inventory']
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style lang="scss" scoped>
|
||||
.cart {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
height: min-content;
|
||||
|
||||
cursor: pointer;
|
||||
z-index: 3;
|
||||
|
||||
&-counter {
|
||||
color: var(--color-background);
|
||||
background-color: var(--color-yellow);
|
||||
padding: 0.2rem 0.5rem;
|
||||
height: min-content;
|
||||
|
||||
margin-right: 0.5rem;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
border-bottom: unset;
|
||||
}
|
||||
}
|
||||
|
||||
.dark .icon {
|
||||
color: var(--color-background);
|
||||
}
|
||||
|
||||
.icon {
|
||||
font-size: 1.5rem;
|
||||
color: white;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user