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

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 (204) hide show
  1. package/lib/admonitions.css +4 -0
  2. package/lib/default.css +3038 -0
  3. package/lib/getSwizzleConfig.js +9 -2
  4. package/lib/index.js +4 -4
  5. package/lib/nprogress.css +41 -0
  6. package/lib/nprogress.js +46 -0
  7. package/lib/theme-classic.d.ts +315 -33
  8. package/lib/validateThemeConfig.js +72 -14
  9. package/lib-next/theme/BackToTopButton/index.js +6 -102
  10. package/lib-next/theme/BlogLayout/index.js +1 -5
  11. package/lib-next/theme/BlogListPaginator/index.js +25 -28
  12. package/lib-next/theme/BlogPostAuthor/index.js +3 -6
  13. package/lib-next/theme/BlogPostItem/styles.module.css +9 -0
  14. package/lib-next/theme/BlogPostPaginator/index.js +25 -28
  15. package/lib-next/theme/BlogSidebar/Desktop/index.js +41 -0
  16. package/lib-next/theme/BlogSidebar/{styles.module.css → Desktop/styles.module.css} +1 -2
  17. package/lib-next/theme/BlogSidebar/Mobile/index.js +36 -0
  18. package/lib-next/theme/BlogSidebar/index.js +11 -31
  19. package/lib-next/theme/BlogTagsListPage/index.js +2 -3
  20. package/lib-next/theme/BlogTagsPostsPage/index.js +4 -6
  21. package/lib-next/theme/CodeBlock/Container/index.js +29 -0
  22. package/lib-next/theme/CodeBlock/Container/styles.module.css +14 -0
  23. package/lib-next/theme/CodeBlock/Content/Element.js +23 -0
  24. package/lib-next/theme/CodeBlock/Content/String.js +104 -0
  25. package/{src/theme/CodeBlock → lib-next/theme/CodeBlock/Content}/styles.module.css +39 -9
  26. package/lib-next/theme/CodeBlock/CopyButton/index.js +3 -2
  27. package/lib-next/theme/CodeBlock/CopyButton/styles.module.css +0 -19
  28. package/lib-next/theme/CodeBlock/Line/index.js +49 -0
  29. package/lib-next/theme/CodeBlock/Line/styles.module.css +51 -0
  30. package/lib-next/theme/CodeBlock/WordWrapButton/index.js +40 -0
  31. package/lib-next/theme/CodeBlock/WordWrapButton/styles.module.css +15 -0
  32. package/lib-next/theme/CodeBlock/index.js +27 -133
  33. package/lib-next/theme/Details/index.js +1 -1
  34. package/lib-next/theme/DocBreadcrumbs/index.js +50 -23
  35. package/lib-next/theme/DocBreadcrumbs/styles.module.css +8 -0
  36. package/lib-next/theme/DocCardList/index.js +6 -4
  37. package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +3 -3
  38. package/lib-next/theme/DocCategoryGeneratedIndexPage/styles.module.css +8 -0
  39. package/lib-next/theme/DocItem/index.js +1 -1
  40. package/lib-next/theme/DocItem/styles.module.css +6 -0
  41. package/lib-next/theme/DocPage/Layout/Main/index.js +29 -0
  42. package/lib-next/theme/DocPage/Layout/Main/styles.module.css +28 -0
  43. package/lib-next/theme/DocPage/Layout/Sidebar/ExpandButton/index.js +34 -0
  44. package/lib-next/theme/DocPage/Layout/Sidebar/ExpandButton/styles.module.css +33 -0
  45. package/lib-next/theme/DocPage/Layout/Sidebar/index.js +68 -0
  46. package/lib-next/theme/DocPage/Layout/Sidebar/index.module.css +32 -0
  47. package/lib-next/theme/DocPage/Layout/index.js +34 -0
  48. package/lib-next/theme/{BlogPostAuthor/styles.module.css → DocPage/Layout/index.module.css} +6 -3
  49. package/lib-next/theme/DocPage/index.js +28 -146
  50. package/lib-next/theme/DocPaginator/index.js +25 -28
  51. package/lib-next/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +11 -9
  52. package/lib-next/theme/DocSidebar/Desktop/Content/styles.module.css +6 -0
  53. package/lib-next/theme/DocSidebar/Desktop/index.js +4 -2
  54. package/lib-next/theme/DocSidebarItem/Category.js +197 -0
  55. package/lib-next/theme/DocSidebarItem/Html.js +27 -0
  56. package/{src/theme/DocSidebarItem/styles.module.css → lib-next/theme/DocSidebarItem/Html.module.css} +0 -4
  57. package/lib-next/theme/DocSidebarItem/Link.js +53 -0
  58. package/{src/theme/MDXComponents/Ul.module.css → lib-next/theme/DocSidebarItem/Link.module.css} +2 -3
  59. package/lib-next/theme/DocSidebarItem/index.js +4 -246
  60. package/lib-next/theme/DocSidebarItems/index.js +1 -6
  61. package/lib-next/theme/DocTagDocListPage/index.js +3 -3
  62. package/lib-next/theme/DocVersionBanner/index.js +2 -2
  63. package/lib-next/theme/Footer/Links/MultiColumn/index.js +1 -1
  64. package/lib-next/theme/Heading/index.js +4 -20
  65. package/lib-next/theme/IconHome/index.js +17 -0
  66. package/lib-next/theme/LastUpdated/index.js +1 -0
  67. package/lib-next/theme/Layout/index.js +1 -1
  68. package/lib-next/theme/MDXComponents/Ul.js +2 -4
  69. package/lib-next/theme/Navbar/Content/index.js +6 -1
  70. package/lib-next/theme/Navbar/Logo/index.js +1 -1
  71. package/lib-next/theme/Navbar/Search/index.js +11 -0
  72. package/lib-next/theme/Navbar/Search/styles.module.css +20 -0
  73. package/lib-next/theme/NavbarItem/ComponentTypes.js +27 -0
  74. package/lib-next/theme/NavbarItem/DocNavbarItem.js +11 -28
  75. package/lib-next/theme/NavbarItem/DocSidebarNavbarItem.js +10 -42
  76. package/lib-next/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +25 -29
  77. package/lib-next/theme/NavbarItem/DocsVersionNavbarItem.js +2 -9
  78. package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +4 -1
  79. package/lib-next/theme/NavbarItem/HtmlNavbarItem.js +30 -0
  80. package/lib-next/theme/NavbarItem/LocaleDropdownNavbarItem/index.js +5 -10
  81. package/lib-next/theme/NavbarItem/NavbarNavLink.js +49 -31
  82. package/lib-next/theme/NavbarItem/SearchNavbarItem.js +6 -1
  83. package/lib-next/theme/NavbarItem/index.js +4 -23
  84. package/lib-next/theme/NavbarItem/utils.js +2 -1
  85. package/lib-next/theme/PaginatorNavLink/index.js +8 -2
  86. package/lib-next/theme/SiteMetadata/index.js +8 -7
  87. package/lib-next/theme/SkipToContent/index.js +3 -29
  88. package/lib-next/theme/TOCCollapsible/CollapseButton.js +29 -0
  89. package/{src/theme/TOCCollapsible/styles.module.css → lib-next/theme/TOCCollapsible/CollapseButton.module.css} +1 -22
  90. package/lib-next/theme/TOCCollapsible/index.js +3 -13
  91. package/lib-next/theme/TOCCollapsible/index.module.css +31 -0
  92. package/lib-next/theme/TOCItems/Tree.js +40 -0
  93. package/lib-next/theme/TOCItems/index.js +3 -34
  94. package/lib-next/theme/TabItem/index.js +3 -1
  95. package/lib-next/theme/{MDXComponents/Ul.module.css → TabItem/styles.module.css} +2 -3
  96. package/lib-next/theme/Tabs/__tests__/index.test.js +3 -3
  97. package/lib-next/theme/Tabs/index.js +3 -3
  98. package/lib-next/theme/Tabs/styles.module.css +4 -0
  99. package/lib-next/theme/Tag/index.js +2 -3
  100. package/lib-next/theme/TagsListInline/index.js +1 -1
  101. package/package.json +23 -18
  102. package/src/admonitions.css +4 -0
  103. package/src/getSwizzleConfig.ts +10 -2
  104. package/src/index.ts +4 -3
  105. package/src/nprogress.css +41 -0
  106. package/src/nprogress.ts +31 -0
  107. package/src/theme/BackToTopButton/index.tsx +5 -112
  108. package/src/theme/BlogLayout/index.tsx +1 -5
  109. package/src/theme/BlogListPaginator/index.tsx +25 -28
  110. package/src/theme/BlogPostAuthor/index.tsx +3 -7
  111. package/src/theme/BlogPostItem/styles.module.css +9 -0
  112. package/src/theme/BlogPostPaginator/index.tsx +25 -28
  113. package/src/theme/BlogSidebar/Desktop/index.tsx +45 -0
  114. package/src/theme/BlogSidebar/{styles.module.css → Desktop/styles.module.css} +1 -2
  115. package/src/theme/BlogSidebar/Mobile/index.tsx +38 -0
  116. package/src/theme/BlogSidebar/index.tsx +10 -31
  117. package/src/theme/BlogTagsListPage/index.tsx +2 -3
  118. package/src/theme/BlogTagsPostsPage/index.tsx +8 -5
  119. package/src/theme/CodeBlock/Container/index.tsx +35 -0
  120. package/src/theme/CodeBlock/Container/styles.module.css +14 -0
  121. package/src/theme/CodeBlock/Content/Element.tsx +30 -0
  122. package/src/theme/CodeBlock/Content/String.tsx +111 -0
  123. package/{lib-next/theme/CodeBlock → src/theme/CodeBlock/Content}/styles.module.css +39 -9
  124. package/src/theme/CodeBlock/CopyButton/index.tsx +3 -2
  125. package/src/theme/CodeBlock/CopyButton/styles.module.css +0 -19
  126. package/src/theme/CodeBlock/Line/index.tsx +48 -0
  127. package/src/theme/CodeBlock/Line/styles.module.css +51 -0
  128. package/src/theme/CodeBlock/WordWrapButton/index.tsx +49 -0
  129. package/src/theme/CodeBlock/WordWrapButton/styles.module.css +15 -0
  130. package/src/theme/CodeBlock/index.tsx +29 -133
  131. package/src/theme/Details/index.tsx +1 -1
  132. package/src/theme/DocBreadcrumbs/index.tsx +50 -20
  133. package/src/theme/DocBreadcrumbs/styles.module.css +8 -0
  134. package/src/theme/DocCardList/index.tsx +5 -7
  135. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +3 -3
  136. package/src/theme/DocCategoryGeneratedIndexPage/styles.module.css +8 -0
  137. package/src/theme/DocItem/index.tsx +1 -1
  138. package/src/theme/DocItem/styles.module.css +6 -0
  139. package/src/theme/DocPage/Layout/Main/index.tsx +37 -0
  140. package/src/theme/DocPage/Layout/Main/styles.module.css +28 -0
  141. package/src/theme/DocPage/Layout/Sidebar/ExpandButton/index.tsx +40 -0
  142. package/src/theme/DocPage/Layout/Sidebar/ExpandButton/styles.module.css +33 -0
  143. package/src/theme/DocPage/Layout/Sidebar/index.module.css +32 -0
  144. package/src/theme/DocPage/Layout/Sidebar/index.tsx +74 -0
  145. package/src/theme/{BlogPostAuthor/styles.module.css → DocPage/Layout/index.module.css} +6 -3
  146. package/src/theme/DocPage/Layout/index.tsx +39 -0
  147. package/src/theme/DocPage/index.tsx +28 -157
  148. package/src/theme/DocPaginator/index.tsx +25 -28
  149. package/src/theme/DocSidebar/Desktop/CollapseButton/styles.module.css +11 -9
  150. package/src/theme/DocSidebar/Desktop/Content/styles.module.css +6 -0
  151. package/src/theme/DocSidebar/Desktop/index.tsx +4 -2
  152. package/src/theme/DocSidebarItem/Category.tsx +210 -0
  153. package/{lib-next/theme/DocSidebarItem/styles.module.css → src/theme/DocSidebarItem/Html.module.css} +0 -4
  154. package/src/theme/DocSidebarItem/Html.tsx +34 -0
  155. package/src/theme/DocSidebarItem/Link.module.css +10 -0
  156. package/src/theme/DocSidebarItem/Link.tsx +58 -0
  157. package/src/theme/DocSidebarItem/index.tsx +4 -259
  158. package/src/theme/DocSidebarItems/index.tsx +1 -6
  159. package/src/theme/DocTagDocListPage/index.tsx +3 -4
  160. package/src/theme/DocVersionBanner/index.tsx +2 -2
  161. package/src/theme/Footer/Links/MultiColumn/index.tsx +1 -1
  162. package/src/theme/Heading/index.tsx +4 -18
  163. package/src/theme/IconHome/index.tsx +20 -0
  164. package/src/theme/LastUpdated/index.tsx +1 -0
  165. package/src/theme/Layout/index.tsx +1 -1
  166. package/src/theme/MDXComponents/Details.tsx +2 -3
  167. package/src/theme/MDXComponents/Ul.tsx +2 -6
  168. package/src/theme/Navbar/Content/index.tsx +6 -1
  169. package/src/theme/Navbar/Logo/index.tsx +1 -1
  170. package/src/theme/Navbar/Search/index.tsx +15 -0
  171. package/src/theme/Navbar/Search/styles.module.css +20 -0
  172. package/src/theme/NavbarItem/ComponentTypes.tsx +32 -0
  173. package/src/theme/NavbarItem/DocNavbarItem.tsx +13 -32
  174. package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +9 -49
  175. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +26 -33
  176. package/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +3 -10
  177. package/src/theme/NavbarItem/DropdownNavbarItem.tsx +4 -1
  178. package/src/theme/NavbarItem/HtmlNavbarItem.tsx +32 -0
  179. package/src/theme/NavbarItem/LocaleDropdownNavbarItem/index.tsx +5 -9
  180. package/src/theme/NavbarItem/NavbarNavLink.tsx +41 -25
  181. package/src/theme/NavbarItem/SearchNavbarItem.tsx +6 -1
  182. package/src/theme/NavbarItem/index.tsx +9 -38
  183. package/src/theme/NavbarItem/utils.ts +5 -2
  184. package/src/theme/PaginatorNavLink/index.tsx +8 -2
  185. package/src/theme/SiteMetadata/index.tsx +8 -8
  186. package/src/theme/SkipToContent/index.tsx +3 -29
  187. package/{lib-next/theme/TOCCollapsible/styles.module.css → src/theme/TOCCollapsible/CollapseButton.module.css} +1 -22
  188. package/src/theme/TOCCollapsible/CollapseButton.tsx +35 -0
  189. package/src/theme/TOCCollapsible/index.module.css +31 -0
  190. package/src/theme/TOCCollapsible/index.tsx +3 -14
  191. package/src/theme/TOCItems/Tree.tsx +46 -0
  192. package/src/theme/TOCItems/index.tsx +2 -41
  193. package/src/theme/TabItem/index.tsx +7 -1
  194. package/src/theme/TabItem/styles.module.css +10 -0
  195. package/src/theme/Tabs/index.tsx +3 -3
  196. package/src/theme/Tabs/styles.module.css +4 -0
  197. package/src/theme/Tag/index.tsx +2 -4
  198. package/src/theme/TagsListInline/index.tsx +1 -1
  199. package/src/theme-classic.d.ts +315 -33
  200. package/src/validateThemeConfig.ts +80 -13
  201. package/lib/types.d.ts +0 -11
  202. package/lib-next/theme/DocPage/styles.module.css +0 -82
  203. package/src/theme/DocPage/styles.module.css +0 -82
  204. package/src/types.d.ts +0 -11
