@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/lib/theme-classic.d.ts
CHANGED
|
@@ -149,23 +149,33 @@ declare module '@theme/DocSidebar' {
|
|
|
149
149
|
declare module '@theme/DocSidebarItem' {
|
|
150
150
|
import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
|
|
151
151
|
|
|
152
|
-
type DocSidebarPropsBase = {
|
|
152
|
+
export type DocSidebarPropsBase = {
|
|
153
153
|
readonly activePath: string;
|
|
154
154
|
readonly onItemClick?: (item: PropSidebarItem) => void;
|
|
155
155
|
readonly level: number;
|
|
156
156
|
readonly tabIndex?: number;
|
|
157
157
|
};
|
|
158
158
|
|
|
159
|
-
export interface Props
|
|
159
|
+
export interface Props {
|
|
160
|
+
readonly activePath: string;
|
|
161
|
+
readonly onItemClick?: (item: PropSidebarItem) => void;
|
|
162
|
+
readonly level: number;
|
|
163
|
+
readonly tabIndex?: number;
|
|
160
164
|
readonly item: PropSidebarItem;
|
|
161
165
|
}
|
|
162
|
-
const DocSidebarItem: (props: Props) => JSX.Element;
|
|
163
|
-
export default DocSidebarItem;
|
|
164
166
|
|
|
165
|
-
export
|
|
167
|
+
export default function DocSidebarItem(props: Props): JSX.Element;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
declare module '@theme/DocSidebarItems' {
|
|
171
|
+
import type {Props as DocSidebarItemProps} from '@theme/DocSidebarItem';
|
|
172
|
+
import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
|
|
173
|
+
|
|
174
|
+
export type Props = Omit<DocSidebarItemProps, 'item'> & {
|
|
166
175
|
readonly items: readonly PropSidebarItem[];
|
|
167
176
|
};
|
|
168
|
-
|
|
177
|
+
|
|
178
|
+
export default function DocSidebarItems(props: Props): JSX.Element;
|
|
169
179
|
}
|
|
170
180
|
|
|
171
181
|
declare module '@theme/DocVersionSuggestions' {
|
|
@@ -196,12 +206,13 @@ declare module '@theme/Footer' {
|
|
|
196
206
|
declare module '@theme/Heading' {
|
|
197
207
|
import type {ComponentProps} from 'react';
|
|
198
208
|
|
|
199
|
-
|
|
200
|
-
|
|
209
|
+
type HeadingType = 'h1' | 'h2' | 'h3' | 'h4' | 'h5' | 'h6';
|
|
210
|
+
|
|
211
|
+
export interface Props extends ComponentProps<HeadingType> {
|
|
212
|
+
as: HeadingType;
|
|
213
|
+
}
|
|
201
214
|
|
|
202
|
-
|
|
203
|
-
export default Heading;
|
|
204
|
-
export const MainHeading: (props: Props) => JSX.Element;
|
|
215
|
+
export default function Heading(props: Props): JSX.Element;
|
|
205
216
|
}
|
|
206
217
|
|
|
207
218
|
declare module '@theme/hooks/useHideableNavbar' {
|
|
@@ -372,18 +383,9 @@ declare module '@theme/Navbar' {
|
|
|
372
383
|
}
|
|
373
384
|
|
|
374
385
|
declare module '@theme/NavbarItem/DefaultNavbarItem' {
|
|
375
|
-
import type {
|
|
376
|
-
import type {LinkProps} from '@docusaurus/Link';
|
|
386
|
+
import type {Props as NavbarNavLinkProps} from '@theme/NavbarItem/NavbarNavLink';
|
|
377
387
|
|
|
378
|
-
export type
|
|
379
|
-
readonly activeBasePath?: string;
|
|
380
|
-
readonly activeBaseRegex?: string;
|
|
381
|
-
readonly exact?: boolean;
|
|
382
|
-
readonly label?: ReactNode;
|
|
383
|
-
readonly prependBaseUrlToHref?: string;
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
export type DesktopOrMobileNavBarItemProps = NavLinkProps & {
|
|
388
|
+
export type DesktopOrMobileNavBarItemProps = NavbarNavLinkProps & {
|
|
387
389
|
readonly isDropdownItem?: boolean;
|
|
388
390
|
readonly className?: string;
|
|
389
391
|
readonly position?: 'left' | 'right';
|
|
@@ -393,17 +395,30 @@ declare module '@theme/NavbarItem/DefaultNavbarItem' {
|
|
|
393
395
|
readonly mobile?: boolean;
|
|
394
396
|
}
|
|
395
397
|
|
|
396
|
-
export
|
|
398
|
+
export default function DefaultNavbarItem(props: Props): JSX.Element;
|
|
399
|
+
}
|
|
397
400
|
|
|
398
|
-
|
|
399
|
-
|
|
401
|
+
declare module '@theme/NavbarItem/NavbarNavLink' {
|
|
402
|
+
import type {ReactNode} from 'react';
|
|
403
|
+
import type {LinkProps} from '@docusaurus/Link';
|
|
404
|
+
|
|
405
|
+
export type Props = LinkProps & {
|
|
406
|
+
readonly activeBasePath?: string;
|
|
407
|
+
readonly activeBaseRegex?: string;
|
|
408
|
+
readonly exact?: boolean;
|
|
409
|
+
readonly label?: ReactNode;
|
|
410
|
+
readonly prependBaseUrlToHref?: string;
|
|
411
|
+
};
|
|
412
|
+
|
|
413
|
+
export default function NavbarNavLink(props: Props): JSX.Element;
|
|
400
414
|
}
|
|
401
415
|
|
|
402
416
|
declare module '@theme/NavbarItem/DropdownNavbarItem' {
|
|
403
|
-
import type {
|
|
417
|
+
import type {Props as NavbarNavLinkProps} from '@theme/NavbarItem/NavbarNavLink';
|
|
418
|
+
|
|
404
419
|
import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
|
|
405
420
|
|
|
406
|
-
export type DesktopOrMobileNavBarItemProps =
|
|
421
|
+
export type DesktopOrMobileNavBarItemProps = NavbarNavLinkProps & {
|
|
407
422
|
readonly position?: 'left' | 'right';
|
|
408
423
|
readonly items: readonly LinkLikeNavbarItemProps[];
|
|
409
424
|
readonly className?: string;
|
|
@@ -526,6 +541,10 @@ declare module '@theme/NavbarItem' {
|
|
|
526
541
|
export default NavbarItem;
|
|
527
542
|
}
|
|
528
543
|
|
|
544
|
+
declare module '@theme/NavbarItem/utils' {
|
|
545
|
+
export function getInfimaActiveClassName(mobile?: boolean): string;
|
|
546
|
+
}
|
|
547
|
+
|
|
529
548
|
declare module '@theme/PaginatorNavLink' {
|
|
530
549
|
import type {ReactNode} from 'react';
|
|
531
550
|
import type {PropNavigationLink} from '@docusaurus/plugin-content-docs';
|
|
@@ -11,7 +11,7 @@ import DocPaginator from '@theme/DocPaginator';
|
|
|
11
11
|
import Seo from '@theme/Seo';
|
|
12
12
|
import DocVersionBanner from '@theme/DocVersionBanner';
|
|
13
13
|
import DocVersionBadge from '@theme/DocVersionBadge';
|
|
14
|
-
import
|
|
14
|
+
import Heading from '@theme/Heading';
|
|
15
15
|
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
16
16
|
import styles from './styles.module.css';
|
|
17
17
|
export default function DocCategoryGeneratedIndexPage({
|
|
@@ -30,9 +30,9 @@ export default function DocCategoryGeneratedIndexPage({
|
|
|
30
30
|
<DocVersionBanner />
|
|
31
31
|
<DocVersionBadge />
|
|
32
32
|
<header>
|
|
33
|
-
<
|
|
33
|
+
<Heading as="h1" className={styles.title}>
|
|
34
34
|
{categoryGeneratedIndex.title}
|
|
35
|
-
</
|
|
35
|
+
</Heading>
|
|
36
36
|
{categoryGeneratedIndex.description && (
|
|
37
37
|
<p>{categoryGeneratedIndex.description}</p>
|
|
38
38
|
)}
|
|
@@ -14,7 +14,7 @@ import Seo from '@theme/Seo';
|
|
|
14
14
|
import DocItemFooter from '@theme/DocItemFooter';
|
|
15
15
|
import TOC from '@theme/TOC';
|
|
16
16
|
import TOCCollapsible from '@theme/TOCCollapsible';
|
|
17
|
-
import
|
|
17
|
+
import Heading from '@theme/Heading';
|
|
18
18
|
import styles from './styles.module.css';
|
|
19
19
|
import {ThemeClassNames} from '@docusaurus/theme-common';
|
|
20
20
|
export default function DocItem(props) {
|
|
@@ -79,7 +79,11 @@ export default function DocItem(props) {
|
|
|
79
79
|
To make both cases consistent, the added title is added under the same div.markdown block
|
|
80
80
|
See https://github.com/facebook/docusaurus/pull/4882#issuecomment-853021120
|
|
81
81
|
*/}
|
|
82
|
-
{shouldAddTitle &&
|
|
82
|
+
{shouldAddTitle && (
|
|
83
|
+
<header>
|
|
84
|
+
<Heading as="h1">{title}</Heading>
|
|
85
|
+
</header>
|
|
86
|
+
)}
|
|
83
87
|
|
|
84
88
|
<DocContent />
|
|
85
89
|
</div>
|
|
@@ -17,7 +17,7 @@ import useWindowSize from '@theme/hooks/useWindowSize';
|
|
|
17
17
|
import Logo from '@theme/Logo';
|
|
18
18
|
import IconArrow from '@theme/IconArrow';
|
|
19
19
|
import {translate} from '@docusaurus/Translate';
|
|
20
|
-
import
|
|
20
|
+
import DocSidebarItems from '@theme/DocSidebarItems';
|
|
21
21
|
import styles from './styles.module.css';
|
|
22
22
|
|
|
23
23
|
function useShowAnnouncementBar() {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React, {useEffect,
|
|
7
|
+
import React, {useEffect, useMemo} from 'react';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
9
|
import {
|
|
10
10
|
isActiveSidebarItem,
|
|
@@ -18,22 +18,9 @@ import Link from '@docusaurus/Link';
|
|
|
18
18
|
import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
19
19
|
import {translate} from '@docusaurus/Translate';
|
|
20
20
|
import IconExternalLink from '@theme/IconExternalLink';
|
|
21
|
+
import DocSidebarItems from '@theme/DocSidebarItems';
|
|
21
22
|
import styles from './styles.module.css';
|
|
22
|
-
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
23
|
-
// TODO this item should probably not receive the "activePath" props
|
|
24
|
-
// TODO this triggers whole sidebar re-renders on navigation
|
|
25
|
-
|
|
26
|
-
export const DocSidebarItems = memo(({items, ...props}) => (
|
|
27
|
-
<>
|
|
28
|
-
{items.map((item, index) => (
|
|
29
|
-
<DocSidebarItem
|
|
30
|
-
key={index} // sidebar is static, the index does not change
|
|
31
|
-
item={item}
|
|
32
|
-
{...props}
|
|
33
|
-
/>
|
|
34
|
-
))}
|
|
35
|
-
</>
|
|
36
|
-
));
|
|
23
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
37
24
|
export default function DocSidebarItem({item, ...props}) {
|
|
38
25
|
switch (item.type) {
|
|
39
26
|
case 'category':
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import React, {memo} from 'react';
|
|
8
|
+
import DocSidebarItem from '@theme/DocSidebarItem';
|
|
9
|
+
|
|
10
|
+
// TODO this item should probably not receive the "activePath" props
|
|
11
|
+
// TODO this triggers whole sidebar re-renders on navigation
|
|
12
|
+
function DocSidebarItems({items, ...props}) {
|
|
13
|
+
return (
|
|
14
|
+
<>
|
|
15
|
+
{items.map((item, index) => (
|
|
16
|
+
<DocSidebarItem
|
|
17
|
+
key={index} // sidebar is static, the index does not change
|
|
18
|
+
item={item}
|
|
19
|
+
{...props}
|
|
20
|
+
/>
|
|
21
|
+
))}
|
|
22
|
+
</>
|
|
23
|
+
);
|
|
24
|
+
} // Optimize sidebar at each "level"
|
|
25
|
+
|
|
26
|
+
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
|
+
}
|
|
@@ -10,53 +10,50 @@ import {translate} from '@docusaurus/Translate';
|
|
|
10
10
|
import {useThemeConfig} from '@docusaurus/theme-common';
|
|
11
11
|
import './styles.css';
|
|
12
12
|
import styles from './styles.module.css';
|
|
13
|
-
// eslint-disable-next-line react/function-component-definition
|
|
14
|
-
export const MainHeading = ({...props}) => (
|
|
15
|
-
<header>
|
|
16
|
-
<h1
|
|
17
|
-
{...props}
|
|
18
|
-
id={undefined} // h1 headings do not need an id because they don't appear in the TOC
|
|
19
|
-
>
|
|
20
|
-
{props.children}
|
|
21
|
-
</h1>
|
|
22
|
-
</header>
|
|
23
|
-
);
|
|
24
13
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
14
|
+
function AnchorHeading({as: As, id, ...props}) {
|
|
15
|
+
const {
|
|
16
|
+
navbar: {hideOnScroll},
|
|
17
|
+
} = useThemeConfig();
|
|
18
|
+
|
|
19
|
+
if (!id) {
|
|
20
|
+
return <As {...props} />;
|
|
21
|
+
}
|
|
31
22
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
23
|
+
return (
|
|
24
|
+
<As
|
|
25
|
+
{...props}
|
|
26
|
+
className={clsx('anchor', {
|
|
27
|
+
[styles.anchorWithHideOnScrollNavbar]: hideOnScroll,
|
|
28
|
+
[styles.anchorWithStickyNavbar]: !hideOnScroll,
|
|
29
|
+
})}
|
|
30
|
+
id={id}>
|
|
31
|
+
{props.children}
|
|
32
|
+
<a
|
|
33
|
+
className="hash-link"
|
|
34
|
+
href={`#${id}`}
|
|
35
|
+
title={translate({
|
|
36
|
+
id: 'theme.common.headingLinkTitle',
|
|
37
|
+
message: 'Direct link to heading',
|
|
38
|
+
description: 'Title for link to heading',
|
|
39
|
+
})}>
|
|
40
|
+
​
|
|
41
|
+
</a>
|
|
42
|
+
</As>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
35
45
|
|
|
46
|
+
export default function Heading({as, ...props}) {
|
|
47
|
+
if (as === 'h1') {
|
|
36
48
|
return (
|
|
37
|
-
<
|
|
49
|
+
<h1
|
|
38
50
|
{...props}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
[styles.anchorWithStickyNavbar]: !hideOnScroll,
|
|
42
|
-
})}
|
|
43
|
-
id={id}>
|
|
51
|
+
id={undefined} // h1 headings do not need an id because they don't appear in the TOC
|
|
52
|
+
>
|
|
44
53
|
{props.children}
|
|
45
|
-
|
|
46
|
-
className="hash-link"
|
|
47
|
-
href={`#${id}`}
|
|
48
|
-
title={translate({
|
|
49
|
-
id: 'theme.common.headingLinkTitle',
|
|
50
|
-
message: 'Direct link to heading',
|
|
51
|
-
description: 'Title for link to heading',
|
|
52
|
-
})}>
|
|
53
|
-
​
|
|
54
|
-
</a>
|
|
55
|
-
</Tag>
|
|
54
|
+
</h1>
|
|
56
55
|
);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const Heading = (headingType) =>
|
|
60
|
-
headingType === 'h1' ? MainHeading : createAnchorHeading(headingType);
|
|
56
|
+
}
|
|
61
57
|
|
|
62
|
-
|
|
58
|
+
return <AnchorHeading as={as} {...props} />;
|
|
59
|
+
}
|
|
@@ -55,11 +55,11 @@ const MDXComponents = {
|
|
|
55
55
|
</Details>
|
|
56
56
|
);
|
|
57
57
|
},
|
|
58
|
-
h1: Heading
|
|
59
|
-
h2: Heading
|
|
60
|
-
h3: Heading
|
|
61
|
-
h4: Heading
|
|
62
|
-
h5: Heading
|
|
63
|
-
h6: Heading
|
|
58
|
+
h1: (props) => <Heading as="h1" {...props} />,
|
|
59
|
+
h2: (props) => <Heading as="h2" {...props} />,
|
|
60
|
+
h3: (props) => <Heading as="h3" {...props} />,
|
|
61
|
+
h4: (props) => <Heading as="h4" {...props} />,
|
|
62
|
+
h5: (props) => <Heading as="h5" {...props} />,
|
|
63
|
+
h6: (props) => <Heading as="h6" {...props} />,
|
|
64
64
|
};
|
|
65
65
|
export default MDXComponents;
|
|
@@ -6,70 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import React from 'react';
|
|
8
8
|
import clsx from 'clsx';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import IconExternalLink from '@theme/IconExternalLink';
|
|
12
|
-
import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
13
|
-
import {isRegexpStringMatch} from '@docusaurus/theme-common';
|
|
14
|
-
import {getInfimaActiveClassName} from './index';
|
|
15
|
-
const dropdownLinkActiveClass = 'dropdown__link--active';
|
|
16
|
-
export function NavLink({
|
|
17
|
-
activeBasePath,
|
|
18
|
-
activeBaseRegex,
|
|
19
|
-
to,
|
|
20
|
-
href,
|
|
21
|
-
label,
|
|
22
|
-
activeClassName = '',
|
|
23
|
-
prependBaseUrlToHref,
|
|
24
|
-
...props
|
|
25
|
-
}) {
|
|
26
|
-
// TODO all this seems hacky
|
|
27
|
-
// {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
|
|
28
|
-
const toUrl = useBaseUrl(to);
|
|
29
|
-
const activeBaseUrl = useBaseUrl(activeBasePath);
|
|
30
|
-
const normalizedHref = useBaseUrl(href, {
|
|
31
|
-
forcePrependBaseUrl: true,
|
|
32
|
-
});
|
|
33
|
-
const isExternalLink = label && href && !isInternalUrl(href);
|
|
34
|
-
const isDropdownLink = activeClassName === dropdownLinkActiveClass;
|
|
35
|
-
return (
|
|
36
|
-
<Link
|
|
37
|
-
{...(href
|
|
38
|
-
? {
|
|
39
|
-
href: prependBaseUrlToHref ? normalizedHref : href,
|
|
40
|
-
}
|
|
41
|
-
: {
|
|
42
|
-
isNavLink: true,
|
|
43
|
-
activeClassName: !props.className?.includes(activeClassName)
|
|
44
|
-
? activeClassName
|
|
45
|
-
: '',
|
|
46
|
-
to: toUrl,
|
|
47
|
-
...(activeBasePath || activeBaseRegex
|
|
48
|
-
? {
|
|
49
|
-
isActive: (_match, location) =>
|
|
50
|
-
activeBaseRegex
|
|
51
|
-
? isRegexpStringMatch(activeBaseRegex, location.pathname)
|
|
52
|
-
: location.pathname.startsWith(activeBaseUrl),
|
|
53
|
-
}
|
|
54
|
-
: null),
|
|
55
|
-
})}
|
|
56
|
-
{...props}>
|
|
57
|
-
{isExternalLink ? (
|
|
58
|
-
<span>
|
|
59
|
-
{label}
|
|
60
|
-
<IconExternalLink
|
|
61
|
-
{...(isDropdownLink && {
|
|
62
|
-
width: 12,
|
|
63
|
-
height: 12,
|
|
64
|
-
})}
|
|
65
|
-
/>
|
|
66
|
-
</span>
|
|
67
|
-
) : (
|
|
68
|
-
label
|
|
69
|
-
)}
|
|
70
|
-
</Link>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
9
|
+
import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
|
|
10
|
+
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
73
11
|
|
|
74
12
|
function DefaultNavbarItemDesktop({
|
|
75
13
|
className,
|
|
@@ -77,7 +15,7 @@ function DefaultNavbarItemDesktop({
|
|
|
77
15
|
...props
|
|
78
16
|
}) {
|
|
79
17
|
const element = (
|
|
80
|
-
<
|
|
18
|
+
<NavbarNavLink
|
|
81
19
|
className={clsx(
|
|
82
20
|
isDropdownItem ? 'dropdown__link' : 'navbar__item navbar__link',
|
|
83
21
|
className,
|
|
@@ -100,7 +38,7 @@ function DefaultNavbarItemMobile({
|
|
|
100
38
|
}) {
|
|
101
39
|
return (
|
|
102
40
|
<li className="menu__list-item">
|
|
103
|
-
<
|
|
41
|
+
<NavbarNavLink className={clsx('menu__link', className)} {...props} />
|
|
104
42
|
</li>
|
|
105
43
|
);
|
|
106
44
|
}
|
|
@@ -8,7 +8,7 @@ import React from 'react';
|
|
|
8
8
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
9
9
|
import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
|
|
10
10
|
import clsx from 'clsx';
|
|
11
|
-
import {getInfimaActiveClassName} from '
|
|
11
|
+
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
12
12
|
import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
|
|
13
13
|
|
|
14
14
|
function getDocInVersions(versions, docId) {
|
|
@@ -8,7 +8,7 @@ import React from 'react';
|
|
|
8
8
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
9
9
|
import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
|
|
10
10
|
import clsx from 'clsx';
|
|
11
|
-
import {getInfimaActiveClassName} from '
|
|
11
|
+
import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
|
|
12
12
|
import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
|
|
13
13
|
|
|
14
14
|
function getSidebarLink(versions, sidebarId) {
|
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
isRegexpStringMatch,
|
|
14
14
|
useLocalPathname,
|
|
15
15
|
} from '@docusaurus/theme-common';
|
|
16
|
-
import
|
|
16
|
+
import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
|
|
17
17
|
import NavbarItem from '@theme/NavbarItem';
|
|
18
18
|
const dropdownLinkActiveClass = 'dropdown__link--active';
|
|
19
19
|
|
|
@@ -63,7 +63,7 @@ function DropdownNavbarItemDesktop({items, position, className, ...props}) {
|
|
|
63
63
|
'dropdown--right': position === 'right',
|
|
64
64
|
'dropdown--show': showDropdown,
|
|
65
65
|
})}>
|
|
66
|
-
<
|
|
66
|
+
<NavbarNavLink
|
|
67
67
|
href={props.to ? undefined : '#'}
|
|
68
68
|
className={clsx('navbar__link', className)}
|
|
69
69
|
{...props}
|
|
@@ -75,7 +75,7 @@ function DropdownNavbarItemDesktop({items, position, className, ...props}) {
|
|
|
75
75
|
}
|
|
76
76
|
}}>
|
|
77
77
|
{props.children ?? props.label}
|
|
78
|
-
</
|
|
78
|
+
</NavbarNavLink>
|
|
79
79
|
<ul className="dropdown__menu">
|
|
80
80
|
{items.map((childItemProps, i) => (
|
|
81
81
|
<NavbarItem
|
|
@@ -124,7 +124,7 @@ function DropdownNavbarItemMobile({
|
|
|
124
124
|
className={clsx('menu__list-item', {
|
|
125
125
|
'menu__list-item--collapsed': collapsed,
|
|
126
126
|
})}>
|
|
127
|
-
<
|
|
127
|
+
<NavbarNavLink
|
|
128
128
|
role="button"
|
|
129
129
|
className={clsx('menu__link menu__link--sublist', className)}
|
|
130
130
|
{...props}
|
|
@@ -133,7 +133,7 @@ function DropdownNavbarItemMobile({
|
|
|
133
133
|
toggleCollapsed();
|
|
134
134
|
}}>
|
|
135
135
|
{props.children ?? props.label}
|
|
136
|
-
</
|
|
136
|
+
</NavbarNavLink>
|
|
137
137
|
<Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
|
|
138
138
|
{items.map((childItemProps, i) => (
|
|
139
139
|
<NavbarItem
|
|
@@ -0,0 +1,70 @@
|
|
|
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
|
+
import React from 'react';
|
|
8
|
+
import Link from '@docusaurus/Link';
|
|
9
|
+
import useBaseUrl from '@docusaurus/useBaseUrl';
|
|
10
|
+
import IconExternalLink from '@theme/IconExternalLink';
|
|
11
|
+
import isInternalUrl from '@docusaurus/isInternalUrl';
|
|
12
|
+
import {isRegexpStringMatch} from '@docusaurus/theme-common';
|
|
13
|
+
const dropdownLinkActiveClass = 'dropdown__link--active';
|
|
14
|
+
export default function NavbarNavLink({
|
|
15
|
+
activeBasePath,
|
|
16
|
+
activeBaseRegex,
|
|
17
|
+
to,
|
|
18
|
+
href,
|
|
19
|
+
label,
|
|
20
|
+
activeClassName = '',
|
|
21
|
+
prependBaseUrlToHref,
|
|
22
|
+
...props
|
|
23
|
+
}) {
|
|
24
|
+
// TODO all this seems hacky
|
|
25
|
+
// {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
|
|
26
|
+
const toUrl = useBaseUrl(to);
|
|
27
|
+
const activeBaseUrl = useBaseUrl(activeBasePath);
|
|
28
|
+
const normalizedHref = useBaseUrl(href, {
|
|
29
|
+
forcePrependBaseUrl: true,
|
|
30
|
+
});
|
|
31
|
+
const isExternalLink = label && href && !isInternalUrl(href);
|
|
32
|
+
const isDropdownLink = activeClassName === dropdownLinkActiveClass;
|
|
33
|
+
return (
|
|
34
|
+
<Link
|
|
35
|
+
{...(href
|
|
36
|
+
? {
|
|
37
|
+
href: prependBaseUrlToHref ? normalizedHref : href,
|
|
38
|
+
}
|
|
39
|
+
: {
|
|
40
|
+
isNavLink: true,
|
|
41
|
+
activeClassName: !props.className?.includes(activeClassName)
|
|
42
|
+
? activeClassName
|
|
43
|
+
: '',
|
|
44
|
+
to: toUrl,
|
|
45
|
+
...(activeBasePath || activeBaseRegex
|
|
46
|
+
? {
|
|
47
|
+
isActive: (_match, location) =>
|
|
48
|
+
activeBaseRegex
|
|
49
|
+
? isRegexpStringMatch(activeBaseRegex, location.pathname)
|
|
50
|
+
: location.pathname.startsWith(activeBaseUrl),
|
|
51
|
+
}
|
|
52
|
+
: null),
|
|
53
|
+
})}
|
|
54
|
+
{...props}>
|
|
55
|
+
{isExternalLink ? (
|
|
56
|
+
<span>
|
|
57
|
+
{label}
|
|
58
|
+
<IconExternalLink
|
|
59
|
+
{...(isDropdownLink && {
|
|
60
|
+
width: 12,
|
|
61
|
+
height: 12,
|
|
62
|
+
})}
|
|
63
|
+
/>
|
|
64
|
+
</span>
|
|
65
|
+
) : (
|
|
66
|
+
label
|
|
67
|
+
)}
|
|
68
|
+
</Link>
|
|
69
|
+
);
|
|
70
|
+
}
|
|
@@ -46,8 +46,6 @@ function getComponentType(type, isDropdown) {
|
|
|
46
46
|
return type;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
export const getInfimaActiveClassName = (mobile) =>
|
|
50
|
-
mobile ? 'menu__link--active' : 'navbar__link--active';
|
|
51
49
|
export default function NavbarItem({type, ...props}) {
|
|
52
50
|
const componentType = getComponentType(type, props.items !== undefined);
|
|
53
51
|
const NavbarItemComponent = getNavbarItemComponent(componentType);
|
|
@@ -0,0 +1,9 @@
|
|
|
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
|
+
// eslint-disable-next-line import/no-named-export
|
|
8
|
+
export const getInfimaActiveClassName = (mobile) =>
|
|
9
|
+
mobile ? 'menu__link--active' : 'navbar__link--active';
|
|
@@ -7,4 +7,5 @@
|
|
|
7
7
|
// Re-expose useDocs
|
|
8
8
|
// Ensure it's always statically available even if user is not using the docs plugin
|
|
9
9
|
// Problem reported for the blog-only mode: https://github.com/facebook/docusaurus/issues/3360
|
|
10
|
+
// eslint-disable-next-line import/no-named-export
|
|
10
11
|
export * from '@docusaurus/plugin-content-docs/lib/theme/hooks/useDocs';
|