Skip to content

Commit 48ab95c

Browse files
pplrmeteorlxy
andauthoredDec 8, 2022
feat(theme-default): collapsible nested item in sidebar (close #883) (#1158)
Co-authored-by: meteorlxy <meteor.lxy@foxmail.com>
1 parent b0a7a0e commit 48ab95c

File tree

4 files changed

+13
-18
lines changed

4 files changed

+13
-18
lines changed
 

‎docs/reference/default-theme/config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export default {
313313

314314
To configure the sidebar items manually, you can set this option to a _sidebar array_, each item of which could be a `SidebarItem` object or a string:
315315

316-
- A `SidebarItem` object should have a `text` field, could have an optional `link` field and an optional `children` field. The `children` field should be a _sidebar array_. When a `SidebarItem` object is placed at the root-level, it could have an extra optional `collapsible` field to control whether it is collapsible.
316+
- A `SidebarItem` object should have a `text` field, could have an optional `link` field, an optional `children` field and an optional `collapsible` field. The `children` field should be a _sidebar array_. The `collapsible` field controls whether the item is collapsible.
317317
- A string should be the path to the target page file. It will be converted to a `SidebarItem` object, whose `text` is the page title, `link` is the page route path, and `children` is automatically generated from the page headers.
318318

319319
If you want to set different sidebar for different sub paths, you can set this option to a _sidebar object_:

‎docs/zh/reference/default-theme/config.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ export default {
313313

314314
为了手动配置侧边栏元素,你可以将其设置为 _侧边栏数组_ ,其中的每个元素是一个 `SidebarItem` 对象或者一个字符串:
315315

316-
- `SidebarItem` 对象应该有一个 `text` 字段,有一个可选的 `link` 字段和一个可选的 `children` 字段。 `children` 字段同样是一个 _侧边栏数组_`SidebarItem` 对象处于根节点时,它还有一个额外可选的 `collapsible` 字段来控制它是否可折叠。
316+
- `SidebarItem` 对象应该有一个 `text` 字段,有一个可选的 `link` 字段、一个可选的 `children` 字段和一个可选的 `collapsible` 字段。 `children` 字段同样是一个 _侧边栏数组_`collapsible` 字段来控制它是否可折叠。
317317
- 字符串应为目标页面文件的路径。它将会被转换为 `SidebarItem` 对象,将页面标题作为 `text` ,将页面路由路径作为 `link` ,并根据页面小标题自动生成 `children`
318318

319319
如果你想在不同子路径中使用不同的侧边栏,你可以将该配置项设置为 _侧边栏对象_

‎ecosystem/theme-default/src/client/styles/sidebar.scss

+7-7
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@
8383
@include dropdown_wrapper;
8484
margin-bottom: 0.75rem;
8585
}
86+
}
8687

87-
&.collapsible {
88-
cursor: pointer;
88+
&.collapsible {
89+
cursor: pointer;
8990

90-
.arrow {
91-
position: relative;
92-
top: -0.12em;
93-
left: 0.5em;
94-
}
91+
.arrow {
92+
position: relative;
93+
top: -0.12em;
94+
left: 0.5em;
9595
}
9696
}
9797

‎ecosystem/theme-default/src/shared/nav.ts

+4-9
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,10 @@ export type ResolvedNavbarItem = NavbarItem | NavGroup<ResolvedNavbarItem>
3939
// user config
4040
export type SidebarItem = NavItem & Partial<NavLink>
4141
export type SidebarGroup = SidebarItem &
42-
NavGroup<SidebarItem | SidebarGroup | string>
43-
export type SidebarGroupCollapsible = SidebarGroup & {
44-
collapsible?: boolean
45-
}
46-
export type SidebarConfigArray = (
47-
| SidebarItem
48-
| SidebarGroupCollapsible
49-
| string
50-
)[]
42+
NavGroup<SidebarItem | SidebarGroup | string> & {
43+
collapsible?: boolean
44+
}
45+
export type SidebarConfigArray = (SidebarItem | SidebarGroup | string)[]
5146
export type SidebarConfigObject = Record<string, SidebarConfigArray>
5247
export type SidebarConfig = SidebarConfigArray | SidebarConfigObject
5348
// resolved

0 commit comments

Comments
 (0)
Please sign in to comment.