Skip to content

Commit d10bf42

Browse files
kiakingbrc-dd
andauthored
feat(theme): new design for local nav and global header (#3359)
Co-authored-by: Divyansh Singh <[email protected]>
1 parent 6212543 commit d10bf42

15 files changed

+244
-196
lines changed

Diff for: src/client/theme-default/components/VPDoc.vue

+3-15
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useData } from '../composables/data'
55
import { useSidebar } from '../composables/sidebar'
66
import VPDocAside from './VPDocAside.vue'
77
import VPDocFooter from './VPDocFooter.vue'
8-
import VPDocOutlineDropdown from './VPDocOutlineDropdown.vue'
98
109
const { theme } = useData()
1110
@@ -43,7 +42,6 @@ const pageName = computed(() =>
4342
<div class="content">
4443
<div class="content-container">
4544
<slot name="doc-before" />
46-
<VPDocOutlineDropdown />
4745
<main class="main">
4846
<Content
4947
class="vp-doc"
@@ -70,16 +68,6 @@ const pageName = computed(() =>
7068
width: 100%;
7169
}
7270
73-
.VPDoc .VPDocOutlineDropdown {
74-
display: none;
75-
}
76-
77-
@media (min-width: 960px) and (max-width: 1279px) {
78-
.VPDoc .VPDocOutlineDropdown {
79-
display: block;
80-
}
81-
}
82-
8371
@media (min-width: 768px) {
8472
.VPDoc {
8573
padding: 48px 32px 128px;
@@ -88,7 +76,7 @@ const pageName = computed(() =>
8876
8977
@media (min-width: 960px) {
9078
.VPDoc {
91-
padding: 32px 32px 0;
79+
padding: 48px 32px 0;
9280
}
9381
9482
.VPDoc:not(.has-sidebar) .container {
@@ -147,7 +135,7 @@ const pageName = computed(() =>
147135
.aside-container {
148136
position: fixed;
149137
top: 0;
150-
padding-top: calc(var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + var(--vp-doc-top-height, 0px) + 32px);
138+
padding-top: calc(var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + var(--vp-doc-top-height, 0px) + 48px);
151139
width: 224px;
152140
height: 100vh;
153141
overflow-x: hidden;
@@ -171,7 +159,7 @@ const pageName = computed(() =>
171159
.aside-content {
172160
display: flex;
173161
flex-direction: column;
174-
min-height: calc(100vh - (var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + 32px));
162+
min-height: calc(100vh - (var(--vp-nav-height) + var(--vp-layout-top-height, 0px) + 48px));
175163
padding-bottom: 32px;
176164
}
177165

Diff for: src/client/theme-default/components/VPDocAsideOutline.vue

+2-3
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,8 @@ useActiveAnchor(container, marker)
8080
}
8181
8282
.outline-title {
83-
letter-spacing: 0.4px;
84-
line-height: 28px;
85-
font-size: 13px;
83+
line-height: 32px;
84+
font-size: 14px;
8685
font-weight: 600;
8786
}
8887
</style>

Diff for: src/client/theme-default/components/VPDocOutlineDropdown.vue

-85
This file was deleted.

Diff for: src/client/theme-default/components/VPDocOutlineItem.vue

+5-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ function onClick({ target: el }: Event) {
1414
</script>
1515

1616
<template>
17-
<ul :class="root ? 'root' : 'nested'">
17+
<ul class="VPDocOutlineItem" :class="root ? 'root' : 'nested'">
1818
<li v-for="{ children, link, title } in headers">
1919
<a class="outline-link" :href="link" @click="onClick" :title="title">{{ title }}</a>
2020
<template v-if="children?.length">
@@ -31,18 +31,20 @@ function onClick({ target: el }: Event) {
3131
}
3232
3333
.nested {
34+
padding-right: 16px;
3435
padding-left: 16px;
3536
}
3637
3738
.outline-link {
3839
display: block;
39-
line-height: 28px;
40+
line-height: 32px;
41+
font-size: 14px;
42+
font-weight: 400;
4043
color: var(--vp-c-text-2);
4144
white-space: nowrap;
4245
overflow: hidden;
4346
text-overflow: ellipsis;
4447
transition: color 0.5s;
45-
font-weight: 400;
4648
}
4749
4850
.outline-link:hover,

Diff for: src/client/theme-default/components/VPLocalNav.vue

+60-28
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
<script lang="ts" setup>
22
import { useWindowScroll } from '@vueuse/core'
33
import { onContentUpdated } from 'vitepress'
4-
import { computed, onMounted, ref, shallowRef } from 'vue'
4+
import { computed, onMounted, ref } from 'vue'
55
import { useData } from '../composables/data'
6-
import { getHeaders, type MenuItem } from '../composables/outline'
6+
import { useLocalNav } from '../composables/local-nav'
7+
import { getHeaders } from '../composables/outline'
78
import { useSidebar } from '../composables/sidebar'
89
import VPLocalNavOutlineDropdown from './VPLocalNavOutlineDropdown.vue'
910
import VPIconAlignLeft from './icons/VPIconAlignLeft.vue'
@@ -18,9 +19,9 @@ defineEmits<{
1819
1920
const { theme, frontmatter } = useData()
2021
const { hasSidebar } = useSidebar()
22+
const { headers } = useLocalNav()
2123
const { y } = useWindowScroll()
2224
23-
const headers = shallowRef<MenuItem[]>([])
2425
const navHeight = ref(0)
2526
2627
onMounted(() => {
@@ -36,37 +37,44 @@ onContentUpdated(() => {
3637
})
3738
3839
const empty = computed(() => {
39-
return headers.value.length === 0 && !hasSidebar.value
40+
return headers.value.length === 0
41+
})
42+
43+
const emptyAndNoSidebar = computed(() => {
44+
return empty.value && !hasSidebar.value
4045
})
4146
4247
const classes = computed(() => {
4348
return {
4449
VPLocalNav: true,
45-
fixed: empty.value,
46-
'reached-top': y.value >= navHeight.value
50+
'has-sidebar': hasSidebar.value,
51+
empty: empty.value,
52+
fixed: emptyAndNoSidebar.value
4753
}
4854
})
4955
</script>
5056

5157
<template>
5258
<div
53-
v-if="frontmatter.layout !== 'home' && (!empty || y >= navHeight)"
59+
v-if="frontmatter.layout !== 'home' && (!emptyAndNoSidebar || y >= navHeight)"
5460
:class="classes"
5561
>
56-
<button
57-
v-if="hasSidebar"
58-
class="menu"
59-
:aria-expanded="open"
60-
aria-controls="VPSidebarNav"
61-
@click="$emit('open-menu')"
62-
>
63-
<VPIconAlignLeft class="menu-icon" />
64-
<span class="menu-text">
65-
{{ theme.sidebarMenuLabel || 'Menu' }}
66-
</span>
67-
</button>
68-
69-
<VPLocalNavOutlineDropdown :headers="headers" :navHeight="navHeight" />
62+
<div class="container">
63+
<button
64+
v-if="hasSidebar"
65+
class="menu"
66+
:aria-expanded="open"
67+
aria-controls="VPSidebarNav"
68+
@click="$emit('open-menu')"
69+
>
70+
<VPIconAlignLeft class="menu-icon" />
71+
<span class="menu-text">
72+
{{ theme.sidebarMenuLabel || 'Menu' }}
73+
</span>
74+
</button>
75+
76+
<VPLocalNavOutlineDropdown :headers="headers" :navHeight="navHeight" />
77+
</div>
7078
</div>
7179
</template>
7280

@@ -77,10 +85,6 @@ const classes = computed(() => {
7785
/*rtl:ignore*/
7886
left: 0;
7987
z-index: var(--vp-z-index-local-nav);
80-
display: flex;
81-
justify-content: space-between;
82-
align-items: center;
83-
border-top: 1px solid var(--vp-c-gutter);
8488
border-bottom: 1px solid var(--vp-c-gutter);
8589
padding-top: var(--vp-layout-top-height, 0px);
8690
width: 100%;
@@ -91,16 +95,38 @@ const classes = computed(() => {
9195
position: fixed;
9296
}
9397
94-
.VPLocalNav.reached-top {
95-
border-top-color: transparent;
98+
@media (min-width: 960px) {
99+
.VPLocalNav {
100+
top: var(--vp-nav-height);
101+
}
102+
103+
.VPLocalNav.has-sidebar {
104+
padding-left: var(--vp-sidebar-width);
105+
}
106+
107+
.VPLocalNav.empty {
108+
display: none;
109+
}
96110
}
97111
98-
@media (min-width: 960px) {
112+
@media (min-width: 1280px) {
99113
.VPLocalNav {
100114
display: none;
101115
}
102116
}
103117
118+
@media (min-width: 1440px) {
119+
.VPLocalNav.has-sidebar {
120+
padding-left: calc((100vw - var(--vp-layout-max-width)) / 2 + var(--vp-sidebar-width));
121+
}
122+
}
123+
124+
.container {
125+
display: flex;
126+
justify-content: space-between;
127+
align-items: center;
128+
}
129+
104130
.menu {
105131
display: flex;
106132
align-items: center;
@@ -123,6 +149,12 @@ const classes = computed(() => {
123149
}
124150
}
125151
152+
@media (min-width: 960px) {
153+
.menu {
154+
display: none;
155+
}
156+
}
157+
126158
.menu-icon {
127159
margin-right: 8px;
128160
width: 16px;

0 commit comments

Comments
 (0)