@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
@@ -6,201 +6,27 @@
6
6
  */
7
7
 
8
8
  import React from 'react';
9
- import clsx from 'clsx';
10
9
 
11
- import Link from '@docusaurus/Link';
12
- import {
13
- type FooterLinkItem,
14
- useThemeConfig,
15
- type MultiColumnFooter,
16
- type SimpleFooter,
17
- } from '@docusaurus/theme-common';
18
- import useBaseUrl from '@docusaurus/useBaseUrl';
19
- import isInternalUrl from '@docusaurus/isInternalUrl';
20
- import styles from './styles.module.css';
21
- import ThemedImage, {type Props as ThemedImageProps} from '@theme/ThemedImage';
22
- import IconExternalLink from '@theme/IconExternalLink';
23
-
24
- function FooterLink({
25
- to,
26
- href,
27
- label,
28
- prependBaseUrlToHref,
29
- ...props
30
- }: FooterLinkItem) {
31
- const toUrl = useBaseUrl(to);
32
- const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
33
-
34
- return (
35
- <Link
36
- className="footer__link-item"
37
- {...(href
38
- ? {
39
- href: prependBaseUrlToHref ? normalizedHref : href,
40
- }
41
- : {
42
- to: toUrl,
43
- })}
44
- {...props}>
45
- {href && !isInternalUrl(href) ? (
46
- <span>
47
- {label}
48
- <IconExternalLink />
49
- </span>
50
- ) : (
51
- label
52
- )}
53
- </Link>
54
- );
55
- }
56
-
57
- function FooterLogo({
58
- sources,
59
- alt,
60
- width,
61
- height,
62
- }: Pick<ThemedImageProps, 'sources' | 'alt' | 'width' | 'height'>) {
63
- return (
64
- <ThemedImage
65
- className="footer__logo"
66
- alt={alt}
67
- sources={sources}
68
- width={width}
69
- height={height}
70
- />
71
- );
72
- }
73
-
74
- function MultiColumnLinks({links}: {links: MultiColumnFooter['links']}) {
75
- return (
76
- <>
77
- {links.map((linkItem, i) => (
78
- <div key={i} className="col footer__col">
79
- <div className="footer__title">{linkItem.title}</div>
80
- <ul className="footer__items">
81
- {linkItem.items.map((item, key) =>
82
- item.html ? (
83
- <li
84
- key={key}
85
- className="footer__item"
86
- // Developer provided the HTML, so assume it's safe.
87
- // eslint-disable-next-line react/no-danger
88
- dangerouslySetInnerHTML={{
89
- __html: item.html,
90
- }}
91
- />
92
- ) : (
93
- <li key={item.href || item.to} className="footer__item">
94
- <FooterLink {...item} />
95
- </li>
96
- ),
97
- )}
98
- </ul>
99
- </div>
100
- ))}
101
- </>
102
- );
103
- }
104
-
105
- function SimpleLinks({links}: {links: SimpleFooter['links']}) {
106
- return (
107
- <div className="footer__links">
108
- {links.map((item, key) => (
109
- <React.Fragment key={key}>
110
- {item.html ? (
111
- <span
112
- className="footer__link-item"
113
- // Developer provided the HTML, so assume it's safe.
114
- // eslint-disable-next-line react/no-danger
115
- dangerouslySetInnerHTML={{
116
- __html: item.html,
117
- }}
118
- />
119
- ) : (
120
- <FooterLink {...item} />
121
- )}
122
- {links.length !== key + 1 && (
123
- <span className="footer__link-separator">·</span>
124
- )}
125
- </React.Fragment>
126
- ))}
127
- </div>
128
- );
129
- }
130
-
131
- function isMultiColumnFooterLinks(
132
- links: MultiColumnFooter['links'] | SimpleFooter['links'],
133
- ): links is MultiColumnFooter['links'] {
134
- return 'title' in links[0];
135
- }
10
+ import {useThemeConfig} from '@docusaurus/theme-common';
11
+ import FooterLinks from '@theme/Footer/Links';
12
+ import FooterLogo from '@theme/Footer/Logo';
13
+ import FooterCopyright from '@theme/Footer/Copyright';
14
+ import FooterLayout from '@theme/Footer/Layout';
136
15
 
