feat(theme): add active status to nav menu group (#820)

Co-authored-by: Kia King Ishii <kia.king.08@gmail.com>
pull/837/head
Alex 2 years ago committed by GitHub
parent 47f1df5a5a
commit fdb5720acd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -83,6 +83,7 @@ type NavItemWithLink = {
interface NavItemWithChildren {
text?: string
items: NavItemWithLink[]
activeMatch?: string
}
```

@ -72,6 +72,14 @@ function onBlur() {
fill: var(--vp-c-text-2);
}
.VPFlyout.active .text {
color: var(--vp-c-brand);
}
.VPFlyout.active:hover .text {
color: var(--vp-c-brand-dark);
}
.VPFlyout:hover .menu,
.button[aria-expanded="true"] + .menu {
opacity: 1;

@ -1,12 +1,27 @@
<script lang="ts" setup>
import { useData } from 'vitepress'
import type { DefaultTheme } from 'vitepress/theme'
import { isActive } from '../support/utils'
import VPFlyout from './VPFlyout.vue'
defineProps<{
item: DefaultTheme.NavItemWithChildren
}>()
const { page } = useData()
</script>
<template>
<VPFlyout :button="item.text" :items="item.items" />
<VPFlyout
:class="{
VPNavBarMenuGroup: true,
active: isActive(
page.relativePath,
item.activeMatch,
!!item.activeMatch
)
}"
:button="item.text"
:items="item.items"
/>
</template>

@ -94,6 +94,12 @@ export namespace DefaultTheme {
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 -----------------------------------------------------------------------

Loading…
Cancel
Save