@@ -0,0 +1,15 @@
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
+ .wordWrapButtonIcon {
9
+ width: 1.2rem;
10
+ height: 1.2rem;
11
+ }
12
+
13
+ .wordWrapButtonEnabled .wordWrapButtonIcon {
14
+ color: var(--ifm-color-primary);
15
+ }
@@ -5,145 +5,41 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import React, {isValidElement, useEffect, useState} from 'react';
9
- import clsx from 'clsx';
10
- import Highlight, {defaultProps, type Language} from 'prism-react-renderer';
11
- import {
12
- useThemeConfig,
13
- parseCodeBlockTitle,
14
- parseLanguage,
15
- parseLines,
16
- ThemeClassNames,
17
- usePrismTheme,
18
- } from '@docusaurus/theme-common';
19
- import CopyButton from '@theme/CodeBlock/CopyButton';
8
+ import React, {isValidElement, type ReactNode} from 'react';
9
+ import useIsBrowser from '@docusaurus/useIsBrowser';
20
10
  import type {Props} from '@theme/CodeBlock';
11
+ import ElementContent from '@theme/CodeBlock/Content/Element';
12
+ import StringContent from '@theme/CodeBlock/Content/String';
21
13
 
22
- import styles from './styles.module.css';
23
-
24
- export default function CodeBlock({
25
- children,
26
- className: blockClassName = '',
27
- metastring,
28
- title,
29
- language: languageProp,
30
- }: Props): JSX.Element {
31
- const {prism} = useThemeConfig();
32
-
33
- const [mounted, setMounted] = useState(false);
34
- // The Prism theme on SSR is always the default theme but the site theme
35
- // can be in a different mode. React hydration doesn't update DOM styles
36
- // that come from SSR. Hence force a re-render after mounting to apply the
37
- // current relevant styles. There will be a flash seen of the original
38
- // styles seen using this current approach but that's probably ok. Fixing
39
- // the flash will require changing the theming approach and is not worth it
40
- // at this point.
41
- useEffect(() => {
42
- setMounted(true);
43
- }, []);
44
-
45
- // We still parse the metastring in case we want to support more syntax in the
46
- // future. Note that MDX doesn't strip quotes when parsing metastring:
47
- // "title=\"xyz\"" => title: "\"xyz\""
48
- const codeBlockTitle = parseCodeBlockTitle(metastring) || title;
49
- const prismTheme = usePrismTheme();
50
-
51
- // <pre> tags in markdown map to CodeBlocks and they may contain JSX children.
52
- // When the children is not a simple string, we just return a styled block
53
- // without actually highlighting.
14
+ /**
15
+ * Best attempt to make the children a plain string so it is copyable. If there
16
+ * are react elements, we will not be able to copy the content, and it will
17
+ * return `children` as-is; otherwise, it concatenates the string children
18
+ * together.
19
+ */
20
+ function maybeStringifyChildren(children: ReactNode): ReactNode {
54
21
  if (React.Children.toArray(children).some((el) => isValidElement(el))) {
55
- return (
56
- <Highlight
57
- {...defaultProps}
58
- key={String(mounted)}
59
- theme={prismTheme}
60
- code=""
61
- language={'text' as Language}>
62
- {({className, style}) => (
63
- <pre
64
- /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
65
- tabIndex={0}
66
- className={clsx(
67
- className,
68
- styles.codeBlockStandalone,
69
- 'thin-scrollbar',
70
- styles.codeBlockContainer,
71
- blockClassName,
72
- ThemeClassNames.common.codeBlock,
73
- )}
74
- style={style}>
75
- <code className={styles.codeBlockLines}>{children}</code>
76
- </pre>
77
- )}
78
- </Highlight>
79
- );
22
+ return children;
80
23
  }
81
-
82
24
  // The children is now guaranteed to be one/more plain strings
83
- const content = Array.isArray(children)
84
- ? children.join('')
85
- : (children as string);
86
-
87
- const language =
88
- languageProp ?? parseLanguage(blockClassName) ?? prism.defaultLanguage;
89
- const {highlightLines, code} = parseLines(content, metastring, language);
25
+ return Array.isArray(children) ? children.join('') : (children as string);
26
+ }
90
27
 
28
+ export default function CodeBlock({
29
+ children: rawChildren,
30
+ ...props
31
+ }: Props): JSX.Element {
32
+ // The Prism theme on SSR is always the default theme but the site theme can
33
+ // be in a different mode. React hydration doesn't update DOM styles that come
34
+ // from SSR. Hence force a re-render after mounting to apply the current
35
+ // relevant styles.
36
+ const isBrowser = useIsBrowser();
37
+ const children = maybeStringifyChildren(rawChildren);
38
+ const CodeBlockComp =
39
+ typeof children === 'string' ? StringContent : ElementContent;
91
40
  return (
92
- <Highlight
93
- {...defaultProps}
94
- key={String(mounted)}
95
- theme={prismTheme}
96
- code={code}
97
- language={(language ?? 'text') as Language}>
98
- {({className, style, tokens, getLineProps, getTokenProps}) => (
99
- <div
100
- className={clsx(
101
- styles.codeBlockContainer,
102
- blockClassName,
103
- {
104
- [`language-${language}`]:
105
- language && !blockClassName.includes(`language-${language}`),
106
- },
107
- ThemeClassNames.common.codeBlock,
108
- )}>
109
- {codeBlockTitle && (
110
- <div style={style} className={styles.codeBlockTitle}>
111
- {codeBlockTitle}
112
- </div>
113
- )}
114
- <div className={styles.codeBlockContent} style={style}>
115
- <pre
116
- /* eslint-disable-next-line jsx-a11y/no-noninteractive-tabindex */
117
- tabIndex={0}
118
- className={clsx(className, styles.codeBlock, 'thin-scrollbar')}>
119
- <code className={styles.codeBlockLines}>
120
- {tokens.map((line, i) => {
121
- if (line.length === 1 && line[0]!.content === '\n') {
122
- line[0]!.content = '';
123
- }
124
-
125
- const lineProps = getLineProps({line, key: i});
126
-
127
- if (highlightLines.includes(i)) {
128
- lineProps.className += ' docusaurus-highlight-code-line';
129
- }
130
-
131
- return (
132
- <span key={i} {...lineProps}>
133
- {line.map((token, key) => (
134
- <span key={key} {...getTokenProps({token, key})} />
135
- ))}
136
- <br />
137
- </span>
138
- );
139
- })}
140
- </code>
141
- </pre>
142
-
143
- <CopyButton code={code} />
144
- </div>
145
- </div>
146
- )}
147
- </Highlight>
41
+ <CodeBlockComp key={String(isBrowser)} {...props}>
42
+ {children as string}
43
+ </CodeBlockComp>
148
44
  );
149
45
  }
@@ -7,7 +7,7 @@
7
7
 
8
8
  import React from 'react';
9
9
  import clsx from 'clsx';
10
- import {Details as DetailsGeneric} from '@docusaurus/theme-common';
10
+ import {Details as DetailsGeneric} from '@docusaurus/theme-common/Details';
11
11
  import type {Props} from '@theme/Details';
12
12
  import styles from './styles.module.css';
13
13
 
@@ -15,24 +15,38 @@ import styles from './styles.module.css';
15
15
  import clsx from 'clsx';
16
16
  import Link from '@docusaurus/Link';
17
17
  import useBaseUrl from '@docusaurus/useBaseUrl';
18
+ import {translate} from '@docusaurus/Translate';
19
+ import IconHome from '@theme/IconHome';
18
20
 
19
21
  // TODO move to design system folder
20
22
  function BreadcrumbsItemLink({
21
23
  children,
22
24
  href,
25
+ isLast,
23
26
  }: {
24
27
  children: ReactNode;
25
- href?: string;
28
+ href: string | undefined;
29
+ isLast: boolean;
26
30
  }): JSX.Element {
27
31
  const className = 'breadcrumbs__link';
32
+ if (isLast) {
33
+ return (
34
+ <span className={className} itemProp="name">
35
+ {children}
36
+ </span>
37
+ );
38
+ }
28
39
  return href ? (
29
40
  <Link className={className} href={href} itemProp="item">
30
41
  <span itemProp="name">{children}</span>
31
42
  </Link>
32
43
  ) : (
33
- <span className={className} itemProp="item name">
34
- {children}
35
- </span>
44
+ // TODO Google search console doesn't like breadcrumb items without href.
45
+ // The schema doesn't seem to require `id` for each `item`, although Google
46
+ // insist to infer one, even if it's invalid. Removing `itemProp="item
47
+ // name"` for now, since I don't know how to properly fix it.
48
+ // See https://github.com/facebook/docusaurus/issues/7241
49
+ <span className={className}>{children}</span>
36
50
  );
37
51
  }
38
52
 
@@ -41,16 +55,20 @@ function BreadcrumbsItem({
41
55
  children,
42
56
  active,
43
57
  index,
58
+ addMicrodata,
44
59
  }: {
45
60
  children: ReactNode;
46
61
  active?: boolean;
47
62
  index: number;
63
+ addMicrodata: boolean;
48
64
  }): JSX.Element {
49
65
  return (
50
66
  <li
51
- itemScope
52
- itemProp="itemListElement"
53
- itemType="https://schema.org/ListItem"
67
+ {...(addMicrodata && {
68
+ itemScope: true,
69
+ itemProp: 'itemListElement',
70
+ itemType: 'https://schema.org/ListItem',
71
+ })}
54
72
  className={clsx('breadcrumbs__item', {
55
73
  'breadcrumbs__item--active': active,
56
74
  })}>
@@ -65,9 +83,14 @@ function HomeBreadcrumbItem() {
65
83
  return (
66
84
  <li className="breadcrumbs__item">
67
85
  <Link
86
+ aria-label={translate({
87
+ id: 'theme.docs.breadcrumbs.home',
88
+ message: 'Home page',
89
+ description: 'The ARIA label for the home page in the breadcrumbs',
90
+ })}
68
91
  className={clsx('breadcrumbs__link', styles.breadcrumbsItemLink)}
69
92
  href={homeHref}>
70
- 🏠
93
+ <IconHome className={styles.breadcrumbHomeIcon} />
71
94
  </Link>
72
95
  </li>
73
96
  );
@@ -87,23 +110,30 @@ export default function DocBreadcrumbs(): JSX.Element | null {
87
110
  ThemeClassNames.docs.docBreadcrumbs,
88
111
  styles.breadcrumbsContainer,
89
112
  )}
90
- aria-label="breadcrumbs">
113
+ aria-label={translate({
114
+ id: 'theme.docs.breadcrumbs.navAriaLabel',
115
+ message: 'Breadcrumbs',
116
+ description: 'The ARIA label for the breadcrumbs',
117
+ })}>
91
118
  <ul
92
119
  className="breadcrumbs"
93
120
  itemScope
94
121
  itemType="https://schema.org/BreadcrumbList">
95
122
  {homePageRoute && <HomeBreadcrumbItem />}
96
- {breadcrumbs.map((item, idx) => (
97
- <BreadcrumbsItem
98
- key={idx}
99
- active={idx === breadcrumbs.length - 1}
100
- index={idx}>
101
- <BreadcrumbsItemLink
102
- href={idx < breadcrumbs.length - 1 ? item.href : undefined}>
103
- {item.label}
104
- </BreadcrumbsItemLink>
105
- </BreadcrumbsItem>
106
- ))}
123
+ {breadcrumbs.map((item, idx) => {
124
+ const isLast = idx === breadcrumbs.length - 1;
125
+ return (
126
+ <BreadcrumbsItem
127
+ key={idx}
128
+ active={isLast}
129
+ index={idx}
130
+ addMicrodata={!!item.href}>
131
+ <BreadcrumbsItemLink href={item.href} isLast={isLast}>
132
+ {item.label}
133
+ </BreadcrumbsItemLink>
134
+ </BreadcrumbsItem>
135
+ );
136
+ })}
107
137
  </ul>
108
138
  </nav>
109
139
  );
@@ -9,3 +9,11 @@
9
9
  --ifm-breadcrumb-size-multiplier: 0.8;
10
10
  margin-bottom: 0.8rem;
11
11
  }
12
+
13
+ .breadcrumbHomeIcon {
14
+ position: relative;
15
+ top: 1px;
16
+ vertical-align: top;
17
+ height: 1.1rem;
18
+ width: 1.1rem;
19
+ }
@@ -6,10 +6,12 @@
6
6
  */
7
7
 
8
8
  import React from 'react';
9
+ import clsx from 'clsx';
9
10
 
10
11
  import DocCard from '@theme/DocCard';
11
12
  import type {PropSidebarItem} from '@docusaurus/plugin-content-docs';
12
13
  import {findFirstCategoryLink} from '@docusaurus/theme-common';
14
+ import type {Props} from '@theme/DocCardList';
13
15
 
14
16
  // Filter categories that don't have a link.
15
17
  function filterItems(items: PropSidebarItem[]): PropSidebarItem[] {
@@ -21,18 +23,14 @@ function filterItems(items: PropSidebarItem[]): PropSidebarItem[] {
21
23
  });
22
24
  }
