@docusaurus/theme-classic 2.0.0-beta.17 → 2.0.0-beta.18

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 (184) hide show
  1. package/lib/getSwizzleConfig.js +113 -2
  2. package/lib/index.js +7 -12
  3. package/lib/theme-classic.d.ts +286 -60
  4. package/lib/translations.js +12 -2
  5. package/lib/validateThemeConfig.js +1 -1
  6. package/lib-next/theme/BackToTopButton/index.js +1 -3
  7. package/lib-next/theme/BlogArchivePage/index.js +14 -10
  8. package/lib-next/theme/BlogListPage/index.js +34 -13
  9. package/lib-next/theme/BlogPostItem/index.js +6 -6
  10. package/lib-next/theme/BlogPostPage/index.js +56 -45
  11. package/lib-next/theme/BlogTagsListPage/index.js +16 -12
  12. package/lib-next/theme/BlogTagsPostsPage/index.js +40 -33
  13. package/lib-next/theme/CodeBlock/CopyButton/index.js +60 -0
  14. package/lib-next/theme/CodeBlock/CopyButton/styles.module.css +66 -0
  15. package/lib-next/theme/CodeBlock/index.js +4 -36
  16. package/lib-next/theme/CodeBlock/styles.module.css +2 -22
  17. package/lib-next/theme/ColorModeToggle/index.js +36 -57
  18. package/lib-next/theme/ColorModeToggle/styles.module.css +8 -24
  19. package/lib-next/theme/DocBreadcrumbs/index.js +28 -11
  20. package/lib-next/theme/DocBreadcrumbs/styles.module.css +2 -17
  21. package/lib-next/theme/DocCard/index.js +17 -15
  22. package/lib-next/theme/DocCard/styles.module.css +8 -17
  23. package/lib-next/theme/DocCardList/index.js +15 -3
  24. package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +27 -6
  25. package/lib-next/theme/DocItem/index.js +84 -66
  26. package/lib-next/theme/DocPage/index.js +88 -89
  27. package/lib-next/theme/DocPage/styles.module.css +0 -4
  28. package/lib-next/theme/DocSidebar/Desktop/CollapseButton/index.js +34 -0
  29. package/lib-next/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +44 -0
  30. package/lib-next/theme/DocSidebar/Desktop/Content/index.js +46 -0
  31. package/lib-next/theme/DocSidebar/Desktop/Content/styles.module.css +17 -0
  32. package/lib-next/theme/DocSidebar/Desktop/index.js +34 -0
  33. package/lib-next/theme/DocSidebar/Desktop/styles.module.css +50 -0
  34. package/lib-next/theme/DocSidebar/Mobile/index.js +49 -0
  35. package/lib-next/theme/DocSidebar/index.js +6 -113
  36. package/lib-next/theme/DocSidebarItem/index.js +14 -13
  37. package/lib-next/theme/DocSidebarItem/styles.module.css +4 -0
  38. package/lib-next/theme/DocTagDocListPage/index.js +38 -31
  39. package/lib-next/theme/DocTagsListPage/index.js +21 -16
  40. package/lib-next/theme/Footer/Copyright/index.js +18 -0
  41. package/lib-next/theme/Footer/Layout/index.js +26 -0
  42. package/lib-next/theme/Footer/LinkItem/index.js +33 -0
  43. package/lib-next/theme/Footer/Links/MultiColumn/index.js +47 -0
  44. package/lib-next/theme/Footer/Links/Simple/index.js +41 -0
  45. package/lib-next/theme/Footer/Links/index.js +17 -0
  46. package/lib-next/theme/Footer/Logo/index.js +38 -0
  47. package/lib-next/theme/Footer/{styles.module.css → Logo/styles.module.css} +0 -0
  48. package/lib-next/theme/Footer/index.js +11 -163
  49. package/lib-next/theme/Heading/index.js +6 -4
  50. package/lib-next/theme/IconExternalLink/styles.module.css +0 -2
  51. package/lib-next/theme/Layout/index.js +15 -10
  52. package/lib-next/theme/LayoutProviders/index.js +5 -4
  53. package/lib-next/theme/MDXComponents/A.js +11 -0
  54. package/lib-next/theme/MDXComponents/Code.js +28 -0
  55. package/lib-next/theme/MDXComponents/Details.js +20 -0
  56. package/lib-next/theme/MDXComponents/Head.js +26 -0
  57. package/lib-next/theme/MDXComponents/Heading.js +11 -0
  58. package/lib-next/theme/MDXComponents/Img.js +24 -0
  59. package/lib-next/theme/MDXComponents/Img.module.css +10 -0
  60. package/lib-next/theme/MDXComponents/Pre.js +18 -0
  61. package/lib-next/theme/MDXComponents/Ul.js +23 -0
  62. package/{src/theme/MDXComponents/styles.css → lib-next/theme/MDXComponents/Ul.module.css} +1 -5
  63. package/lib-next/theme/MDXComponents/index.js +22 -71
  64. package/lib-next/theme/MDXContent/index.js +12 -0
  65. package/lib-next/theme/MDXPage/index.js +33 -28
  66. package/lib-next/theme/Navbar/ColorModeToggle/index.js +25 -0
  67. package/lib-next/theme/Navbar/Content/index.js +70 -0
  68. package/lib-next/theme/Navbar/Content/styles.module.css +15 -0
  69. package/lib-next/theme/Navbar/Layout/index.js +54 -0
  70. package/{src/theme/Navbar → lib-next/theme/Navbar/Layout}/styles.module.css +0 -13
  71. package/lib-next/theme/Navbar/Logo/index.js +17 -0
  72. package/lib-next/theme/Navbar/MobileSidebar/Header/index.js +33 -0
  73. package/lib-next/theme/Navbar/MobileSidebar/Layout/index.js +28 -0
  74. package/lib-next/theme/Navbar/MobileSidebar/PrimaryMenu/index.js +33 -0
  75. package/lib-next/theme/Navbar/MobileSidebar/SecondaryMenu/index.js +36 -0
  76. package/lib-next/theme/Navbar/MobileSidebar/Toggle/index.js +23 -0
  77. package/lib-next/theme/Navbar/MobileSidebar/index.js +31 -0
  78. package/lib-next/theme/Navbar/index.js +6 -271
  79. package/lib-next/theme/NavbarItem/DefaultNavbarItem.js +2 -6
  80. package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +10 -2
  81. package/lib-next/theme/NavbarItem/NavbarNavLink.js +8 -12
  82. package/lib-next/theme/NotFound.js +38 -33
  83. package/lib-next/theme/{LayoutHead → SiteMetadata}/index.js +11 -26
  84. package/lib-next/theme/TOCCollapsible/index.js +1 -3
  85. package/lib-next/theme/Tabs/__tests__/index.test.js +5 -5
  86. package/lib-next/theme/Tabs/index.js +2 -2
  87. package/lib-next/theme/Tag/index.js +4 -4
  88. package/lib-next/theme/ThemedImage/index.js +3 -3
  89. package/package.json +17 -17
  90. package/src/getSwizzleConfig.ts +122 -1
  91. package/src/index.ts +10 -12
  92. package/src/theme/BackToTopButton/index.tsx +1 -3
  93. package/src/theme/BlogArchivePage/index.tsx +18 -17
  94. package/src/theme/BlogLayout/index.tsx +1 -1
  95. package/src/theme/BlogListPage/index.tsx +32 -13
  96. package/src/theme/BlogPostItem/index.tsx +6 -6
  97. package/src/theme/BlogPostPage/index.tsx +55 -48
  98. package/src/theme/BlogTagsListPage/index.tsx +16 -12
  99. package/src/theme/BlogTagsPostsPage/index.tsx +39 -32
  100. package/src/theme/CodeBlock/CopyButton/index.tsx +66 -0
  101. package/src/theme/CodeBlock/CopyButton/styles.module.css +66 -0
  102. package/src/theme/CodeBlock/index.tsx +6 -38
  103. package/src/theme/CodeBlock/styles.module.css +2 -22
  104. package/src/theme/ColorModeToggle/index.tsx +36 -61
  105. package/src/theme/ColorModeToggle/styles.module.css +8 -24
  106. package/src/theme/DocBreadcrumbs/index.tsx +29 -10
  107. package/src/theme/DocBreadcrumbs/styles.module.css +2 -17
  108. package/src/theme/DocCard/index.tsx +24 -17
  109. package/src/theme/DocCard/styles.module.css +8 -17
  110. package/src/theme/DocCardList/index.tsx +14 -3
  111. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +31 -4
  112. package/src/theme/DocItem/index.tsx +71 -55
  113. package/src/theme/DocPage/index.tsx +89 -90
  114. package/src/theme/DocPage/styles.module.css +0 -4
  115. package/src/theme/DocSidebar/Desktop/CollapseButton/index.tsx +38 -0
  116. package/src/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +44 -0
  117. package/src/theme/DocSidebar/Desktop/Content/index.tsx +55 -0
  118. package/src/theme/DocSidebar/Desktop/Content/styles.module.css +17 -0
  119. package/src/theme/DocSidebar/Desktop/index.tsx +38 -0
  120. package/src/theme/DocSidebar/Desktop/styles.module.css +50 -0
  121. package/src/theme/DocSidebar/Mobile/index.tsx +54 -0
  122. package/src/theme/DocSidebar/index.tsx +6 -121
  123. package/src/theme/DocSidebarItem/index.tsx +15 -16
  124. package/src/theme/DocSidebarItem/styles.module.css +4 -0
  125. package/src/theme/DocTagDocListPage/index.tsx +38 -30
  126. package/src/theme/DocTagsListPage/index.tsx +21 -16
  127. package/src/theme/DocVersionBanner/index.tsx +3 -4
  128. package/src/theme/Footer/Copyright/index.tsx +20 -0
  129. package/src/theme/Footer/Layout/index.tsx +34 -0
  130. package/src/theme/Footer/LinkItem/index.tsx +36 -0
  131. package/src/theme/Footer/Links/MultiColumn/index.tsx +51 -0
  132. package/src/theme/Footer/Links/Simple/index.tsx +42 -0
  133. package/src/theme/Footer/Links/index.tsx +21 -0
  134. package/src/theme/Footer/Logo/index.tsx +41 -0
  135. package/src/theme/Footer/{styles.module.css → Logo/styles.module.css} +0 -0
  136. package/src/theme/Footer/index.tsx +12 -186
  137. package/src/theme/Heading/index.tsx +6 -4
  138. package/src/theme/IconExternalLink/styles.module.css +0 -2
  139. package/src/theme/Layout/index.tsx +15 -10
  140. package/src/theme/LayoutProviders/index.tsx +5 -4
  141. package/src/theme/MDXComponents/A.tsx +14 -0
  142. package/src/theme/MDXComponents/Code.tsx +37 -0
  143. package/src/theme/MDXComponents/Details.tsx +26 -0
  144. package/src/theme/MDXComponents/Head.tsx +29 -0
  145. package/src/theme/MDXComponents/Heading.tsx +14 -0
  146. package/src/theme/MDXComponents/Img.module.css +10 -0
  147. package/src/theme/MDXComponents/Img.tsx +26 -0
  148. package/src/theme/MDXComponents/Pre.tsx +22 -0
  149. package/{lib-next/theme/MDXComponents/styles.css → src/theme/MDXComponents/Ul.module.css} +1 -5
  150. package/src/theme/MDXComponents/Ul.tsx +28 -0
  151. package/src/theme/MDXComponents/index.tsx +23 -80
  152. package/src/theme/MDXContent/index.tsx +15 -0
  153. package/src/theme/MDXPage/index.tsx +33 -28
  154. package/src/theme/Navbar/ColorModeToggle/index.tsx +30 -0
  155. package/src/theme/Navbar/Content/index.tsx +81 -0
  156. package/src/theme/Navbar/Content/styles.module.css +15 -0
  157. package/src/theme/Navbar/Layout/index.tsx +57 -0
  158. package/{lib-next/theme/Navbar → src/theme/Navbar/Layout}/styles.module.css +0 -13
  159. package/src/theme/Navbar/Logo/index.tsx +19 -0
  160. package/src/theme/Navbar/MobileSidebar/Header/index.tsx +34 -0
  161. package/src/theme/Navbar/MobileSidebar/Layout/index.tsx +31 -0
  162. package/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx +38 -0
  163. package/src/theme/Navbar/MobileSidebar/SecondaryMenu/index.tsx +38 -0
  164. package/src/theme/Navbar/MobileSidebar/Toggle/index.tsx +25 -0
  165. package/src/theme/Navbar/MobileSidebar/index.tsx +33 -0
  166. package/src/theme/Navbar/index.tsx +6 -286
  167. package/src/theme/NavbarItem/DefaultNavbarItem.tsx +2 -2
  168. package/src/theme/NavbarItem/DropdownNavbarItem.tsx +11 -2
  169. package/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +1 -1
  170. package/src/theme/NavbarItem/NavbarNavLink.tsx +3 -7
  171. package/src/theme/NavbarItem/index.tsx +3 -4
  172. package/src/theme/NotFound.tsx +38 -33
  173. package/src/theme/{LayoutHead → SiteMetadata}/index.tsx +11 -25
  174. package/src/theme/TOCCollapsible/index.tsx +1 -3
  175. package/src/theme/Tabs/index.tsx +5 -6
  176. package/src/theme/Tag/index.tsx +4 -4
  177. package/src/theme/ThemedImage/index.tsx +4 -3
  178. package/src/theme-classic.d.ts +286 -60
  179. package/src/translations.ts +12 -6
  180. package/src/validateThemeConfig.ts +6 -6
  181. package/lib-next/theme/DocSidebar/styles.module.css +0 -107
  182. package/lib-next/theme/Seo/index.js +0 -40
  183. package/src/theme/DocSidebar/styles.module.css +0 -107
  184. package/src/theme/Seo/index.tsx +0 -49
