Skip to content

Commit

Permalink
feat(theme): new design for local nav and global header (#3359)
Browse files Browse the repository at this point in the history
Co-authored-by: Divyansh Singh <40380293+brc-dd@users.noreply.github.com>
  • Loading branch information
kiaking and brc-dd authored Dec 30, 2023
1 parent 6212543 commit d10bf42
Show file tree
Hide file tree
Showing 15 changed files with 244 additions and 196 deletions.
18 changes: 3 additions & 15 deletions src/client/theme-default/components/VPDoc.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { useData } from '../composables/data'
import { useSidebar } from '../composables/sidebar'
import VPDocAside from './VPDocAside.vue'
import VPDocFooter from './VPDocFooter.vue'
import VPDocOutlineDropdown from './VPDocOutlineDropdown.vue'
const { theme } = useData()
Expand Down Expand Up @@ -43,7 +42,6 @@ const pageName = computed(() =>
<div class="content">
<div class="content-container">
<slot name="doc-before" />
<VPDocOutlineDropdown />
<main class="main">
<Content
class="vp-doc"
Expand All @@ -70,16 +68,6 @@ const pageName = computed(() =>
width: 100%;
}
.VPDoc .VPDocOutlineDropdown {
display: none;
}
@media (min-width: 960px) and (max-width: 1279px) {
.VPDoc .VPDocOutlineDropdown {
display: block;
}
}
@media (min-width: 768px) {
.VPDoc {
padding: 48px 32px 128px;
Expand All @@ -88,7 +76,7 @@ const pageName = computed(() =>
@media (min-width: 960px) {
.VPDoc {
padding: 32px 32px 0;
padding: 48px 32px 0;
}
.VPDoc:not(.has-sidebar) .container {
Expand Down Expand Up @@ -147,7 +135,7 @@ const pageName = computed(() =>
.aside-container {
position: fixed;
top: 0;
padding-top: calc(var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + var(--vp-doc-top-height, 0px) + 32px);
padding-top: calc(var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + var(--vp-doc-top-height, 0px) + 48px);
width: 224px;
height: 100vh;
overflow-x: hidden;
Expand All @@ -171,7 +159,7 @@ const pageName = computed(() =>
.aside-content {
display: flex;
flex-direction: column;
min-height: calc(100vh - (var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + 32px));
min-height: calc(100vh - (var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + 48px));
padding-bottom: 32px;
}
Expand Down
5 changes: 2 additions & 3 deletions src/client/theme-default/components/VPDocAsideOutline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ useActiveAnchor(container, marker)
}
.outline-title {
letter-spacing: 0.4px;
line-height: 28px;
font-size: 13px;
line-height: 32px;
font-size: 14px;
font-weight: 600;
}
</style>
85 changes: 0 additions & 85 deletions src/client/theme-default/components/VPDocOutlineDropdown.vue

This file was deleted.

8 changes: 5 additions & 3 deletions src/client/theme-default/components/VPDocOutlineItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function onClick({ target: el }: Event) {
</script>

<template>
<ul :class="root ? 'root' : 'nested'">
<ul class="VPDocOutlineItem" :class="root ? 'root' : 'nested'">
<li v-for="{ children, link, title } in headers">
<a class="outline-link" :href="link" @click="onClick" :title="title">{{ title }}</a>
<template v-if="children?.length">
Expand All @@ -31,18 +31,20 @@ function onClick({ target: el }: Event) {
}
.nested {
padding-right: 16px;
padding-left: 16px;
}
.outline-link {
display: block;
line-height: 28px;
line-height: 32px;
font-size: 14px;
font-weight: 400;
color: var(--vp-c-text-2);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
transition: color 0.5s;
font-weight: 400;
}
.outline-link:hover,
Expand Down
88 changes: 60 additions & 28 deletions src/client/theme-default/components/VPLocalNav.vue
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<script lang="ts" setup>
import { useWindowScroll } from '@vueuse/core'
import { onContentUpdated } from 'vitepress'
import { computed, onMounted, ref, shallowRef } from 'vue'
import { computed, onMounted, ref } from 'vue'
import { useData } from '../composables/data'
import { getHeaders, type MenuItem } from '../composables/outline'
import { useLocalNav } from '../composables/local-nav'
import { getHeaders } from '../composables/outline'
import { useSidebar } from '../composables/sidebar'
import VPLocalNavOutlineDropdown from './VPLocalNavOutlineDropdown.vue'
import VPIconAlignLeft from './icons/VPIconAlignLeft.vue'
Expand All @@ -18,9 +19,9 @@ defineEmits<{
const { theme, frontmatter } = useData()
const { hasSidebar } = useSidebar()
const { headers } = useLocalNav()
const { y } = useWindowScroll()
const headers = shallowRef<MenuItem[]>([])
const navHeight = ref(0)
onMounted(() => {
Expand All @@ -36,37 +37,44 @@ onContentUpdated(() => {
})
const empty = computed(() => {
return headers.value.length === 0 && !hasSidebar.value
return headers.value.length === 0
})
const emptyAndNoSidebar = computed(() => {
return empty.value && !hasSidebar.value
})
const classes = computed(() => {
return {
VPLocalNav: true,
fixed: empty.value,
'reached-top': y.value >= navHeight.value
'has-sidebar': hasSidebar.value,
empty: empty.value,
fixed: emptyAndNoSidebar.value
}
})
</script>

<template>
<div
v-if="frontmatter.layout !== 'home' && (!empty || y >= navHeight)"
v-if="frontmatter.layout !== 'home' && (!emptyAndNoSidebar || y >= navHeight)"
:class="classes"
>
<button
v-if="hasSidebar"
class="menu"
:aria-expanded="open"
aria-controls="VPSidebarNav"
@click="$emit('open-menu')"
>
<VPIconAlignLeft class="menu-icon" />
<span class="menu-text">
{{ theme.sidebarMenuLabel || 'Menu' }}
</span>
</button>

<VPLocalNavOutlineDropdown :headers="headers" :navHeight="navHeight" />
<div class="container">
<button
v-if="hasSidebar"
class="menu"
:aria-expanded="open"
aria-controls="VPSidebarNav"
@click="$emit('open-menu')"
>
<VPIconAlignLeft class="menu-icon" />
<span class="menu-text">
{{ theme.sidebarMenuLabel || 'Menu' }}
</span>
</button>

<VPLocalNavOutlineDropdown :headers="headers" :navHeight="navHeight" />
</div>
</div>
</template>

Expand All @@ -77,10 +85,6 @@ const classes = computed(() => {
/*rtl:ignore*/
left: 0;
z-index: var(--vp-z-index-local-nav);
display: flex;
justify-content: space-between;
align-items: center;
border-top: 1px solid var(--vp-c-gutter);
border-bottom: 1px solid var(--vp-c-gutter);
padding-top: var(--vp-layout-top-height, 0px);
width: 100%;
Expand All @@ -91,16 +95,38 @@ const classes = computed(() => {
position: fixed;
}
.VPLocalNav.reached-top {
border-top-color: transparent;
@media (min-width: 960px) {
.VPLocalNav {
top: var(--vp-nav-height);
}
.VPLocalNav.has-sidebar {
padding-left: var(--vp-sidebar-width);
}
.VPLocalNav.empty {
display: none;
}
}
@media (min-width: 960px) {
@media (min-width: 1280px) {
.VPLocalNav {
display: none;
}
}
@media (min-width: 1440px) {
.VPLocalNav.has-sidebar {
padding-left: calc((100vw - var(--vp-layout-max-width)) / 2 + var(--vp-sidebar-width));
}
}
.container {
display: flex;
justify-content: space-between;
align-items: center;
}
.menu {
display: flex;
align-items: center;
Expand All @@ -123,6 +149,12 @@ const classes = computed(() => {
}
}
@media (min-width: 960px) {
.menu {
display: none;
}
}
.menu-icon {
margin-right: 8px;
width: 16px;
Expand Down
Loading

0 comments on commit d10bf42

Please sign in to comment.