mirror of https://github.com/vuejs/vitepress
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1020 B
43 lines
1020 B
<script lang="ts" setup>
|
|
import type { DefaultTheme } from 'vitepress/theme'
|
|
import { computed } from 'vue'
|
|
import { useData } from '../composables/data'
|
|
import { isActive } from '../../shared'
|
|
import VPFlyout from './VPFlyout.vue'
|
|
|
|
const props = defineProps<{
|
|
item: DefaultTheme.NavItemWithChildren
|
|
}>()
|
|
|
|
const { page } = useData()
|
|
|
|
const isChildActive = (navItem: DefaultTheme.NavItem) => {
|
|
if ('component' in navItem) return false
|
|
|
|
if ('link' in navItem) {
|
|
return isActive(
|
|
page.value.relativePath,
|
|
typeof navItem.link === "function" ? navItem.link(page.value) : navItem.link,
|
|
!!props.item.activeMatch
|
|
)
|
|
}
|
|
|
|
return navItem.items.some(isChildActive)
|
|
}
|
|
|
|
const childrenActive = computed(() => isChildActive(props.item))
|
|
</script>
|
|
|
|
<template>
|
|
<VPFlyout
|
|
:class="{
|
|
VPNavBarMenuGroup: true,
|
|
active:
|
|
isActive(page.relativePath, item.activeMatch, !!item.activeMatch) ||
|
|
childrenActive
|
|
}"
|
|
:button="item.text"
|
|
:items="item.items"
|
|
/>
|
|
</template>
|