Commit 0274157c9b

0274157c9b300feafe17db6d6f097bd77b6d3c05

parent: c1d05f4b1b

Unsigned

TubaApollo <86665265+TubaApollo@users.noreply.github.com> · 2026-04-09 21:12 UTC

feat: add sidebar navigation on homepage (desktop + mobile)

Desktop: hamburger icon in navbar opens left slideout sidebar with
full site navigation, logo header, and arrow key scrolling.

Mobile: VitePress NavScreen restyled as floating panel with rounded
corners, blur, and slide-from-left animation. Sidebar categories
added via slot. Outside click closes the panel.

Layout: unified · split

docs/.vitepress/theme/Layout.vue +96 −2
@@ -15,7 +15,9 @@ import { usePreferredReducedMotion } from '@vueuse/core'
1515import { useData, useRoute } from 'vitepress'
1616import type { DefaultTheme as Theme } from 'vitepress'
1717import DefaultTheme from 'vitepress/theme'
18import { computed, onMounted, onUnmounted, ref } from 'vue'
18import VPSidebarGroup from 'vitepress/dist/client/theme-default/components/VPSidebarGroup.vue'
19import { getSidebarGroups } from 'vitepress/dist/client/theme-default/support/sidebar'
20import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
1921import { sidebar } from '../configs/constants'
2022import AnnouncementPill from './components/AnnouncementPill.vue'
2123import NotFoundComponent from './components/NotFound.vue'
@@ -28,8 +30,26 @@ import { TakodachiStorageKey } from './constants'
2830import { v2add, v2mag, v2norm, v2smul, v2sub, type Vec2D } from './math'
2931
3032const route = useRoute()
33const { frontmatter, site, theme } = useData()
3134const { Layout } = DefaultTheme
3235
36// Home sidebar menu
37const isHome = computed(() => frontmatter.value.layout === 'home')
38const homeSidebarOpen = ref(false)
39const sidebarRef = ref<HTMLElement | null>(null)
40const homeSidebarGroups = getSidebarGroups(sidebar as any)
41const logoSrc = computed(() =>
42 typeof theme.value.logo === 'string' ? theme.value.logo : theme.value.logo?.src
43)
44
45watch(() => route.path, () => {
46 homeSidebarOpen.value = false
47})
48
49function onSidebarEnter() {
50 sidebarRef.value?.focus()
51}
52
3353interface BreadcrumbItem {
3454 text: string
3555 link?: string
@@ -153,6 +173,32 @@ const reloadTakodachi = () => {
153173onMounted(() => {
154174 if (import.meta.env.SSR) return
155175
176 // Arrow key scrolling + Escape close for desktop sidebar
177 useEventListener(document, 'keydown', (e: KeyboardEvent) => {
178 if (!homeSidebarOpen.value || !sidebarRef.value) return
179 if (e.key === 'Escape') {
180 homeSidebarOpen.value = false
181 return
182 }
183 if (e.key === 'ArrowDown') {
184 e.preventDefault()
185 sidebarRef.value.scrollBy({ top: 60, behavior: 'smooth' })
186 } else if (e.key === 'ArrowUp') {
187 e.preventDefault()
188 sidebarRef.value.scrollBy({ top: -60, behavior: 'smooth' })
189 }
190 })
191
192 // Close home NavScreen on outside click
193 useEventListener(document, 'click', (e: Event) => {
194 if (!isHome.value) return
195 const screen = document.getElementById('VPNavScreen')
196 if (!screen) return
197 const hamburger = document.querySelector('.VPNavBarHamburger')
198 if (screen.contains(e.target as Node) || hamburger?.contains(e.target as Node)) return
199 requestAnimationFrame(() => (hamburger as HTMLElement)?.click())
200 })
201
156202 // Storage changed in other documents.
157203 useEventListener(window, 'storage', () => {
158204 reloadTakodachi()
@@ -185,6 +231,36 @@ onUnmounted(() => {
185231 top: `${position.y}px`
186232 }"
187233 />
234 <!-- Home sidebar menu -->
235 <template v-if="isHome">
236 <Transition name="home-fade">
237 <div
238 v-if="homeSidebarOpen"
239 class="home-sidebar-backdrop"
240 @click="homeSidebarOpen = false"
241 />
242 </Transition>
243 <Transition name="home-slide" @after-enter="onSidebarEnter">
244 <aside
245 v-if="homeSidebarOpen"
246 ref="sidebarRef"
247 class="home-sidebar"
248 tabindex="-1"
249 @click.stop
250 >
251 <div class="home-sidebar-header">
252 <a href="/" class="home-sidebar-logo">
253 <img v-if="logoSrc" :src="logoSrc" class="home-sidebar-logo-img" alt="Logo" />
254 <span>{{ theme.siteTitle ?? site.title }}</span>
255 </a>
256 </div>
257 <nav id="VPSidebarNav" class="home-sidebar-nav">
258 <VPSidebarGroup :items="homeSidebarGroups" />
259 </nav>
260 <SidebarCard />
261 </aside>
262 </Transition>
263 </template>
188264 </template>
189265 <template #doc-before>
190266 <!-- Breadcrumb Navigation -->
@@ -234,8 +310,26 @@ onUnmounted(() => {
234310 <template #nav-bar-content-after>
235311 <NolebaseEnhancedReadabilitiesMenu />
236312 </template>
313 <template #nav-screen-content-before>
314 <nav v-if="isHome" id="VPSidebarNavMobile" class="home-screen-nav">
315 <VPSidebarGroup :items="homeSidebarGroups" />
316 </nav>
317 </template>
237318 <template #nav-screen-content-after>
238 <NolebaseEnhancedReadabilitiesScreenMenu />
319 <NolebaseEnhancedReadabilitiesScreenMenu v-if="!isHome" />
320 </template>
321 <template #nav-bar-title-before>
322 <span
323 v-if="isHome"
324 class="home-menu-btn"
325 role="button"
326 tabindex="0"
327 aria-label="Menu"
328 @click.prevent.stop="homeSidebarOpen = !homeSidebarOpen"
329 @keydown.enter.prevent.stop="homeSidebarOpen = !homeSidebarOpen"
330 >
331 <span class="vpi-align-left home-menu-icon" />
332 </span>
239333 </template>
240334 </Layout>
241335</template>
docs/.vitepress/theme/styles/style.scss +183 −1
@@ -612,7 +612,8 @@ table tr:nth-child(odd) {
612612 }
613613}
614614
615#VPSidebarNav > .group {
615#VPSidebarNav > .group,
616#VPSidebarNavMobile > .group {
616617 @apply border-t-0 min-h-11 pt-2.25;
617618
618619 & > .VPSidebarItem {
@@ -1224,3 +1225,184 @@ table tr:nth-child(odd) {
12241225.VPNavBarSearch.search {
12251226 @apply ml-2 pl-0!;
12261227}
1228
1229%thin-scrollbar {
1230 scrollbar-width: thin;
1231 &::-webkit-scrollbar { width: 8px; }
1232 &::-webkit-scrollbar-track { background: transparent; }
1233 &::-webkit-scrollbar-thumb { border-radius: 4px; }
1234}
1235
1236%thin-scrollbar-narrow {
1237 scrollbar-width: thin;
1238 &::-webkit-scrollbar { width: 6px; }
1239 &::-webkit-scrollbar-track { background: transparent; }
1240 &::-webkit-scrollbar-thumb { border-radius: 3px; background-color: var(--vp-c-divider); }
1241}
1242
1243/* Home sidebar menu button in navbar */
1244.home-menu-btn {
1245 display: none;
1246 align-items: center;
1247 justify-content: center;
1248 margin-right: 16px;
1249 color: var(--vp-c-text-2);
1250 cursor: pointer;
1251 transition: color 0.25s;
1252
1253 &:hover {
1254 color: var(--vp-c-text-1);
1255 }
1256
1257 @media (min-width: 960px) {
1258 display: inline-flex;
1259 }
1260}
1261
1262.home-menu-icon {
1263 font-size: 20px;
1264}
1265
1266.home-sidebar-backdrop {
1267 position: fixed;
1268 inset: 0;
1269 z-index: var(--vp-z-index-backdrop, 100);
1270 background-color: rgba(0, 0, 0, 0.6);
1271}
1272
1273/* Home desktop sidebar (left slideout) */
1274.home-sidebar {
1275 position: fixed;
1276 top: 0;
1277 bottom: 0;
1278 left: 0;
1279 z-index: calc(var(--vp-z-index-backdrop, 100) + 1);
1280 padding: 0 32px 96px;
1281 width: var(--vp-sidebar-width);
1282 max-width: calc(100vw - 64px);
1283 background-color: var(--vp-sidebar-bg-color);
1284 box-shadow: var(--vp-c-shadow-3);
1285 overflow-x: hidden;
1286 overflow-y: auto;
1287 overscroll-behavior: contain;
1288 @extend %thin-scrollbar;
1289
1290 .dark & {
1291 box-shadow: var(--vp-shadow-1);
1292 }
1293}
1294
1295.home-sidebar-header {
1296 position: sticky;
1297 top: 0;
1298 z-index: 1;
1299 height: var(--vp-nav-height);
1300 display: flex;
1301 align-items: center;
1302 background-color: var(--vp-sidebar-bg-color);
1303 border-bottom: 1px solid var(--vp-c-divider);
1304}
1305
1306.home-sidebar-logo {
1307 display: flex;
1308 align-items: center;
1309 height: var(--vp-nav-height);
1310 font-size: 16px;
1311 font-weight: 600;
1312 color: var(--vp-c-text-1);
1313 text-decoration: none;
1314}
1315
1316.home-sidebar-logo-img {
1317 margin-right: 8px;
1318 height: var(--vp-nav-logo-height);
1319}
1320
1321.home-sidebar-nav {
1322 padding-top: 10px;
1323}
1324
1325/* Desktop sidebar transitions */
1326.home-fade-enter-active,
1327.home-fade-leave-active {
1328 transition: opacity 0.25s;
1329}
1330
1331.home-fade-enter-from,
1332.home-fade-leave-to {
1333 opacity: 0;
1334}
1335
1336.home-slide-enter-active {
1337 transition: transform 0.5s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.25s;
1338}
1339
1340.home-slide-leave-active {
1341 transition: transform 0.25s ease, opacity 0.5s;
1342}
1343
1344.home-slide-enter-from,
1345.home-slide-leave-to {
1346 transform: translateX(-100%);
1347 opacity: 0;
1348}
1349
1350/* Hide navbar border when home NavScreen is open */
1351.VPNavBar.home.screen-open {
1352 border-bottom: none !important;
1353}
1354
1355/* Home NavScreen: restyle as left-aligned floating panel matching VPSidebar */
1356.VPNavScreen:has(.home-screen-nav) {
1357 @apply bg-white/85 dark:bg-neutral-800/85
1358 border dark:border-neutral-700 border-neutral-200
1359 rounded-3xl backdrop-blur shadow-lg;
1360 padding: 0 !important;
1361 left: 0.5rem !important;
1362 right: auto !important;
1363 top: 0.5rem !important;
1364 bottom: 0.5rem !important;
1365 width: calc(100vw - 64px) !important;
1366 max-width: 320px !important;
1367 overflow-x: hidden !important;
1368 @extend %thin-scrollbar-narrow;
1369
1370 & > * {
1371 max-width: 100% !important;
1372 padding: 16px 16px 0 !important;
1373 display: flex !important;
1374 flex-direction: column !important;
1375 min-height: 100%;
1376 }
1377
1378 .VPNavScreenAppearance {
1379 margin-top: 24px !important;
1380 }
1381
1382 .VPNavScreenSocialLinks {
1383 margin-top: auto !important;
1384 padding: 16px 0 !important;
1385 display: flex;
1386 justify-content: center;
1387 }
1388}
1389
1390.home-screen-nav {
1391 padding-top: 8px;
1392}
1393
1394/* Override NavScreen fade transition to slide-from-left on home */
1395.VPNavScreen:has(.home-screen-nav) {
1396 &.fade-enter-active,
1397 &.fade-leave-active {
1398 transition: transform 0.3s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.25s !important;
1399
1400 .container { transform: none !important; }
1401 }
1402
1403 &.fade-enter-from,
1404 &.fade-leave-to {
1405 transform: translateX(-100%) !important;
1406 opacity: 0 !important;
1407 }
1408}