@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.
Files changed (64) hide show
  1. package/lib/getSwizzleConfig.js +42 -1
  2. package/lib/theme/AnnouncementBar/styles.module.css +9 -1
  3. package/lib/theme/CodeBlock/Line/index.js +2 -4
  4. package/lib/theme/ColorModeToggle/index.js +2 -1
  5. package/lib/theme/DocBreadcrumbs/Items/Home/index.d.ts +8 -0
  6. package/lib/theme/DocBreadcrumbs/Items/Home/index.js +29 -0
  7. package/lib/theme/DocBreadcrumbs/Items/Home/styles.module.css +14 -0
  8. package/lib/theme/DocBreadcrumbs/index.js +1 -19
  9. package/lib/theme/DocBreadcrumbs/styles.module.css +0 -8
  10. package/lib/theme/DocPage/Layout/Sidebar/ExpandButton/styles.module.css +3 -2
  11. package/lib/theme/DocPage/Layout/Sidebar/index.js +13 -8
  12. package/lib/theme/DocPage/Layout/Sidebar/styles.module.css +7 -0
  13. package/lib/theme/DocPage/Layout/styles.module.css +1 -0
  14. package/lib/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +1 -0
  15. package/lib/theme/DocSidebar/Desktop/Content/index.js +6 -0
  16. package/lib/theme/DocSidebar/Desktop/styles.module.css +0 -6
  17. package/lib/theme/Heading/index.js +17 -8
  18. package/lib/theme/Layout/Provider/index.js +0 -2
  19. package/lib/theme/Layout/index.js +6 -1
  20. package/lib/theme/Layout/styles.module.css +2 -0
  21. package/lib/theme/MDXComponents/Code.js +24 -4
  22. package/lib/theme/MDXComponents/index.js +2 -0
  23. package/lib/theme/Mermaid.d.ts +7 -0
  24. package/lib/theme/Mermaid.js +13 -0
  25. package/lib/theme/Navbar/Layout/index.js +6 -0
  26. package/lib/theme/Navbar/MobileSidebar/Header/index.js +6 -0
  27. package/lib/theme/Navbar/MobileSidebar/Toggle/index.js +11 -6
  28. package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +4 -1
  29. package/lib/theme/NavbarItem/LocaleDropdownNavbarItem/index.js +5 -1
  30. package/lib/theme/SkipToContent/index.js +2 -18
  31. package/lib/theme/Tabs/index.js +67 -131
  32. package/lib/theme/Tag/styles.module.css +1 -1
  33. package/package.json +14 -14
  34. package/src/getSwizzleConfig.ts +47 -1
  35. package/src/theme/AnnouncementBar/styles.module.css +9 -1
  36. package/src/theme/CodeBlock/Line/index.tsx +2 -4
  37. package/src/theme/ColorModeToggle/index.tsx +2 -1
  38. package/src/theme/DocBreadcrumbs/Items/Home/index.tsx +33 -0
  39. package/src/theme/DocBreadcrumbs/Items/Home/styles.module.css +14 -0
  40. package/src/theme/DocBreadcrumbs/index.tsx +1 -20
  41. package/src/theme/DocBreadcrumbs/styles.module.css +0 -8
  42. package/src/theme/DocPage/Layout/Sidebar/ExpandButton/styles.module.css +3 -2
  43. package/src/theme/DocPage/Layout/Sidebar/index.tsx +13 -8
  44. package/src/theme/DocPage/Layout/Sidebar/styles.module.css +7 -0
  45. package/src/theme/DocPage/Layout/styles.module.css +1 -0
  46. package/src/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +1 -0
  47. package/src/theme/DocSidebar/Desktop/Content/index.tsx +6 -0
  48. package/src/theme/DocSidebar/Desktop/styles.module.css +0 -6
  49. package/src/theme/Heading/index.tsx +18 -8
  50. package/src/theme/Layout/Provider/index.tsx +0 -2
  51. package/src/theme/Layout/index.tsx +6 -1
  52. package/src/theme/Layout/styles.module.css +2 -0
  53. package/src/theme/MDXComponents/Code.tsx +24 -4
  54. package/src/theme/MDXComponents/index.tsx +2 -0
  55. package/src/theme/Mermaid.tsx +16 -0
  56. package/src/theme/Navbar/Layout/index.tsx +6 -0
  57. package/src/theme/Navbar/MobileSidebar/Header/index.tsx +6 -0
  58. package/src/theme/Navbar/MobileSidebar/Toggle/index.tsx +11 -6
  59. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +4 -1
  60. package/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +5 -1
  61. package/src/theme/SkipToContent/index.tsx +2 -18
  62. package/src/theme/Tabs/index.tsx +87 -144
  63. package/src/theme/Tag/styles.module.css +1 -1
  64. 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
