-
Notifications
You must be signed in to change notification settings - Fork 353
/
Copy pathSideBar.vue
127 lines (125 loc) · 3.15 KB
/
SideBar.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
123
124
125
126
127
<template>
<div class="sidebar"
:data="backgroundColor" data-background-color="darkblue">
<!--
Tip 1: you can change the color of the sidebar's background using: data-background-color="white | black | darkblue"
Tip 2: you can change the color of the active button using the data-active-color="primary | info | success | warning | danger"
-->
<!-- -->
<div class="sidebar-wrapper" id="style-3">
<div class="logo" style="text-align: center;">
<a class="simple-text logo-normal">
{{title}}
</a>
</div>
<slot>
</slot>
<ul class="nav">
<!--By default vue-router adds an active class to each route link. This way the links are colored when clicked-->
<slot name="links">
<sidebar-link v-for="(link,index) in sidebarLinks"
:key="index"
:to="link.path"
:name="link.name"
:icon="link.icon">
</sidebar-link>
</slot>
</ul>
</div>
</div>
</template>
<script>
import SidebarLink from "./SidebarLink";
export default {
props: {
title: {
type: String,
default: "XSS Hunter Express"
},
backgroundColor: {
type: String,
default: "FFFFFF"
},
activeColor: {
type: String,
default: "success",
validator: value => {
let acceptedValues = [
"primary",
"info",
"success",
"warning",
"danger"
];
return acceptedValues.indexOf(value) !== -1;
}
},
sidebarLinks: {
type: Array,
default: () => []
},
autoClose: {
type: Boolean,
default: true
}
},
provide() {
return {
autoClose: this.autoClose,
addLink: this.addLink,
removeLink: this.removeLink
};
},
components: {
SidebarLink
},
computed: {
/**
* Styles to animate the arrow near the current active sidebar link
* @returns {{transform: string}}
*/
arrowMovePx() {
return this.linkHeight * this.activeLinkIndex;
},
shortTitle() {
return this.title.split(' ')
.map(word => word.charAt(0))
.join('').toUpperCase();
}
},
data() {
return {
linkHeight: 65,
activeLinkIndex: 0,
windowWidth: 0,
isWindows: false,
hasAutoHeight: false,
links: []
};
},
methods: {
findActiveLink() {
this.links.forEach((link, index) => {
if (link.isActive()) {
this.activeLinkIndex = index;
}
});
},
addLink(link) {
const index = this.$slots.links.indexOf(link.$vnode);
this.links.splice(index, 0, link);
},
removeLink(link) {
const index = this.links.indexOf(link);
if (index > -1) {
this.links.splice(index, 1);
}
}
},
mounted() {
this.$watch("$route", this.findActiveLink, {
immediate: true
});
}
};
</script>