From 3e68b44771f4c3b0604af312e33e2edc4e8a1e12 Mon Sep 17 00:00:00 2001 From: pengzhanbo Date: Thu, 12 Feb 2026 01:02:57 +0800 Subject: [PATCH] feat(theme): add sidebar collapse button, close #687 (#839) --- theme/src/client/components/Nav/VPNavBar.vue | 11 +- .../client/components/Nav/VPNavBarTitle.vue | 7 +- theme/src/client/components/VPContent.vue | 11 +- theme/src/client/components/VPDoc.vue | 10 +- theme/src/client/components/VPFooter.vue | 7 +- theme/src/client/components/VPLocalNav.vue | 13 +- theme/src/client/components/VPSidebar.vue | 90 ++++++++- theme/src/client/components/VPSidebarItem.vue | 4 +- theme/src/client/components/VPSignDown.vue | 7 +- theme/src/client/composables/aside.ts | 23 --- theme/src/client/composables/collections.ts | 7 +- theme/src/client/composables/index.ts | 2 +- theme/src/client/composables/layout.ts | 96 ++++++++++ theme/src/client/composables/outline.ts | 19 +- .../src/client/composables/posts-post-list.ts | 4 +- theme/src/client/composables/sidebar-data.ts | 32 ++-- theme/src/client/composables/sidebar.ts | 172 +++++++----------- theme/src/client/layouts/Layout.vue | 25 +-- theme/src/client/styles/icons.css | 8 + 19 files changed, 333 insertions(+), 215 deletions(-) delete mode 100644 theme/src/client/composables/aside.ts create mode 100644 theme/src/client/composables/layout.ts diff --git a/theme/src/client/components/Nav/VPNavBar.vue b/theme/src/client/components/Nav/VPNavBar.vue index 4f1eb5bc..5b2984a2 100644 --- a/theme/src/client/components/Nav/VPNavBar.vue +++ b/theme/src/client/components/Nav/VPNavBar.vue @@ -9,23 +9,22 @@ import VPNavBarTitle from '@theme/Nav/VPNavBarTitle.vue' import VPNavBarTranslations from '@theme/Nav/VPNavBarTranslations.vue' import { useWindowScroll } from '@vueuse/core' import { ref, watchPostEffect } from 'vue' -import { useData, useSidebar } from '../../composables/index.js' +import { useLayout, useSidebarControl } from '../../composables/index.js' const { isScreenOpen } = defineProps<{ isScreenOpen: boolean }>() defineEmits<(e: 'toggleScreen') => void>() -const { frontmatter } = useData() - const { y } = useWindowScroll() -const { hasSidebar } = useSidebar() +const { hasSidebar, isHome } = useLayout() +const { isSidebarCollapsed } = useSidebarControl() const classes = ref>({}) watchPostEffect(() => { classes.value = { - 'has-sidebar': hasSidebar.value, - 'home': frontmatter.value.pageLayout === 'home', + 'has-sidebar': hasSidebar.value && !isSidebarCollapsed.value, + 'home': isHome.value, 'top': y.value === 0, 'screen-open': isScreenOpen, } diff --git a/theme/src/client/components/Nav/VPNavBarTitle.vue b/theme/src/client/components/Nav/VPNavBarTitle.vue index 9f872daa..f5d87af7 100644 --- a/theme/src/client/components/Nav/VPNavBarTitle.vue +++ b/theme/src/client/components/Nav/VPNavBarTitle.vue @@ -2,15 +2,16 @@ import VPImage from '@theme/VPImage.vue' import VPLink from '@theme/VPLink.vue' import { useRouteLocale } from 'vuepress/client' -import { useData, useSidebar } from '../../composables/index.js' +import { useData, useLayout, useSidebarControl } from '../../composables/index.js' const { theme, site } = useData() -const { hasSidebar } = useSidebar() +const { hasSidebar } = useLayout() const routeLocale = useRouteLocale() +const { isSidebarCollapsed } = useSidebarControl()