-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTocTree.vue
More file actions
49 lines (46 loc) · 1.17 KB
/
TocTree.vue
File metadata and controls
49 lines (46 loc) · 1.17 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
<script setup lang="ts">
import type { PropType } from 'vue'
interface TocLink {
id: string
text: string
level: number
children: TocLink[]
}
defineProps({
links: {
type: Array as PropType<TocLink[]>,
required: true
},
checkActive: {
type: Function as PropType<(hash: string) => string | null>,
required: true
},
scrollToHeading: {
type: Function as PropType<(id: string) => void>,
required: true
}
})
</script>
<template>
<Menu v-if="links && links.length" class="w-full">
<MenuItem v-for="link in links" :key="link.id">
<NuxtLink :href="`#${link.id}`" custom>
<template #default="{ route }">
<a
class="block px-2 py-1 text-base-content hover:bg-accent/10 rounded cursor-pointer"
:class="checkActive(route?.hash || '')"
@click.prevent="scrollToHeading(link.id)"
>
{{ link.text }}
</a>
</template>
</NuxtLink>
<TocTree
v-if="link.children && link.children.length"
:links="link.children"
:check-active="checkActive"
:scroll-to-heading="scrollToHeading"
/>
</MenuItem>
</Menu>
</template>