Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): add option to toggle sidebar category open by default #2613

Merged
merged 7 commits into from
Apr 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,30 @@ module.exports = {
docs: [
{
type: 'category',
collapsed: true,
label: 'level 1',
items: [
'a',
{
type: 'category',
collapsed: true,
label: 'level 2',
items: [
{
type: 'category',
collapsed: true,
label: 'level 3',
items: [
'c',
{
type: 'category',
collapsed: true,
label: 'level 4',
items: [
'd',
{
type: 'category',
collapsed: true,
label: 'deeper more more',
items: ['e'],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"docs": [
{
"type": "category",
"label": "Introduction",
"items": [
"doc1"
],
"collapsed": false
},
{
"type": "category",
"label": "Powering MDX",
"items": [
"doc2"
],
"collapsed": false
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"docs": {
"Test": [
{
"type": "category",
"label": "Introduction",
"items": ["doc1"],
"collapsed": false
}
],
"Reference": [
{
"type": "category",
"label": "Powering MDX",
"items": ["doc2"],
"collapsed": false
}
]
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`simple website content 1`] = `
Object {
"docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"items": Array [
Expand Down Expand Up @@ -36,6 +37,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/hello",
Expand Down Expand Up @@ -200,6 +202,7 @@ exports[`versioned website content: all sidebars 1`] = `
Object {
"docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/next/foo/bar",
Expand All @@ -211,6 +214,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/next/hello",
Expand All @@ -224,6 +228,7 @@ Object {
],
"version-1.0.0/docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/1.0.0/foo/bar",
Expand All @@ -240,6 +245,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/1.0.0/hello",
Expand All @@ -253,6 +259,7 @@ Object {
],
"version-1.0.1/docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/foo/bar",
Expand All @@ -264,6 +271,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/hello",
Expand All @@ -283,6 +291,7 @@ Object {
"docsSidebars": Object {
"version-1.0.0/docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/1.0.0/foo/bar",
Expand All @@ -299,6 +308,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/1.0.0/hello",
Expand All @@ -325,6 +335,7 @@ Object {
"docsSidebars": Object {
"version-1.0.1/docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/foo/bar",
Expand All @@ -336,6 +347,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/hello",
Expand All @@ -361,6 +373,7 @@ Object {
"docsSidebars": Object {
"docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/next/foo/bar",
Expand All @@ -372,6 +385,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"href": "/docs/next/hello",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`loadSidebars sidebars link 1`] = `
Object {
"docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"href": "https://github.com",
Expand All @@ -18,30 +19,107 @@ Object {
}
`;

exports[`loadSidebars sidebars with category.collapsed property 1`] = `
Object {
"docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"collapsed": false,
"items": Array [
Object {
"id": "doc1",
"type": "doc",
},
],
"label": "Introduction",
"type": "category",
},
],
"label": "Test",
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"collapsed": false,
"items": Array [
Object {
"id": "doc2",
"type": "doc",
},
],
"label": "Powering MDX",
"type": "category",
},
],
"label": "Reference",
"type": "category",
},
],
}
`;

exports[`loadSidebars sidebars with category.collapsed property at first level 1`] = `
Object {
"docs": Array [
Object {
"collapsed": false,
"items": Array [
Object {
"id": "doc1",
"type": "doc",
},
],
"label": "Introduction",
"type": "category",
},
Object {
"collapsed": false,
"items": Array [
Object {
"id": "doc2",
"type": "doc",
},
],
"label": "Powering MDX",
"type": "category",
},
],
}
`;

exports[`loadSidebars sidebars with deep level of category 1`] = `
Object {
"docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"id": "a",
"type": "doc",
},
Object {
"collapsed": true,
"items": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"id": "c",
"type": "doc",
},
Object {
"collapsed": true,
"items": Array [
Object {
"id": "d",
"type": "doc",
},
Object {
"collapsed": true,
"items": Array [
Object {
"id": "e",
Expand Down Expand Up @@ -100,6 +178,7 @@ exports[`loadSidebars sidebars with known sidebar item type 1`] = `
Object {
"docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"id": "foo/bar",
Expand All @@ -123,6 +202,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"id": "hello",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`docsVersion first time versioning 1`] = `
Object {
"version-1.0.0/docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"items": Array [
Expand Down Expand Up @@ -33,6 +34,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"id": "version-1.0.0/hello",
Expand All @@ -50,6 +52,7 @@ exports[`docsVersion not the first time versioning 1`] = `
Object {
"version-2.0.0/docs": Array [
Object {
"collapsed": true,
"items": Array [
Object {
"id": "version-2.0.0/foo/bar",
Expand All @@ -60,6 +63,7 @@ Object {
"type": "category",
},
Object {
"collapsed": true,
"items": Array [
Object {
"id": "version-2.0.0/hello",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,19 @@ describe('loadSidebars', () => {
const result = loadSidebars(null);
expect(result).toEqual({});
});

test('sidebars with category.collapsed property', async () => {
const sidebarPath = path.join(fixtureDir, 'sidebars-collapsed.json');
const result = loadSidebars([sidebarPath]);
expect(result).toMatchSnapshot();
});

test('sidebars with category.collapsed property at first level', async () => {
const sidebarPath = path.join(
fixtureDir,
'sidebars-collapsed-first-level.json',
);
const result = loadSidebars([sidebarPath]);
expect(result).toMatchSnapshot();
});
});
Loading