@@ -0,0 +1,33 @@
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 NavbarColorModeToggle from '@theme/Navbar/ColorModeToggle';
9
+ import IconClose from '@theme/IconClose';
10
+ import NavbarLogo from '@theme/Navbar/Logo';
11
+ import {useNavbarMobileSidebar} from '@docusaurus/theme-common';
12
+
13
+ function CloseButton() {
14
+ const mobileSidebar = useNavbarMobileSidebar();
15
+ return (
16
+ <button
17
+ type="button"
18
+ className="clean-btn navbar-sidebar__close"
19
+ onClick={() => mobileSidebar.toggle()}>
20
+ <IconClose color="var(--ifm-color-emphasis-600)" />
21
+ </button>
22
+ );
23
+ }
24
+
25
+ export default function NavbarMobileSidebarHeader() {
26
+ return (
27
+ <div className="navbar-sidebar__brand">
28
+ <NavbarLogo />
29
+ <NavbarColorModeToggle className="margin-right--md" />
30
+ <CloseButton />
31
+ </div>
32
+ );
33
+ }
@@ -0,0 +1,28 @@
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 clsx from 'clsx';
9
+ import {useNavbarSecondaryMenu} from '@docusaurus/theme-common';
10
+ export default function NavbarMobileSidebarLayout({
11
+ header,
12
+ primaryMenu,
13
+ secondaryMenu,
14
+ }) {
15
+ const {shown: secondaryMenuShown} = useNavbarSecondaryMenu();
16
+ return (
17
+ <div className="navbar-sidebar">
18
+ {header}
19
+ <div
20
+ className={clsx('navbar-sidebar__items', {
21
+ 'navbar-sidebar__items--show-secondary': secondaryMenuShown,
22
+ })}>
23
+ <div className="navbar-sidebar__item menu">{primaryMenu}</div>
24
+ <div className="navbar-sidebar__item menu">{secondaryMenu}</div>
25
+ </div>
26
+ </div>
27
+ );
28
+ }
@@ -0,0 +1,33 @@
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 {useNavbarMobileSidebar, useThemeConfig} from '@docusaurus/theme-common';
9
+ import NavbarItem from '../../../NavbarItem';
10
+
11
+ function useNavbarItems() {
12
+ // TODO temporary casting until ThemeConfig type is improved
13
+ return useThemeConfig().navbar.items;
14
+ } // The primary menu displays the navbar items
15
+
16
+ export default function NavbarMobilePrimaryMenu() {
17
+ const mobileSidebar = useNavbarMobileSidebar(); // TODO how can the order be defined for mobile?
18
+ // Should we allow providing a different list of items?
19
+
20
+ const items = useNavbarItems();
21
+ return (
22
+ <ul className="menu__list">
23
+ {items.map((item, i) => (
24
+ <NavbarItem
25
+ mobile
26
+ {...item}
27
+ onClick={() => mobileSidebar.toggle()}
28
+ key={i}
29
+ />
30
+ ))}
31
+ </ul>
32
+ );
33
+ }
@@ -0,0 +1,36 @@
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 {useNavbarSecondaryMenu, useThemeConfig} from '@docusaurus/theme-common';
9
+ import Translate from '@docusaurus/Translate';
10
+
11
+ function SecondaryMenuBackButton(props) {
12
+ return (
13
+ <button {...props} type="button" className="clean-btn navbar-sidebar__back">
14
+ <Translate
15
+ id="theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel"
16
+ description="The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)">
17
+ ← Back to main menu
18
+ </Translate>
19
+ </button>
20
+ );
21
+ } // The secondary menu slides from the right and shows contextual information
22
+ // such as the docs sidebar
23
+
24
+ export default function NavbarMobileSidebarSecondaryMenu() {
25
+ const isPrimaryMenuEmpty = useThemeConfig().navbar.items.length === 0;
26
+ const secondaryMenu = useNavbarSecondaryMenu();
27
+ return (
28
+ <>
29
+ {/* edge-case: prevent returning to the primaryMenu when it's empty */}
30
+ {!isPrimaryMenuEmpty && (
31
+ <SecondaryMenuBackButton onClick={() => secondaryMenu.hide()} />
32
+ )}
33
+ {secondaryMenu.content}
34
+ </>
35
+ );
36
+ }
@@ -0,0 +1,23 @@
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 IconMenu from '@theme/IconMenu';
9
+ import {useNavbarMobileSidebar} from '@docusaurus/theme-common';
10
+ export default function MobileSidebarToggle() {
11
+ const mobileSidebar = useNavbarMobileSidebar();
12
+ return (
13
+ <button
14
+ onClick={mobileSidebar.toggle}
15
+ onKeyDown={mobileSidebar.toggle}
16
+ aria-label="Navigation bar toggle"
17
+ className="navbar__toggle clean-btn"
18
+ type="button"
19
+ tabIndex={0}>
20
+ <IconMenu />
21
+ </button>
22
+ );
23
+ }
@@ -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
+ import React from 'react';
8
+ import NavbarMobileSidebarLayout from '@theme/Navbar/MobileSidebar/Layout';
9
+ import NavbarMobileSidebarHeader from '@theme/Navbar/MobileSidebar/Header';
10
+ import {
11
+ useLockBodyScroll,
12
+ useNavbarMobileSidebar,
13
+ } from '@docusaurus/theme-common';
14
+ import NavbarMobileSidebarPrimaryMenu from '@theme/Navbar/MobileSidebar/PrimaryMenu';
15
+ import NavbarMobileSidebarSecondaryMenu from '@theme/Navbar/MobileSidebar/SecondaryMenu';
16
+ export default function NavbarMobileSidebar() {
17
+ const mobileSidebar = useNavbarMobileSidebar();
18
+ useLockBodyScroll(mobileSidebar.shown);
19
+
20
+ if (!mobileSidebar.shouldRender) {
21
+ return null;
22
+ }
23
+
24
+ return (
25
+ <NavbarMobileSidebarLayout
26
+ header={<NavbarMobileSidebarHeader />}
27
+ primaryMenu={<NavbarMobileSidebarPrimaryMenu />}
28
+ secondaryMenu={<NavbarMobileSidebarSecondaryMenu />}
29
+ />
30
+ );
31
+ }
@@ -4,278 +4,13 @@
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, {useCallback, useState, useEffect} from 'react';
8
- import clsx from 'clsx';
9
- import Translate from '@docusaurus/Translate';
10
- import SearchBar from '@theme/SearchBar';
11
- import ColorModeToggle from '@theme/ColorModeToggle';
12
- import {
13
- useThemeConfig,
14
- useMobileSecondaryMenuRenderer,
15
- usePrevious,
16
- useHistoryPopHandler,
17
- useHideableNavbar,
18
- useLockBodyScroll,
19
- useWindowSize,
20
- useColorMode,
21
- } from '@docusaurus/theme-common';
22
- import {useActivePlugin} from '@docusaurus/plugin-content-docs/client';
23
- import NavbarItem from '@theme/NavbarItem';
24
- import Logo from '@theme/Logo';
25
- import IconMenu from '@theme/IconMenu';
26
- import IconClose from '@theme/IconClose';
27
- import styles from './styles.module.css'; // retrocompatible with v1
28
-
29
- const DefaultNavItemPosition = 'right';
30
-
31
- function useNavbarItems() {
32
- // TODO temporary casting until ThemeConfig type is improved
33
- return useThemeConfig().navbar.items;
34
- } // If split links by left/right
35
- // if position is unspecified, fallback to right (as v1)
36
-
37
- function splitNavItemsByPosition(items) {
38
- const leftItems = items.filter(
39
- (item) => (item.position ?? DefaultNavItemPosition) === 'left',
40
- );
41
- const rightItems = items.filter(
42
- (item) => (item.position ?? DefaultNavItemPosition) === 'right',
43
- );
44
- return {
45
- leftItems,
46
- rightItems,
47
- };
48
- }
49
-
50
- function useMobileSidebar() {
51
- const windowSize = useWindowSize(); // Mobile sidebar not visible on hydration: can avoid SSR rendering
52
-
53
- const shouldRender = windowSize === 'mobile'; // || windowSize === 'ssr';
54
-
55
- const [shown, setShown] = useState(false); // Close mobile sidebar on navigation pop
56
- // Most likely firing when using the Android back button (but not only)
57
-
58
- useHistoryPopHandler(() => {
59
- if (shown) {
60
- setShown(false); // Should we prevent the navigation here?
61
- // See https://github.com/facebook/docusaurus/pull/5462#issuecomment-911699846
62
-
63
- return false; // prevent pop navigation
64
- }
65
-
66
- return undefined;
67
- });
68
- const toggle = useCallback(() => {
69
- setShown((s) => !s);
70
- }, []);
71
- useEffect(() => {
72
- if (windowSize === 'desktop') {
73
- setShown(false);
74
- }
75
- }, [windowSize]);
76
- return {
77
- shouldRender,
78
- toggle,
79
- shown,
80
- };
81
- }
82
-
83
- function useColorModeToggle() {
84
- const {
85
- colorMode: {disableSwitch},
86
- } = useThemeConfig();
87
- const {isDarkTheme, setLightTheme, setDarkTheme} = useColorMode();
88
- const toggle = useCallback(
89
- (e) => (e.target.checked ? setDarkTheme() : setLightTheme()),
90
- [setLightTheme, setDarkTheme],
91
- );
92
- return {
93
- isDarkTheme,
94
- toggle,
95
- disabled: disableSwitch,
96
- };
97
- }
98
-
99
- function useSecondaryMenu({sidebarShown, toggleSidebar}) {
100
- const content = useMobileSecondaryMenuRenderer()?.({
101
- toggleSidebar,
102
- });
103
- const previousContent = usePrevious(content);
104
- const [shown, setShown] = useState(
105
- () =>
106
- // /!\ content is set with useEffect,
107
- // so it's not available on mount anyway
108
- // "return !!content" => always returns false
109
- false,
110
- ); // When content is become available for the first time (set in useEffect)
111
- // we set this content to be shown!
112
-
113
- useEffect(() => {
114
- const contentBecameAvailable = content && !previousContent;
115
-
116
- if (contentBecameAvailable) {
117
- setShown(true);
118
- }
119
- }, [content, previousContent]);
120
- const hasContent = !!content; // On sidebar close, secondary menu is set to be shown on next re-opening
121
- // (if any secondary menu content available)
122
-
123
- useEffect(() => {
124
- if (!hasContent) {
125
- setShown(false);
126
- return;
127
- }
128
-
129
- if (!sidebarShown) {
130
- setShown(true);
131
- }
132
- }, [sidebarShown, hasContent]);
133
- const hide = useCallback(() => {
134
- setShown(false);
135
- }, []);
136
- return {
137
- shown,
138
- hide,
139
- content,
140
- };
141
- }
142
-
143
- function NavbarMobileSidebar({sidebarShown, toggleSidebar}) {
144
- useLockBodyScroll(sidebarShown);
145
- const items = useNavbarItems();
146
- const colorModeToggle = useColorModeToggle();
147
- const secondaryMenu = useSecondaryMenu({
148
- sidebarShown,
149
- toggleSidebar,
150
- });
151
- return (
152
- <div className="navbar-sidebar">
153
- <div className="navbar-sidebar__brand">
154
- <Logo
155
- className="navbar__brand"
156
- imageClassName="navbar__logo"
157
- titleClassName="navbar__title"
158
- />
159
- {!colorModeToggle.disabled && (
160
- <ColorModeToggle
161
- className={styles.navbarSidebarToggle}
162
- checked={colorModeToggle.isDarkTheme}
163
- onChange={colorModeToggle.toggle}
164
- />
165
- )}
166
- <button
167
- type="button"
168
- className="clean-btn navbar-sidebar__close"
169
- onClick={toggleSidebar}>
170
- <IconClose
171
- color="var(--ifm-color-emphasis-600)"
172
- className={styles.navbarSidebarCloseSvg}
173
- />
174
- </button>
175
- </div>
176
-
177
- <div
178
- className={clsx('navbar-sidebar__items', {
179
- 'navbar-sidebar__items--show-secondary': secondaryMenu.shown,
180
- })}>
181
- <div className="navbar-sidebar__item menu">
182
- <ul className="menu__list">
183
- {items.map((item, i) => (
184
- <NavbarItem mobile {...item} onClick={toggleSidebar} key={i} />
185
- ))}
186
- </ul>
187
- </div>
188
-
189
- <div className="navbar-sidebar__item menu">
190
- {items.length > 0 && (
191
- <button
192
- type="button"
193
- className="clean-btn navbar-sidebar__back"
194
- onClick={secondaryMenu.hide}>
195
- <Translate
196
- id="theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel"
197
- description="The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)">
198
- ← Back to main menu
199
- </Translate>
200
- </button>
201
- )}
202
- {secondaryMenu.content}
203
- </div>
204
- </div>
205
- </div>
206
- );
207
- }
208
-
7
+ import React from 'react';
8
+ import NavbarLayout from '@theme/Navbar/Layout';
9
+ import NavbarContent from '@theme/Navbar/Content';
209
10
  export default function Navbar() {
210
- const {
211
- navbar: {hideOnScroll, style},
212
- } = useThemeConfig();
213
- const mobileSidebar = useMobileSidebar();
214
- const colorModeToggle = useColorModeToggle();
215
- const activeDocPlugin = useActivePlugin();
216
- const {navbarRef, isNavbarVisible} = useHideableNavbar(hideOnScroll);
217
- const items = useNavbarItems();
218
- const hasSearchNavbarItem = items.some((item) => item.type === 'search');
219
- const {leftItems, rightItems} = splitNavItemsByPosition(items);
220
11
  return (
221
- <nav
222
- ref={navbarRef}
223
- className={clsx('navbar', 'navbar--fixed-top', {
224
- 'navbar--dark': style === 'dark',
225
- 'navbar--primary': style === 'primary',
226
- 'navbar-sidebar--show': mobileSidebar.shown,
227
- [styles.navbarHideable]: hideOnScroll,
228
- [styles.navbarHidden]: hideOnScroll && !isNavbarVisible,
229
- })}>
230
- <div className="navbar__inner">
231
- <div className="navbar__items">
232
- {(items?.length > 0 || activeDocPlugin) && (
233
- <button
234
- aria-label="Navigation bar toggle"
235
- className="navbar__toggle clean-btn"
236
- type="button"
237
- tabIndex={0}
238
- onClick={mobileSidebar.toggle}
239
- onKeyDown={mobileSidebar.toggle}>
240
- <IconMenu />
241
- </button>
242
- )}
243
- <Logo
244
- className="navbar__brand"
245
- imageClassName="navbar__logo"
246
- titleClassName="navbar__title"
247
- />
248
- {leftItems.map((item, i) => (
249
- <NavbarItem {...item} key={i} />
250
- ))}
251
- </div>
252
- <div className="navbar__items navbar__items--right">
253
- {rightItems.map((item, i) => (
254
- <NavbarItem {...item} key={i} />
255
- ))}
256
- {!colorModeToggle.disabled && (
257
- <ColorModeToggle
258
- className={styles.toggle}
259
- checked={colorModeToggle.isDarkTheme}
260
- onChange={colorModeToggle.toggle}
261
- />
262
- )}
263
- {!hasSearchNavbarItem && <SearchBar />}
264
- </div>
265
- </div>
266
-
267
- <div
268
- role="presentation"
269
- className="navbar-sidebar__backdrop"
270
- onClick={mobileSidebar.toggle}
271
- />
272
-
273
- {mobileSidebar.shouldRender && (
274
- <NavbarMobileSidebar
275
- sidebarShown={mobileSidebar.shown}
276
- toggleSidebar={mobileSidebar.toggle}
277
- />
278
- )}
279
- </nav>
12
+ <NavbarLayout>
13
+ <NavbarContent />
14
+ </NavbarLayout>
280
15
  );
281
16
  }
