Commit 487f79188b

487f79188b6f815682dc3b5cec8c96faced33f69

parent: 720a0ff01a

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 +46 −4
@@ -36,6 +36,7 @@ const { Layout } = DefaultTheme
36// Home sidebar menu 36// Home sidebar menu
37const isHome = computed(() => frontmatter.value.layout === 'home') 37const isHome = computed(() => frontmatter.value.layout === 'home')
38const homeSidebarOpen = ref(false) 38const homeSidebarOpen = ref(false)
39const sidebarRef = ref<HTMLElement | null>(null)
39const homeSidebarGroups = getSidebarGroups(sidebar as any) 40const homeSidebarGroups = getSidebarGroups(sidebar as any)
40const logoSrc = computed(() => 41const logoSrc = computed(() =>
41 typeof theme.value.logo === 'string' ? theme.value.logo : theme.value.logo?.src 42 typeof theme.value.logo === 'string' ? theme.value.logo : theme.value.logo?.src
@@ -45,6 +46,10 @@ watch(() => route.path, () => {
45 homeSidebarOpen.value = false 46 homeSidebarOpen.value = false
46}) 47})
47 48
49function onSidebarEnter() {
50 sidebarRef.value?.focus()
51}
52
48interface BreadcrumbItem { 53interface BreadcrumbItem {
49 text: string 54 text: string
50 link?: string 55 link?: string
@@ -168,6 +173,32 @@ const reloadTakodachi = () => {
168onMounted(() => { 173onMounted(() => {
169 if (import.meta.env.SSR) return 174 if (import.meta.env.SSR) return
170 175
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
171 // Storage changed in other documents. 202 // Storage changed in other documents.
172 useEventListener(window, 'storage', () => { 203 useEventListener(window, 'storage', () => {
173 reloadTakodachi() 204 reloadTakodachi()
@@ -200,7 +231,7 @@ onUnmounted(() => {
200 top: `${position.y}px` 231 top: `${position.y}px`
201 }" 232 }"
202 /> 233 />
203 <!-- Home sidebar menu (desktop only) --> 234 <!-- Home sidebar menu -->
204 <template v-if="isHome"> 235 <template v-if="isHome">
205 <Transition name="home-fade"> 236 <Transition name="home-fade">
206 <div 237 <div
@@ -209,8 +240,14 @@ onUnmounted(() => {
209 @click="homeSidebarOpen = false" 240 @click="homeSidebarOpen = false"
210 /> 241 />
211 </Transition> 242 </Transition>
212 <Transition name="home-slide"> 243 <Transition name="home-slide" @after-enter="onSidebarEnter">
213 <aside v-if="homeSidebarOpen" class="home-sidebar" @click.stop> 244 <aside
245 v-if="homeSidebarOpen"
246 ref="sidebarRef"
247 class="home-sidebar"
248 tabindex="-1"
249 @click.stop
250 >
214 <div class="home-sidebar-header"> 251 <div class="home-sidebar-header">
215 <a href="/" class="home-sidebar-logo"> 252 <a href="/" class="home-sidebar-logo">
216 <img v-if="logoSrc" :src="logoSrc" class="home-sidebar-logo-img" alt="Logo" /> 253 <img v-if="logoSrc" :src="logoSrc" class="home-sidebar-logo-img" alt="Logo" />
@@ -273,8 +310,13 @@ onUnmounted(() => {
273 <template #nav-bar-content-after> 310 <template #nav-bar-content-after>
274 <NolebaseEnhancedReadabilitiesMenu /> 311 <NolebaseEnhancedReadabilitiesMenu />
275 </template> 312 </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>
276 <template #nav-screen-content-after> 318 <template #nav-screen-content-after>
277 <NolebaseEnhancedReadabilitiesScreenMenu /> 319 <NolebaseEnhancedReadabilitiesScreenMenu v-if="!isHome" />
278 </template> 320 </template>
279 <template #nav-bar-title-before> 321 <template #nav-bar-title-before>
280 <span 322 <span
docs/.vitepress/theme/styles/style.scss +79 −2
@@ -612,7 +612,8 @@ table tr:nth-child(odd) {
612 } 612 }
613} 613}
614 614
615#VPSidebarNav > .group { 615#VPSidebarNav > .group,
616#VPSidebarNavMobile > .group {
616 @apply border-t-0 min-h-11 pt-2.25; 617 @apply border-t-0 min-h-11 pt-2.25;
617 618
618 & > .VPSidebarItem { 619 & > .VPSidebarItem {
@@ -1225,6 +1226,20 @@ table tr:nth-child(odd) {
1225 @apply ml-2 pl-0!; 1226 @apply ml-2 pl-0!;
1226} 1227}
1227 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
1228/* Home sidebar menu button in navbar */ 1243/* Home sidebar menu button in navbar */
1229.home-menu-btn { 1244.home-menu-btn {
1230 display: none; 1245 display: none;
@@ -1255,6 +1270,7 @@ table tr:nth-child(odd) {
1255 background-color: rgba(0, 0, 0, 0.6); 1270 background-color: rgba(0, 0, 0, 0.6);
1256} 1271}
1257 1272
1273/* Home desktop sidebar (left slideout) */
1258.home-sidebar { 1274.home-sidebar {
1259 position: fixed; 1275 position: fixed;
1260 top: 0; 1276 top: 0;
@@ -1269,6 +1285,7 @@ table tr:nth-child(odd) {
1269 overflow-x: hidden; 1285 overflow-x: hidden;
1270 overflow-y: auto; 1286 overflow-y: auto;
1271 overscroll-behavior: contain; 1287 overscroll-behavior: contain;
1288 @extend %thin-scrollbar;
1272 1289
1273 .dark & { 1290 .dark & {
1274 box-shadow: var(--vp-shadow-1); 1291 box-shadow: var(--vp-shadow-1);
@@ -1279,7 +1296,6 @@ table tr:nth-child(odd) {
1279 position: sticky; 1296 position: sticky;
1280 top: 0; 1297 top: 0;
1281 z-index: 1; 1298 z-index: 1;
1282 padding: 0;
1283 height: var(--vp-nav-height); 1299 height: var(--vp-nav-height);
1284 display: flex; 1300 display: flex;
1285 align-items: center; 1301 align-items: center;
@@ -1306,6 +1322,7 @@ table tr:nth-child(odd) {
1306 padding-top: 10px; 1322 padding-top: 10px;
1307} 1323}
1308 1324
1325/* Desktop sidebar transitions */
1309.home-fade-enter-active, 1326.home-fade-enter-active,
1310.home-fade-leave-active { 1327.home-fade-leave-active {
1311 transition: opacity 0.25s; 1328 transition: opacity 0.25s;
@@ -1329,3 +1346,63 @@ table tr:nth-child(odd) {
1329 transform: translateX(-100%); 1346 transform: translateX(-100%);
1330 opacity: 0; 1347 opacity: 0;
1331} 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}