Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add active status to navbar menu Group #820

Merged
merged 6 commits into from Jun 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion docs/.vitepress/config.ts
Expand Up @@ -44,11 +44,15 @@ export default defineConfig({

function nav() {
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: 'Changelog',
link: 'https://github.com/vuejs/vitepress/blob/main/CHANGELOG.md'
},{
text:'Gruop Nav',
activeMatch: '/guide/',
items: [{ text: 'Guide', link: '/guide/what-is-vitepress', },]
casyalex marked this conversation as resolved.
Show resolved Hide resolved
}
]
}
Expand Down
23 changes: 8 additions & 15 deletions src/client/theme-default/components/VPFlyout.vue
Expand Up @@ -23,20 +23,9 @@ function onBlur() {
</script>

<template>
<div
class="VPFlyout"
ref="el"
@mouseenter="open = true"
@mouseleave="open = false"
>
<button
type="button"
class="button"
aria-haspopup="true"
:aria-expanded="open"
:aria-label="label"
@click="open = !open"
>
<div class="VPFlyout" ref="el" @mouseenter="open = true" @mouseleave="open = false">
<button type="button" class="button" aria-haspopup="true" :aria-expanded="open" :aria-label="label"
@click="open = !open">
casyalex marked this conversation as resolved.
Show resolved Hide resolved
<span v-if="button || icon" class="text">
<component v-if="icon" :is="icon" class="option-icon" />
{{ button }}
Expand All @@ -59,6 +48,10 @@ function onBlur() {
position: relative;
}

.VPFlyout.active .text {
color: var(--vp-c-brand);
}

.VPFlyout:hover {
color: var(--vp-c-bland);
transition: color 0.25s;
Expand All @@ -73,7 +66,7 @@ function onBlur() {
}

.VPFlyout:hover .menu,
.button[aria-expanded="true"] + .menu {
.button[aria-expanded="true"]+.menu {
opacity: 1;
visibility: visible;
transform: translateY(0);
Expand Down
12 changes: 10 additions & 2 deletions src/client/theme-default/components/VPNavBarMenuGroup.vue
@@ -1,12 +1,20 @@
<script lang="ts" setup>
import type { DefaultTheme } from 'vitepress/theme'
import VPFlyout from './VPFlyout.vue'
import { useData } from 'vitepress'
import { isActive } from '../support/utils'

defineProps<{
item: DefaultTheme.NavItemWithChildren
}>()
const { page } = useData()
</script>

<template>
<VPFlyout :button="item.text" :items="item.items" />
</template>
<VPFlyout :class="{
VPNavBarMenuGroup: true,
active: isActive(page.relativePath,
item.activeMatch,
!!item.activeMatch)
}" :button="item.text" :items="item.items" />
</template>
6 changes: 6 additions & 0 deletions types/default-theme.d.ts
Expand Up @@ -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 -----------------------------------------------------------------------
Expand Down