返回 slidev
TocList.vue
根目录 / packages / client / builtin / TocList.vue
1 <!--
2 TOC list
3 (used by Toc component, you don't need to use this component directly)
4
5 Usage:
6
7 <TocList :list="list"/>
8 -->
9 <script setup lang="ts">
10 import type { TocItem } from '@slidev/types'
11 import { toArray } from '@antfu/utils'
12 import { computed } from 'vue'
13 import TitleRenderer from '#slidev/title-renderer'
14 import { useNav } from '../composables/useNav'
15
16 const props = withDefaults(
17 defineProps<{
18 level?: number
19 start?: string | number
20 listStyle?: string | string[]
21 list: TocItem[]
22 listClass?: string | string[]
23 }>(),
24 { level: 1 },
25 )
26
27 const { isPresenter } = useNav()
28
29 const classes = computed(() => {
30 return [
31 ...toArray(props.listClass || []),
32 'slidev-toc-list',
33 `slidev-toc-list-level-${props.level}`,
34 ]
35 })
36
37 const styles = computed(() => {
38 return [
39 ...toArray(props.listStyle || []),
40 ]
41 })
42 </script>
43
44 <template>
45 <ol
46 v-if="list && list.length > 0"
47 :class="classes"
48 :start="level === 1 ? start : undefined"
49 :style="styles.length >= level ? `list-style:${styles[level - 1]}` : undefined"
50 >
51 <li
52 v-for="item of list"
53 :key="item.path" class="slidev-toc-item"
54 :class="[{ 'slidev-toc-item-active': item.active }, { 'slidev-toc-item-parent-active': item.activeParent }]"
55 >
56 <Link :to="isPresenter ? `/presenter${item.path}` : item.path">
57 <TitleRenderer :no="item.no" />
58 </Link>
59 <TocList
60 v-if="item.children.length > 0"
61 :level="level + 1"
62 :list-style="listStyle"
63 :list="item.children"
64 :list-class="listClass"
65 />
66 </li>
67 </ol>
68 </template>
69
70 <style>
71 .slidev-layout .slidev-toc-item p {
72 margin: 0;
73 }
74 .slidev-layout .slidev-toc-item div,
75 .slidev-layout .slidev-toc-item div p {
76 display: initial;
77 }
78 </style>
79
79 lines Plain Text