-
-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathContentSidebar.vue
More file actions
143 lines (125 loc) · 3.53 KB
/
Copy pathContentSidebar.vue
File metadata and controls
143 lines (125 loc) · 3.53 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
<template>
<div class="content-sidebar-wrapper">
<div ref="sidebar" class="content-sidebar">
<p class="content-sidebar-title">{{ title }}</p>
<label id="inheritToggle" for="inherited" v-if="isAPI">Hide inherited</label><input type="checkbox" id="inherited" name="inherited" v-model="checkedValue" v-if="isAPI"/>
<ul class="content-sidebar-links" v-if="items.length">
<li v-for="(item, i) in items" :key="i">
<ContentSidebarLink :item="item"/>
</li>
</ul>
</div>
</div>
</template>
<script>
import Vue from 'vue'
import ContentSidebarLink from '@theme/components/ContentSidebarLink.vue'
import { groupHeaders } from '@theme/util'
export default {
components: { ContentSidebarLink },
data: function () {
return {
currentAnchor: null
}
},
mounted () {
Vue.$vuepress.$on('contentAnchorChanged', this.onAnchorChanged)
},
beforeDestroy () {
Vue.$vuepress.store.$off('contentAnchorChanged', this.onAnchorChanged)
},
computed: {
title () {
return this.$themeConfig.contentSidebarTitle || 'Contents'
},
isAPI () {
return this.$route.path.includes("/api/")
},
items () {
const headers = groupHeaders(this.$page.headers || [])
return headers.map(header => {
const currentAnchor = this.currentAnchor || { hash: this.$route.hash !== '' ? this.$route.hash : '#' + this.$page.headers[0].slug, path: this.$route.path }
const selfActive = currentAnchor.hash === '#' + header.slug
const active = selfActive || (header.children && header.children.some(c => currentAnchor.hash === '#' + c.slug))
return {
type: 'auto',
title: header.title,
basePath: this.$page.path,
path: this.$page.path + '#' + header.slug,
active: active,
children: (header.children || []).map(child => {
child.active = currentAnchor.hash === '#' + child.slug
return child
})
}
})
},
checkedValue: {
get() {
return this.currentState
},
set(newValue) {
this.currentState = newValue;
var elements = document.querySelectorAll(".isInherited");
if (newValue) {
for (const el of elements) {
el.style.display = "none";
}
} else {
for (const el of elements) {
el.style.display = "block";
}
}
}
}
},
methods: {
onAnchorChanged (newAnchor) {
this.currentAnchor = newAnchor
}
}
}
</script>
<style lang="stylus">
.content-sidebar
font-size 0.82rem
height "calc(100vh - %s)" % ($navbarHeight + 4rem)
overflow-y auto
#inheritToggle
padding 0.4rem 0.4rem 0 0.7rem
border-left 1px solid $borderColor
cursor pointer
display inline-block
ul
padding 0
margin 0
list-style-type none
>ul
border-left 1px solid $borderColor
.content-sidebar-title
text-transform uppercase
letter-spacing 1px
font-size 0.6rem
font-weight 800
color $gray-dk
padding-left 0.7rem
margin 0.7rem 0 0 0
border-left 1px solid $borderColor
.content-sidebar-links
padding 1rem 0
&::-webkit-scrollbar
width 6px
&-track
background $white
&-thumb
background $gray
border-radius 3px
&-thumb:hover
background $gray-dk
@media (max-width: $MQMobile)
.content-sidebar-wrapper
padding 0
.content-sidebar
font-size 1rem
height "calc(100vh - %s)" % $navbarHeight
</style>