@docusaurus/theme-classic 3.7.0 → 3.8.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 (136) hide show
  1. package/lib/getSwizzleConfig.js +1 -1
  2. package/lib/index.js +9 -0
  3. package/lib/inlineScripts.js +6 -27
  4. package/lib/inlineSvgSprites.d.ts +7 -0
  5. package/lib/inlineSvgSprites.js +14 -0
  6. package/lib/options.js +5 -0
  7. package/lib/theme/AnnouncementBar/index.js +6 -2
  8. package/lib/theme/CodeBlock/{WordWrapButton → Buttons/Button}/index.d.ts +2 -2
  9. package/lib/theme/CodeBlock/Buttons/Button/index.js +13 -0
  10. package/lib/theme/CodeBlock/Buttons/CopyButton/index.d.ts +9 -0
  11. package/lib/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/index.js +36 -25
  12. package/lib/theme/CodeBlock/Buttons/WordWrapButton/index.d.ts +9 -0
  13. package/lib/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/index.js +12 -7
  14. package/lib/theme/CodeBlock/{CopyButton → Buttons}/index.d.ts +2 -2
  15. package/lib/theme/CodeBlock/Buttons/index.js +27 -0
  16. package/lib/theme/CodeBlock/Buttons/styles.module.css +37 -0
  17. package/lib/theme/CodeBlock/Content/Element.js +4 -2
  18. package/lib/theme/CodeBlock/Content/String.d.ts +1 -1
  19. package/lib/theme/CodeBlock/Content/String.js +22 -92
  20. package/lib/theme/CodeBlock/Content/index.d.ts +9 -0
  21. package/lib/theme/CodeBlock/Content/index.js +74 -0
  22. package/lib/theme/CodeBlock/Content/styles.module.css +0 -52
  23. package/lib/theme/CodeBlock/Layout/index.d.ts +9 -0
  24. package/lib/theme/CodeBlock/Layout/index.js +30 -0
  25. package/lib/theme/CodeBlock/Layout/styles.module.css +27 -0
  26. package/lib/theme/CodeBlock/Line/Token/index.d.ts +9 -0
  27. package/lib/theme/CodeBlock/Line/Token/index.js +11 -0
  28. package/lib/theme/CodeBlock/Line/index.d.ts +1 -1
  29. package/lib/theme/CodeBlock/Line/index.js +21 -7
  30. package/lib/theme/CodeBlock/Title/index.d.ts +9 -0
  31. package/lib/theme/CodeBlock/Title/index.js +10 -0
  32. package/lib/theme/ColorModeToggle/index.d.ts +1 -1
  33. package/lib/theme/ColorModeToggle/index.js +85 -27
  34. package/lib/theme/ColorModeToggle/styles.module.css +7 -2
  35. package/lib/theme/DocBreadcrumbs/StructuredData/index.d.ts +9 -0
  36. package/lib/theme/DocBreadcrumbs/StructuredData/index.js +21 -0
  37. package/lib/theme/DocBreadcrumbs/index.js +36 -54
  38. package/lib/theme/DocCard/index.js +6 -4
  39. package/lib/theme/DocCardList/index.js +12 -6
  40. package/lib/theme/DocCardList/styles.module.css +14 -0
  41. package/lib/theme/DocCategoryGeneratedIndexPage/index.js +1 -1
  42. package/lib/theme/DocCategoryGeneratedIndexPage/styles.module.css +0 -8
  43. package/lib/theme/DocItem/Paginator/index.js +7 -1
  44. package/lib/theme/DocPaginator/index.js +3 -2
  45. package/lib/theme/DocSidebarItem/Category/index.js +8 -1
  46. package/lib/theme/Footer/Layout/index.js +2 -1
  47. package/lib/theme/Footer/Links/MultiColumn/index.js +7 -1
  48. package/lib/theme/Icon/ExternalLink/index.js +4 -5
  49. package/lib/theme/Icon/SystemColorMode/index.d.ts +9 -0
  50. package/lib/theme/Icon/SystemColorMode/index.js +16 -0
  51. package/lib/theme/Layout/index.js +1 -0
  52. package/lib/theme/Navbar/ColorModeToggle/index.js +5 -4
  53. package/lib/theme/Navbar/Content/index.js +20 -3
  54. package/lib/theme/Navbar/Content/styles.module.css +8 -0
  55. package/lib/theme/Navbar/Layout/index.js +2 -1
  56. package/lib/theme/Navbar/MobileSidebar/Layout/index.js +35 -4
  57. package/lib/theme/NavbarItem/DefaultNavbarItem/Desktop/index.d.ts +9 -0
  58. package/lib/theme/NavbarItem/DefaultNavbarItem/Desktop/index.js +29 -0
  59. package/lib/theme/NavbarItem/DefaultNavbarItem/Mobile/index.d.ts +9 -0
  60. package/lib/theme/NavbarItem/DefaultNavbarItem/Mobile/index.js +20 -0
  61. package/lib/theme/NavbarItem/DefaultNavbarItem/index.js +25 -0
  62. package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.d.ts +1 -1
  63. package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +50 -7
  64. package/lib/theme/NavbarItem/DropdownNavbarItem/Desktop/index.d.ts +9 -0
  65. package/lib/theme/NavbarItem/DropdownNavbarItem/Desktop/index.js +74 -0
  66. package/lib/theme/NavbarItem/DropdownNavbarItem/Mobile/index.d.ts +10 -0
  67. package/lib/theme/NavbarItem/DropdownNavbarItem/Mobile/index.js +142 -0
  68. package/lib/theme/NavbarItem/DropdownNavbarItem/index.js +3 -142
  69. package/lib/theme/Tag/index.js +1 -0
  70. package/lib/theme/ThemeProvider/TitleFormatter/index.d.ts +9 -0
  71. package/lib/theme/ThemeProvider/TitleFormatter/index.js +19 -0
  72. package/lib/theme/ThemeProvider/index.d.ts +9 -0
  73. package/lib/theme/ThemeProvider/index.js +11 -0
  74. package/package.json +15 -15
  75. package/src/getSwizzleConfig.ts +1 -1
  76. package/src/index.ts +9 -0
  77. package/src/inlineScripts.ts +6 -27
  78. package/src/inlineSvgSprites.ts +12 -0
  79. package/src/options.ts +15 -0
  80. package/src/theme/AnnouncementBar/index.tsx +6 -2
  81. package/src/theme/CodeBlock/Buttons/Button/index.tsx +19 -0
  82. package/src/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/index.tsx +42 -26
  83. package/src/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/index.tsx +15 -12
  84. package/src/theme/CodeBlock/Buttons/index.tsx +32 -0
  85. package/src/theme/CodeBlock/Buttons/styles.module.css +37 -0
  86. package/src/theme/CodeBlock/Content/Element.tsx +4 -2
  87. package/src/theme/CodeBlock/Content/String.tsx +24 -101
  88. package/src/theme/CodeBlock/Content/index.tsx +84 -0
  89. package/src/theme/CodeBlock/Content/styles.module.css +0 -52
  90. package/src/theme/CodeBlock/Layout/index.tsx +34 -0
  91. package/src/theme/CodeBlock/Layout/styles.module.css +27 -0
  92. package/src/theme/CodeBlock/Line/Token/index.tsx +18 -0
  93. package/src/theme/CodeBlock/Line/index.tsx +26 -7
  94. package/src/theme/CodeBlock/Title/index.tsx +15 -0
  95. package/src/theme/ColorModeToggle/index.tsx +102 -32
  96. package/src/theme/ColorModeToggle/styles.module.css +7 -2
  97. package/src/theme/DocBreadcrumbs/StructuredData/index.tsx +24 -0
  98. package/src/theme/DocBreadcrumbs/index.tsx +35 -57
  99. package/src/theme/DocCard/index.tsx +8 -2
  100. package/src/theme/DocCardList/index.tsx +18 -7
  101. package/src/theme/DocCardList/styles.module.css +14 -0
  102. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +1 -1
  103. package/src/theme/DocCategoryGeneratedIndexPage/styles.module.css +0 -8
  104. package/src/theme/DocItem/Paginator/index.tsx +7 -1
  105. package/src/theme/DocPaginator/index.tsx +3 -2
  106. package/src/theme/DocSidebarItem/Category/index.tsx +8 -1
  107. package/src/theme/Footer/Layout/index.tsx +2 -1
  108. package/src/theme/Footer/Links/MultiColumn/index.tsx +7 -1
  109. package/src/theme/Icon/ExternalLink/index.tsx +5 -5
  110. package/src/theme/Icon/SystemColorMode/index.tsx +20 -0
  111. package/src/theme/Layout/index.tsx +1 -0
  112. package/src/theme/Navbar/ColorModeToggle/index.tsx +5 -4
  113. package/src/theme/Navbar/Content/index.tsx +20 -3
  114. package/src/theme/Navbar/Content/styles.module.css +8 -0
  115. package/src/theme/Navbar/Layout/index.tsx +2 -1
  116. package/src/theme/Navbar/MobileSidebar/Layout/index.tsx +43 -4
  117. package/src/theme/NavbarItem/DefaultNavbarItem/Desktop/index.tsx +34 -0
  118. package/src/theme/NavbarItem/DefaultNavbarItem/Mobile/index.tsx +23 -0
  119. package/src/theme/NavbarItem/DefaultNavbarItem/index.tsx +28 -0
  120. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +87 -9
  121. package/src/theme/NavbarItem/DropdownNavbarItem/Desktop/index.tsx +86 -0
  122. package/src/theme/NavbarItem/DropdownNavbarItem/Mobile/index.tsx +166 -0
  123. package/src/theme/NavbarItem/DropdownNavbarItem/index.tsx +4 -168
  124. package/src/theme/Tag/index.tsx +1 -0
  125. package/src/theme/ThemeProvider/TitleFormatter/index.tsx +27 -0
  126. package/src/theme/ThemeProvider/index.tsx +14 -0
  127. package/src/theme-classic.d.ts +175 -20
  128. package/lib/theme/NavbarItem/DefaultNavbarItem.js +0 -52
  129. package/src/theme/NavbarItem/DefaultNavbarItem.tsx +0 -66
  130. /package/lib/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/styles.module.css +0 -0
  131. /package/lib/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/styles.module.css +0 -0
  132. /package/lib/theme/NavbarItem/{DefaultNavbarItem.d.ts → DefaultNavbarItem/index.d.ts} +0 -0
  133. /package/lib/theme/NavbarItem/DropdownNavbarItem/{styles.module.css → Mobile/styles.module.css} +0 -0
  134. /package/src/theme/CodeBlock/{CopyButton → Buttons/CopyButton}/styles.module.css +0 -0
  135. /package/src/theme/CodeBlock/{WordWrapButton → Buttons/WordWrapButton}/styles.module.css +0 -0
  136. /package/src/theme/NavbarItem/DropdownNavbarItem/{styles.module.css → Mobile/styles.module.css} +0 -0
