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): redesign mobile UX: inline TOC + doc sidebar in main menu #4273

Merged
merged 45 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
fa06ace
feat(v2): mobile TOC
lex111 Feb 23, 2021
41120ea
Bug fixes and various improvements
lex111 Feb 24, 2021
e21914e
Merge remote-tracking branch 'origin/master' into lex111/iss2220
lex111 May 16, 2021
9f6ebff
Redesign
lex111 May 16, 2021
cab8033
Merge remote-tracking branch 'origin' into lex111/iss2220
lex111 Jun 11, 2021
bb8c046
Merge remote-tracking branch 'origin' into lex111/iss2220
lex111 Jun 24, 2021
20e4951
Merge branch 'master' into lex111/iss2220
slorber Jul 1, 2021
7014880
extract TOCCollapsible component
slorber Jul 1, 2021
977ffa5
Merge branch 'master' into lex111/iss2220
slorber Jul 1, 2021
a4ba0f7
TS improvements
slorber Jul 1, 2021
7f9e8a1
Assign sidebar name directly to the doc route => no need for either p…
slorber Jul 5, 2021
774a82c
revert changes to useWindowSize, fix FOUC issues
slorber Jul 6, 2021
e533a17
extract DocSidebarDesktop component
slorber Jul 6, 2021
defdd49
remove now useless menu infima classes
slorber Jul 6, 2021
c160e1f
TOCHeadings => rename + remove unused onClick prop
slorber Jul 6, 2021
be0c30e
Extract DocSidebarItem
slorber Jul 6, 2021
845d716
minor renaming
slorber Jul 6, 2021
c7a4398
replace GlobalData usage by a React teleport system to render in the …
slorber Jul 6, 2021
a4282cc
useWindowSize => simulate SSR size in dev to make FOUC issues more ob…
slorber Jul 7, 2021
0ca7ff8
fix remaining sidebar layout shift
slorber Jul 7, 2021
05961af
update docs snapshots
slorber Jul 7, 2021
afa8d43
remove unused code translations
slorber Jul 7, 2021
af9d8f3
remove unused code translations
slorber Jul 7, 2021
49cbb62
fix minor update-code-translations bug
slorber Jul 7, 2021
a8a7a06
Add more build-size paths to watch
slorber Jul 7, 2021
83b26a1
Restyle back button
lex111 Jul 7, 2021
563c5ff
Add missing`menu` class
lex111 Jul 7, 2021
6490006
extract useShallowMemoizedObject
slorber Jul 7, 2021
bf424f6
fix routes tests + better routes formatting
slorber Jul 7, 2021
44b3c43
use Translate api for labels
slorber Jul 7, 2021
105e9aa
use Translate api for labels
slorber Jul 7, 2021
f00e88e
Update translations
slorber Jul 7, 2021
0e3440f
Improve dark mode support for back button
lex111 Jul 7, 2021
27ed803
Merge branch 'master' into lex111/inline-color-code
slorber Jul 7, 2021
9951423
Merge branch 'master' into lex111/iss2220
slorber Jul 7, 2021
8802dfd
replace useCollapse by new useCollapsible
slorber Jul 7, 2021
10d0080
Merge branch 'master' into lex111/iss2220
slorber Jul 7, 2021
426ce69
Cleanup and use clean-btn for TOCCollapsible button
lex111 Jul 7, 2021
91666bb
Make TOC links clickable over full width
lex111 Jul 7, 2021
3cf7769
Merge branch 'master' into lex111/iss2220
slorber Jul 8, 2021
0e75bf5
Cleanup
lex111 Jul 8, 2021
3e7cf0f
Merge branch 'lex111/iss2220' of github.com:facebook/docusaurus into …
lex111 Jul 8, 2021
7ab833e
fix uncollapsible sidebar that can be collapsed + create <Collapsible…
slorber Jul 9, 2021
53f3352
dependency array typo
slorber Jul 9, 2021
3dd78dc
rollback sidebars community commit typo
slorber Jul 9, 2021
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
2 changes: 1 addition & 1 deletion .github/workflows/v2-build-size-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
with:
repo-token: '${{ secrets.GITHUB_TOKEN }}'
build-script: 'build:v2:en'
pattern: '{website/build/assets/js/main*js,website/build/assets/css/styles*css,website/.docusaurus/globalData.json,website/build/index.html,website/build/blog/**/introducing-docusaurus/*,website/build/docs/index.html,website/build/docs/introduction/index.html,website/build/docs-tests/index.html,website/build/docs-tests/standalone/index.html}'
pattern: '{website/build/assets/js/main*js,website/build/assets/css/styles*css,website/.docusaurus/globalData.json,website/build/index.html,website/build/blog/index.html,website/build/blog/**/introducing-docusaurus/*,website/build/docs/index.html,website/build/docs/installation/index.html,website/build/docs-tests/index.html,website/build/docs-tests/standalone/index.html}'
strip-hash: '\.([^;]\w{7})\.'
minimum-change-threshold: 30
compression: 'none'
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,6 @@ Object {
]
}
]
},
\\"permalinkToSidebar\\": {
\\"/docs/foo/bar\\": \\"docs\\",
\\"/docs/foo/bazSlug.html\\": \\"docs\\",
\\"/docs/\\": \\"docs\\"
}
}",
}
Expand Down Expand Up @@ -575,6 +570,7 @@ Array [
"content": "@site/docs/hello.md",
},
"path": "/docs/",
"sidebar": "docs",
},
Object {
"component": "@theme/DocItem",
Expand All @@ -591,6 +587,7 @@ Array [
"content": "@site/docs/foo/bar.md",
},
"path": "/docs/foo/bar",
"sidebar": "docs",
},
Object {
"component": "@theme/DocItem",
Expand All @@ -599,6 +596,7 @@ Array [
"content": "@site/docs/foo/baz.md",
},
"path": "/docs/foo/bazSlug.html",
"sidebar": "docs",
},
Object {
"component": "@theme/DocItem",
Expand Down Expand Up @@ -883,9 +881,6 @@ Object {
\\"href\\": \\"/community/team\\"
}
]
},
\\"permalinkToSidebar\\": {
\\"/community/team\\": \\"version-1.0.0/community\\"
}
}",
"version-current-metadata-prop-751.json": "{
Expand All @@ -902,9 +897,6 @@ Object {
\\"href\\": \\"/community/next/team\\"
}
]
},
\\"permalinkToSidebar\\": {
\\"/community/next/team\\": \\"community\\"
}
}",
}
Expand Down Expand Up @@ -968,6 +960,7 @@ Array [
"content": "@site/i18n/en/docusaurus-plugin-content-docs-community/current/team.md",
},
"path": "/community/next/team",
"sidebar": "community",
},
],
},
Expand All @@ -987,6 +980,7 @@ Array [
"content": "@site/community_versioned_docs/version-1.0.0/team.md",
},
"path": "/community/team",
"sidebar": "version-1.0.0/community",
},
],
},
Expand Down Expand Up @@ -1439,11 +1433,6 @@ Object {
]
}
]
},
\\"permalinkToSidebar\\": {
\\"/docs/1.0.0/foo/barSlug\\": \\"version-1.0.0/docs\\",
\\"/docs/1.0.0/foo/baz\\": \\"version-1.0.0/docs\\",
\\"/docs/1.0.0/\\": \\"version-1.0.0/docs\\"
}
}",
"version-1-0-1-metadata-prop-e87.json": "{
Expand Down Expand Up @@ -1479,10 +1468,6 @@ Object {
]
}
]
},
\\"permalinkToSidebar\\": {
\\"/docs/foo/bar\\": \\"version-1.0.1/docs\\",
\\"/docs/\\": \\"version-1.0.1/docs\\"
}
}",
"version-current-metadata-prop-751.json": "{
Expand Down Expand Up @@ -1518,10 +1503,6 @@ Object {
]
}
]
},
\\"permalinkToSidebar\\": {
\\"/docs/next/foo/barSlug\\": \\"docs\\",
\\"/docs/next/\\": \\"docs\\"
}
}",
"version-with-slugs-metadata-prop-2bf.json": "{
Expand All @@ -1545,9 +1526,6 @@ Object {
]
}
]
},
\\"permalinkToSidebar\\": {
\\"/docs/withSlugs/rootAbsoluteSlug\\": \\"version-1.0.1/docs\\"
}
}",
}
Expand Down Expand Up @@ -1714,6 +1692,7 @@ Array [
"content": "@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md",
},
"path": "/docs/1.0.0/",
"sidebar": "version-1.0.0/docs",
},
Object {
"component": "@theme/DocItem",
Expand All @@ -1722,6 +1701,7 @@ Array [
"content": "@site/versioned_docs/version-1.0.0/foo/bar.md",
},
"path": "/docs/1.0.0/foo/barSlug",
"sidebar": "version-1.0.0/docs",
},
Object {
"component": "@theme/DocItem",
Expand All @@ -1730,6 +1710,7 @@ Array [
"content": "@site/versioned_docs/version-1.0.0/foo/baz.md",
},
"path": "/docs/1.0.0/foo/baz",
"sidebar": "version-1.0.0/docs",
},
],
},
Expand All @@ -1749,6 +1730,7 @@ Array [
"content": "@site/docs/hello.md",
},
"path": "/docs/next/",
"sidebar": "docs",
},
Object {
"component": "@theme/DocItem",
Expand All @@ -1765,6 +1747,7 @@ Array [
"content": "@site/docs/foo/bar.md",
},
"path": "/docs/next/foo/barSlug",
"sidebar": "docs",
},
Object {
"component": "@theme/DocItem",
Expand Down Expand Up @@ -1824,6 +1807,7 @@ Array [
"content": "@site/versioned_docs/version-withSlugs/rootAbsoluteSlug.md",
},
"path": "/docs/withSlugs/rootAbsoluteSlug",
"sidebar": "version-1.0.1/docs",
},
Object {
"component": "@theme/DocItem",
Expand Down Expand Up @@ -1883,6 +1867,7 @@ Array [
"content": "@site/versioned_docs/version-1.0.1/hello.md",
},
"path": "/docs/",
"sidebar": "version-1.0.1/docs",
},
Object {
"component": "@theme/DocItem",
Expand All @@ -1891,6 +1876,7 @@ Array [
"content": "@site/versioned_docs/version-1.0.1/foo/bar.md",
},
"path": "/docs/foo/bar",
"sidebar": "version-1.0.1/docs",
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ Object {
],
"isLast": true,
"mainDocId": "",
"permalinkToSidebar": Object {},
"routePriority": undefined,
"sidebarFilePath": "any",
"sidebars": Object {
Expand Down Expand Up @@ -292,7 +291,6 @@ Object {
],
"isLast": true,
"mainDocId": "",
"permalinkToSidebar": Object {},
"routePriority": undefined,
"sidebarFilePath": "any",
"sidebars": Object {
Expand Down Expand Up @@ -433,7 +431,6 @@ Object {
],
"isLast": true,
"mainDocId": "",
"permalinkToSidebar": Object {},
"routePriority": undefined,
"sidebarFilePath": "any",
"sidebars": Object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,6 @@ Entries created:
`version-${kebabCase(version.versionName)}-metadata-prop`,
);
expect(versionMetadataProp.docsSidebars).toEqual(toSidebarsProp(version));
expect(versionMetadataProp.permalinkToSidebar).toEqual(
version.permalinkToSidebar,
);
},

expectSnapshot: () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ function createSampleVersion(
versionLabel: `${version.versionName} label`,
versionPath: '/docs/',
mainDocId: '',
permalinkToSidebar: {},
routePriority: undefined,
sidebarFilePath: 'any',
isLast: true,
Expand Down
34 changes: 16 additions & 18 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import {
DocFile,
DocsMarkdownOption,
} from './types';
import {PermalinkToSidebar} from '@docusaurus/plugin-content-docs-types';
import {RuleSetRule} from 'webpack';
import {cliDocsVersionCommand} from './cli';
import {VERSIONS_JSON_FILE} from './constants';
Expand Down Expand Up @@ -224,14 +223,6 @@ export default function pluginContentDocs(
// sort to ensure consistent output for tests
docs.sort((a, b) => a.id.localeCompare(b.id));

// TODO really useful? replace with global state logic?
const permalinkToSidebar: PermalinkToSidebar = {};
Object.values(docs).forEach((doc) => {
if (doc.sidebar) {
permalinkToSidebar[doc.permalink] = doc.sidebar;
}
});

// The "main doc" is the "version entry point"
// We browse this doc by clicking on a version:
// - the "home" doc (at '/docs/')
Expand All @@ -256,7 +247,6 @@ export default function pluginContentDocs(
...versionMetadata,
mainDocId: getMainDoc().unversionedId,
sidebars,
permalinkToSidebar,
docs: docs.map(addNavData),
};
}
Expand Down Expand Up @@ -300,30 +290,36 @@ export default function pluginContentDocs(
JSON.stringify(metadataItem, null, 2),
);

return {
const docRoute: RouteConfig = {
path: metadataItem.permalink,
component: docItemComponent,
exact: true,
modules: {
content: metadataItem.source,
},
// Because the parent (DocPage) comp need to access it easily
// This permits to render the sidebar once without unmount/remount when navigating (and preserve sidebar state)
...(metadataItem.sidebar && {
sidebar: metadataItem.sidebar,
}),
};

return docRoute;
}),
);

