@docusaurus/theme-classic 2.1.0 → 2.3.0
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/getSwizzleConfig.js +42 -1
- package/lib/theme/AnnouncementBar/styles.module.css +9 -1
- package/lib/theme/CodeBlock/Line/index.js +2 -4
- package/lib/theme/ColorModeToggle/index.js +2 -1
- package/lib/theme/DocBreadcrumbs/Items/Home/index.d.ts +8 -0
- package/lib/theme/DocBreadcrumbs/Items/Home/index.js +29 -0
- package/lib/theme/DocBreadcrumbs/Items/Home/styles.module.css +14 -0
- package/lib/theme/DocBreadcrumbs/index.js +1 -19
- package/lib/theme/DocBreadcrumbs/styles.module.css +0 -8
- package/lib/theme/DocPage/Layout/Sidebar/ExpandButton/styles.module.css +3 -2
- package/lib/theme/DocPage/Layout/Sidebar/index.js +13 -8
- package/lib/theme/DocPage/Layout/Sidebar/styles.module.css +7 -0
- package/lib/theme/DocPage/Layout/styles.module.css +1 -0
- package/lib/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +1 -0
- package/lib/theme/DocSidebar/Desktop/Content/index.js +6 -0
- package/lib/theme/DocSidebar/Desktop/styles.module.css +0 -6
- package/lib/theme/Heading/index.js +17 -8
- package/lib/theme/Layout/Provider/index.js +0 -2
- package/lib/theme/Layout/index.js +6 -1
- package/lib/theme/Layout/styles.module.css +2 -0
- package/lib/theme/MDXComponents/Code.js +24 -4
- package/lib/theme/MDXComponents/index.js +2 -0
- package/lib/theme/Mermaid.d.ts +7 -0
- package/lib/theme/Mermaid.js +13 -0
- package/lib/theme/Navbar/Layout/index.js +6 -0
- package/lib/theme/Navbar/MobileSidebar/Header/index.js +6 -0
- package/lib/theme/Navbar/MobileSidebar/Toggle/index.js +11 -6
- package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +4 -1
- package/lib/theme/NavbarItem/LocaleDropdownNavbarItem/index.js +5 -1
- package/lib/theme/SkipToContent/index.js +2 -18
- package/lib/theme/Tabs/index.js +67 -131
- package/lib/theme/Tag/styles.module.css +1 -1
- package/package.json +14 -14
- package/src/getSwizzleConfig.ts +47 -1
- package/src/theme/AnnouncementBar/styles.module.css +9 -1
- package/src/theme/CodeBlock/Line/index.tsx +2 -4
- package/src/theme/ColorModeToggle/index.tsx +2 -1
- package/src/theme/DocBreadcrumbs/Items/Home/index.tsx +33 -0
- package/src/theme/DocBreadcrumbs/Items/Home/styles.module.css +14 -0
- package/src/theme/DocBreadcrumbs/index.tsx +1 -20
- package/src/theme/DocBreadcrumbs/styles.module.css +0 -8
- package/src/theme/DocPage/Layout/Sidebar/ExpandButton/styles.module.css +3 -2
- package/src/theme/DocPage/Layout/Sidebar/index.tsx +13 -8
- package/src/theme/DocPage/Layout/Sidebar/styles.module.css +7 -0
- package/src/theme/DocPage/Layout/styles.module.css +1 -0
- package/src/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +1 -0
- package/src/theme/DocSidebar/Desktop/Content/index.tsx +6 -0
- package/src/theme/DocSidebar/Desktop/styles.module.css +0 -6
- package/src/theme/Heading/index.tsx +18 -8
- package/src/theme/Layout/Provider/index.tsx +0 -2
- package/src/theme/Layout/index.tsx +6 -1
- package/src/theme/Layout/styles.module.css +2 -0
- package/src/theme/MDXComponents/Code.tsx +24 -4
- package/src/theme/MDXComponents/index.tsx +2 -0
- package/src/theme/Mermaid.tsx +16 -0
- package/src/theme/Navbar/Layout/index.tsx +6 -0
- package/src/theme/Navbar/MobileSidebar/Header/index.tsx +6 -0
- package/src/theme/Navbar/MobileSidebar/Toggle/index.tsx +11 -6
- package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +4 -1
- package/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +5 -1
- package/src/theme/SkipToContent/index.tsx +2 -18
- package/src/theme/Tabs/index.tsx +87 -144
- package/src/theme/Tag/styles.module.css +1 -1
- package/src/theme-classic.d.ts +18 -25
|
@@ -9,6 +9,7 @@ import React from 'react';
|
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import {translate} from '@docusaurus/Translate';
|
|
11
11
|
import {useThemeConfig} from '@docusaurus/theme-common';
|
|
12
|
+
import Link from '@docusaurus/Link';
|
|
12
13
|
import type {Props} from '@theme/Heading';
|
|
13
14
|
|
|
14
15
|
import styles from './styles.module.css';
|
|
@@ -22,6 +23,17 @@ export default function Heading({as: As, id, ...props}: Props): JSX.Element {
|
|
|
22
23
|
return <As {...props} id={undefined} />;
|
|
23
24
|
}
|
|
24
25
|
|
|
26
|
+
const anchorTitle = translate(
|
|
27
|
+
{
|
|
28
|
+
id: 'theme.common.headingLinkTitle',
|
|
29
|
+
message: 'Direct link to {heading}',
|
|
30
|
+
description: 'Title for link to heading',
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
heading: typeof props.children === 'string' ? props.children : id,
|
|
34
|
+
},
|
|
35
|
+
);
|
|
36
|
+
|
|
25
37
|
return (
|
|
26
38
|
<As
|
|
27
39
|
{...props}
|
|
@@ -30,19 +42,17 @@ export default function Heading({as: As, id, ...props}: Props): JSX.Element {
|
|
|
30
42
|
hideOnScroll
|
|
31
43
|
? styles.anchorWithHideOnScrollNavbar
|
|
32
44
|
: styles.anchorWithStickyNavbar,
|
|
45
|
+
props.className,
|
|
33
46
|
)}
|
|
34
47
|
id={id}>
|
|
35
48
|
{props.children}
|
|
36
|
-
<
|
|
49
|
+
<Link
|
|
37
50
|
className="hash-link"
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
message: 'Direct link to heading',
|
|
42
|
-
description: 'Title for link to heading',
|
|
43
|
-
})}>
|
|
51
|
+
to={`#${id}`}
|
|
52
|
+
aria-label={anchorTitle}
|
|
53
|
+
title={anchorTitle}>
|
|
44
54
|
​
|
|
45
|
-
</
|
|
55
|
+
</Link>
|
|
46
56
|
</As>
|
|
47
57
|
);
|
|
48
58
|
}
|
|
@@ -9,7 +9,6 @@ import React from 'react';
|
|
|
9
9
|
import {composeProviders} from '@docusaurus/theme-common';
|
|
10
10
|
import {
|
|
11
11
|
ColorModeProvider,
|
|
12
|
-
TabGroupChoiceProvider,
|
|
13
12
|
AnnouncementBarProvider,
|
|
14
13
|
DocsPreferredVersionContextProvider,
|
|
15
14
|
ScrollControllerProvider,
|
|
@@ -21,7 +20,6 @@ import type {Props} from '@theme/Layout/Provider';
|
|
|
21
20
|
const Provider = composeProviders([
|
|
22
21
|
ColorModeProvider,
|
|
23
22
|
AnnouncementBarProvider,
|
|
24
|
-
TabGroupChoiceProvider,
|
|
25
23
|
ScrollControllerProvider,
|
|
26
24
|
DocsPreferredVersionContextProvider,
|
|
27
25
|
PluginHtmlClassNameProvider,
|
|
@@ -8,7 +8,11 @@
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import clsx from 'clsx';
|
|
10
10
|
import ErrorBoundary from '@docusaurus/ErrorBoundary';
|
|
11
|
-
import {
|
|
11
|
+
import {
|
|
12
|
+
PageMetadata,
|
|
13
|
+
SkipToContentFallbackId,
|
|
14
|
+
ThemeClassNames,
|
|
15
|
+
} from '@docusaurus/theme-common';
|
|
12
16
|
import {useKeyboardNavigation} from '@docusaurus/theme-common/internal';
|
|
13
17
|
import SkipToContent from '@theme/SkipToContent';
|
|
14
18
|
import AnnouncementBar from '@theme/AnnouncementBar';
|
|
@@ -42,6 +46,7 @@ export default function Layout(props: Props): JSX.Element {
|
|
|
42
46
|
<Navbar />
|
|
43
47
|
|
|
44
48
|
<div
|
|
49
|
+
id={SkipToContentFallbackId}
|
|
45
50
|
className={clsx(
|
|
46
51
|
ThemeClassNames.wrapper.main,
|
|
47
52
|
styles.mainWrapper,
|
|
@@ -13,15 +13,35 @@ import type {Props} from '@theme/MDXComponents/Code';
|
|
|
13
13
|
export default function MDXCode(props: Props): JSX.Element {
|
|
14
14
|
const inlineElements: (string | undefined)[] = [
|
|
15
15
|
'a',
|
|
16
|
+
'abbr',
|
|
16
17
|
'b',
|
|
17
|
-
'
|
|
18
|
+
'br',
|
|
19
|
+
'button',
|
|
20
|
+
'cite',
|
|
21
|
+
'code',
|
|
22
|
+
'del',
|
|
23
|
+
'dfn',
|
|
24
|
+
'em',
|
|
18
25
|
'i',
|
|
26
|
+
'img',
|
|
27
|
+
'input',
|
|
28
|
+
'ins',
|
|
29
|
+
'kbd',
|
|
30
|
+
'label',
|
|
31
|
+
'object',
|
|
32
|
+
'output',
|
|
33
|
+
'q',
|
|
34
|
+
'ruby',
|
|
35
|
+
's',
|
|
36
|
+
'small',
|
|
19
37
|
'span',
|
|
20
|
-
'em',
|
|
21
38
|
'strong',
|
|
22
|
-
'sup',
|
|
23
39
|
'sub',
|
|
24
|
-
'
|
|
40
|
+
'sup',
|
|
41
|
+
'time',
|
|
42
|
+
'u',
|
|
43
|
+
'var',
|
|
44
|
+
'wbr',
|
|
25
45
|
];
|
|
26
46
|
const shouldBeInline = React.Children.toArray(props.children).every(
|
|
27
47
|
(el) =>
|
|
@@ -15,6 +15,7 @@ import MDXHeading from '@theme/MDXComponents/Heading';
|
|
|
15
15
|
import MDXUl from '@theme/MDXComponents/Ul';
|
|
16
16
|
import MDXImg from '@theme/MDXComponents/Img';
|
|
17
17
|
import Admonition from '@theme/Admonition';
|
|
18
|
+
import Mermaid from '@theme/Mermaid';
|
|
18
19
|
|
|
19
20
|
import type {MDXComponentsObject} from '@theme/MDXComponents';
|
|
20
21
|
|
|
@@ -33,6 +34,7 @@ const MDXComponents: MDXComponentsObject = {
|
|
|
33
34
|
h5: (props) => <MDXHeading as="h5" {...props} />,
|
|
34
35
|
h6: (props) => <MDXHeading as="h6" {...props} />,
|
|
35
36
|
admonition: Admonition,
|
|
37
|
+
mermaid: Mermaid,
|
|
36
38
|
};
|
|
37
39
|
|
|
38
40
|
export default MDXComponents;
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
// This component is meant to be implemented by a Mermaid renderer theme
|
|
9
|
+
// It is notable created to be overridden by docusaurus-theme-mermaid
|
|
10
|
+
|
|
11
|
+
// By default, the classic theme does not provide any Mermaid implementation
|
|
12
|
+
// Yet we declare it there so that we can register it in MDX
|
|
13
|
+
// TODO later the mermaid theme should be able to register its MDX component
|
|
14
|
+
// see https://github.com/facebook/docusaurus/pull/7490#issuecomment-1279117288
|
|
15
|
+
|
|
16
|
+
export {default} from '@docusaurus/Noop';
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
useHideableNavbar,
|
|
13
13
|
useNavbarMobileSidebar,
|
|
14
14
|
} from '@docusaurus/theme-common/internal';
|
|
15
|
+
import {translate} from '@docusaurus/Translate';
|
|
15
16
|
import NavbarMobileSidebar from '@theme/Navbar/MobileSidebar';
|
|
16
17
|
import type {Props} from '@theme/Navbar/Layout';
|
|
17
18
|
|
|
@@ -36,6 +37,11 @@ export default function NavbarLayout({children}: Props): JSX.Element {
|
|
|
36
37
|
return (
|
|
37
38
|
<nav
|
|
38
39
|
ref={navbarRef}
|
|
40
|
+
aria-label={translate({
|
|
41
|
+
id: 'theme.NavBar.navAriaLabel',
|
|
42
|
+
message: 'Main',
|
|
43
|
+
description: 'The ARIA label for the main navigation',
|
|
44
|
+
})}
|
|
39
45
|
className={clsx(
|
|
40
46
|
'navbar',
|
|
41
47
|
'navbar--fixed-top',
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal';
|
|
10
|
+
import {translate} from '@docusaurus/Translate';
|
|
10
11
|
import NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle';
|
|
11
12
|
import IconClose from '@theme/Icon/Close';
|
|
12
13
|
import NavbarLogo from '@theme/Navbar/Logo';
|
|
@@ -16,6 +17,11 @@ function CloseButton() {
|
|
|
16
17
|
return (
|
|
17
18
|
<button
|
|
18
19
|
type="button"
|
|
20
|
+
aria-label={translate({
|
|
21
|
+
id: 'theme.docs.sidebar.closeSidebarButtonAriaLabel',
|
|
22
|
+
message: 'Close navigation bar',
|
|
23
|
+
description: 'The ARIA label for close button of mobile sidebar',
|
|
24
|
+
})}
|
|
19
25
|
className="clean-btn navbar-sidebar__close"
|
|
20
26
|
onClick={() => mobileSidebar.toggle()}>
|
|
21
27
|
<IconClose color="var(--ifm-color-emphasis-600)" />
|
|
@@ -7,18 +7,23 @@
|
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
9
|
import {useNavbarMobileSidebar} from '@docusaurus/theme-common/internal';
|
|
10
|
+
import {translate} from '@docusaurus/Translate';
|
|
10
11
|
import IconMenu from '@theme/Icon/Menu';
|
|
11
12
|
|
|
12
13
|
export default function MobileSidebarToggle(): JSX.Element {
|
|
13
|
-
const
|
|
14
|
+
const {toggle, shown} = useNavbarMobileSidebar();
|
|
14
15
|
return (
|
|
15
16
|
<button
|
|
16
|
-
onClick={
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
onClick={toggle}
|
|
18
|
+
aria-label={translate({
|
|
19
|
+
id: 'theme.docs.sidebar.toggleSidebarButtonAriaLabel',
|
|
20
|
+
message: 'Toggle navigation bar',
|
|
21
|
+
description:
|
|
22
|
+
'The ARIA label for hamburger menu button of mobile navigation',
|
|
23
|
+
})}
|
|
24
|
+
aria-expanded={shown}
|
|
19
25
|
className="navbar__toggle clean-btn"
|
|
20
|
-
type="button"
|
|
21
|
-
tabIndex={0}>
|
|
26
|
+
type="button">
|
|
22
27
|
<IconMenu />
|
|
23
28
|
</button>
|
|
24
29
|
);
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
import {useDocsPreferredVersion} from '@docusaurus/theme-common';
|
|
14
14
|
import {useDocsVersionCandidates} from '@docusaurus/theme-common/internal';
|
|
15
15
|
import {translate} from '@docusaurus/Translate';
|
|
16
|
+
import {useLocation} from '@docusaurus/router';
|
|
16
17
|
import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
|
|
17
18
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
18
19
|
import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
|
|
@@ -29,6 +30,7 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
29
30
|
dropdownItemsAfter,
|
|
30
31
|
...props
|
|
31
32
|
}: Props): JSX.Element {
|
|
33
|
+
const {search, hash} = useLocation();
|
|
32
34
|
const activeDocContext = useActiveDocContext(docsPluginId);
|
|
33
35
|
const versions = useVersions(docsPluginId);
|
|
34
36
|
const {savePreferredVersionName} = useDocsPreferredVersion(docsPluginId);
|
|
@@ -40,7 +42,8 @@ export default function DocsVersionDropdownNavbarItem({
|
|
|
40
42
|
getVersionMainDoc(version);
|
|
41
43
|
return {
|
|
42
44
|
label: version.label,
|
|
43
|
-
|
|
45
|
+
// preserve ?search#hash suffix on version switches
|
|
46
|
+
to: `${versionDoc.path}${search}${hash}`,
|
|
44
47
|
isActive: () => version === activeDocContext.activeVersion,
|
|
45
48
|
onClick: () => savePreferredVersionName(version.name),
|
|
46
49
|
};
|
|
@@ -9,6 +9,7 @@ import React from 'react';
|
|
|
9
9
|
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
|
10
10
|
import {useAlternatePageUtils} from '@docusaurus/theme-common/internal';
|
|
11
11
|
import {translate} from '@docusaurus/Translate';
|
|
12
|
+
import {useLocation} from '@docusaurus/router';
|
|
12
13
|
import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
|
|
13
14
|
import IconLanguage from '@theme/Icon/Language';
|
|
14
15
|
import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
|
|
@@ -26,12 +27,15 @@ export default function LocaleDropdownNavbarItem({
|
|
|
26
27
|
i18n: {currentLocale, locales, localeConfigs},
|
|
27
28
|
} = useDocusaurusContext();
|
|
28
29
|
const alternatePageUtils = useAlternatePageUtils();
|
|
30
|
+
const {search, hash} = useLocation();
|
|
29
31
|
|
|
30
32
|
const localeItems = locales.map((locale): LinkLikeNavbarItemProps => {
|
|
31
|
-
const
|
|
33
|
+
const baseTo = `pathname://${alternatePageUtils.createUrl({
|
|
32
34
|
locale,
|
|
33
35
|
fullyQualified: false,
|
|
34
36
|
})}`;
|
|
37
|
+
// preserve ?search#hash suffix on locale switches
|
|
38
|
+
const to = `${baseTo}${search}${hash}`;
|
|
35
39
|
return {
|
|
36
40
|
label: localeConfigs[locale]!.label,
|
|
37
41
|
lang: localeConfigs[locale]!.htmlLang,
|
|
@@ -6,26 +6,10 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import React from 'react';
|
|
9
|
-
import
|
|
10
|
-
import {useSkipToContent} from '@docusaurus/theme-common/internal';
|
|
9
|
+
import {SkipToContentLink} from '@docusaurus/theme-common';
|
|
11
10
|
|
|
12
11
|
import styles from './styles.module.css';
|
|
13
12
|
|
|
14
13
|
export default function SkipToContent(): JSX.Element {
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<div
|
|
18
|
-
ref={containerRef}
|
|
19
|
-
role="region"
|
|
20
|
-
aria-label={translate({id: 'theme.common.skipToMainContent'})}>
|
|
21
|
-
{/* eslint-disable-next-line jsx-a11y/anchor-is-valid */}
|
|
22
|
-
<a href="#" className={styles.skipToContent} onClick={handleSkip}>
|
|
23
|
-
<Translate
|
|
24
|
-
id="theme.common.skipToMainContent"
|
|
25
|
-
description="The skip to content label used for accessibility, allowing to rapidly navigate to main content with keyboard tab/enter navigation">
|
|
26
|
-
Skip to main content
|
|
27
|
-
</Translate>
|
|
28
|
-
</a>
|
|
29
|
-
</div>
|
|
30
|
-
);
|
|
14
|
+
return <SkipToContentLink className={styles.skipToContent} />;
|
|
31
15
|
}
|
package/src/theme/Tabs/index.tsx
CHANGED
|
@@ -5,118 +5,40 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React, {
|
|
9
|
-
useState,
|
|
10
|
-
cloneElement,
|
|
11
|
-
isValidElement,
|
|
12
|
-
type ReactElement,
|
|
13
|
-
} from 'react';
|
|
8
|
+
import React, {cloneElement} from 'react';
|
|
14
9
|
import clsx from 'clsx';
|
|
15
|
-
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
16
|
-
import {duplicates} from '@docusaurus/theme-common';
|
|
17
10
|
import {
|
|
18
11
|
useScrollPositionBlocker,
|
|
19
|
-
|
|
12
|
+
useTabs,
|
|
20
13
|
} from '@docusaurus/theme-common/internal';
|
|
14
|
+
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
21
15
|
import type {Props} from '@theme/Tabs';
|
|
22
|
-
import type {Props as TabItemProps} from '@theme/TabItem';
|
|
23
|
-
|
|
24
16
|
import styles from './styles.module.css';
|
|
25
17
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function TabsComponent(props: Props): JSX.Element {
|
|
35
|
-
const {
|
|
36
|
-
lazy,
|
|
37
|
-
block,
|
|
38
|
-
defaultValue: defaultValueProp,
|
|
39
|
-
values: valuesProp,
|
|
40
|
-
groupId,
|
|
41
|
-
className,
|
|
42
|
-
} = props;
|
|
43
|
-
const children = React.Children.map(props.children, (child) => {
|
|
44
|
-
if (isValidElement(child) && isTabItem(child)) {
|
|
45
|
-
return child;
|
|
46
|
-
}
|
|
47
|
-
// child.type.name will give non-sensical values in prod because of
|
|
48
|
-
// minification, but we assume it won't throw in prod.
|
|
49
|
-
throw new Error(
|
|
50
|
-
`Docusaurus error: Bad <Tabs> child <${
|
|
51
|
-
// @ts-expect-error: guarding against unexpected cases
|
|
52
|
-
typeof child.type === 'string' ? child.type : child.type.name
|
|
53
|
-
}>: all children of the <Tabs> component should be <TabItem>, and every <TabItem> should have a unique "value" prop.`,
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
const values =
|
|
57
|
-
valuesProp ??
|
|
58
|
-
// Only pick keys that we recognize. MDX would inject some keys by default
|
|
59
|
-
children.map(({props: {value, label, attributes}}) => ({
|
|
60
|
-
value,
|
|
61
|
-
label,
|
|
62
|
-
attributes,
|
|
63
|
-
}));
|
|
64
|
-
const dup = duplicates(values, (a, b) => a.value === b.value);
|
|
65
|
-
if (dup.length > 0) {
|
|
66
|
-
throw new Error(
|
|
67
|
-
`Docusaurus error: Duplicate values "${dup
|
|
68
|
-
.map((a) => a.value)
|
|
69
|
-
.join(', ')}" found in <Tabs>. Every value needs to be unique.`,
|
|
70
|
-
);
|
|
71
|
-
}
|
|
72
|
-
// When defaultValueProp is null, don't show a default tab
|
|
73
|
-
const defaultValue =
|
|
74
|
-
defaultValueProp === null
|
|
75
|
-
? defaultValueProp
|
|
76
|
-
: defaultValueProp ??
|
|
77
|
-
children.find((child) => child.props.default)?.props.value ??
|
|
78
|
-
children[0]!.props.value;
|
|
79
|
-
if (defaultValue !== null && !values.some((a) => a.value === defaultValue)) {
|
|
80
|
-
throw new Error(
|
|
81
|
-
`Docusaurus error: The <Tabs> has a defaultValue "${defaultValue}" but none of its children has the corresponding value. Available values are: ${values
|
|
82
|
-
.map((a) => a.value)
|
|
83
|
-
.join(
|
|
84
|
-
', ',
|
|
85
|
-
)}. If you intend to show no default tab, use defaultValue={null} instead.`,
|
|
86
|
-
);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
const {tabGroupChoices, setTabGroupChoices} = useTabGroupChoice();
|
|
90
|
-
const [selectedValue, setSelectedValue] = useState(defaultValue);
|
|
18
|
+
function TabList({
|
|
19
|
+
className,
|
|
20
|
+
block,
|
|
21
|
+
selectedValue,
|
|
22
|
+
selectValue,
|
|
23
|
+
tabValues,
|
|
24
|
+
}: Props & ReturnType<typeof useTabs>) {
|
|
91
25
|
const tabRefs: (HTMLLIElement | null)[] = [];
|
|
92
26
|
const {blockElementScrollPositionUntilNextRender} =
|
|
93
27
|
useScrollPositionBlocker();
|
|
94
28
|
|
|
95
|
-
if (groupId != null) {
|
|
96
|
-
const relevantTabGroupChoice = tabGroupChoices[groupId];
|
|
97
|
-
if (
|
|
98
|
-
relevantTabGroupChoice != null &&
|
|
99
|
-
relevantTabGroupChoice !== selectedValue &&
|
|
100
|
-
values.some((value) => value.value === relevantTabGroupChoice)
|
|
101
|
-
) {
|
|
102
|
-
setSelectedValue(relevantTabGroupChoice);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
|
|
106
29
|
const handleTabChange = (
|
|
107
|
-
event:
|
|
30
|
+
event:
|
|
31
|
+
| React.FocusEvent<HTMLLIElement>
|
|
32
|
+
| React.MouseEvent<HTMLLIElement>
|
|
33
|
+
| React.KeyboardEvent<HTMLLIElement>,
|
|
108
34
|
) => {
|
|
109
35
|
const newTab = event.currentTarget;
|
|
110
36
|
const newTabIndex = tabRefs.indexOf(newTab);
|
|
111
|
-
const newTabValue =
|
|
37
|
+
const newTabValue = tabValues[newTabIndex]!.value;
|
|
112
38
|
|
|
113
39
|
if (newTabValue !== selectedValue) {
|
|
114
40
|
blockElementScrollPositionUntilNextRender(newTab);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (groupId != null) {
|
|
118
|
-
setTabGroupChoices(groupId, String(newTabValue));
|
|
119
|
-
}
|
|
41
|
+
selectValue(newTabValue);
|
|
120
42
|
}
|
|
121
43
|
};
|
|
122
44
|
|
|
@@ -124,6 +46,10 @@ function TabsComponent(props: Props): JSX.Element {
|
|
|
124
46
|
let focusElement: HTMLLIElement | null = null;
|
|
125
47
|
|
|
126
48
|
switch (event.key) {
|
|
49
|
+
case 'Enter': {
|
|
50
|
+
handleTabChange(event);
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
127
53
|
case 'ArrowRight': {
|
|
128
54
|
const nextTab = tabRefs.indexOf(event.currentTarget) + 1;
|
|
129
55
|
focusElement = tabRefs[nextTab] ?? tabRefs[0]!;
|
|
@@ -142,62 +68,79 @@ function TabsComponent(props: Props): JSX.Element {
|
|
|
142
68
|
};
|
|
143
69
|
|
|
144
70
|
return (
|
|
145
|
-
<
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
71
|
+
<ul
|
|
72
|
+
role="tablist"
|
|
73
|
+
aria-orientation="horizontal"
|
|
74
|
+
className={clsx(
|
|
75
|
+
'tabs',
|
|
76
|
+
{
|
|
77
|
+
'tabs--block': block,
|
|
78
|
+
},
|
|
79
|
+
className,
|
|
80
|
+
)}>
|
|
81
|
+
{tabValues.map(({value, label, attributes}) => (
|
|
82
|
+
<li
|
|
83
|
+
// TODO extract TabListItem
|
|
84
|
+
role="tab"
|
|
85
|
+
tabIndex={selectedValue === value ? 0 : -1}
|
|
86
|
+
aria-selected={selectedValue === value}
|
|
87
|
+
key={value}
|
|
88
|
+
ref={(tabControl) => tabRefs.push(tabControl)}
|
|
89
|
+
onKeyDown={handleKeydown}
|
|
90
|
+
onClick={handleTabChange}
|
|
91
|
+
{...attributes}
|
|
92
|
+
className={clsx(
|
|
93
|
+
'tabs__item',
|
|
94
|
+
styles.tabItem,
|
|
95
|
+
attributes?.className as string,
|
|
96
|
+
{
|
|
97
|
+
'tabs__item--active': selectedValue === value,
|
|
98
|
+
},
|
|
99
|
+
)}>
|
|
100
|
+
{label ?? value}
|
|
101
|
+
</li>
|
|
102
|
+
))}
|
|
103
|
+
</ul>
|
|
104
|
+
);
|
|
105
|
+
}
|
|
179
106
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
107
|
+
function TabContent({
|
|
108
|
+
lazy,
|
|
109
|
+
children,
|
|
110
|
+
selectedValue,
|
|
111
|
+
}: Props & ReturnType<typeof useTabs>) {
|
|
112
|
+
if (lazy) {
|
|
113
|
+
const selectedTabItem = children.find(
|
|
114
|
+
(tabItem) => tabItem.props.value === selectedValue,
|
|
115
|
+
);
|
|
116
|
+
if (!selectedTabItem) {
|
|
117
|
+
// fail-safe or fail-fast? not sure what's best here
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
return cloneElement(selectedTabItem, {className: 'margin-top--md'});
|
|
121
|
+
}
|
|
122
|
+
return (
|
|
123
|
+
<div className="margin-top--md">
|
|
124
|
+
{children.map((tabItem, i) =>
|
|
125
|
+
cloneElement(tabItem, {
|
|
126
|
+
key: i,
|
|
127
|
+
hidden: tabItem.props.value !== selectedValue,
|
|
128
|
+
}),
|
|
196
129
|
)}
|
|
197
130
|
</div>
|
|
198
131
|
);
|
|
199
132
|
}
|
|
200
133
|
|
|
134
|
+
function TabsComponent(props: Props): JSX.Element {
|
|
135
|
+
const tabs = useTabs(props);
|
|
136
|
+
return (
|
|
137
|
+
<div className={clsx('tabs-container', styles.tabList)}>
|
|
138
|
+
<TabList {...props} {...tabs} />
|
|
139
|
+
<TabContent {...props} {...tabs} />
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
201
144
|
export default function Tabs(props: Props): JSX.Element {
|
|
202
145
|
const isBrowser = useIsBrowser();
|
|
203
146
|
return (
|