@@ -5,33 +5,12 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- .codeBlockContent {
9
- position: relative;
10
- /* rtl:ignore */
11
- direction: ltr;
12
- border-radius: inherit;
13
- }
14
-
15
- .codeBlockTitle {
16
- border-bottom: 1px solid var(--ifm-color-emphasis-300);
17
- font-size: var(--ifm-code-font-size);
18
- font-weight: 500;
19
- padding: 0.75rem var(--ifm-pre-padding);
20
- border-top-left-radius: inherit;
21
- border-top-right-radius: inherit;
22
- }
23
-
24
8
  .codeBlock {
25
9
  --ifm-pre-background: var(--prism-background-color);
26
10
  margin: 0;
27
11
  padding: 0;
28
12
  }
29
13
 
30
- .codeBlockTitle + .codeBlockContent .codeBlock {
31
- border-top-left-radius: 0;
32
- border-top-right-radius: 0;
33
- }
34
-
35
14
  .codeBlockStandalone {
36
15
  padding: 0;
37
16
  }
@@ -54,34 +33,3 @@
54
33
  white-space: pre-wrap;
55
34
  }
56
35
  }
57
-
58
- .buttonGroup {
59
- display: flex;
60
- column-gap: 0.2rem;
61
- position: absolute;
62
- /* rtl:ignore */
63
- right: calc(var(--ifm-pre-padding) / 2);
64
- top: calc(var(--ifm-pre-padding) / 2);
65
- }
66
-
67
- .buttonGroup button {
68
- display: flex;
69
- align-items: center;
70
- background: var(--prism-background-color);
71
- color: var(--prism-color);
72
- border: 1px solid var(--ifm-color-emphasis-300);
73
- border-radius: var(--ifm-global-radius);
74
- padding: 0.4rem;
75
- line-height: 0;
76
- transition: opacity var(--ifm-transition-fast) ease-in-out;
77
- opacity: 0;
78
- }
79
-
80
- .buttonGroup button:focus-visible,
81
- .buttonGroup button:hover {
82
- opacity: 1 !important;
83
- }
84
-
85
- :global(.theme-code-block:hover) .buttonGroup button {
86
- opacity: 0.4;
87
- }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import type { Props } from '@theme/CodeBlock/Layout';
9
+ export default function CodeBlockLayout({ className }: Props): ReactNode;
@@ -0,0 +1,30 @@
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 {useCodeBlockContext} from '@docusaurus/theme-common/internal';
10
+ import Container from '@theme/CodeBlock/Container';
11
+ import Title from '@theme/CodeBlock/Title';
12
+ import Content from '@theme/CodeBlock/Content';
13
+ import Buttons from '@theme/CodeBlock/Buttons';
14
+ import styles from './styles.module.css';
15
+ export default function CodeBlockLayout({className}) {
16
+ const {metadata} = useCodeBlockContext();
17
+ return (
18
+ <Container as="div" className={clsx(className, metadata.className)}>
19
+ {metadata.title && (
20
+ <div className={styles.codeBlockTitle}>
21
+ <Title>{metadata.title}</Title>
22
+ </div>
23
+ )}
24
+ <div className={styles.codeBlockContent}>
25
+ <Content />
26
+ <Buttons />
27
+ </div>
28
+ </Container>
29
+ );
30
+ }
@@ -0,0 +1,27 @@
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
+ .codeBlockContent {
9
+ position: relative;
10
+ /* rtl:ignore */
11
+ direction: ltr;
12
+ border-radius: inherit;
13
+ }
14
+
15
+ .codeBlockTitle {
16
+ border-bottom: 1px solid var(--ifm-color-emphasis-300);
17
+ font-size: var(--ifm-code-font-size);
18
+ font-weight: 500;
19
+ padding: 0.75rem var(--ifm-pre-padding);
20
+ border-top-left-radius: inherit;
21
+ border-top-right-radius: inherit;
22
+ }
23
+
24
+ .codeBlockTitle + .codeBlockContent .codeBlock {
25
+ border-top-left-radius: 0;
26
+ border-top-right-radius: 0;
27
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import type { Props } from '@theme/CodeBlock/Line/Token';
9
+ export default function CodeBlockLineToken({ line, token, ...props }: Props): ReactNode;
@@ -0,0 +1,11 @@
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
+ // Pass-through components that users can swizzle and customize
9
+ export default function CodeBlockLineToken({line, token, ...props}) {
10
+ return <span {...props} />;
11
+ }
@@ -6,4 +6,4 @@
6
6
  */
7
7
  import { type ReactNode } from 'react';
8
8
  import type { Props } from '@theme/CodeBlock/Line';
9
- export default function CodeBlockLine({ line, classNames, showLineNumbers, getLineProps, getTokenProps, }: Props): ReactNode;
9
+ export default function CodeBlockLine({ line: lineProp, classNames, showLineNumbers, getLineProps, getTokenProps, }: Props): ReactNode;
@@ -6,24 +6,38 @@
6
6
  */
7
7
  import React from 'react';
8
8
  import clsx from 'clsx';
9
+ import LineToken from '@theme/CodeBlock/Line/Token';
9
10
  import styles from './styles.module.css';
11
+ // Replaces '\n' by ''
12
+ // Historical code, not sure why we even need this :/
13
+ function fixLineBreak(line) {
14
+ const singleLineBreakToken =
15
+ line.length === 1 && line[0].content === '\n' ? line[0] : undefined;
16
+ if (singleLineBreakToken) {
17
+ return [{...singleLineBreakToken, content: ''}];
18
+ }
19
+ return line;
20
+ }
10
21
  export default function CodeBlockLine({
11
- line,
22
+ line: lineProp,
12
23
  classNames,
13
24
  showLineNumbers,
14
25
  getLineProps,
15
26
  getTokenProps,
16
27
  }) {
17
- if (line.length === 1 && line[0].content === '\n') {
18
- line[0].content = '';
19
- }
28
+ const line = fixLineBreak(lineProp);
20
29
  const lineProps = getLineProps({
21
30
  line,
22
31
  className: clsx(classNames, showLineNumbers && styles.codeLine),
23
32
  });
24
- const lineTokens = line.map((token, key) => (
25
- <span key={key} {...getTokenProps({token})} />
26
- ));
33
+ const lineTokens = line.map((token, key) => {
34
+ const tokenProps = getTokenProps({token});
35
+ return (
36
+ <LineToken key={key} {...tokenProps} line={line} token={token}>
37
+ {tokenProps.children}
38
+ </LineToken>
39
+ );
40
+ });
27
41
  return (
28
42
  <span {...lineProps}>
29
43
  {showLineNumbers ? (
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { ReactNode } from 'react';
8
+ import type { Props } from '@theme/CodeBlock/Title';
9
+ export default function CodeBlockTitle({ children }: Props): ReactNode;
@@ -0,0 +1,10 @@
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
+ // Just a pass-through component that users can swizzle and customize
8
+ export default function CodeBlockTitle({children}) {
9
+ return children;
10
+ }
@@ -6,6 +6,6 @@
6
6
  */
7
7
  import React, { type ReactNode } from 'react';
8
8
  import type { Props } from '@theme/ColorModeToggle';
9
- declare function ColorModeToggle({ className, buttonClassName, value, onChange, }: Props): ReactNode;
9
+ declare function ColorModeToggle({ className, buttonClassName, respectPrefersColorScheme, value, onChange, }: Props): ReactNode;
10
10
  declare const _default: React.MemoExoticComponent<typeof ColorModeToggle>;
11
11
  export default _default;
@@ -10,30 +10,93 @@ import useIsBrowser from '@docusaurus/useIsBrowser';
10
10
  import {translate} from '@docusaurus/Translate';
11
11
  import IconLightMode from '@theme/Icon/LightMode';
12
12
  import IconDarkMode from '@theme/Icon/DarkMode';
13
+ import IconSystemColorMode from '@theme/Icon/SystemColorMode';
13
14
  import styles from './styles.module.css';
14
- function ColorModeToggle({className, buttonClassName, value, onChange}) {
15
- const isBrowser = useIsBrowser();
16
- const title = translate(
15
+ // The order of color modes is defined here, and can be customized with swizzle
16
+ function getNextColorMode(colorMode, respectPrefersColorScheme) {
17
+ // 2-value transition
18
+ if (!respectPrefersColorScheme) {
19
+ return colorMode === 'dark' ? 'light' : 'dark';
20
+ }
21
+ // 3-value transition
22
+ switch (colorMode) {
23
+ case null:
24
+ return 'light';
25
+ case 'light':
26
+ return 'dark';
27
+ case 'dark':
28
+ return null;
29
+ default:
30
+ throw new Error(`unexpected color mode ${colorMode}`);
31
+ }
32
+ }
33
+ function getColorModeLabel(colorMode) {
34
+ switch (colorMode) {
35
+ case null:
36
+ return translate({
37
+ message: 'system mode',
38
+ id: 'theme.colorToggle.ariaLabel.mode.system',
39
+ description: 'The name for the system color mode',
40
+ });
41
+ case 'light':
42
+ return translate({
43
+ message: 'light mode',
44
+ id: 'theme.colorToggle.ariaLabel.mode.light',
45
+ description: 'The name for the light color mode',
46
+ });
47
+ case 'dark':
48
+ return translate({
49
+ message: 'dark mode',
50
+ id: 'theme.colorToggle.ariaLabel.mode.dark',
51
+ description: 'The name for the dark color mode',
52
+ });
53
+ default:
54
+ throw new Error(`unexpected color mode ${colorMode}`);
55
+ }
56
+ }
57
+ function getColorModeAriaLabel(colorMode) {
58
+ return translate(
17
59
  {
18
60
  message: 'Switch between dark and light mode (currently {mode})',
19
61
  id: 'theme.colorToggle.ariaLabel',
20
- description: 'The ARIA label for the navbar color mode toggle',
62
+ description: 'The ARIA label for the color mode toggle',
21
63
  },
22
64
  {
23
- mode:
24
- value === 'dark'
25
- ? translate({
26
- message: 'dark mode',
27
- id: 'theme.colorToggle.ariaLabel.mode.dark',
28
- description: 'The name for the dark color mode',
29
- })
30
- : translate({
31
- message: 'light mode',
32
- id: 'theme.colorToggle.ariaLabel.mode.light',
33
- description: 'The name for the light color mode',
34
- }),
65
+ mode: getColorModeLabel(colorMode),
35
66
  },
36
67
  );
68
+ }
69
+ function CurrentColorModeIcon() {
70
+ // 3 icons are always rendered for technical reasons
71
+ // We use "data-theme-choice" to render the correct one
72
+ // This must work even before React hydrates
73
+ return (
74
+ <>
75
+ <IconLightMode
76
+ // a18y is handled at the button level,
77
+ // not relying on button content (svg icons)
78
+ aria-hidden
79
+ className={clsx(styles.toggleIcon, styles.lightToggleIcon)}
80
+ />
81
+ <IconDarkMode
82
+ aria-hidden
83
+ className={clsx(styles.toggleIcon, styles.darkToggleIcon)}
84
+ />
85
+ <IconSystemColorMode
86
+ aria-hidden
87
+ className={clsx(styles.toggleIcon, styles.systemToggleIcon)}
88
+ />
89
+ </>
90
+ );
91
+ }
92
+ function ColorModeToggle({
93
+ className,
94
+ buttonClassName,
95
+ respectPrefersColorScheme,
96
+ value,
97
+ onChange,
98
+ }) {
99
+ const isBrowser = useIsBrowser();
37
100
  return (
38
101
  <div className={clsx(styles.toggle, className)}>
39
102
  <button
@@ -44,18 +107,13 @@ function ColorModeToggle({className, buttonClassName, value, onChange}) {
44
107
  buttonClassName,
45
108
  )}
46
109
  type="button"
47
- onClick={() => onChange(value === 'dark' ? 'light' : 'dark')}
110
+ onClick={() =>
111
+ onChange(getNextColorMode(value, respectPrefersColorScheme))
112
+ }
48
113
  disabled={!isBrowser}
49
- title={title}
50
- aria-label={title}
51
- aria-live="polite"
52
- aria-pressed={value === 'dark' ? 'true' : 'false'}>
53
- <IconLightMode
54
- className={clsx(styles.toggleIcon, styles.lightToggleIcon)}
55
- />
56
- <IconDarkMode
57
- className={clsx(styles.toggleIcon, styles.darkToggleIcon)}
58
- />
114
+ title={getColorModeLabel(value)}
115
+ aria-label={getColorModeAriaLabel(value)}>
116
+ <CurrentColorModeIcon />
59
117
  </button>
60
118
  </div>
61
119
  );
@@ -25,11 +25,16 @@
25
25
  background: var(--ifm-color-emphasis-200);
26
26
  }
27
27
 
28
- [data-theme='light'] .darkToggleIcon,
29
- [data-theme='dark'] .lightToggleIcon {
28
+ .toggleIcon {
30
29
  display: none;
31
30
  }
32
31
 
32
+ [data-theme-choice='system'] .systemToggleIcon,
33
+ [data-theme-choice='light'] .lightToggleIcon,
34
+ [data-theme-choice='dark'] .darkToggleIcon {
35
+ display: initial;
36
+ }
37
+
33
38
  .toggleButtonDisabled {
34
39
  cursor: not-allowed;
35
40
  }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import { type ReactNode } from 'react';
8
+ import type { Props } from '@theme/DocBreadcrumbs/StructuredData';
9
+ export default function DocBreadcrumbsStructuredData(props: Props): ReactNode;
@@ -0,0 +1,21 @@
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 Head from '@docusaurus/Head';
9
+ import {useBreadcrumbsStructuredData} from '@docusaurus/plugin-content-docs/client';
10
+ export default function DocBreadcrumbsStructuredData(props) {
11
+ const structuredData = useBreadcrumbsStructuredData({
12
+ breadcrumbs: props.breadcrumbs,
13
+ });
14
+ return (
15
+ <Head>
16
+ <script type="application/ld+json">
17
+ {JSON.stringify(structuredData)}
18
+ </script>
19
+ </Head>
20
+ );
21
+ }
@@ -12,44 +12,30 @@ import {useHomePageRoute} from '@docusaurus/theme-common/internal';
12
12
  import Link from '@docusaurus/Link';
13
13
  import {translate} from '@docusaurus/Translate';
14
14
  import HomeBreadcrumbItem from '@theme/DocBreadcrumbs/Items/Home';
15
+ import DocBreadcrumbsStructuredData from '@theme/DocBreadcrumbs/StructuredData';
15
16
  import styles from './styles.module.css';
16
17
  // TODO move to design system folder
17
18
  function BreadcrumbsItemLink({children, href, isLast}) {
18
19
  const className = 'breadcrumbs__link';
19
20
  if (isLast) {
20
- return (
21
- <span className={className} itemProp="name">
22
- {children}
23
- </span>
24
- );
21
+ return <span className={className}>{children}</span>;
25
22
  }
26
23
  return href ? (
27
- <Link className={className} href={href} itemProp="item">
28
- <span itemProp="name">{children}</span>
24
+ <Link className={className} href={href}>
25
+ <span>{children}</span>
29
26
  </Link>
30
27
  ) : (
31
- // TODO Google search console doesn't like breadcrumb items without href.
32
- // The schema doesn't seem to require `id` for each `item`, although Google
33
- // insist to infer one, even if it's invalid. Removing `itemProp="item
34
- // name"` for now, since I don't know how to properly fix it.
35
- // See https://github.com/facebook/docusaurus/issues/7241
36
28
  <span className={className}>{children}</span>
37
29
  );
38
30
  }
39
31
  // TODO move to design system folder
40
- function BreadcrumbsItem({children, active, index, addMicrodata}) {
32
+ function BreadcrumbsItem({children, active}) {
41
33
  return (
42
34
  <li
43
- {...(addMicrodata && {
44
- itemScope: true,
45
- itemProp: 'itemListElement',
46
- itemType: 'https://schema.org/ListItem',
47
- })}
48
35
  className={clsx('breadcrumbs__item', {
49
36
  'breadcrumbs__item--active': active,
50
37
  })}>
51
38
  {children}
52
- <meta itemProp="position" content={String(index + 1)} />
53
39
  </li>
54
40
  );
55
41
  }
@@ -60,40 +46,36 @@ export default function DocBreadcrumbs() {
60
46
  return null;
61
47
  }
62
48
  return (
63
- <nav
64
- className={clsx(
65
- ThemeClassNames.docs.docBreadcrumbs,
66
- styles.breadcrumbsContainer,
67
- )}
68
- aria-label={translate({
69
- id: 'theme.docs.breadcrumbs.navAriaLabel',
70
- message: 'Breadcrumbs',
71
- description: 'The ARIA label for the breadcrumbs',
72
- })}>
73
- <ul
74
- className="breadcrumbs"
75
- itemScope
76
- itemType="https://schema.org/BreadcrumbList">
77
- {homePageRoute && <HomeBreadcrumbItem />}
78
- {breadcrumbs.map((item, idx) => {
79
- const isLast = idx === breadcrumbs.length - 1;
80
- const href =
81
- item.type === 'category' && item.linkUnlisted
82
- ? undefined
83
- : item.href;
84
- return (
85
- <BreadcrumbsItem
86
- key={idx}
87
- active={isLast}
88
- index={idx}
89
- addMicrodata={!!href}>
90
- <BreadcrumbsItemLink href={href} isLast={isLast}>
91
- {item.label}
92
- </BreadcrumbsItemLink>
93
- </BreadcrumbsItem>
94
- );
95
- })}
96
- </ul>
97
- </nav>
49
+ <>
50
+ <DocBreadcrumbsStructuredData breadcrumbs={breadcrumbs} />
51
+ <nav
52
+ className={clsx(
53
+ ThemeClassNames.docs.docBreadcrumbs,
54
+ styles.breadcrumbsContainer,
55
+ )}
56
+ aria-label={translate({
57
+ id: 'theme.docs.breadcrumbs.navAriaLabel',
58
+ message: 'Breadcrumbs',
59
+ description: 'The ARIA label for the breadcrumbs',
60
+ })}>
61
+ <ul className="breadcrumbs">
62
+ {homePageRoute && <HomeBreadcrumbItem />}
63
+ {breadcrumbs.map((item, idx) => {
64
+ const isLast = idx === breadcrumbs.length - 1;
65
+ const href =
66
+ item.type === 'category' && item.linkUnlisted
67
+ ? undefined
68
+ : item.href;
69
+ return (
70
+ <BreadcrumbsItem key={idx} active={isLast}>
71
+ <BreadcrumbsItemLink href={href} isLast={isLast}>
72
+ {item.label}
73
+ </BreadcrumbsItemLink>
74
+ </BreadcrumbsItem>
75
+ );
76
+ })}
77
+ </ul>
78
+ </nav>
79
+ </>
98
80
  );
99
81
  }
@@ -32,18 +32,18 @@ function useCategoryItemsPlural() {
32
32
  ),
33
33
  );
34
34
  }
35
- function CardContainer({href, children}) {
35
+ function CardContainer({className, href, children}) {
36
36
  return (
37
37
  <Link
38
38
  href={href}
39
- className={clsx('card padding--lg', styles.cardContainer)}>
39
+ className={clsx('card padding--lg', styles.cardContainer, className)}>
40
40
  {children}
41
41
  </Link>
42
42
  );
43
43
  }
44
- function CardLayout({href, icon, title, description}) {
44
+ function CardLayout({className, href, icon, title, description}) {
45
45
  return (
46
- <CardContainer href={href}>
46
+ <CardContainer href={href} className={className}>
47
47
  <Heading
48
48
  as="h2"
49
49
  className={clsx('text--truncate', styles.cardTitle)}
@@ -69,6 +69,7 @@ function CardCategory({item}) {
69
69
  }
70
70
  return (
71
71
  <CardLayout
72
+ className={item.className}
72
73
  href={href}
73
74
  icon="🗃️"
74
75
  title={item.label}
@@ -81,6 +82,7 @@ function CardLink({item}) {
81
82
  const doc = useDocById(item.docId ?? undefined);
82
83
  return (
83
84
  <CardLayout
85
+ className={item.className}
84
86
  href={item.href}
85
87
  icon={icon}
86
88
  title={item.label}
@@ -7,13 +7,21 @@
7
7
  import React from 'react';
8
8
  import clsx from 'clsx';
9
9
  import {
10
- useCurrentSidebarCategory,
10
+ useCurrentSidebarSiblings,
11
11
  filterDocCardListItems,
12
12
  } from '@docusaurus/plugin-content-docs/client';
13
13
  import DocCard from '@theme/DocCard';
14
+ import styles from './styles.module.css';
14
15
  function DocCardListForCurrentSidebarCategory({className}) {
15
- const category = useCurrentSidebarCategory();
16
- return <DocCardList items={category.items} className={className} />;
16
+ const items = useCurrentSidebarSiblings();
17
+ return <DocCardList items={items} className={className} />;
18
+ }
19
+ function DocCardListItem({item}) {
20
+ return (
21
+ <article className={clsx(styles.docCardListItem, 'col col--6')}>
22
+ <DocCard item={item} />
23
+ </article>
24
+ );
17
25
  }
18
26
  export default function DocCardList(props) {
19
27
  const {items, className} = props;
@@ -24,9 +32,7 @@ export default function DocCardList(props) {
24
32
  return (
25
33
  <section className={clsx('row', className)}>
26
34
  {filteredItems.map((item, index) => (
27
- <article key={index} className="col col--6 margin-bottom--lg">
28
- <DocCard item={item} />
29
- </article>
35
+ <DocCardListItem key={index} item={item} />
30
36
  ))}
31
37
  </section>
32
38
  );
@@ -0,0 +1,14 @@
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
+ .docCardListItem {
9
+ margin-bottom: 2rem;
10
+ }
11
+
12
+ .docCardListItem > * {
13
+ height: 100%;
14
+ }
@@ -44,7 +44,7 @@ function DocCategoryGeneratedIndexPageContent({categoryGeneratedIndex}) {
44
44
  <article className="margin-top--lg">
45
45
  <DocCardList items={category.items} className={styles.list} />
46
46
  </article>
47
- <footer className="margin-top--lg">
47
+ <footer className="margin-top--md">
48
48
  <DocPaginator
49
49
  previous={categoryGeneratedIndex.navigation.previous}
50
50
  next={categoryGeneratedIndex.navigation.next}