feat: add active style to VPFlyout, NavbarGroup can active now.

pull/820/head
casyalex 3 years ago
parent 75ca9e4302
commit 0fc32a10b2

@ -44,11 +44,15 @@ export default defineConfig({
function nav() { function nav() {
return [ return [
{ text: 'Guide', link: '/guide/what-is-vitepress', activeMatch: '/guide/' }, // { text: 'Guide', link: '/guide/what-is-vitepress', activeMatch: '/guide/' },
{ text: 'Configs', link: '/config/introduction', activeMatch: '/config/' }, { text: 'Configs', link: '/config/introduction', activeMatch: '/config/' },
{ {
text: 'Changelog', text: 'Changelog',
link: 'https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md' link: 'https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md'
},{
text:'Gruop Nav',
activeMatch: '/guide/',
items: [{ text: 'Guide', link: '/guide/what-is-vitepress', },]
} }
] ]
} }

@ -23,20 +23,9 @@ function onBlur() {
</script> </script>
<template> <template>
<div <div class="VPFlyout" ref="el" @mouseenter="open = true" @mouseleave="open = false">
class="VPFlyout" <button type="button" class="button" aria-haspopup="true" :aria-expanded="open" :aria-label="label"
ref="el" @click="open = !open">
@mouseenter="open = true"
@mouseleave="open = false"
>
<button
type="button"
class="button"
aria-haspopup="true"
:aria-expanded="open"
:aria-label="label"
@click="open = !open"
>
<span v-if="button || icon" class="text"> <span v-if="button || icon" class="text">
<component v-if="icon" :is="icon" class="option-icon" /> <component v-if="icon" :is="icon" class="option-icon" />
{{ button }} {{ button }}
@ -59,6 +48,10 @@ function onBlur() {
position: relative; position: relative;
} }
.VPFlyout.active .text {
color: var(--vp-c-brand);
}
.VPFlyout:hover { .VPFlyout:hover {
color: var(--vp-c-bland); color: var(--vp-c-bland);
transition: color 0.25s; transition: color 0.25s;
@ -73,7 +66,7 @@ function onBlur() {
} }
.VPFlyout:hover .menu, .VPFlyout:hover .menu,
.button[aria-expanded="true"] + .menu { .button[aria-expanded="true"]+.menu {
opacity: 1; opacity: 1;
visibility: visible; visibility: visible;
transform: translateY(0); transform: translateY(0);

@ -1,12 +1,20 @@
<script lang="ts" setup> <script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme' import type { DefaultTheme } from 'vitepress/theme'
import VPFlyout from './VPFlyout.vue' import VPFlyout from './VPFlyout.vue'
import { useData } from 'vitepress'
import { isActive } from '../support/utils'
defineProps<{ defineProps<{
item: DefaultTheme.NavItemWithChildren item: DefaultTheme.NavItemWithChildren
}>() }>()
const { page } = useData()
</script> </script>
<template> <template>
<VPFlyout :button="item.text" :items="item.items" /> <VPFlyout :class="{
</template> 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 { export interface NavItemWithChildren {
text?: string text?: string
items: (NavItemChildren | NavItemWithLink)[] 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 ----------------------------------------------------------------------- // image -----------------------------------------------------------------------

Loading…
Cancel
Save