mirror of
https://github.com/KevinMidboe/planetposen.git
synced 2025-12-08 20:38:56 +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>
|
<template>
|
||||||
<header :class="{ dark: showDarkText }">
|
<header :class="{ dark: showDarkText }">
|
||||||
<div class="main col-wrap max-width">
|
<div class="main col-wrap max-width">
|
||||||
|
|
||||||
|
<!-- Desktop menu -->
|
||||||
<div class="main-content" v-if="!isMobile">
|
<div class="main-content" v-if="!isMobile">
|
||||||
<div class="logo">
|
<div class="logo">
|
||||||
<router-link to="/">
|
<router-link to="/">
|
||||||
@@ -16,13 +18,16 @@
|
|||||||
|
|
||||||
<ul class="secondary-nav-items">
|
<ul class="secondary-nav-items">
|
||||||
<li v-for="item in rightNavItems">
|
<li v-for="item in rightNavItems">
|
||||||
<router-link :to="item.link" class="">
|
<router-link :to="item.link">
|
||||||
<i v-if="item.icon" :class="'icon ' + item.icon"></i>
|
<span>{{ item.name }}</span>
|
||||||
<span v-else>{{ item.name }}</span>
|
|
||||||
</router-link>
|
</router-link>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
|
<cart :isDark="showDarkText" />
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Mobile menu -->
|
||||||
<div class="main-content" v-else>
|
<div class="main-content" v-else>
|
||||||
<div>
|
<div>
|
||||||
<router-link to="/">
|
<router-link to="/">
|
||||||
@@ -31,6 +36,8 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="menu">
|
<div class="menu">
|
||||||
|
<cart :isDark="showDarkText" />
|
||||||
|
|
||||||
<div class="menu-toggle" :class="{ active: showMenu }" @click="showMenu = !showMenu">
|
<div class="menu-toggle" :class="{ active: showMenu }" @click="showMenu = !showMenu">
|
||||||
<span v-if="!showMenu">Menu</span>
|
<span v-if="!showMenu">Menu</span>
|
||||||
<span v-else>Close menu</span>
|
<span v-else>Close menu</span>
|
||||||
@@ -55,10 +62,11 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
import logo from '@/components/ui/logo';
|
import logo from '@/components/ui/logo';
|
||||||
|
import cart from '@/components/ui/cart';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Navigation',
|
name: 'Navigation',
|
||||||
components: { logo },
|
components: { logo, cart },
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
showDarkText: false,
|
showDarkText: false,
|
||||||
@@ -78,10 +86,6 @@ export default {
|
|||||||
rightNavItems: [{
|
rightNavItems: [{
|
||||||
name: 'Admin',
|
name: 'Admin',
|
||||||
link: '/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 {
|
.main-nav-items, .secondary-nav-items {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@@ -180,11 +180,12 @@ a, span {
|
|||||||
|
|
||||||
|
|
||||||
.menu {
|
.menu {
|
||||||
&-toggle {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
|
||||||
|
&-toggle {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 2;
|
z-index: 2;
|
||||||
|
margin-left: 1rem;
|
||||||
|
|
||||||
&.active span {
|
&.active span {
|
||||||
border-bottom: 2px solid white;
|
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