Skip to content

Commit

Permalink
add _meta.json#theme.collapsed option for control state sidebar's f…
Browse files Browse the repository at this point in the history
…olders (#890)

* add `_meta.json#theme.collapsed` option for control state sidebar's folders

* update snapshots
  • Loading branch information
dimaMachina committed Oct 19, 2022
1 parent a8a89e9 commit 9f5af54
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/shy-horses-help.md
@@ -0,0 +1,5 @@
---
'nextra-theme-docs': patch
---

add `_meta.json#theme.collapsed` option for control state sidebar's folders
5 changes: 4 additions & 1 deletion examples/swr-site/pages/docs/_meta.en-US.json
Expand Up @@ -26,7 +26,10 @@
"suspense": "Suspense",
"middleware": "Middleware",
"advanced": {
"title": "Advanced"
"title": "Advanced",
"theme": {
"collapsed": false
}
},
"change-log": {
"title": "Change Log",
Expand Down
Expand Up @@ -6,6 +6,7 @@ exports[`normalize-page > /404 page 1`] = `
"activePath": [],
"activeThemeContext": {
"breadcrumb": true,
"collapsed": false,
"footer": true,
"layout": "default",
"navbar": true,
Expand Down Expand Up @@ -101,6 +102,7 @@ exports[`normalize-page > /500 page 1`] = `
],
"activeThemeContext": {
"breadcrumb": true,
"collapsed": false,
"footer": true,
"layout": "raw",
"navbar": true,
Expand Down Expand Up @@ -364,6 +366,7 @@ exports[`normalize-page > en-US getting-started 1`] = `
],
"activeThemeContext": {
"breadcrumb": true,
"collapsed": false,
"footer": true,
"layout": "default",
"navbar": true,
Expand Down Expand Up @@ -1112,6 +1115,7 @@ exports[`normalize-page > en-US home 1`] = `
],
"activeThemeContext": {
"breadcrumb": true,
"collapsed": false,
"footer": true,
"layout": "default",
"navbar": true,
Expand Down Expand Up @@ -2026,6 +2030,7 @@ exports[`normalize-page > zh-CN getting-started 1`] = `
],
"activeThemeContext": {
"breadcrumb": true,
"collapsed": false,
"footer": true,
"layout": "default",
"navbar": true,
Expand Down Expand Up @@ -2774,6 +2779,7 @@ exports[`normalize-page > zh-CN home 1`] = `
],
"activeThemeContext": {
"breadcrumb": true,
"collapsed": false,
"footer": true,
"layout": "default",
"navbar": true,
Expand Down
9 changes: 7 additions & 2 deletions packages/nextra-theme-docs/src/components/sidebar.tsx
Expand Up @@ -70,10 +70,15 @@ function FolderImpl({

const { setMenu } = useMenu()
const config = useConfig()
const { theme } = item as Item
const open =
TreeState[item.route] !== undefined
? TreeState[item.route]
: active || activeRouteInside || !config.sidebar.defaultMenuCollapsed
: active ||
activeRouteInside ||
(theme && 'collapsed' in theme
? !theme.collapsed
: !config.sidebar.defaultMenuCollapsed)

const rerender = useState({})[1]

Expand Down Expand Up @@ -357,7 +362,7 @@ export function Sidebar({
>
<div
className={cn(
'z-[1]', // for bottom box shadow
'z-[1]', // for bottom box shadow
'md:hidden p-4',
'shadow-[0_2px_14px_6px_#fff] dark:shadow-[0_2px_14px_6px_#111]',
'contrast-more:shadow-none dark:contrast-more:shadow-none'
Expand Down
1 change: 1 addition & 0 deletions packages/nextra-theme-docs/src/constants.tsx
Expand Up @@ -198,6 +198,7 @@ export const LEGACY_CONFIG_OPTIONS: Record<string, string> = {

export const DEFAULT_PAGE_THEME: PageTheme = {
breadcrumb: true,
collapsed: false,
footer: true,
layout: 'default',
navbar: true,
Expand Down
1 change: 1 addition & 0 deletions packages/nextra-theme-docs/src/types.ts
Expand Up @@ -110,6 +110,7 @@ export interface DocsThemeConfig {

export type PageTheme = {
breadcrumb: boolean
collapsed: boolean
footer: boolean
layout: 'default' | 'full' | 'raw'
navbar: boolean
Expand Down
1 change: 1 addition & 0 deletions packages/nextra-theme-docs/src/utils/normalize-pages.ts
Expand Up @@ -20,6 +20,7 @@ export interface Item extends MdxFile {
children?: Item[]
hidden?: boolean
withIndexPage?: boolean
theme?: PageTheme
}

export interface PageItem extends MdxFile {
Expand Down
12 changes: 12 additions & 0 deletions packages/nextra/__test__/__snapshots__/context.test.ts.snap
Expand Up @@ -1124,6 +1124,9 @@ exports[`context > getAllPages() > should work 1`] = `
],
"kind": "Folder",
"meta": {
"theme": {
"collapsed": false,
},
"title": "Advanced",
},
"name": "advanced",
Expand All @@ -1133,6 +1136,9 @@ exports[`context > getAllPages() > should work 1`] = `
"kind": "MdxPage",
"locale": "en-US",
"meta": {
"theme": {
"collapsed": false,
},
"title": "Advanced",
},
"name": "advanced",
Expand Down Expand Up @@ -2901,6 +2907,9 @@ exports[`context > getCurrentLevelPages() > should work 1`] = `
],
"kind": "Folder",
"meta": {
"theme": {
"collapsed": false,
},
"title": "Advanced",
},
"name": "advanced",
Expand All @@ -2910,6 +2919,9 @@ exports[`context > getCurrentLevelPages() > should work 1`] = `
"kind": "MdxPage",
"locale": "en-US",
"meta": {
"theme": {
"collapsed": false,
},
"title": "Advanced",
},
"name": "advanced",
Expand Down
3 changes: 3 additions & 0 deletions packages/nextra/__test__/__snapshots__/page-map.test.ts.snap
Expand Up @@ -188,6 +188,9 @@ exports[`Page Process > pageMap en-US 1`] = `
},
"404-500": "404/500 Custom Error Pages",
"advanced": {
"theme": {
"collapsed": false,
},
"title": "Advanced",
},
"arguments": "Arguments",
Expand Down

0 comments on commit 9f5af54

Please sign in to comment.