Skip to content

Commit 8631727

Browse files
authored
feat(theme): add sidebarScrollbar options, close #425 (#460)
1 parent 861512d commit 8631727

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

docs/notes/theme/config/主题配置.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,14 @@ interface SidebarItem {
657657
}
658658
```
659659

660+
### sidebarScrollbar
661+
662+
- 类型: `boolean`
663+
- 默认值: `true`
664+
- 详情: 是否显示侧边栏滚动条
665+
666+
设置为 `false` 时,仅隐藏滚动条,但不改变滚动行为。
667+
660668
### aside
661669

662670
- 类型: `boolean | 'left'`

theme/src/client/components/VPSidebar.vue

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@ import VPTransitionFadeSlideY from '@theme/VPTransitionFadeSlideY.vue'
44
import { useScrollLock } from '@vueuse/core'
55
import { onMounted, ref, watch } from 'vue'
66
import { useRoutePath } from 'vuepress/client'
7-
import { useSidebar } from '../composables/index.js'
7+
import { useData, useSidebar } from '../composables/index.js'
88
import { inBrowser } from '../utils/index.js'
99
1010
const props = defineProps<{
1111
open: boolean
1212
}>()
1313
14+
const { theme } = useData()
1415
const { sidebarGroups, hasSidebar, sidebarKey } = useSidebar()
1516
const routePath = useRoutePath()
1617
@@ -52,7 +53,7 @@ onMounted(() => {
5253
v-if="hasSidebar"
5354
ref="navEl"
5455
class="vp-sidebar"
55-
:class="{ open }"
56+
:class="{ open, 'hide-scrollbar': !(theme.sidebarScrollbar ?? true) }"
5657
vp-sidebar
5758
@click.stop
5859
>
@@ -114,6 +115,15 @@ onMounted(() => {
114115
transform: translateX(0);
115116
}
116117
118+
.vp-sidebar.hide-scrollbar {
119+
scrollbar-width: none;
120+
}
121+
122+
.vp-sidebar.hide-scrollbar::-webkit-scrollbar {
123+
width: 0;
124+
height: 0;
125+
}
126+
117127
[data-theme="dark"] .vp-sidebar {
118128
box-shadow: var(--vp-shadow-1);
119129
}

theme/src/shared/options/locale.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,12 @@ export interface PlumeThemeLocaleData extends LocaleData {
7777
*/
7878
sidebar?: SidebarMulti
7979

80+
/**
81+
* 是否显示侧边栏滚动条
82+
* @default true
83+
*/
84+
sidebarScrollbar?: boolean
85+
8086
/**
8187
* 要显示的标题级别。
8288
*

0 commit comments

Comments
 (0)