-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathNavigation.vue
122 lines (116 loc) · 3.86 KB
/
Navigation.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<template>
<nav>
<!-- STANDARD NAV -->
<div class="dn db-ns bg-aqua pv3">
<div class="center mw7">
<!-- If in lesson (breadcrumbs) -->
<div v-if="isLesson" class="flex overflow-auto items-center bg-aqua navy f5 fw6 pv3 center tc mw7">
<router-link class="nav-link navy" to="/tutorials">Tutorials</router-link>
<span class="fw4">></span>
<router-link class="nav-link navy" :to="workshopLanding">{{workshopShortname}}</router-link>
</div>
<!-- standard nav -->
<div v-else class="dn flex overflow-auto items-center bg-aqua white pv3 center tc mw7">
<div v-for="(link, idx) in links" :key="`desktop-${idx}`">
<router-link :class="[isActive(link) ? 'white' : 'navy ', 'nav-link']" :to="`${link.path}`">{{link.text}}</router-link>
</div>
</div>
</div>
</div>
<!-- MOBILE NAV -->
<div class="db dn-ns">
<div class="flex items-center bg-aqua pv3 w-100">
<!-- If in lesson (breadcrumbs) -->
<div v-if="isLesson" class="flex-auto link pa2 fw5 f5 db bb border-aqua navy">
<router-link class="nav-link navy" to="/tutorials">Tutorials</router-link>
<span class="fw4"> > </span>
<router-link class="nav-link navy" :to="workshopLanding">{{workshopShortname}}</router-link>
</div>
<!-- standard nav -->
<div v-else class="flex-auto link pa2 fw5 f5 db bb border-aqua white">{{currentPage}}</div>
<button @click="toggleHamburger" class="button-reset bg-transparent b--transparent pr2">
<img v-if="isHamburgerClosed" src="../static/images/burger.svg"/>
<img v-else src="../static/images/close.svg"/>
</button>
</div>
<!-- hamburger displayed when requested -->
<div :class="{ dn: isHamburgerClosed }">
<div class="tc bg-aqua-muted white">
<div v-for="(link, idx) in links" :key="`mobile-${idx}`">
<router-link @click.native="toggleHamburger" :class="[isActive(link) || isActiveLesson(link) ? 'white' : 'navy', 'link pa3 fw5 f4 db bb border-aqua']" :to="`${link.path}`">{{link.text}}</router-link>
</div>
</div>
</div>
</div>
</nav>
</template>
<script>
export default {
name: 'Navigation',
data: (self) => {
return {
isHamburgerClosed: true,
currentPath: self.$route.path.toString(),
workshopShortname: self.$route.path.split('/')[1].split('-').map(e => e.charAt(0).toUpperCase() + e.slice(1)).join(' '),
workshopLanding: `/${self.$route.path.split('/')[1]}`,
links: [
{ text: 'Home', path: '/' },
{ text: 'Tutorials', path: '/tutorials' },
{ text: 'Chapters', path: '/chapters' },
{ text: 'Contribute', path: '/contribute' },
{ text: 'Host', path: '/host' },
{ text: 'Build', path: '/build' }
]
}
},
computed: {
isLesson: function () {
let count = 0
this.links.forEach(link => {
if (link.path === this.currentPath) {
count++
}
})
return count === 0
},
currentPage: function () {
let pageName
this.links.forEach(link => {
if (link.path === this.currentPath) {
pageName = link.text.toString()
}
})
return pageName
}
},
methods: {
toggleHamburger: function () {
this.isHamburgerClosed = !this.isHamburgerClosed
},
isActive: function (link) {
return link.path === this.$route.path
},
isActiveLesson: function (link) {
return this.isLesson && link.path === '/tutorials'
}
}
}
</script>
<style scoped>
.nav-link {
margin: 2px 20px;
font-size: 18px;
font-weight: 700;
text-decoration: none;
cursor: pointer;
}
.nav-link:hover {
color: white;
}
@media screen and (max-width: 479px) {
.nav-link {
margin: 2px 0px;
font-size: 16px;
}
}
</style>