137
16
  function Footer(): JSX.Element | null {
138
17
  const {footer} = useThemeConfig();
139
-
140
- const {copyright, links = [], logo = {}} = footer || {};
141
- const sources = {
142
- light: useBaseUrl(logo.src),
143
- dark: useBaseUrl(logo.srcDark || logo.src),
144
- };
145
-
146
18
  if (!footer) {
147
19
  return null;
148
20
  }
21
+ const {copyright, links, logo, style} = footer;
149
22
 
150
23
  return (
151
- <footer
152
- className={clsx('footer', {
153
- 'footer--dark': footer.style === 'dark',
154
- })}>
155
- <div className="container container-fluid">
156
- {links &&
157
- links.length > 0 &&
158
- (isMultiColumnFooterLinks(links) ? (
159
- <div className="row footer__links">
160
- <MultiColumnLinks links={links} />
161
- </div>
162
- ) : (
163
- <div className="footer__links text--center">
164
- <SimpleLinks links={links} />
165
- </div>
166
- ))}
167
- {(logo || copyright) && (
168
- <div className="footer__bottom text--center">
169
- {logo && (logo.src || logo.srcDark) && (
170
- <div className="margin-bottom--sm">
171
- {logo.href ? (
172
- <Link href={logo.href} className={styles.footerLogoLink}>
173
- <FooterLogo
174
- alt={logo.alt}
175
- sources={sources}
176
- width={logo.width}
177
- height={logo.height}
178
- />
179
- </Link>
180
- ) : (
181
- <FooterLogo
182
- alt={logo.alt}
183
- sources={sources}
184
- width={logo.width}
185
- height={logo.height}
186
- />
187
- )}
188
- </div>
189
- )}
190
- {copyright ? (
191
- <div
192
- className="footer__copyright"
193
- // Developer provided the HTML, so assume it's safe.
194
- // eslint-disable-next-line react/no-danger
195
- dangerouslySetInnerHTML={{
196
- __html: copyright,
197
- }}
198
- />
199
- ) : null}
200
- </div>
201
- )}
202
- </div>
203
- </footer>
24
+ <FooterLayout
25
+ style={style}
26
+ links={links && links.length > 0 && <FooterLinks links={links} />}
27
+ logo={logo && <FooterLogo logo={logo} />}
28
+ copyright={copyright && <FooterCopyright copyright={copyright} />}
29
+ />
204
30
  );
205
31
  }
206
32
 
