1
1
<script lang="ts" setup>
2
2
import type { DefaultTheme } from ' vitepress/theme'
3
- import { inject } from ' vue'
3
+ import { computed , inject } from ' vue'
4
4
import { useData } from ' vitepress'
5
5
import { isActive } from ' ../support/utils'
6
6
import VPLink from ' ./VPLink.vue'
7
7
8
- defineProps <{
9
- item: DefaultTheme .SidebarItem
10
- }>()
11
-
12
- const { page } = useData ()
8
+ withDefaults (defineProps <{ item: DefaultTheme .SidebarItem ; depth? : number }>(), { depth: 1 })
13
9
10
+ const { page, frontmatter } = useData ()
11
+ const maxDepth = computed <number >(() => frontmatter .value .sidebarDepth || Infinity )
14
12
const closeSideBar = inject (' close-sidebar' ) as () => void
15
13
</script >
16
14
17
15
<template >
18
16
<VPLink
19
- :class =" { active: isActive(page.relativePath, item.link) }"
17
+ class =" link"
18
+ :class =" { active: isActive(page.relativePath, item.link), offset: depth > 1 }"
20
19
:href =" item.link"
21
20
@click =" closeSideBar"
22
21
>
23
- <span class =" link-text" >{{ item.text }}</span >
22
+ <span class =" link-text" :class =" { light: depth > 1 }" >{{ item.text }}</span >
23
+ <template
24
+ v-if =" ' items' in item && depth < maxDepth "
25
+ v-for =" child in item .items "
26
+ :key =" child .link "
27
+ >
28
+ <VPSidebarLink :item =" child" :depth =" depth + 1" />
29
+ </template >
24
30
</VPLink >
25
31
</template >
26
32
27
33
<style scoped>
28
34
.link {
29
35
display : block ;
30
- padding : 4px 0 ;
36
+ margin : 4px 0 ;
31
37
color : var (--vp-c-text-2 );
32
38
transition : color 0.5s ;
33
39
}
34
40
41
+ .link.offset {
42
+ padding-left : 16px ;
43
+ }
44
+
35
45
.link :hover {
36
46
color : var (--vp-c-text-1 );
37
47
}
@@ -51,4 +61,9 @@ const closeSideBar = inject('close-sidebar') as () => void
51
61
font-size : 14px ;
52
62
font-weight : 500 ;
53
63
}
64
+
65
+ .link-text.light {
66
+ font-size : 13px ;
67
+ font-weight : 400 ;
68
+ }
54
69
</style >
0 commit comments