return routes.sort((a, b) => a.path.localeCompare(b.path));
};

async function doCreateVersionRoutes(loadedVersion: LoadedVersion) {
async function doCreateVersionRoutes(
loadedVersion: LoadedVersion,
): Promise<void> {
const versionMetadata = toVersionMetadataProp(pluginId, loadedVersion);
const versionMetadataPropPath = await createData(
`${docuHash(
`version-${loadedVersion.versionName}-metadata-prop`,
)}.json`,
JSON.stringify(
toVersionMetadataProp(pluginId, loadedVersion),
null,
2,
),
JSON.stringify(versionMetadata, null, 2),
);

addRoute({
Expand All @@ -341,7 +337,9 @@ export default function pluginContentDocs(
});
}

async function createVersionRoutes(loadedVersion: LoadedVersion) {
async function createVersionRoutes(
loadedVersion: LoadedVersion,
): Promise<void> {
try {
return await doCreateVersionRoutes(loadedVersion);
} catch (e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,13 @@
declare module '@docusaurus/plugin-content-docs-types' {
import type {VersionBanner} from './types';

export type PermalinkToSidebar = {
[permalink: string]: string;
};

export type PropVersionMetadata = {
pluginId: string;
version: string;
label: string;
banner: VersionBanner;
isLast: boolean;
docsSidebars: PropSidebars;
permalinkToSidebar: PermalinkToSidebar;
};

type PropsSidebarItemBase = {
Expand Down Expand Up @@ -60,6 +55,7 @@ declare module '@theme/DocItem' {
readonly component: () => JSX.Element;
readonly exact: boolean;
readonly path: string;
readonly sidebar?: string;
};

export type FrontMatter = {
Expand Down
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,5 @@ export function toVersionMetadataProp(
banner: loadedVersion.versionBanner,
isLast: loadedVersion.isLast,
docsSidebars: toSidebarsProp(loadedVersion),
permalinkToSidebar: loadedVersion.permalinkToSidebar,
};
}
1 change: 0 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ export type LoadedVersion = VersionMetadata & {
mainDocId: string;
docs: DocMetadata[];
sidebars: Sidebars;
permalinkToSidebar: Record<string, string>;
};

export type LoadedContent = {
Expand Down
Loading