@@ -25,10 +25,12 @@ function AnchorHeading({as: As, id, ...props}: Props) {
25
25
  return (
26
26
  <As
27
27
  {...props}
28
- className={clsx('anchor', {
29
- [styles.anchorWithHideOnScrollNavbar]: hideOnScroll,
30
- [styles.anchorWithStickyNavbar]: !hideOnScroll,
31
- })}
28
+ className={clsx(
29
+ 'anchor',
30
+ hideOnScroll
31
+ ? styles.anchorWithHideOnScrollNavbar
32
+ : styles.anchorWithStickyNavbar,
33
+ )}
32
34
  id={id}>
33
35
  {props.children}
34
36
  <a
@@ -7,6 +7,4 @@
7
7
 
8
8
  .iconExternalLink {
9
9
  margin-left: 0.3rem;
10
- position: relative;
11
- top: 1px;
12
10
  }
@@ -13,20 +13,30 @@ import AnnouncementBar from '@theme/AnnouncementBar';
13
13
  import Navbar from '@theme/Navbar';
14
14
  import Footer from '@theme/Footer';
15
15
  import LayoutProviders from '@theme/LayoutProviders';
16
- import LayoutHead from '@theme/LayoutHead';
17
16
  import type {Props} from '@theme/Layout';
18
- import {ThemeClassNames, useKeyboardNavigation} from '@docusaurus/theme-common';
17
+ import {
18
+ PageMetadata,
19
+ ThemeClassNames,
20
+ useKeyboardNavigation,
21
+ } from '@docusaurus/theme-common';
19
22
  import ErrorPageContent from '@theme/ErrorPageContent';
20
23
  import './styles.css';
21
24
 
22
25
  export default function Layout(props: Props): JSX.Element {
23
- const {children, noFooter, wrapperClassName, pageClassName} = props;
26
+ const {
27
+ children,
28
+ noFooter,
29
+ wrapperClassName,
30
+ // not really layout-related, but kept for convenience/retro-compatibility
31
+ title,
32
+ description,
33
+ } = props;
24
34
 
25
35
  useKeyboardNavigation();
26
36
 
27
37
  return (
28
38
  <LayoutProviders>
29
- <LayoutHead {...props} />
39
+ <PageMetadata title={title} description={description} />
30
40
 
31
41
  <SkipToContent />
32
42
 
@@ -34,12 +44,7 @@ export default function Layout(props: Props): JSX.Element {
34
44
 
35
45
  <Navbar />
36
46
 
37
- <div
38
- className={clsx(
39
- ThemeClassNames.wrapper.main,
40
- wrapperClassName,
41
- pageClassName,
42
- )}>
47
+ <div className={clsx(ThemeClassNames.wrapper.main, wrapperClassName)}>
43
48
  <ErrorBoundary fallback={ErrorPageContent}>{children}</ErrorBoundary>
44
49
  </div>
45
50
 
@@ -11,8 +11,9 @@ import {
11
11
  TabGroupChoiceProvider,
12
12
  AnnouncementBarProvider,
13
13
  DocsPreferredVersionContextProvider,
14
- MobileSecondaryMenuProvider,
15
14
  ScrollControllerProvider,
15
+ NavbarProvider,
16
+ PluginHtmlClassNameProvider,
16
17
  } from '@docusaurus/theme-common';
17
18
  import type {Props} from '@theme/LayoutProviders';
18
19
 
@@ -23,9 +24,9 @@ export default function LayoutProviders({children}: Props): JSX.Element {
23
24
  <TabGroupChoiceProvider>
24
25
  <ScrollControllerProvider>
25
26
  <DocsPreferredVersionContextProvider>
26
- <MobileSecondaryMenuProvider>
27
- {children}
28
- </MobileSecondaryMenuProvider>
27
+ <PluginHtmlClassNameProvider>
28
+ <NavbarProvider>{children}</NavbarProvider>
29
+ </PluginHtmlClassNameProvider>
29
30
  </DocsPreferredVersionContextProvider>
30
31
  </ScrollControllerProvider>
31
32
  </TabGroupChoiceProvider>
@@ -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
+ import React from 'react';
9
+ import Link from '@docusaurus/Link';
10
+ import type {Props} from '@theme/MDXComponents/A';
11
+
12
+ export default function MDXA(props: Props): JSX.Element {
13
+ return <Link {...props} />;
14
+ }
@@ -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 type {ComponentProps} from 'react';
9
+ import React, {isValidElement} from 'react';
10
+ import CodeBlock from '@theme/CodeBlock';
11
+ import type {Props} from '@theme/MDXComponents/Code';
12
+
13
+ export default function MDXCode(props: Props): JSX.Element {
14
+ const inlineElements = [
15
+ 'a',
16
+ 'b',
17
+ 'big',
18
+ 'i',
19
+ 'span',
20
+ 'em',
21
+ 'strong',
22
+ 'sup',
23
+ 'sub',
24
+ 'small',
25
+ ];
26
+ const shouldBeInline = React.Children.toArray(props.children).every(
27
+ (el) =>
28
+ (typeof el === 'string' && !el.includes('\n')) ||
29
+ (isValidElement(el) && inlineElements.includes(el.props.mdxType)),
30
+ );
31
+
32
+ return shouldBeInline ? (
33
+ <code {...props} />
34
+ ) : (
35
+ <CodeBlock {...(props as ComponentProps<typeof CodeBlock>)} />
36
+ );
37
+ }
@@ -0,0 +1,26 @@
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 ComponentProps, type ReactElement} from 'react';
9
+ import Details from '@theme/Details';
10
+ import type {Props} from '@theme/MDXComponents/Details';
11
+
12
+ export default function MDXDetails(props: Props): JSX.Element {
13
+ const items = React.Children.toArray(props.children) as ReactElement[];
14
+ // Split summary item from the rest to pass it as a separate prop to the
15
+ // Details theme component
16
+ const summary: ReactElement<ComponentProps<'summary'>> = items.find(
17
+ (item) => item?.props?.mdxType === 'summary',
18
+ )!;
19
+ const children = <>{items.filter((item) => item !== summary)}</>;
20
+
21
+ return (
22
+ <Details {...props} summary={summary}>
23
+ {children}
24
+ </Details>
25
+ );
26
+ }
@@ -0,0 +1,29 @@
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 ReactElement, type ComponentProps} from 'react';
9
+ import Head from '@docusaurus/Head';
10
+ import type {Props} from '@theme/MDXComponents/Head';
11
+
12
+ // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
13
+ // with Head/Helmet) we need to unwrap those elements.
14
+ function unwrapMDXElement(element: ReactElement) {
15
+ if (element?.props?.mdxType && element?.props?.originalType) {
16
+ const {mdxType, originalType, ...newProps} = element.props;
17
+ return React.createElement(element.props.originalType, newProps);
18
+ }
19
+ return element;
20
+ }
21
+
22
+ export default function MDXHead(props: Props): JSX.Element {
23
+ const unwrappedChildren = React.Children.map(props.children, (child) =>
24
+ unwrapMDXElement(child as ReactElement),
25
+ );
26
+ return (
27
+ <Head {...(props as ComponentProps<typeof Head>)}>{unwrappedChildren}</Head>
28
+ );
29
+ }
@@ -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
+ import React from 'react';
9
+ import Heading from '@theme/Heading';
10
+ import type {Props} from '@theme/MDXComponents/Heading';
11
+
12
+ export default function MDXHeading(props: Props): JSX.Element {
13
+ return <Heading {...props} />;
14
+ }
@@ -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
+
8
+ .img {
9
+ height: auto;
10
+ }
@@ -0,0 +1,26 @@
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 type {Props} from '@theme/MDXComponents/Img';
10
+ import styles from './Img.module.css';
11
+ import clsx from 'clsx';
12
+
13
+ function transformImgClassName(className?: string): string {
14
+ return clsx(className, styles.img);
15
+ }
16
+
17
+ export default function MDXImg(props: Props): JSX.Element {
18
+ return (
19
+ // eslint-disable-next-line jsx-a11y/alt-text
20
+ <img
21
+ loading="lazy"
22
+ {...props}
23
+ className={transformImgClassName(props.className)}
24
+ />
25
+ );
26
+ }
@@ -0,0 +1,22 @@
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, {isValidElement} from 'react';
9
+ import CodeBlock from '@theme/CodeBlock';
10
+ import type {Props} from '@theme/MDXComponents/Pre';
11
+
12
+ export default function MDXPre(props: Props): JSX.Element {
13
+ return (
14
+ <CodeBlock
15
+ // If this pre is created by a ``` fenced codeblock, unwrap the children
16
+ {...(isValidElement(props.children) &&
17
+ props.children.props.originalType === 'code'
18
+ ? props.children?.props
19
+ : {...props})}
20
+ />
21
+ );
22
+ }
@@ -5,11 +5,7 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- ul.contains-task-list {
8
+ .contains-task-list {
9
9
  padding-left: 0;
10
10
  list-style: none;
11
11
  }
12
-
13
- img {
14
- height: auto;
15
- }
@@ -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
+ import React from 'react';
9
+ import clsx from 'clsx';
10
+ import type {Props} from '@theme/MDXComponents/Ul';
11
+
12
+ import styles from './Ul.module.css';
13
+
14
+ const containsClassListLocalClass = styles['contains-task-list'];
15
+
16
+ function transformUlClassName(className?: string): string {
17
+ return clsx(
18
+ className,
19
+ // This class is set globally by GitHub/MDX
20
+ // We keep the global class, but apply scoped CSS
21
+ // See https://github.com/syntax-tree/mdast-util-to-hast/issues/28
22
+ className?.includes('contains-task-list') && containsClassListLocalClass,
23
+ );
24
+ }
25
+
26
+ export default function MDXUl(props: Props): JSX.Element {
27
+ return <ul {...props} className={transformUlClassName(props.className)} />;
28
+ }
@@ -5,89 +5,32 @@
5
5
  * LICENSE file in the root directory of this source tree.
6
6
  */
7
7
 
8
- import React, {
9
- type ComponentProps,
10
- isValidElement,
11
- type ReactElement,
12
- } from 'react';
13
- import Head from '@docusaurus/Head';
14
- import Link from '@docusaurus/Link';
15
- import CodeBlock from '@theme/CodeBlock';
16
- import Heading from '@theme/Heading';
17
- import Details from '@theme/Details';
18
- import type {MDXComponentsObject} from '@theme/MDXComponents';
19
-
20
- import './styles.css';
8
+ import React from 'react';
9
+ import MDXHead from '@theme/MDXComponents/Head';
10
+ import MDXCode from '@theme/MDXComponents/Code';
11
+ import MDXA from '@theme/MDXComponents/A';
12
+ import MDXPre from '@theme/MDXComponents/Pre';
13
+ import MDXDetails from '@theme/MDXComponents/Details';
14
+ import MDXHeading from '@theme/MDXComponents/Heading';
15
+ import MDXUl from '@theme/MDXComponents/Ul';
16
+ import MDXImg from '@theme/MDXComponents/Img';
21
17
 
22
- // MDX elements are wrapped through the MDX pragma. In some cases (notably usage
23
- // with Head/Helmet) we need to unwrap those elements.
24
- function unwrapMDXElement(element: ReactElement) {
25
- if (element?.props?.mdxType && element?.props?.originalType) {
26
- const {mdxType, originalType, ...newProps} = element.props;
27
- return React.createElement(element.props.originalType, newProps);
28
- }
29
- return element;
30
- }
18
+ import type {MDXComponentsObject} from '@theme/MDXComponents';
31
19
 
32
20
  const MDXComponents: MDXComponentsObject = {
33
- head: (props) => {
34
- const unwrappedChildren = React.Children.map(props.children, (child) =>
35
- unwrapMDXElement(child as ReactElement),
36
- );
37
- return <Head {...props}>{unwrappedChildren}</Head>;
38
- },
39
- code: (props) => {
40
- const inlineElements = [
41
- 'a',
42
- 'b',
43
- 'big',
44
- 'i',
45
- 'span',
46
- 'em',
47
- 'strong',
48
- 'sup',
49
- 'sub',
50
- 'small',
51
- ];
52
- const shouldBeInline = React.Children.toArray(props.children).every(
53
- (el) =>
54
- (typeof el === 'string' && !el.includes('\n')) ||
55
- (React.isValidElement(el) && inlineElements.includes(el.props.mdxType)),
56
- );
57
-
58
- return shouldBeInline ? <code {...props} /> : <CodeBlock {...props} />;
59
- },
60
- a: (props) => <Link {...props} />,
61
- pre: (props) => (
62
- <CodeBlock
63
- // If this pre is created by a ``` fenced codeblock, unwrap the children
64
- {...(isValidElement(props.children) &&
65
- props.children.props.originalType === 'code'
66
- ? props.children?.props
67
- : {...props})}
68
- />
69
- ),
70
- details: (props): JSX.Element => {
71
- const items = React.Children.toArray(props.children) as ReactElement[];
72
- // Split summary item from the rest to pass it as a separate prop to the
73
- // Details theme component
74
- const summary: ReactElement<ComponentProps<'summary'>> = items.find(
75
- (item) => item?.props?.mdxType === 'summary',
76
- )!;
77
- const children = <>{items.filter((item) => item !== summary)}</>;
78
-
79
- return (
80
- <Details {...props} summary={summary}>
81
- {children}
82
- </Details>
83
- );
84
- },
85
- h1: (props) => <Heading as="h1" {...props} />,
86
- h2: (props) => <Heading as="h2" {...props} />,
87
- h3: (props) => <Heading as="h3" {...props} />,
88
- h4: (props) => <Heading as="h4" {...props} />,
89
- h5: (props) => <Heading as="h5" {...props} />,
90
- h6: (props) => <Heading as="h6" {...props} />,
21
+ head: MDXHead,
22
+ code: MDXCode,
23
+ a: MDXA,
24
+ pre: MDXPre,
25
+ details: MDXDetails,
26
+ ul: MDXUl,
27
+ img: MDXImg,
28
+ h1: (props) => <MDXHeading as="h1" {...props} />,
29
+ h2: (props) => <MDXHeading as="h2" {...props} />,
30
+ h3: (props) => <MDXHeading as="h3" {...props} />,
31
+ h4: (props) => <MDXHeading as="h4" {...props} />,
32
+ h5: (props) => <MDXHeading as="h5" {...props} />,
33
+ h6: (props) => <MDXHeading as="h6" {...props} />,
91
34
  };
92
35
 
93
36
  export default MDXComponents;
@@ -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
+ import React from 'react';
9
+ import {MDXProvider} from '@mdx-js/react';
10
+ import MDXComponents from '@theme/MDXComponents';
11
+ import type {Props} from '@theme/MDXContent';
12
+
13
+ export default function MDXContent({children}: Props): JSX.Element {
14
+ return <MDXProvider components={MDXComponents}>{children}</MDXProvider>;
15
+ }