-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
VPSidebarGroup.vue
112 lines (96 loc) · 2.15 KB
/
VPSidebarGroup.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
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import { ref } from 'vue'
import VPIconPlusSquare from './icons/VPIconPlusSquare.vue'
import VPIconMinusSquare from './icons/VPIconMinusSquare.vue'
import VPSidebarLink from './VPSidebarLink.vue'
const props = defineProps<{
text?: string
items: DefaultTheme.SidebarItem[]
collapsible?: boolean
collapsed?: boolean
}>()
const collapsed = ref(props.collapsible && props.collapsed)
function toggle() {
if (props.collapsible) {
collapsed.value = !collapsed.value
}
}
</script>
<template>
<section class="VPSidebarGroup" :class="{ collapsible, collapsed }">
<div
v-if="text"
class="title"
:role="collapsible ? 'button' : undefined"
@click="toggle"
>
<h2 class="title-text">{{ text }}</h2>
<div class="action">
<VPIconMinusSquare class="icon minus" />
<VPIconPlusSquare class="icon plus" />
</div>
</div>
<div class="items">
<template v-for="item in items" :key="item.link">
<VPSidebarLink :item="item" />
</template>
</div>
</section>
</template>
<style scoped>
.title {
display: flex;
justify-content: space-between;
align-items: flex-start;
z-index: 2;
}
.title-text {
padding-top: 6px;
padding-bottom: 6px;
line-height: 20px;
font-size: 14px;
font-weight: 700;
color: var(--vp-c-text-1);
}
.action {
display: none;
position: relative;
margin-right: -8px;
border-radius: 4px;
width: 32px;
height: 32px;
color: var(--vp-c-text-3);
transition: color 0.25s;
}
.VPSidebarGroup.collapsible .action {
display: block;
}
.title:hover .action {
color: var(--vp-c-text-2);
}
.icon {
position: absolute;
top: 8px;
left: 8px;
width: 16px;
height: 16px;
fill: currentColor;
}
.icon.minus { opacity: 1; }
.icon.plus { opacity: 0; }
.VPSidebarGroup.collapsed .icon.minus { opacity: 0; }
.VPSidebarGroup.collapsed .icon.plus { opacity: 1; }
.items {
overflow: hidden;
}
.VPSidebarGroup.collapsed .items {
margin-bottom: -22px;
max-height: 0;
}
@media (min-width: 960px) {
.VPSidebarGroup.collapsed .items {
margin-bottom: -14px;
}
}
</style>