Skip to content

Commit

Permalink
fix(theme): don't nest sidebar links (#1279)
Browse files Browse the repository at this point in the history
  • Loading branch information
brc-dd committed Sep 3, 2022
1 parent 496bd34 commit f840dbc
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions src/client/theme-default/components/VPSidebarLink.vue
Expand Up @@ -5,29 +5,35 @@ import { useData } from 'vitepress'
import { isActive } from '../support/utils.js'
import VPLink from './VPLink.vue'
withDefaults(defineProps<{ item: DefaultTheme.SidebarItem; depth?: number }>(), { depth: 1 })
withDefaults(
defineProps<{ item: DefaultTheme.SidebarItem; depth?: number }>(),
{ depth: 1 }
)
const { page, frontmatter } = useData()
const maxDepth = computed<number>(() => frontmatter.value.sidebarDepth || Infinity)
const maxDepth = computed<number>(
() => frontmatter.value.sidebarDepth || Infinity
)
const closeSideBar = inject('close-sidebar') as () => void
</script>

<template>
<VPLink
class="link"
:class="{ active: isActive(page.relativePath, item.link), offset: depth > 1 }"
:class="{ active: isActive(page.relativePath, item.link) }"
:style="{ paddingLeft: 16 * (depth - 1) + 'px' }"
:href="item.link"
@click="closeSideBar"
>
<span class="link-text" :class="{ light: depth > 1 }">{{ item.text }}</span>
<template
v-if="'items' in item && depth < maxDepth"
v-for="child in item.items"
:key="child.link"
>
<VPSidebarLink :item="child" :depth="depth + 1" />
</template>
</VPLink>
<template
v-if="'items' in item && depth < maxDepth"
v-for="child in item.items"
:key="child.link"
>
<VPSidebarLink :item="child" :depth="depth + 1" />
</template>
</template>

<style scoped>
Expand All @@ -38,10 +44,6 @@ const closeSideBar = inject('close-sidebar') as () => void
transition: color 0.5s;
}
.link.offset {
padding-left: 16px;
}
.link:hover {
color: var(--vp-c-text-1);
}
Expand Down

0 comments on commit f840dbc

Please sign in to comment.