23
25
 
24
- export default function DocCardList({
25
- items,
26
- }: {
27
- items: PropSidebarItem[];
28
- }): JSX.Element {
26
+ export default function DocCardList({items, className}: Props): JSX.Element {
29
27
  return (
30
- <div className="row">
28
+ <section className={clsx('row', className)}>
31
29
  {filterItems(items).map((item, index) => (
32
30
  <article key={index} className="col col--6 margin-bottom--lg">
33
31
  <DocCard key={index} item={item} />
34
32
  </article>
35
33
  ))}
36
- </div>
34
+ </section>
37
35
  );
38
36
  }
@@ -60,9 +60,9 @@ function DocCategoryGeneratedIndexPageContent({
60
60
  <p>{categoryGeneratedIndex.description}</p>
61
61
  )}
62
62
  </header>
63
- <main className="margin-top--lg">
64
- <DocCardList items={category.items} />
65
- </main>
63
+ <article className="margin-top--lg">
64
+ <DocCardList items={category.items} className={styles.list} />
65
+ </article>
66
66
  <footer className="margin-top--lg">
67
67
  <DocPaginator
68
68
  previous={categoryGeneratedIndex.navigation.previous}
@@ -9,6 +9,10 @@
9
9
  .generatedIndexPage {
10
10
  max-width: 75% !important;
11
11
  }
12
+
13
+ .list article:nth-last-child(-n + 2) {
14
+ margin-bottom: 0 !important;
15
+ }
12
16
  }
