@docusaurus/theme-classic 0.0.0-4364 → 0.0.0-4375
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-classic.d.ts +46 -27
- package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +3 -3
- package/lib-next/theme/DocItem/index.js +6 -2
- package/lib-next/theme/DocSidebar/index.js +1 -1
- package/lib-next/theme/DocSidebarItem/index.js +3 -16
- package/lib-next/theme/DocSidebarItems/index.js +26 -0
- package/lib-next/theme/DocSidebarItems/styles.module.css +19 -0
- package/lib-next/theme/Heading/index.js +39 -42
- package/lib-next/theme/MDXComponents/index.js +6 -6
- package/lib-next/theme/NavbarItem/DefaultNavbarItem.js +4 -66
- package/lib-next/theme/NavbarItem/DocNavbarItem.js +1 -1
- package/lib-next/theme/NavbarItem/DocSidebarNavbarItem.js +1 -1
- package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +5 -5
- package/lib-next/theme/NavbarItem/NavbarNavLink.js +70 -0
- package/lib-next/theme/NavbarItem/index.js +0 -2
- package/lib-next/theme/NavbarItem/utils.js +9 -0
- package/lib-next/theme/hooks/useDocs.js +1 -0
- package/package.json +12 -12
- package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +3 -3
- package/src/theme/DocItem/index.tsx +6 -2
- package/src/theme/DocSidebar/index.tsx +1 -1
- package/src/theme/DocSidebarItem/index.tsx +3 -19
- package/src/theme/DocSidebarItems/index.tsx +31 -0
- package/src/theme/DocSidebarItems/styles.module.css +19 -0
- package/src/theme/Heading/index.tsx +39 -46
- package/src/theme/MDXComponents/index.tsx +6 -6
- package/src/theme/NavbarItem/DefaultNavbarItem.tsx +6 -62
- package/src/theme/NavbarItem/DocNavbarItem.tsx +1 -1
- package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +3 -2
- package/src/theme/NavbarItem/DropdownNavbarItem.tsx +5 -5
- package/src/theme/NavbarItem/NavbarNavLink.tsx +68 -0
- package/src/theme/NavbarItem/index.tsx +0 -3
- package/src/theme/NavbarItem/utils.ts +10 -0
- package/src/theme/hooks/useDocs.ts +1 -0
- package/src/theme-classic.d.ts +46 -27
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-4375",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -23,14 +23,14 @@
|
|
|
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-4375",
|
|
27
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4375",
|
|
28
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4375",
|
|
29
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4375",
|
|
30
|
+
"@docusaurus/theme-common": "0.0.0-4375",
|
|
31
|
+
"@docusaurus/theme-translations": "0.0.0-4375",
|
|
32
|
+
"@docusaurus/utils": "0.0.0-4375",
|
|
33
|
+
"@docusaurus/utils-validation": "0.0.0-4375",
|
|
34
34
|
"@mdx-js/mdx": "^1.6.21",
|
|
35
35
|
"@mdx-js/react": "^1.6.21",
|
|
36
36
|
"clsx": "^1.1.1",
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"rtlcss": "^3.3.0"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|
|
48
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
49
|
-
"@docusaurus/types": "0.0.0-
|
|
48
|
+
"@docusaurus/module-type-aliases": "0.0.0-4375",
|
|
49
|
+
"@docusaurus/types": "0.0.0-4375",
|
|
50
50
|
"@types/mdx-js__react": "^1.5.4",
|
|
51
51
|
"@types/parse-numeric-range": "^0.0.1",
|
|
52
52
|
"@types/rtlcss": "^3.1.1",
|
|
@@ -61,5 +61,5 @@
|
|
|
61
61
|
"engines": {
|
|
62
62
|
"node": ">=14"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "5738b5a5cb1c7446430167058e8d246fe6b596de"
|
|
65
65
|
}
|
|
@@ -13,7 +13,7 @@ import DocPaginator from '@theme/DocPaginator';
|
|
|
13
13
|
import Seo from '@theme/Seo';
|
|
14
14
|
import DocVersionBanner from '@theme/DocVersionBanner';
|
|
15
15
|
import DocVersionBadge from '@theme/DocVersionBadge';
|
|
16
|
-
import
|
|
16
|
+
import Heading from '@theme/Heading';
|
|
17
17
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
18
18
|
|
|
19
19
|
import styles from './styles.module.css';
|
|
@@ -35,9 +35,9 @@ export default function DocCategoryGeneratedIndexPage({
|
|
|
35
35
|
<DocVersionBanner />
|
|
36
36
|
<DocVersionBadge />
|
|
37
37
|
<header>
|
|
38
|
-
<
|
|
38
|
+
<Heading as="h1" className={styles.title}>
|
|
39
39
|
{categoryGeneratedIndex.title}
|
|
40
|
-
</
|
|
40
|
+
</Heading>
|
|
41
41
|
{categoryGeneratedIndex.description && (
|
|
42
42
|
<p>{categoryGeneratedIndex.description}</p>
|
|
43
43
|
)}
|
|
@@ -16,7 +16,7 @@ import type {Props} from '@theme/DocItem';
|
|
|
16
16
|
import DocItemFooter from '@theme/DocItemFooter';
|
|
17
17
|
import TOC from '@theme/TOC';
|
|
18
18
|
import TOCCollapsible from '@theme/TOCCollapsible';
|
|
19
|
-
import
|
|
19
|
+
import Heading from '@theme/Heading';
|
|
20
20
|
import styles from './styles.module.css';
|
|
21
21
|
import {ThemeClassNames} from '@docusaurus/theme-common';
|
|
22
22
|
|
|
@@ -80,7 +80,11 @@ export default function DocItem(props: Props): JSX.Element {
|
|
|
80
80
|
To make both cases consistent, the added title is added under the same div.markdown block
|
|
81
81
|
See https://github.com/facebook/docusaurus/pull/4882#issuecomment-853021120
|
|
82
82
|
*/}
|
|
83
|
-
{shouldAddTitle &&
|
|
83
|
+
{shouldAddTitle && (
|
|
84
|
+
<header>
|
|
85
|
+
<Heading as="h1">{title}</Heading>
|
|
86
|
+
</header>
|
|
87
|
+
)}
|
|
84
88
|
|
|
85
89
|
<DocContent />
|
|
86
90
|
</div>
|
|
@@ -19,7 +19,7 @@ import useWindowSize from '@theme/hooks/useWindowSize';
|
|
|
19
19
|
import Logo from '@theme/Logo';
|
|
20
20
|
import IconArrow from '@theme/IconArrow';
|
|
21
21
|
import {translate} from '@docusaurus/Translate';
|
|
22
|
-
import
|
|
22
|
+
import DocSidebarItems from '@theme/DocSidebarItems';
|
|
23
23
|
import type {Props} from '@theme/DocSidebar';
|
|
24
24
|
|
|
25
25
|
import styles from './styles.module.css';
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {useEffect,
|
|
8
|
+
import React, {useEffect, useMemo} from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import {
|
|
11
11
|
isActiveSidebarItem,
|
|
@@ -20,7 +20,8 @@ import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
|
20
20
|
import {translate} from '@docusaurus/Translate';
|
|
21
21
|
import IconExternalLink from '@theme/IconExternalLink';
|
|
22
22
|
|
|
23
|
-
import
|
|
23
|
+
import DocSidebarItems from '@theme/DocSidebarItems';
|
|
24
|
+
import type {Props} from '@theme/DocSidebarItem';
|
|
24
25
|
import type {
|
|
25
26
|
PropSidebarItemCategory,
|
|
26
27
|
PropSidebarItemLink,
|
|
@@ -29,23 +30,6 @@ import type {
|
|
|
29
30
|
import styles from './styles.module.css';
|
|
30
31
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
31
32
|
|
|
32
|
-
// Optimize sidebar at each "level"
|
|
33
|
-
// TODO this item should probably not receive the "activePath" props
|
|
34
|
-
// TODO this triggers whole sidebar re-renders on navigation
|
|
35
|
-
export const DocSidebarItems = memo(
|
|
36
|
-
({items, ...props}: DocSidebarItemsProps): JSX.Element => (
|
|
37
|
-
<>
|
|
38
|
-
{items.map((item, index) => (
|
|
39
|
-
<DocSidebarItem
|
|
40
|
-
key={index} // sidebar is static, the index does not change
|
|
41
|
-
item={item}
|
|
42
|
-
{...props}
|
|
43
|
-
/>
|
|
44
|
-
))}
|
|
45
|
-
</>
|
|
46
|
-
),
|
|
47
|
-
);
|
|
48
|
-
|
|
49
33
|
export default function DocSidebarItem({
|
|
50
34
|
item,
|
|
51
35
|
...props
|
|
@@ -0,0 +1,31 @@
|
|
|
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, {memo} from 'react';
|
|
9
|
+
|
|
10
|
+
import DocSidebarItem from '@theme/DocSidebarItem';
|
|
11
|
+
|
|
12
|
+
import type {Props} from '@theme/DocSidebarItems';
|
|
13
|
+
|
|
14
|
+
// TODO this item should probably not receive the "activePath" props
|
|
15
|
+
// TODO this triggers whole sidebar re-renders on navigation
|
|
16
|
+
function DocSidebarItems({items, ...props}: Props): JSX.Element {
|
|
17
|
+
return (
|
|
18
|
+
<>
|
|
19
|
+
{items.map((item, index) => (
|
|
20
|
+
<DocSidebarItem
|
|
21
|
+
key={index} // sidebar is static, the index does not change
|
|
22
|
+
item={item}
|
|
23
|
+
{...props}
|
|
24
|
+
/>
|
|
25
|
+
))}
|
|
26
|
+
</>
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Optimize sidebar at each "level"
|
|
31
|
+
export default memo(DocSidebarItems);
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
.menuLinkText {
|
|
10
|
+
cursor: initial;
|
|
11
|
+
}
|
|
12
|
+
.menuLinkText:hover {
|
|
13
|
+
background: none;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.menuLinkText.hasHref {
|
|
17
|
+
cursor: pointer;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -7,62 +7,55 @@
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
|
-
import type {
|
|
10
|
+
import type {Props} from '@theme/Heading';
|
|
11
11
|
import {translate} from '@docusaurus/Translate';
|
|
12
12
|
import {useThemeConfig} from '@docusaurus/theme-common';
|
|
13
13
|
|
|
14
14
|
import './styles.css';
|
|
15
15
|
import styles from './styles.module.css';
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
function AnchorHeading({as: As, id, ...props}: Props) {
|
|
18
|
+
const {
|
|
19
|
+
navbar: {hideOnScroll},
|
|
20
|
+
} = useThemeConfig();
|
|
18
21
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
22
|
+
if (!id) {
|
|
23
|
+
return <As {...props} />;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<As
|
|
23
28
|
{...props}
|
|
24
|
-
|
|
25
|
-
|
|
29
|
+
className={clsx('anchor', {
|
|
30
|
+
[styles.anchorWithHideOnScrollNavbar]: hideOnScroll,
|
|
31
|
+
[styles.anchorWithStickyNavbar]: !hideOnScroll,
|
|
32
|
+
})}
|
|
33
|
+
id={id}>
|
|
26
34
|
{props.children}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
35
|
+
<a
|
|
36
|
+
className="hash-link"
|
|
37
|
+
href={`#${id}`}
|
|
38
|
+
title={translate({
|
|
39
|
+
id: 'theme.common.headingLinkTitle',
|
|
40
|
+
message: 'Direct link to heading',
|
|
41
|
+
description: 'Title for link to heading',
|
|
42
|
+
})}>
|
|
43
|
+
​
|
|
44
|
+
</a>
|
|
45
|
+
</As>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export default function Heading({as, ...props}: Props) {
|
|
50
|
+
if (as === 'h1') {
|
|
42
51
|
return (
|
|
43
|
-
<
|
|
52
|
+
<h1
|
|
44
53
|
{...props}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
[styles.anchorWithStickyNavbar]: !hideOnScroll,
|
|
48
|
-
})}
|
|
49
|
-
id={id}>
|
|
54
|
+
id={undefined} // h1 headings do not need an id because they don't appear in the TOC
|
|
55
|
+
>
|
|
50
56
|
{props.children}
|
|
51
|
-
|
|
52
|
-
className="hash-link"
|
|
53
|
-
href={`#${id}`}
|
|
54
|
-
title={translate({
|
|
55
|
-
id: 'theme.common.headingLinkTitle',
|
|
56
|
-
message: 'Direct link to heading',
|
|
57
|
-
description: 'Title for link to heading',
|
|
58
|
-
})}>
|
|
59
|
-
​
|
|
60
|
-
</a>
|
|
61
|
-
</Tag>
|
|
57
|
+
</h1>
|
|
62
58
|
);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
headingType === 'h1' ? MainHeading : createAnchorHeading(headingType);
|
|
67
|
-
|
|
68
|
-
export default Heading;
|
|
59
|
+
}
|
|
60
|
+
return <AnchorHeading as={as} {...props} />;
|
|
61
|
+
}
|
|
@@ -67,12 +67,12 @@ const MDXComponents: MDXComponentsObject = {
|
|
|
67
67
|
</Details>
|
|
68
68
|
);
|
|
69
69
|
},
|
|
70
|
-
h1: Heading
|
|
71
|
-
h2: Heading
|
|
72
|
-
h3: Heading
|
|
73
|
-
h4: Heading
|
|
74
|
-
h5: Heading
|
|
75
|
-
h6: Heading
|
|
70
|
+
h1: (props) => <Heading as="h1" {...props} />,
|
|
71
|
+
h2: (props) => <Heading as="h2" {...props} />,
|
|
72
|
+
h3: (props) => <Heading as="h3" {...props} />,
|
|
73
|
+
h4: (props) => <Heading as="h4" {...props} />,
|
|
74
|
+
h5: (props) => <Heading as="h5" {...props} />,
|
|
75
|
+
h6: (props) => <Heading as="h6" {...props} />,
|
|
76
76
|
};
|
|
77
77
|
|
|
78
78
|
export default MDXComponents;
|
|
@@ -7,71 +7,15 @@
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
|
-
|
|
11
|
-
import
|
|
10
|
+
|
|
11
|
+
import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
|
|
12
|
+
|
|
12
13
|
import type {
|
|
13
|
-
NavLinkProps,
|
|
14
14
|
DesktopOrMobileNavBarItemProps,
|
|
15
15
|
Props,
|
|
16
16
|
} from '@theme/NavbarItem/DefaultNavbarItem';
|
|
17
|
-
import IconExternalLink from '@theme/IconExternalLink';
|
|
18
|
-
import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
19
|
-
import {isRegexpStringMatch} from '@docusaurus/theme-common';
|
|
20
|
-
import {getInfimaActiveClassName} from './index';
|
|
21
|
-
|
|
22
|
-
const dropdownLinkActiveClass = 'dropdown__link--active';
|
|
23
|
-
|
|
24
|
-
export function NavLink({
|
|
25
|
-
activeBasePath,
|
|
26
|
-
activeBaseRegex,
|
|
27
|
-
to,
|
|
28
|
-
href,
|
|
29
|
-
label,
|
|
30
|
-
activeClassName = '',
|
|
31
|
-
prependBaseUrlToHref,
|
|
32
|
-
...props
|
|
33
|
-
}: NavLinkProps): JSX.Element {
|
|
34
|
-
// TODO all this seems hacky
|
|
35
|
-
// {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
|
|
36
|
-
const toUrl = useBaseUrl(to);
|
|
37
|
-
const activeBaseUrl = useBaseUrl(activeBasePath);
|
|
38
|
-
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
|
|
39
|
-
const isExternalLink = label && href && !isInternalUrl(href);
|
|
40
|
-
const isDropdownLink = activeClassName === dropdownLinkActiveClass;
|
|
41
17
|
|
|
42
|
-
|
|
43
|
-
<Link
|
|
44
|
-
{...(href
|
|
45
|
-
? {
|
|
46
|
-
href: prependBaseUrlToHref ? normalizedHref : href,
|
|
47
|
-
}
|
|
48
|
-
: {
|
|
49
|
-
isNavLink: true,
|
|
50
|
-
activeClassName: !props.className?.includes(activeClassName)
|
|
51
|
-
? activeClassName
|
|
52
|
-
: '',
|
|
53
|
-
to: toUrl,
|
|
54
|
-
...(activeBasePath || activeBaseRegex
|
|
55
|
-
? {
|
|
56
|
-
isActive: (_match, location) =>
|
|
57
|
-
activeBaseRegex
|
|
58
|
-
? isRegexpStringMatch(activeBaseRegex, location.pathname)
|
|
59
|
-
: location.pathname.startsWith(activeBaseUrl),
|
|
60
|
-
}
|
|
61
|
-
: null),
|
|
62
|
-
})}
|
|
63
|
-
{...props}>
|
|
64
|
-
{isExternalLink ? (
|
|
65
|
-
<span>
|
|
66
|
-
{label}
|
|
67
|
-
<IconExternalLink {...(isDropdownLink && {width: 12, height: 12})} />
|
|
68
|
-
</span>
|
|
69
|
-
) : (
|
|
70
|
-
label
|
|
71
|
-
)}
|
|
72
|
-
</Link>
|
|
73
|
-
);
|
|
74
|
-
}
|
|
18
|
+
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
75
19
|
|
|
76
20
|
function DefaultNavbarItemDesktop({
|
|
77
21
|
className,
|
|
@@ -79,7 +23,7 @@ function DefaultNavbarItemDesktop({
|
|
|
79
23
|
...props
|
|
80
24
|
}: DesktopOrMobileNavBarItemProps) {
|
|
81
25
|
const element = (
|
|
82
|
-
<
|
|
26
|
+
<NavbarNavLink
|
|
83
27
|
className={clsx(
|
|
84
28
|
isDropdownItem ? 'dropdown__link' : 'navbar__item navbar__link',
|
|
85
29
|
className,
|
|
@@ -102,7 +46,7 @@ function DefaultNavbarItemMobile({
|
|
|
102
46
|
}: DesktopOrMobileNavBarItemProps) {
|
|
103
47
|
return (
|
|
104
48
|
<li className="menu__list-item">
|
|
105
|
-
<
|
|
49
|
+
<NavbarNavLink className={clsx('menu__link', className)} {...props} />
|
|
106
50
|
</li>
|
|
107
51
|
);
|
|
108
52
|
}
|
|
@@ -9,7 +9,7 @@ import React from 'react';
|
|
|
9
9
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
10
10
|
import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
|
|
11
11
|
import clsx from 'clsx';
|
|
12
|
-
import {getInfimaActiveClassName} from '
|
|
12
|
+
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
13
13
|
import type {Props} from '@theme/NavbarItem/DocNavbarItem';
|
|
14
14
|
import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
|
|
15
15
|
import type {GlobalDataVersion} from '@docusaurus/plugin-content-docs';
|
|
@@ -9,9 +9,10 @@ import React from 'react';
|
|
|
9
9
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
10
10
|
import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
|
|
11
11
|
import clsx from 'clsx';
|
|
12
|
-
import {getInfimaActiveClassName} from '
|
|
13
|
-
import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem';
|
|
12
|
+
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
14
13
|
import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
|
|
14
|
+
|
|
15
|
+
import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem';
|
|
15
16
|
import type {
|
|
16
17
|
GlobalDataVersion,
|
|
17
18
|
GlobalDataSidebar,
|
|
@@ -20,7 +20,7 @@ import type {
|
|
|
20
20
|
} from '@theme/NavbarItem/DropdownNavbarItem';
|
|
21
21
|
import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
|
|
22
22
|
|
|
23
|
-
import
|
|
23
|
+
import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
|
|
24
24
|
import NavbarItem from '@theme/NavbarItem';
|
|
25
25
|
|
|
26
26
|
const dropdownLinkActiveClass = 'dropdown__link--active';
|
|
@@ -84,7 +84,7 @@ function DropdownNavbarItemDesktop({
|
|
|
84
84
|
'dropdown--right': position === 'right',
|
|
85
85
|
'dropdown--show': showDropdown,
|
|
86
86
|
})}>
|
|
87
|
-
<
|
|
87
|
+
<NavbarNavLink
|
|
88
88
|
href={props.to ? undefined : '#'}
|
|
89
89
|
className={clsx('navbar__link', className)}
|
|
90
90
|
{...props}
|
|
@@ -96,7 +96,7 @@ function DropdownNavbarItemDesktop({
|
|
|
96
96
|
}
|
|
97
97
|
}}>
|
|
98
98
|
{props.children ?? props.label}
|
|
99
|
-
</
|
|
99
|
+
</NavbarNavLink>
|
|
100
100
|
<ul className="dropdown__menu">
|
|
101
101
|
{items.map((childItemProps, i) => (
|
|
102
102
|
<NavbarItem
|
|
@@ -146,7 +146,7 @@ function DropdownNavbarItemMobile({
|
|
|
146
146
|
className={clsx('menu__list-item', {
|
|
147
147
|
'menu__list-item--collapsed': collapsed,
|
|
148
148
|
})}>
|
|
149
|
-
<
|
|
149
|
+
<NavbarNavLink
|
|
150
150
|
role="button"
|
|
151
151
|
className={clsx('menu__link menu__link--sublist', className)}
|
|
152
152
|
{...props}
|
|
@@ -155,7 +155,7 @@ function DropdownNavbarItemMobile({
|
|
|
155
155
|
toggleCollapsed();
|
|
156
156
|
}}>
|
|
157
157
|
{props.children ?? props.label}
|
|
158
|
-
</
|
|
158
|
+
</NavbarNavLink>
|
|
159
159
|
<Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
|
|
160
160
|
{items.map((childItemProps, i) => (
|
|
161
161
|
<NavbarItem
|
|
@@ -0,0 +1,68 @@
|
|
|
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 Link from '@docusaurus/Link';
|
|
10
|
+
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
11
|
+
import type {Props} from '@theme/NavbarItem/NavbarNavLink';
|
|
12
|
+
import IconExternalLink from '@theme/IconExternalLink';
|
|
13
|
+
import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
14
|
+
import {isRegexpStringMatch} from '@docusaurus/theme-common';
|
|
15
|
+
|
|
16
|
+
const dropdownLinkActiveClass = 'dropdown__link--active';
|
|
17
|
+
|
|
18
|
+
export default function NavbarNavLink({
|
|
19
|
+
activeBasePath,
|
|
20
|
+
activeBaseRegex,
|
|
21
|
+
to,
|
|
22
|
+
href,
|
|
23
|
+
label,
|
|
24
|
+
activeClassName = '',
|
|
25
|
+
prependBaseUrlToHref,
|
|
26
|
+
...props
|
|
27
|
+
}: Props): JSX.Element {
|
|
28
|
+
// TODO all this seems hacky
|
|
29
|
+
// {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
|
|
30
|
+
const toUrl = useBaseUrl(to);
|
|
31
|
+
const activeBaseUrl = useBaseUrl(activeBasePath);
|
|
32
|
+
const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
|
|
33
|
+
const isExternalLink = label && href && !isInternalUrl(href);
|
|
34
|
+
const isDropdownLink = activeClassName === dropdownLinkActiveClass;
|
|
35
|
+
|
|
36
|
+
return (
|
|
37
|
+
<Link
|
|
38
|
+
{...(href
|
|
39
|
+
? {
|
|
40
|
+
href: prependBaseUrlToHref ? normalizedHref : href,
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
isNavLink: true,
|
|
44
|
+
activeClassName: !props.className?.includes(activeClassName)
|
|
45
|
+
? activeClassName
|
|
46
|
+
: '',
|
|
47
|
+
to: toUrl,
|
|
48
|
+
...(activeBasePath || activeBaseRegex
|
|
49
|
+
? {
|
|
50
|
+
isActive: (_match, location) =>
|
|
51
|
+
activeBaseRegex
|
|
52
|
+
? isRegexpStringMatch(activeBaseRegex, location.pathname)
|
|
53
|
+
: location.pathname.startsWith(activeBaseUrl),
|
|
54
|
+
}
|
|
55
|
+
: null),
|
|
56
|
+
})}
|
|
57
|
+
{...props}>
|
|
58
|
+
{isExternalLink ? (
|
|
59
|
+
<span>
|
|
60
|
+
{label}
|
|
61
|
+
<IconExternalLink {...(isDropdownLink && {width: 12, height: 12})} />
|
|
62
|
+
</span>
|
|
63
|
+
) : (
|
|
64
|
+
label
|
|
65
|
+
)}
|
|
66
|
+
</Link>
|
|
67
|
+
);
|
|
68
|
+
}
|
|
@@ -58,9 +58,6 @@ function getComponentType(
|
|
|
58
58
|
return type as NavbarItemComponentType;
|
|
59
59
|
}
|
|
60
60
|
|
|
61
|
-
export const getInfimaActiveClassName = (mobile?: boolean): string =>
|
|
62
|
-
mobile ? 'menu__link--active' : 'navbar__link--active';
|
|
63
|
-
|
|
64
61
|
export default function NavbarItem({type, ...props}: Props): JSX.Element {
|
|
65
62
|
const componentType = getComponentType(
|
|
66
63
|
type,
|
|
@@ -0,0 +1,10 @@
|
|
|
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
|
+
// eslint-disable-next-line import/no-named-export
|
|
9
|
+
export const getInfimaActiveClassName = (mobile?: boolean): string =>
|
|
10
|
+
mobile ? 'menu__link--active' : 'navbar__link--active';
|
|
@@ -8,4 +8,5 @@
|
|
|
8
8
|
// Re-expose useDocs
|
|
9
9
|
// Ensure it's always statically available even if user is not using the docs plugin
|
|
10
10
|
// Problem reported for the blog-only mode: https://github.com/facebook/docusaurus/issues/3360
|
|
11
|
+
// eslint-disable-next-line import/no-named-export
|
|
11
12
|
export * from '@docusaurus/plugin-content-docs/lib/theme/hooks/useDocs';
|