- <a
49
+ <Link
37
50
  className="hash-link"
38
- href={`#${id}`}
39
- title={translate({
40
- id: 'theme.common.headingLinkTitle',
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
  &#8203;
45
- </a>
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 {PageMetadata, ThemeClassNames} from '@docusaurus/theme-common';
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,
@@ -12,6 +12,8 @@ body {
12
12
 
13
13
  .mainWrapper {
14
14
  flex: 1 0 auto;
15
+ display: flex;
16
+ flex-direction: column;
15
17
  }
16
18
 
17
19
  /* Docusaurus-specific utility class */
@@ -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
- 'big',
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
- 'small',
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 mobileSidebar = useNavbarMobileSidebar();
14
+ const {toggle, shown} = useNavbarMobileSidebar();
14
15
  return (
15
16
  <button
16
- onClick={mobileSidebar.toggle}
17
- onKeyDown={mobileSidebar.toggle}
18
- aria-label="Navigation bar toggle"
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
- to: versionDoc.path,
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 to = `pathname://${alternatePageUtils.createUrl({
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 Translate, {translate} from '@docusaurus/Translate';
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
- const {containerRef, handleSkip} = useSkipToContent();
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
  }
@@ -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
- useTabGroupChoice,
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
- // A very rough duck type, but good enough to guard against mistakes while
27
- // allowing customization
28
- function isTabItem(
29
- comp: ReactElement<object>,
30
- ): comp is ReactElement<TabItemProps> {
31
- return 'value' in comp.props;
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: React.FocusEvent<HTMLLIElement> | React.MouseEvent<HTMLLIElement>,
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 = values[newTabIndex]!.value;
37
+ const newTabValue = tabValues[newTabIndex]!.value;
112
38
 
113
39
  if (newTabValue !== selectedValue) {
114
40
  blockElementScrollPositionUntilNextRender(newTab);
115
- setSelectedValue(newTabValue);
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
- <div className={clsx('tabs-container', styles.tabList)}>
146
- <ul
147
- role="tablist"
148
- aria-orientation="horizontal"
149
- className={clsx(
150
- 'tabs',
151
- {
152
- 'tabs--block': block,
153
- },
154
- className,
155
- )}>
156
- {values.map(({value, label, attributes}) => (
157
- <li
158
- role="tab"
159
- tabIndex={selectedValue === value ? 0 : -1}
160
- aria-selected={selectedValue === value}
161
- key={value}
162
- ref={(tabControl) => tabRefs.push(tabControl)}
163
- onKeyDown={handleKeydown}
164
- onFocus={handleTabChange}
165
- onClick={handleTabChange}
166
- {...attributes}
167
- className={clsx(
168
- 'tabs__item',
169
- styles.tabItem,
170
- attributes?.className as string,
171
- {
172
- 'tabs__item--active': selectedValue === value,
173
- },
174
- )}>
175
- {label ?? value}
176
- </li>
177
- ))}
178
- </ul>
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
- {lazy ? (
181
- cloneElement(
182
- children.filter(
183
- (tabItem) => tabItem.props.value === selectedValue,
184
- )[0]!,
185
- {className: 'margin-top--md'},
186
- )
187
- ) : (
188
- <div className="margin-top--md">
189
- {children.map((tabItem, i) =>
190
- cloneElement(tabItem, {
191
- key: i,
192
- hidden: tabItem.props.value !== selectedValue,
193
- }),
194
- )}
195
- </div>
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 (
@@ -20,7 +20,7 @@
20
20
  }
21
21
 
22
22
  .tagRegular {
23
- border-radius: 0.5rem;
23
+ border-radius: var(--ifm-global-radius);
24
24
  padding: 0.2rem 0.5rem 0.3rem;
25
25
  font-size: 90%;
26
26
  }