13
17
 
14
18
  /* Duplicated from .markdown h1 */
@@ -16,3 +20,7 @@
16
20
  --ifm-h1-font-size: 3rem;
17
21
  margin-bottom: calc(1.25 * var(--ifm-leading));
18
22
  }
23
+
24
+ .list article:last-child {
25
+ margin-bottom: 0 !important;
26
+ }
@@ -47,7 +47,7 @@ function DocItemContent(props: Props): JSX.Element {
47
47
  const {title} = metadata;
48
48
 
49
49
  // We only add a title if:
50
- // - user asks to hide it with front matter
50
+ // - user doesn't ask to hide it with front matter
51
51
  // - the markdown content does not already contain a top-level h1 heading
52
52
  const shouldAddTitle =
53
53
  !hideTitle && typeof DocContent.contentTitle === 'undefined';
@@ -20,3 +20,9 @@
20
20
  display: none;
21
21
  }
22
22
  }
23
+
24
+ @media print {
25
+ .tocMobile {
26
+ display: none;
27
+ }
28
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+
10
+ import {useDocsSidebar} from '@docusaurus/theme-common';
11
+
12
+ import clsx from 'clsx';
13
+ import styles from './styles.module.css';
14
+ import type {Props} from '@theme/DocPage/Layout/Main';
15
+
16
+ export default function DocPageLayoutMain({
17
+ hiddenSidebarContainer,
18
+ children,
19
+ }: Props): JSX.Element {
20
+ const sidebar = useDocsSidebar();
21
+ return (
22
+ <main
23
+ className={clsx(
24
+ styles.docMainContainer,
25
+ (hiddenSidebarContainer || !sidebar) && styles.docMainContainerEnhanced,
26
+ )}>
27
+ <div
28
+ className={clsx(
29
+ 'container padding-top--md padding-bottom--lg',
30
+ styles.docItemWrapper,
31
+ hiddenSidebarContainer && styles.docItemWrapperEnhanced,
32
+ )}>
33
+ {children}
34
+ </div>
35
+ </main>
36
+ );
37
+ }
@@ -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
+
8
+ .docMainContainer {
9
+ display: flex;
10
+ width: 100%;
11
+ }
12
+
13
+ @media (min-width: 997px) {
14
+ .docMainContainer {
15
+ flex-grow: 1;
16
+ max-width: calc(100% - var(--doc-sidebar-width));
17
+ }
18
+
19
+ .docMainContainerEnhanced {
20
+ max-width: calc(100% - var(--doc-sidebar-hidden-width));
21
+ }
22
+
23
+ .docItemWrapperEnhanced {
24
+ max-width: calc(
25
+ var(--ifm-container-width) + var(--doc-sidebar-width)
26
+ ) !important;
27
+ }
28
+ }
@@ -0,0 +1,40 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React from 'react';
9
+ import IconArrow from '@theme/IconArrow';
10
+ import {translate} from '@docusaurus/Translate';
11
+ import type {Props} from '@theme/DocPage/Layout/Sidebar/ExpandButton';
12
+
13
+ import styles from './styles.module.css';
14
+
15
+ export default function DocPageLayoutSidebarExpandButton({
16
+ toggleSidebar,
17
+ }: Props): JSX.Element {
18
+ return (
19
+ <div
20
+ className={styles.expandButton}
21
+ title={translate({
22
+ id: 'theme.docs.sidebar.expandButtonTitle',
23
+ message: 'Expand sidebar',
24
+ description:
25
+ 'The ARIA label and title attribute for expand button of doc sidebar',
26
+ })}
27
+ aria-label={translate({
28
+ id: 'theme.docs.sidebar.expandButtonAriaLabel',
29
+ message: 'Expand sidebar',
30
+ description:
31
+ 'The ARIA label and title attribute for expand button of doc sidebar',
32
+ })}
33
+ tabIndex={0}
34
+ role="button"
35
+ onKeyDown={toggleSidebar}
36
+ onClick={toggleSidebar}>
37
+ <IconArrow className={styles.expandButtonIcon} />
38
+ </div>
39
+ );
40
+ }
@@ -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
+
8
+ @media (min-width: 997px) {
9
+ .expandButton {
10
+ position: sticky;
11
+ top: 0;
12
+ height: 100%;
13
+ max-height: 100vh;
14
+ display: flex;
15
+ align-items: center;
16
+ justify-content: center;
17
+ transition: background-color var(--ifm-transition-fast) ease;
18
+ background-color: var(--docusaurus-collapse-button-bg);
19
+ }
20
+
21
+ .expandButton:hover,
22
+ .expandButton:focus {
23
+ background-color: var(--docusaurus-collapse-button-bg-hover);
24
+ }
25
+
26
+ .expandButtonIcon {
27
+ transform: rotate(0);
28
+ }
29
+
30
+ [dir='rtl'] .expandButtonIcon {
31
+ transform: rotate(180deg);
32
+ }
33
+ }
@@ -0,0 +1,32 @@
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
+ :root {
9
+ --doc-sidebar-width: 300px;
10
+ --doc-sidebar-hidden-width: 30px;
11
+ }
12
+
13
+ .docSidebarContainer {
14
+ display: none;
15
+ }
16
+
17
+ @media (min-width: 997px) {
18
+ .docSidebarContainer {
19
+ display: block;
20
+ width: var(--doc-sidebar-width);
21
+ margin-top: calc(-1 * var(--ifm-navbar-height));
22
+ border-right: 1px solid var(--ifm-toc-border-color);
23
+ will-change: width;
24
+ transition: width var(--ifm-transition-fast) ease;
25
+ clip-path: inset(0);
26
+ }
27
+
28
+ .docSidebarContainerHidden {
29
+ width: var(--doc-sidebar-hidden-width);
30
+ cursor: pointer;
31
+ }
32
+ }
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import React, {type ReactNode, useState, useCallback} from 'react';
9
+ import DocSidebar from '@theme/DocSidebar';
10
+ import {useLocation} from '@docusaurus/router';
11
+ import type {Props} from '@theme/DocPage/Layout/Sidebar';
12
+ import ExpandButton from '@theme/DocPage/Layout/Sidebar/ExpandButton';
13
+
14
+ import clsx from 'clsx';
15
+ import styles from './index.module.css';
16
+
17
+ import {ThemeClassNames, useDocsSidebar} from '@docusaurus/theme-common';
18
+
19
+ // Reset sidebar state when sidebar changes
20
+ // Use React key to unmount/remount the children
21
+ // See https://github.com/facebook/docusaurus/issues/3414
22
+ function ResetOnSidebarChange({children}: {children: ReactNode}) {
23
+ const sidebar = useDocsSidebar();
24
+ return (
25
+ <React.Fragment key={sidebar?.name ?? 'noSidebar'}>
26
+ {children}
27
+ </React.Fragment>
28
+ );
29
+ }
30
+
31
+ export default function DocPageLayoutSidebar({
32
+ sidebar,
33
+ hiddenSidebarContainer,
34
+ setHiddenSidebarContainer,
35
+ }: Props): JSX.Element {
36
+ const {pathname} = useLocation();
37
+
38
+ const [hiddenSidebar, setHiddenSidebar] = useState(false);
39
+ const toggleSidebar = useCallback(() => {
40
+ if (hiddenSidebar) {
41
+ setHiddenSidebar(false);
42
+ }
43
+ setHiddenSidebarContainer((value) => !value);
44
+ }, [setHiddenSidebarContainer, hiddenSidebar]);
45
+
46
+ return (
47
+ <aside
48
+ className={clsx(
49
+ ThemeClassNames.docs.docSidebarContainer,
50
+ styles.docSidebarContainer,
51
+ hiddenSidebarContainer && styles.docSidebarContainerHidden,
52
+ )}
53
+ onTransitionEnd={(e) => {
54
+ if (!e.currentTarget.classList.contains(styles.docSidebarContainer!)) {
55
+ return;
56
+ }
57
+
58
+ if (hiddenSidebarContainer) {
59
+ setHiddenSidebar(true);
60
+ }
61
+ }}>
62
+ <ResetOnSidebarChange>
63
+ <DocSidebar
64
+ sidebar={sidebar}
65
+ path={pathname}
66
+ onCollapse={toggleSidebar}
67
+ isHidden={hiddenSidebar}
68
+ />
69
+ </ResetOnSidebarChange>
70
+
71
+ {hiddenSidebar && <ExpandButton toggleSidebar={toggleSidebar} />}
72
+ </aside>
73
+ );
74
+ }