-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathNavLink.vue
90 lines (87 loc) · 2.81 KB
/
NavLink.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
<template>
<li v-if="!childrenLinks && isHeader" :class="{headerLink: true, [className]: className}">
<router-link :to="link" class="sidebar-link">
<span class="icon">
<i :class="fullIconName"></i>
</span>
{{header}} <sup v-if="label" :class="'text-' + labelColor" class="headerLabel">{{label}}</sup>
<b-badge v-if="badge" variant="primary" pill>{{badge}}</b-badge>
</router-link>
</li>
<li v-else-if="childrenLinks" :class="{headerLink: true, [className]: className}">
<div @click="() => togglePanelCollapse(link)">
<router-link :to="link" event="" class="d-flex sidebar-link">
<span class="icon">
<i :class="fullIconName"></i>
</span>
{{header}} <sup v-if="label" :class="'text-' + labelColor" class="ml-1 headerLabel">{{label}}</sup>
<div :class="{caretWrapper: true, carretActive: isActive}">
<i class="fa fa-angle-right" />
</div>
</router-link>
</div>
<b-collapse :id="'collapse' + index" :visible="isActive">
<ul class="sub-menu">
<NavLink v-for="link in childrenLinks"
:activeItem="activeItem"
:header="link.header"
:index="link.index"
:link="link.link"
:childrenLinks="link.childrenLinks"
:key="link.link"
/>
</ul>
</b-collapse>
</li>
<li v-else>
<router-link :to="index !== 'menu' && link">
{{header}} <sup v-if="label" :class="'text-' + labelColor" class="headerLabel">{{label}}</sup>
</router-link>
</li>
</template>
<script>
import { mapActions } from 'vuex';
export default {
name: 'NavLink',
props: {
badge: { type: String, default: '' },
header: { type: String, default: '' },
iconName: { type: String, default: '' },
c: { type: String, default: '' },
headerLink: { type: String, default: '' },
link: { type: String, default: '' },
childrenLinks: { type: Array, default: null },
className: { type: String, default: '' },
isHeader: { type: Boolean, default: false },
deep: { type: Number, default: 0 },
activeItem: { type: String, default: '' },
label: { type: String },
labelColor: { type: String, default: 'warning' },
index: { type: String },
},
data() {
return {
headerLinkWasClicked: true,
};
},
methods: {
...mapActions('layout', ['changeSidebarActive']),
togglePanelCollapse(link) {
this.changeSidebarActive(link);
this.headerLinkWasClicked = !this.headerLinkWasClicked
|| !this.activeItem.includes(this.index);
},
},
computed: {
fullIconName() {
return `fi ${this.iconName}`;
},
isActive() {
return (this.activeItem
&& this.activeItem.includes(this.index)
&& this.headerLinkWasClicked);
},
},
};
</script>
<style src="./NavLink.scss" lang="scss" scoped />