@docusaurus/theme-classic 0.0.0-4224 → 0.0.0-4241
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/theme/DocCard/index.js +84 -0
- package/lib/theme/DocCard/styles.module.css +43 -0
- package/lib/theme/DocCardList/index.js +28 -0
- package/lib/theme/DocCategoryGeneratedIndexPage/index.js +57 -0
- package/lib/theme/DocCategoryGeneratedIndexPage/styles.module.css +18 -0
- package/lib/theme/DocItem/index.js +6 -7
- package/lib/theme/DocPage/index.js +16 -9
- package/lib/theme/DocPaginator/index.js +6 -7
- package/lib/theme/DocSidebar/index.js +10 -1
- package/lib/theme/DocSidebarItem/index.js +64 -30
- package/lib/theme/DocSidebarItem/styles.module.css +4 -0
- package/lib/theme/DocVersionBadge/index.js +34 -0
- package/lib/theme/DocVersionBanner/index.js +8 -8
- package/lib/theme-classic.d.ts +5 -4
- package/lib-next/theme/DocCard/index.js +80 -0
- package/lib-next/theme/DocCard/styles.module.css +43 -0
- package/lib-next/theme/DocCardList/index.js +19 -0
- package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +49 -0
- package/lib-next/theme/DocCategoryGeneratedIndexPage/styles.module.css +18 -0
- package/lib-next/theme/DocItem/index.js +5 -12
- package/lib-next/theme/DocPage/index.js +31 -14
- package/lib-next/theme/DocPaginator/index.js +7 -11
- package/lib-next/theme/DocSidebar/index.js +10 -1
- package/lib-next/theme/DocSidebarItem/index.js +78 -37
- package/lib-next/theme/DocSidebarItem/styles.module.css +4 -0
- package/lib-next/theme/DocVersionBadge/index.js +27 -0
- package/lib-next/theme/DocVersionBanner/index.js +12 -5
- package/lib-next/theme-classic.d.ts +5 -4
- package/package.json +16 -16
- package/src/theme/DocCard/index.tsx +100 -0
- package/src/theme/DocCard/styles.module.css +43 -0
- package/src/theme/DocCardList/index.tsx +27 -0
- package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +53 -0
- package/src/theme/DocCategoryGeneratedIndexPage/styles.module.css +18 -0
- package/src/theme/DocItem/index.tsx +5 -12
- package/src/theme/DocPage/index.tsx +28 -12
- package/src/theme/DocPaginator/index.tsx +9 -13
- package/src/theme/DocSidebar/index.tsx +9 -1
- package/src/theme/DocSidebarItem/index.tsx +77 -38
- package/src/theme/DocSidebarItem/styles.module.css +4 -0
- package/src/theme/DocVersionBadge/index.tsx +30 -0
- package/src/theme/DocVersionBanner/index.tsx +23 -7
- package/src/theme-classic.d.ts +5 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4241",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -14,30 +14,30 @@
|
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
16
|
"scripts": {
|
|
17
|
-
"build": "tsc --noEmit && yarn babel:lib && yarn babel:lib-next && yarn
|
|
17
|
+
"build": "tsc --noEmit && yarn babel:lib && yarn babel:lib-next && yarn format:lib-next",
|
|
18
18
|
"watch": "concurrently --names \"lib,lib-next,tsc\" --kill-others \"yarn babel:lib --watch\" \"yarn babel:lib-next --watch\" \"yarn tsc --watch\"",
|
|
19
19
|
"babel:lib": "cross-env BABEL_ENV=lib babel src -d lib --extensions \".tsx,.ts\" --ignore \"**/*.d.ts\" --copy-files",
|
|
20
20
|
"babel:lib-next": "cross-env BABEL_ENV=lib-next babel src -d lib-next --extensions \".tsx,.ts\" --ignore \"**/*.d.ts\" --copy-files",
|
|
21
|
-
"
|
|
22
|
-
"
|
|
21
|
+
"format": "prettier --config ../../.prettierrc --ignore-path ../../.prettierignore --write \"**/*.{js,ts,jsx,tsc}\"",
|
|
22
|
+
"format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\"",
|
|
23
23
|
"update-code-translations": "node -e 'require(\"./update-code-translations.js\").run()'"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@docusaurus/core": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
28
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
29
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
30
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
31
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
32
|
-
"@docusaurus/utils": "0.0.0-
|
|
33
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
26
|
+
"@docusaurus/core": "0.0.0-4241",
|
|
27
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4241",
|
|
28
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4241",
|
|
29
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4241",
|
|
30
|
+
"@docusaurus/theme-common": "0.0.0-4241",
|
|
31
|
+
"@docusaurus/theme-translations": "0.0.0-4241",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-4241",
|
|
33
|
+
"@docusaurus/utils-validation": "0.0.0-4241",
|
|
34
34
|
"@mdx-js/mdx": "^1.6.21",
|
|
35
35
|
"@mdx-js/react": "^1.6.21",
|
|
36
36
|
"chalk": "^4.1.2",
|
|
37
37
|
"clsx": "^1.1.1",
|
|
38
38
|
"copy-text-to-clipboard": "^3.0.1",
|
|
39
39
|
"globby": "^11.0.2",
|
|
40
|
-
"infima": "0.2.0-alpha.
|
|
40
|
+
"infima": "0.2.0-alpha.36",
|
|
41
41
|
"lodash": "^4.17.20",
|
|
42
42
|
"postcss": "^8.3.7",
|
|
43
43
|
"prism-react-renderer": "^1.2.1",
|
|
@@ -46,8 +46,8 @@
|
|
|
46
46
|
"rtlcss": "^3.3.0"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
50
|
-
"@docusaurus/types": "0.0.0-
|
|
49
|
+
"@docusaurus/module-type-aliases": "0.0.0-4241",
|
|
50
|
+
"@docusaurus/types": "0.0.0-4241",
|
|
51
51
|
"@types/mdx-js__react": "^1.5.4",
|
|
52
52
|
"@types/parse-numeric-range": "^0.0.1",
|
|
53
53
|
"@types/rtlcss": "^3.1.1",
|
|
@@ -62,5 +62,5 @@
|
|
|
62
62
|
"engines": {
|
|
63
63
|
"node": ">=14"
|
|
64
64
|
},
|
|
65
|
-
"gitHead": "
|
|
65
|
+
"gitHead": "c9609b8c3e97c86812a67a377c7f0ebdca8b07f0"
|
|
66
66
|
}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React, {ReactNode} from 'react';
|
|
9
|
+
import Link from '@docusaurus/Link';
|
|
10
|
+
import {
|
|
11
|
+
PropSidebarItemCategory,
|
|
12
|
+
PropSidebarItemLink,
|
|
13
|
+
} from '@docusaurus/plugin-content-docs';
|
|
14
|
+
import type {Props} from '@theme/DocCard';
|
|
15
|
+
import {findFirstCategoryLink, useDocById} from '@docusaurus/theme-common';
|
|
16
|
+
import clsx from 'clsx';
|
|
17
|
+
import styles from './styles.module.css';
|
|
18
|
+
import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
19
|
+
|
|
20
|
+
function CardContainer({
|
|
21
|
+
href,
|
|
22
|
+
children,
|
|
23
|
+
}: {
|
|
24
|
+
href?: string;
|
|
25
|
+
children: ReactNode;
|
|
26
|
+
}): JSX.Element {
|
|
27
|
+
const className = clsx(
|
|
28
|
+
'card margin-bottom--lg padding--lg',
|
|
29
|
+
styles.cardContainer,
|
|
30
|
+
href && styles.cardContainerLink,
|
|
31
|
+
);
|
|
32
|
+
return href ? (
|
|
33
|
+
<Link href={href} className={className}>
|
|
34
|
+
{children}
|
|
35
|
+
</Link>
|
|
36
|
+
) : (
|
|
37
|
+
<div className={className}>{children}</div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function CardLayout({
|
|
42
|
+
href,
|
|
43
|
+
icon,
|
|
44
|
+
title,
|
|
45
|
+
description,
|
|
46
|
+
}: {
|
|
47
|
+
href?: string;
|
|
48
|
+
icon: ReactNode;
|
|
49
|
+
title: string;
|
|
50
|
+
description?: string;
|
|
51
|
+
}): JSX.Element {
|
|
52
|
+
return (
|
|
53
|
+
<CardContainer href={href}>
|
|
54
|
+
<h2 className={clsx('text--truncate', styles.cardTitle)} title={title}>
|
|
55
|
+
{icon} {title}
|
|
56
|
+
</h2>
|
|
57
|
+
<div
|
|
58
|
+
className={clsx('text--truncate', styles.cardDescription)}
|
|
59
|
+
title={description}>
|
|
60
|
+
{description}
|
|
61
|
+
</div>
|
|
62
|
+
</CardContainer>
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function CardCategory({item}: {item: PropSidebarItemCategory}): JSX.Element {
|
|
67
|
+
const href = findFirstCategoryLink(item);
|
|
68
|
+
return (
|
|
69
|
+
<CardLayout
|
|
70
|
+
href={href}
|
|
71
|
+
icon="🗃️"
|
|
72
|
+
title={item.label}
|
|
73
|
+
description={`${item.items.length} items`}
|
|
74
|
+
/>
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function CardLink({item}: {item: PropSidebarItemLink}): JSX.Element {
|
|
79
|
+
const icon = isInternalUrl(item.href) ? '📄️' : '🔗';
|
|
80
|
+
const doc = useDocById(item.docId ?? undefined);
|
|
81
|
+
return (
|
|
82
|
+
<CardLayout
|
|
83
|
+
href={item.href}
|
|
84
|
+
icon={icon}
|
|
85
|
+
title={item.label}
|
|
86
|
+
description={doc?.description}
|
|
87
|
+
/>
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export default function DocCard({item}: Props): JSX.Element {
|
|
92
|
+
switch (item.type) {
|
|
93
|
+
case 'link':
|
|
94
|
+
return <CardLink item={item} />;
|
|
95
|
+
case 'category':
|
|
96
|
+
return <CardCategory item={item} />;
|
|
97
|
+
default:
|
|
98
|
+
throw new Error(`unknown item type ${JSON.stringify(item)}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
.cardContainer {
|
|
9
|
+
height: 8rem;
|
|
10
|
+
|
|
11
|
+
color: var(--ifm-color-emphasis-800);
|
|
12
|
+
--ifm-link-color: var(--ifm-color-emphasis-800);
|
|
13
|
+
--ifm-link-hover-color: var(--ifm-color-emphasis-800);
|
|
14
|
+
--ifm-link-hover-decoration: none;
|
|
15
|
+
|
|
16
|
+
/* box-shadow: var(--ifm-global-shadow-lw); */
|
|
17
|
+
box-shadow: 0 1.5px 3px 0 rgba(0, 0, 0, 0.15);
|
|
18
|
+
border: 1px solid var(--ifm-color-emphasis-200);
|
|
19
|
+
transition: box-shadow var(--ifm-transition-fast) ease,
|
|
20
|
+
background-color var(--ifm-transition-fast) ease;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.cardContainer.cardContainerLink:hover {
|
|
24
|
+
/* box-shadow: var(--ifm-global-shadow-md); */
|
|
25
|
+
box-shadow: 0 4px 8px 0 rgba(0, 0, 0, 0.2);
|
|
26
|
+
}
|
|
27
|
+
html[data-theme='dark'] .cardContainer.cardContainerLink:hover {
|
|
28
|
+
--ifm-card-background-color: #2d2d2d; /* original, non-hovered color is #242526 */
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.cardContainer:not(.cardContainerLink) {
|
|
32
|
+
cursor: not-allowed;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.cardTitle {
|
|
36
|
+
font-size: 1.2rem;
|
|
37
|
+
min-height: 1.2rem;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.cardDescription {
|
|
41
|
+
font-size: 0.8rem;
|
|
42
|
+
min-height: 0.8rem;
|
|
43
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
|
|
10
|
+
import DocCard from '@theme/DocCard';
|
|
11
|
+
import {PropSidebarItem} from '@docusaurus/plugin-content-docs';
|
|
12
|
+
|
|
13
|
+
export default function DocCardList({
|
|
14
|
+
items,
|
|
15
|
+
}: {
|
|
16
|
+
items: PropSidebarItem[];
|
|
17
|
+
}): JSX.Element {
|
|
18
|
+
return (
|
|
19
|
+
<div className="row">
|
|
20
|
+
{items.map((item, index) => (
|
|
21
|
+
<article key={index} className="col col--6">
|
|
22
|
+
<DocCard item={item} />
|
|
23
|
+
</article>
|
|
24
|
+
))}
|
|
25
|
+
</div>
|
|
26
|
+
);
|
|
27
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
|
10
|
+
import type {Props} from '@theme/DocCategoryGeneratedIndexPage';
|
|
11
|
+
import DocCardList from '@theme/DocCardList';
|
|
12
|
+
import DocPaginator from '@theme/DocPaginator';
|
|
13
|
+
import Seo from '@theme/Seo';
|
|
14
|
+
import DocVersionBanner from '@theme/DocVersionBanner';
|
|
15
|
+
import DocVersionBadge from '@theme/DocVersionBadge';
|
|
16
|
+
import {MainHeading} from '@theme/Heading';
|
|
17
|
+
|
|
18
|
+
import styles from './styles.module.css';
|
|
19
|
+
|
|
20
|
+
export default function DocCategoryGeneratedIndexPage({
|
|
21
|
+
categoryGeneratedIndex,
|
|
22
|
+
}: Props): JSX.Element {
|
|
23
|
+
const category = useCurrentSidebarCategory();
|
|
24
|
+
return (
|
|
25
|
+
<>
|
|
26
|
+
<Seo
|
|
27
|
+
title={categoryGeneratedIndex.title}
|
|
28
|
+
description={categoryGeneratedIndex.description}
|
|
29
|
+
/>
|
|
30
|
+
<div className={styles.generatedIndexPage}>
|
|
31
|
+
<DocVersionBanner />
|
|
32
|
+
<DocVersionBadge />
|
|
33
|
+
<header>
|
|
34
|
+
<MainHeading className={styles.title}>
|
|
35
|
+
{categoryGeneratedIndex.title}
|
|
36
|
+
</MainHeading>
|
|
37
|
+
{categoryGeneratedIndex.description && (
|
|
38
|
+
<p>{categoryGeneratedIndex.description}</p>
|
|
39
|
+
)}
|
|
40
|
+
</header>
|
|
41
|
+
<main className="margin-top--lg">
|
|
42
|
+
<DocCardList items={category.items} />
|
|
43
|
+
</main>
|
|
44
|
+
<footer className="margin-top--lg">
|
|
45
|
+
<DocPaginator
|
|
46
|
+
previous={categoryGeneratedIndex.navigation.previous}
|
|
47
|
+
next={categoryGeneratedIndex.navigation.next}
|
|
48
|
+
/>
|
|
49
|
+
</footer>
|
|
50
|
+
</div>
|
|
51
|
+
</>
|
|
52
|
+
);
|
|
53
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
@media (min-width: 997px) {
|
|
9
|
+
.generatedIndexPage {
|
|
10
|
+
max-width: 75% !important;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/* Duplicated from .markdown h1 */
|
|
15
|
+
.title {
|
|
16
|
+
--ifm-h1-font-size: 3rem;
|
|
17
|
+
margin-bottom: calc(1.25 * var(--ifm-leading));
|
|
18
|
+
}
|
|
@@ -10,6 +10,7 @@ import clsx from 'clsx';
|
|
|
10
10
|
import useWindowSize from '@theme/hooks/useWindowSize';
|
|
11
11
|
import DocPaginator from '@theme/DocPaginator';
|
|
12
12
|
import DocVersionBanner from '@theme/DocVersionBanner';
|
|
13
|
+
import DocVersionBadge from '@theme/DocVersionBadge';
|
|
13
14
|
import Seo from '@theme/Seo';
|
|
14
15
|
import type {Props} from '@theme/DocItem';
|
|
15
16
|
import DocItemFooter from '@theme/DocItemFooter';
|
|
@@ -20,7 +21,7 @@ import styles from './styles.module.css';
|
|
|
20
21
|
import {ThemeClassNames} from '@docusaurus/theme-common';
|
|
21
22
|
|
|
22
23
|
export default function DocItem(props: Props): JSX.Element {
|
|
23
|
-
const {content: DocContent
|
|
24
|
+
const {content: DocContent} = props;
|
|
24
25
|
const {metadata, frontMatter} = DocContent;
|
|
25
26
|
const {
|
|
26
27
|
image,
|
|
@@ -55,18 +56,10 @@ export default function DocItem(props: Props): JSX.Element {
|
|
|
55
56
|
className={clsx('col', {
|
|
56
57
|
[styles.docItemCol]: !hideTableOfContents,
|
|
57
58
|
})}>
|
|
58
|
-
<DocVersionBanner
|
|
59
|
+
<DocVersionBanner />
|
|
59
60
|
<div className={styles.docItemContainer}>
|
|
60
61
|
<article>
|
|
61
|
-
|
|
62
|
-
<span
|
|
63
|
-
className={clsx(
|
|
64
|
-
ThemeClassNames.docs.docVersionBadge,
|
|
65
|
-
'badge badge--secondary',
|
|
66
|
-
)}>
|
|
67
|
-
Version: {versionMetadata.label}
|
|
68
|
-
</span>
|
|
69
|
-
)}
|
|
62
|
+
<DocVersionBadge />
|
|
70
63
|
|
|
71
64
|
{canRenderTOC && (
|
|
72
65
|
<TOCCollapsible
|
|
@@ -95,7 +88,7 @@ export default function DocItem(props: Props): JSX.Element {
|
|
|
95
88
|
<DocItemFooter {...props} />
|
|
96
89
|
</article>
|
|
97
90
|
|
|
98
|
-
<DocPaginator metadata={metadata} />
|
|
91
|
+
<DocPaginator previous={metadata.previous} next={metadata.next} />
|
|
99
92
|
</div>
|
|
100
93
|
</div>
|
|
101
94
|
{renderTocDesktop && (
|
|
@@ -23,27 +23,30 @@ import {translate} from '@docusaurus/Translate';
|
|
|
23
23
|
|
|
24
24
|
import clsx from 'clsx';
|
|
25
25
|
import styles from './styles.module.css';
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
ThemeClassNames,
|
|
28
|
+
docVersionSearchTag,
|
|
29
|
+
DocsSidebarProvider,
|
|
30
|
+
useDocsSidebar,
|
|
31
|
+
DocsVersionProvider,
|
|
32
|
+
} from '@docusaurus/theme-common';
|
|
27
33
|
import Head from '@docusaurus/Head';
|
|
28
34
|
|
|
29
35
|
type DocPageContentProps = {
|
|
30
36
|
readonly currentDocRoute: DocumentRoute;
|
|
31
37
|
readonly versionMetadata: PropVersionMetadata;
|
|
32
38
|
readonly children: ReactNode;
|
|
39
|
+
readonly sidebarName: string | undefined;
|
|
33
40
|
};
|
|
34
41
|
|
|
35
42
|
function DocPageContent({
|
|
36
43
|
currentDocRoute,
|
|
37
44
|
versionMetadata,
|
|
38
45
|
children,
|
|
46
|
+
sidebarName,
|
|
39
47
|
}: DocPageContentProps): JSX.Element {
|
|
48
|
+
const sidebar = useDocsSidebar();
|
|
40
49
|
const {pluginId, version} = versionMetadata;
|
|
41
|
-
|
|
42
|
-
const sidebarName = currentDocRoute.sidebar;
|
|
43
|
-
const sidebar = sidebarName
|
|
44
|
-
? versionMetadata.docsSidebars[sidebarName]
|
|
45
|
-
: undefined;
|
|
46
|
-
|
|
47
50
|
const [hiddenSidebarContainer, setHiddenSidebarContainer] = useState(false);
|
|
48
51
|
const [hiddenSidebar, setHiddenSidebar] = useState(false);
|
|
49
52
|
const toggleSidebar = useCallback(() => {
|
|
@@ -150,17 +153,30 @@ function DocPage(props: Props): JSX.Element {
|
|
|
150
153
|
if (!currentDocRoute) {
|
|
151
154
|
return <NotFound />;
|
|
152
155
|
}
|
|
156
|
+
|
|
157
|
+
// For now, the sidebarName is added as route config: not ideal!
|
|
158
|
+
const sidebarName = currentDocRoute.sidebar;
|
|
159
|
+
|
|
160
|
+
const sidebar = sidebarName
|
|
161
|
+
? versionMetadata.docsSidebars[sidebarName]
|
|
162
|
+
: null;
|
|
163
|
+
|
|
153
164
|
return (
|
|
154
165
|
<>
|
|
155
166
|
<Head>
|
|
156
167
|
{/* TODO we should add a core addRoute({htmlClassName}) generic plugin option */}
|
|
157
168
|
<html className={versionMetadata.className} />
|
|
158
169
|
</Head>
|
|
159
|
-
<
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
170
|
+
<DocsVersionProvider version={versionMetadata}>
|
|
171
|
+
<DocsSidebarProvider sidebar={sidebar}>
|
|
172
|
+
<DocPageContent
|
|
173
|
+
currentDocRoute={currentDocRoute}
|
|
174
|
+
versionMetadata={versionMetadata}
|
|
175
|
+
sidebarName={sidebarName}>
|
|
176
|
+
{renderRoutes(docRoutes, {versionMetadata})}
|
|
177
|
+
</DocPageContent>
|
|
178
|
+
</DocsSidebarProvider>
|
|
179
|
+
</DocsVersionProvider>
|
|
164
180
|
</>
|
|
165
181
|
);
|
|
166
182
|
}
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import Link from '@docusaurus/Link';
|
|
10
10
|
import Translate, {translate} from '@docusaurus/Translate';
|
|
11
|
-
import type {
|
|
11
|
+
import type {PropNavigation} from '@docusaurus/plugin-content-docs';
|
|
12
12
|
|
|
13
|
-
function DocPaginator(props:
|
|
14
|
-
const {
|
|
13
|
+
function DocPaginator(props: PropNavigation): JSX.Element {
|
|
14
|
+
const {previous, next} = props;
|
|
15
15
|
|
|
16
16
|
return (
|
|
17
17
|
<nav
|
|
@@ -22,10 +22,8 @@ function DocPaginator(props: Props): JSX.Element {
|
|
|
22
22
|
description: 'The ARIA label for the docs pagination',
|
|
23
23
|
})}>
|
|
24
24
|
<div className="pagination-nav__item">
|
|
25
|
-
{
|
|
26
|
-
<Link
|
|
27
|
-
className="pagination-nav__link"
|
|
28
|
-
to={metadata.previous.permalink}>
|
|
25
|
+
{previous && (
|
|
26
|
+
<Link className="pagination-nav__link" to={previous.permalink}>
|
|
29
27
|
<div className="pagination-nav__sublabel">
|
|
30
28
|
<Translate
|
|
31
29
|
id="theme.docs.paginator.previous"
|
|
@@ -34,14 +32,14 @@ function DocPaginator(props: Props): JSX.Element {
|
|
|
34
32
|
</Translate>
|
|
35
33
|
</div>
|
|
36
34
|
<div className="pagination-nav__label">
|
|
37
|
-
« {
|
|
35
|
+
« {previous.title}
|
|
38
36
|
</div>
|
|
39
37
|
</Link>
|
|
40
38
|
)}
|
|
41
39
|
</div>
|
|
42
40
|
<div className="pagination-nav__item pagination-nav__item--next">
|
|
43
|
-
{
|
|
44
|
-
<Link className="pagination-nav__link" to={
|
|
41
|
+
{next && (
|
|
42
|
+
<Link className="pagination-nav__link" to={next.permalink}>
|
|
45
43
|
<div className="pagination-nav__sublabel">
|
|
46
44
|
<Translate
|
|
47
45
|
id="theme.docs.paginator.next"
|
|
@@ -49,9 +47,7 @@ function DocPaginator(props: Props): JSX.Element {
|
|
|
49
47
|
Next
|
|
50
48
|
</Translate>
|
|
51
49
|
</div>
|
|
52
|
-
<div className="pagination-nav__label">
|
|
53
|
-
{metadata.next.title} »
|
|
54
|
-
</div>
|
|
50
|
+
<div className="pagination-nav__label">{next.title} »</div>
|
|
55
51
|
</Link>
|
|
56
52
|
)}
|
|
57
53
|
</div>
|
|
@@ -100,7 +100,15 @@ const DocSidebarMobileSecondaryMenu: MobileSecondaryMenuComponent<Props> = ({
|
|
|
100
100
|
<DocSidebarItems
|
|
101
101
|
items={sidebar}
|
|
102
102
|
activePath={path}
|
|
103
|
-
onItemClick={() =>
|
|
103
|
+
onItemClick={(item) => {
|
|
104
|
+
// Mobile sidebar should only be closed if the category has a link
|
|
105
|
+
if (item.type === 'category' && item.href) {
|
|
106
|
+
toggleSidebar();
|
|
107
|
+
}
|
|
108
|
+
if (item.type === 'link') {
|
|
109
|
+
toggleSidebar();
|
|
110
|
+
}
|
|
111
|
+
}}
|
|
104
112
|
level={1}
|
|
105
113
|
/>
|
|
106
114
|
</ul>
|
|
@@ -5,17 +5,19 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {useEffect, memo} from 'react';
|
|
8
|
+
import React, {useEffect, memo, useMemo} from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import {
|
|
11
|
-
|
|
11
|
+
isActiveSidebarItem,
|
|
12
12
|
usePrevious,
|
|
13
13
|
Collapsible,
|
|
14
14
|
useCollapsible,
|
|
15
|
+
findFirstCategoryLink,
|
|
15
16
|
ThemeClassNames,
|
|
16
17
|
} from '@docusaurus/theme-common';
|
|
17
18
|
import Link from '@docusaurus/Link';
|
|
18
19
|
import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
20
|
+
import {translate} from '@docusaurus/Translate';
|
|
19
21
|
import IconExternalLink from '@theme/IconExternalLink';
|
|
20
22
|
|
|
21
23
|
import type {Props, DocSidebarItemsProps} from '@theme/DocSidebarItem';
|
|
@@ -25,21 +27,7 @@ import type {
|
|
|
25
27
|
} from '@docusaurus/plugin-content-docs';
|
|
26
28
|
|
|
27
29
|
import styles from './styles.module.css';
|
|
28
|
-
|
|
29
|
-
const isActiveSidebarItem = (
|
|
30
|
-
item: Props['item'],
|
|
31
|
-
activePath: string,
|
|
32
|
-
): boolean => {
|
|
33
|
-
if (item.type === 'link') {
|
|
34
|
-
return isSamePath(item.href, activePath);
|
|
35
|
-
}
|
|
36
|
-
if (item.type === 'category') {
|
|
37
|
-
return item.items.some((subItem) =>
|
|
38
|
-
isActiveSidebarItem(subItem, activePath),
|
|
39
|
-
);
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
};
|
|
30
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
43
31
|
|
|
44
32
|
// Optimize sidebar at each "level"
|
|
45
33
|
// TODO this item should probably not receive the "activePath" props
|
|
@@ -93,6 +81,28 @@ function useAutoExpandActiveCategory({
|
|
|
93
81
|
}, [isActive, wasActive, collapsed, setCollapsed]);
|
|
94
82
|
}
|
|
95
83
|
|
|
84
|
+
// When a collapsible category has no link, we still link it to its first child during SSR as a temporary fallback
|
|
85
|
+
// This allows to be able to navigate inside the category even when JS fails to load, is delayed or simply disabled
|
|
86
|
+
// React hydration becomes an optional progressive enhancement
|
|
87
|
+
// see https://github.com/facebookincubator/infima/issues/36#issuecomment-772543188
|
|
88
|
+
// see https://github.com/facebook/docusaurus/issues/3030
|
|
89
|
+
function useCategoryHrefWithSSRFallback(
|
|
90
|
+
item: PropSidebarItemCategory,
|
|
91
|
+
): string | undefined {
|
|
92
|
+
const isBrowser = useIsBrowser();
|
|
93
|
+
return useMemo(() => {
|
|
94
|
+
if (item.href) {
|
|
95
|
+
return item.href;
|
|
96
|
+
}
|
|
97
|
+
// In these cases, it's not necessary to render a fallback
|
|
98
|
+
// We skip the "findFirstCategoryLink" computation
|
|
99
|
+
if (isBrowser || !item.collapsible) {
|
|
100
|
+
return undefined;
|
|
101
|
+
}
|
|
102
|
+
return findFirstCategoryLink(item);
|
|
103
|
+
}, [item, isBrowser]);
|
|
104
|
+
}
|
|
105
|
+
|
|
96
106
|
function DocSidebarItemCategory({
|
|
97
107
|
item,
|
|
98
108
|
onItemClick,
|
|
@@ -100,7 +110,8 @@ function DocSidebarItemCategory({
|
|
|
100
110
|
level,
|
|
101
111
|
...props
|
|
102
112
|
}: Props & {item: PropSidebarItemCategory}) {
|
|
103
|
-
const {items, label, collapsible, className} = item;
|
|
113
|
+
const {items, label, collapsible, className, href} = item;
|
|
114
|
+
const hrefWithSSRFallback = useCategoryHrefWithSSRFallback(item);
|
|
104
115
|
|
|
105
116
|
const isActive = isActiveSidebarItem(item, activePath);
|
|
106
117
|
|
|
@@ -128,25 +139,53 @@ function DocSidebarItemCategory({
|
|
|
128
139
|
},
|
|
129
140
|
className,
|
|
130
141
|
)}>
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
142
|
+
<div className="menu__list-item-collapsible">
|
|
143
|
+
<Link
|
|
144
|
+
className={clsx('menu__link', {
|
|
145
|
+
'menu__link--sublist': collapsible && !href,
|
|
146
|
+
'menu__link--active': isActive,
|
|
147
|
+
[styles.menuLinkText]: !collapsible,
|
|
148
|
+
[styles.hasHref]: !!hrefWithSSRFallback,
|
|
149
|
+
})}
|
|
150
|
+
onClick={
|
|
151
|
+
collapsible
|
|
152
|
+
? (e) => {
|
|
153
|
+
onItemClick?.(item);
|
|
154
|
+
if (href) {
|
|
155
|
+
setCollapsed(false);
|
|
156
|
+
} else {
|
|
157
|
+
e.preventDefault();
|
|
158
|
+
toggleCollapsed();
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
: () => {
|
|
162
|
+
onItemClick?.(item);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
href={collapsible ? hrefWithSSRFallback ?? '#' : hrefWithSSRFallback}
|
|
166
|
+
{...props}>
|
|
167
|
+
{label}
|
|
168
|
+
</Link>
|
|
169
|
+
{href && collapsible && (
|
|
170
|
+
<button
|
|
171
|
+
aria-label={translate(
|
|
172
|
+
{
|
|
173
|
+
id: 'theme.DocSidebarItem.toggleCollapsedCategoryAriaLabel',
|
|
174
|
+
message: "Toggle the collapsible sidebar category '{label}'",
|
|
175
|
+
description:
|
|
176
|
+
'The ARIA label to toggle the collapsible sidebar category',
|
|
177
|
+
},
|
|
178
|
+
{label},
|
|
179
|
+
)}
|
|
180
|
+
type="button"
|
|
181
|
+
className="clean-btn menu__caret"
|
|
182
|
+
onClick={(e) => {
|
|
183
|
+
e.preventDefault();
|
|
184
|
+
toggleCollapsed();
|
|
185
|
+
}}
|
|
186
|
+
/>
|
|
187
|
+
)}
|
|
188
|
+
</div>
|
|
150
189
|
|
|
151
190
|
<Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
|
|
152
191
|
<DocSidebarItems
|
|
@@ -186,7 +225,7 @@ function DocSidebarItemLink({
|
|
|
186
225
|
aria-current={isActive ? 'page' : undefined}
|
|
187
226
|
to={href}
|
|
188
227
|
{...(isInternalUrl(href) && {
|
|
189
|
-
onClick: onItemClick,
|
|
228
|
+
onClick: onItemClick ? () => onItemClick(item) : undefined,
|
|
190
229
|
})}
|
|
191
230
|
{...props}>
|
|
192
231
|
{isInternalUrl(href) ? (
|