feat(theme): allow link on nav item with children

fix/2989
Divyansh Singh 1 year ago
parent 4f9a60b0cf
commit 36313dbe0e

@ -5,7 +5,7 @@ import { isActive } from '../../shared'
import VPLink from './VPLink.vue'
defineProps<{
item: DefaultTheme.NavItemWithLink
item: DefaultTheme.NavItem
}>()
const { page } = useData()

@ -6,21 +6,16 @@ import { isActive } from '../../shared'
import VPFlyout from './VPFlyout.vue'
const props = defineProps<{
item: DefaultTheme.NavItemWithChildren
item: DefaultTheme.NavItem
}>()
const { page } = useData()
const isChildActive = (navItem: DefaultTheme.NavItem) => {
if ('link' in navItem) {
return isActive(
page.value.relativePath,
navItem.link,
!!props.item.activeMatch
)
} else {
return navItem.items.some(isChildActive)
}
return (
isActive(page.value.relativePath, navItem.link, !!props.item.activeMatch) ||
navItem.items?.some(isChildActive)
)
}
const childrenActive = computed(() => isChildActive(props.item))
@ -30,11 +25,9 @@ const childrenActive = computed(() => isChildActive(props.item))
<VPFlyout
:class="{
VPNavBarMenuGroup: true,
active: isActive(
page.relativePath,
item.activeMatch,
!!item.activeMatch
) || childrenActive
active:
isActive(page.relativePath, item.activeMatch, !!item.activeMatch) ||
childrenActive
}"
:button="item.text"
:items="item.items"

@ -5,7 +5,7 @@ import { isActive } from '../../shared'
import VPLink from './VPLink.vue'
defineProps<{
item: DefaultTheme.NavItemWithLink
item: DefaultTheme.NavItem
}>()
const { page } = useData()

@ -9,15 +9,15 @@ const { theme } = useData()
<template>
<nav v-if="theme.nav" class="VPNavScreenMenu">
<template v-for="item in theme.nav" :key="item.text">
<VPNavScreenMenuLink
v-if="'link' in item"
:item="item"
/>
<VPNavScreenMenuGroup
v-else
v-if="item.items"
:text="item.text || ''"
:items="item.items"
/>
<VPNavScreenMenuLink
v-else
:item="item"
/>
</template>
</nav>
</template>

@ -4,7 +4,7 @@ import { inject } from 'vue'
import VPLink from './VPLink.vue'
defineProps<{
item: DefaultTheme.NavItemWithLink
item: DefaultTheme.NavItem
}>()
const closeScreen = inject('close-screen') as () => void

@ -4,7 +4,7 @@ import VPNavScreenMenuGroupLink from './VPNavScreenMenuGroupLink.vue'
defineProps<{
text?: string
items: DefaultTheme.NavItemWithLink[]
items: DefaultTheme.NavItem[]
}>()
</script>

@ -4,7 +4,7 @@ import { inject } from 'vue'
import VPLink from './VPLink.vue'
defineProps<{
item: DefaultTheme.NavItemWithLink
item: DefaultTheme.NavItem
}>()
const closeScreen = inject('close-screen') as () => void

@ -149,12 +149,10 @@ export namespace DefaultTheme {
// nav -----------------------------------------------------------------------
export type NavItem = NavItemWithLink | NavItemWithChildren
export interface NavItemWithLink {
export interface NavItem {
text: string
link: string
items?: never
link?: string
items?: NavItem[]
/**
* `activeMatch` is expected to be a regex string. We can't use actual
@ -165,22 +163,6 @@ export namespace DefaultTheme {
rel?: string
}
export interface NavItemChildren {
text?: string
items: NavItemWithLink[]
}
export interface NavItemWithChildren {
text?: string
items: (NavItemChildren | NavItemWithLink)[]
/**
* `activeMatch` is expected to be a regex string. We can't use actual
* RegExp object here because it isn't serializable
*/
activeMatch?: string
}
// image ---------------------------------------------------------------------
export type ThemeableImage =

Loading…
Cancel
Save