@@ -31,11 +31,7 @@ function DefaultNavbarItemDesktop({
31
31
  return element;
32
32
  }
33
33
 
34
- function DefaultNavbarItemMobile({
35
- className,
36
- isDropdownItem: _isDropdownItem,
37
- ...props
38
- }) {
34
+ function DefaultNavbarItemMobile({className, isDropdownItem, ...props}) {
39
35
  return (
40
36
  <li className="menu__list-item">
41
37
  <NavbarNavLink className={clsx('menu__link', className)} {...props} />
@@ -45,7 +41,7 @@ function DefaultNavbarItemMobile({
45
41
 
46
42
  export default function DefaultNavbarItem({
47
43
  mobile = false,
48
- position: _position,
44
+ position,
49
45
  // Need to destructure position from props so that it doesn't get passed on.
50
46
  ...props
51
47
  }) {
@@ -64,6 +64,9 @@ function DropdownNavbarItemDesktop({items, position, className, ...props}) {
64
64
  'dropdown--show': showDropdown,
65
65
  })}>
66
66
  <NavbarNavLink
67
+ aria-haspopup="true"
68
+ aria-expanded={showDropdown}
69
+ role="button"
67
70
  href={props.to ? undefined : '#'}
68
71
  className={clsx('navbar__link', className)}
69
72
  {...props}
@@ -87,7 +90,12 @@ function DropdownNavbarItemDesktop({items, position, className, ...props}) {
87
90
  const nextNavbarItem = dropdownRef.current.nextElementSibling;
88
91
 
89
92
  if (nextNavbarItem) {
90
- nextNavbarItem.focus();
93
+ const targetItem =
94
+ nextNavbarItem instanceof HTMLAnchorElement
95
+ ? nextNavbarItem // Next item is another dropdown; focus on the inner
96
+ : // anchor element instead so there's outline
97
+ nextNavbarItem.querySelector('a');
98
+ targetItem.focus();
91
99
  }
92
100
  }
93
101
  }}
@@ -104,7 +112,7 @@ function DropdownNavbarItemDesktop({items, position, className, ...props}) {
104
112
  function DropdownNavbarItemMobile({
105
113
  items,
106
114
  className,
107
- position: _position,
115
+ position,
108
116
  // Need to destructure position from props so that it doesn't get passed on.
109
117
  ...props
110
118
  }) {
@@ -52,18 +52,14 @@ export default function NavbarNavLink({
52
52
  : null),
53
53
  })}
54
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
55
+ {label}
56
+ {isExternalLink && (
57
+ <IconExternalLink
58
+ {...(isDropdownLink && {
59
+ width: 12,
60
+ height: 12,
61
+ })}
62
+ />
67
63
  )}
68
64
  </Link>
69
65
  );
@@ -7,41 +7,46 @@
7
7
  import React from 'react';
8
8
  import Layout from '@theme/Layout';
9
9
  import Translate, {translate} from '@docusaurus/Translate';
10
+ import {PageMetadata} from '@docusaurus/theme-common';
10
11
  export default function NotFound() {
11
12
  return (
12
- <Layout
13
- title={translate({
14
- id: 'theme.NotFound.title',
15
- message: 'Page Not Found',
16
- })}>
17
- <main className="container margin-vert--xl">
18
- <div className="row">
19
- <div className="col col--6 col--offset-3">
20
- <h1 className="hero__title">
21
- <Translate
22
- id="theme.NotFound.title"
23
- description="The title of the 404 page">
24
- Page Not Found
25
- </Translate>
26
- </h1>
27
- <p>
28
- <Translate
29
- id="theme.NotFound.p1"
30
- description="The first paragraph of the 404 page">
31
- We could not find what you were looking for.
32
- </Translate>
33
- </p>
34
- <p>
35
- <Translate
36
- id="theme.NotFound.p2"
37
- description="The 2nd paragraph of the 404 page">
38
- Please contact the owner of the site that linked you to the
39
- original URL and let them know their link is broken.
40
- </Translate>
41
- </p>
13
+ <>
14
+ <PageMetadata
15
+ title={translate({
16
+ id: 'theme.NotFound.title',
17
+ message: 'Page Not Found',
18
+ })}
19
+ />
20
+ <Layout>
21
+ <main className="container margin-vert--xl">
22
+ <div className="row">
23
+ <div className="col col--6 col--offset-3">
24
+ <h1 className="hero__title">
25
+ <Translate
26
+ id="theme.NotFound.title"
27
+ description="The title of the 404 page">
28
+ Page Not Found
29
+ </Translate>
30
+ </h1>
31
+ <p>
32
+ <Translate
33
+ id="theme.NotFound.p1"
34
+ description="The first paragraph of the 404 page">
35
+ We could not find what you were looking for.
36
+ </Translate>
37
+ </p>
38
+ <p>
39
+ <Translate
40
+ id="theme.NotFound.p2"
41
+ description="The 2nd paragraph of the 404 page">
42
+ Please contact the owner of the site that linked you to the
43
+ original URL and let them know their link is broken.
44
+ </Translate>
45
+ </p>
46
+ </div>
42
47
  </div>
43
- </div>
44
- </main>
45
- </Layout>
48
+ </main>
49
+ </Layout>
50
+ </>
46
51
  );
47
52
  }