@docusaurus/theme-classic 2.0.0-beta.15a2b59f9 → 2.0.0-beta.17

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 (407) hide show
  1. package/README.md +2 -2
  2. package/lib/admonitions.css +35 -0
  3. package/{lib-next/theme/Toggle/styles.module.css → lib/deps.d.ts} +5 -9
  4. package/lib/getSwizzleConfig.js +125 -0
  5. package/lib/index.js +36 -41
  6. package/lib/prism-include-languages.js +9 -5
  7. package/lib/theme-classic.d.ts +771 -0
  8. package/lib/translations.js +40 -34
  9. package/lib/types.d.ts +0 -587
  10. package/lib/validateThemeConfig.js +242 -250
  11. package/lib-next/theme/Admonition/index.js +101 -0
  12. package/lib-next/theme/AnnouncementBar/index.js +8 -16
  13. package/lib-next/theme/AnnouncementBar/styles.module.css +23 -32
  14. package/lib-next/theme/BackToTopButton/index.js +131 -0
  15. package/lib-next/theme/BackToTopButton/styles.module.css +44 -0
  16. package/lib-next/theme/BlogArchivePage/index.js +80 -0
  17. package/lib-next/theme/BlogLayout/index.js +37 -0
  18. package/lib-next/theme/BlogListPage/index.js +18 -29
  19. package/lib-next/theme/BlogListPaginator/index.js +13 -16
  20. package/lib-next/theme/BlogPostAuthor/index.js +52 -0
  21. package/{lib/theme/IconEdit → lib-next/theme/BlogPostAuthor}/styles.module.css +4 -3
  22. package/lib-next/theme/BlogPostAuthors/index.js +44 -0
  23. package/{src/theme/Toggle → lib-next/theme/BlogPostAuthors}/styles.module.css +11 -7
  24. package/lib-next/theme/BlogPostItem/index.js +94 -96
  25. package/lib-next/theme/BlogPostPage/index.js +75 -39
  26. package/lib-next/theme/BlogPostPaginator/index.js +12 -19
  27. package/lib-next/theme/BlogSidebar/index.js +11 -13
  28. package/lib-next/theme/BlogSidebar/styles.module.css +4 -2
  29. package/lib-next/theme/BlogTagsListPage/index.js +15 -59
  30. package/lib-next/theme/BlogTagsPostsPage/index.js +33 -41
  31. package/lib-next/theme/CodeBlock/index.js +64 -154
  32. package/lib-next/theme/CodeBlock/styles.module.css +17 -9
  33. package/lib-next/theme/ColorModeToggle/index.js +83 -0
  34. package/lib-next/theme/ColorModeToggle/styles.module.css +51 -0
  35. package/lib-next/theme/Details/index.js +21 -0
  36. package/lib-next/theme/Details/styles.module.css +13 -0
  37. package/lib-next/theme/DocBreadcrumbs/index.js +76 -0
  38. package/lib-next/theme/DocBreadcrumbs/styles.module.css +26 -0
  39. package/lib-next/theme/DocCard/index.js +91 -0
  40. package/lib-next/theme/DocCard/styles.module.css +43 -0
  41. package/lib-next/theme/DocCardList/index.js +19 -0
  42. package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +54 -0
  43. package/lib-next/theme/DocCategoryGeneratedIndexPage/styles.module.css +18 -0
  44. package/lib-next/theme/DocItem/index.js +53 -58
  45. package/lib-next/theme/DocItem/styles.module.css +6 -10
  46. package/lib-next/theme/DocItemFooter/index.js +79 -0
  47. package/{lib/theme/DocItem → lib-next/theme/DocItemFooter}/styles.module.css +1 -9
  48. package/lib-next/theme/DocPage/index.js +54 -55
  49. package/lib-next/theme/DocPage/styles.module.css +9 -3
  50. package/lib-next/theme/DocPaginator/index.js +15 -24
  51. package/lib-next/theme/DocSidebar/index.js +65 -286
  52. package/lib-next/theme/DocSidebar/styles.module.css +5 -22
  53. package/lib-next/theme/DocSidebarItem/index.js +264 -0
  54. package/{lib/theme/BlogPostItem → lib-next/theme/DocSidebarItem}/styles.module.css +5 -10
  55. package/lib-next/theme/DocSidebarItems/index.js +28 -0
  56. package/lib-next/theme/DocTagDocListPage/index.js +89 -0
  57. package/lib-next/theme/DocTagsListPage/index.js +35 -0
  58. package/lib-next/theme/DocVersionBadge/index.js +34 -0
  59. package/lib-next/theme/DocVersionBanner/index.js +32 -15
  60. package/lib-next/theme/EditThisPage/index.js +6 -1
  61. package/lib-next/theme/ErrorPageContent.js +35 -0
  62. package/lib-next/theme/Footer/index.js +95 -40
  63. package/lib-next/theme/Footer/styles.module.css +2 -1
  64. package/lib-next/theme/Heading/index.js +39 -48
  65. package/lib-next/theme/Heading/styles.module.css +25 -5
  66. package/lib-next/theme/IconArrow/index.js +2 -5
  67. package/lib-next/theme/IconClose/index.js +23 -0
  68. package/lib-next/theme/IconDarkMode/index.js +17 -0
  69. package/lib-next/theme/IconEdit/index.js +2 -5
  70. package/lib-next/theme/IconExternalLink/index.js +2 -5
  71. package/lib-next/theme/IconLanguage/index.js +5 -8
  72. package/lib-next/theme/IconLightMode/index.js +17 -0
  73. package/lib-next/theme/IconMenu/index.js +7 -5
  74. package/lib-next/theme/LastUpdated/index.js +3 -2
  75. package/lib-next/theme/Layout/index.js +5 -7
  76. package/lib-next/theme/LayoutHead/index.js +27 -32
  77. package/lib-next/theme/LayoutProviders/index.js +15 -9
  78. package/lib-next/theme/Logo/index.js +25 -24
  79. package/lib-next/theme/MDXComponents/index.js +59 -30
  80. package/{src/theme/hooks → lib-next/theme/MDXComponents}/styles.css +7 -2
  81. package/lib-next/theme/MDXPage/index.js +10 -12
  82. package/lib-next/theme/Navbar/index.js +199 -64
  83. package/lib-next/theme/Navbar/styles.module.css +10 -3
  84. package/lib-next/theme/NavbarItem/DefaultNavbarItem.js +35 -201
  85. package/lib-next/theme/NavbarItem/DocNavbarItem.js +11 -8
  86. package/lib-next/theme/NavbarItem/DocSidebarNavbarItem.js +73 -0
  87. package/lib-next/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +34 -20
  88. package/lib-next/theme/NavbarItem/DocsVersionNavbarItem.js +4 -1
  89. package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +156 -0
  90. package/lib-next/theme/NavbarItem/{LocaleDropdownNavbarItem.js → LocaleDropdownNavbarItem/index.js} +12 -13
  91. package/{lib/theme/hooks/styles.css → lib-next/theme/NavbarItem/LocaleDropdownNavbarItem/styles.module.css} +3 -2
  92. package/lib-next/theme/NavbarItem/NavbarNavLink.js +70 -0
  93. package/lib-next/theme/NavbarItem/index.js +26 -14
  94. package/lib-next/theme/{UserPreferencesContext.js → NavbarItem/utils.js} +3 -3
  95. package/lib-next/theme/NotFound.js +1 -4
  96. package/lib-next/theme/PaginatorNavLink/index.js +17 -0
  97. package/lib-next/theme/SearchBar.js +1 -1
  98. package/lib-next/theme/SearchMetadata/index.js +34 -0
  99. package/lib-next/theme/Seo/index.js +11 -7
  100. package/lib-next/theme/SkipToContent/index.js +3 -5
  101. package/lib-next/theme/SkipToContent/styles.module.css +7 -0
  102. package/lib-next/theme/TOC/index.js +12 -39
  103. package/lib-next/theme/TOC/styles.module.css +1 -1
  104. package/lib-next/theme/TOCCollapsible/index.js +54 -0
  105. package/lib-next/theme/TOCCollapsible/styles.module.css +50 -0
  106. package/lib-next/theme/TOCInline/index.js +10 -31
  107. package/lib-next/theme/TOCItems/index.js +85 -0
  108. package/lib-next/theme/TabItem/index.js +1 -4
  109. package/lib-next/theme/Tabs/__tests__/index.test.js +146 -0
  110. package/lib-next/theme/Tabs/index.js +108 -50
  111. package/lib-next/theme/Tabs/styles.module.css +0 -13
  112. package/lib-next/theme/Tag/index.js +24 -0
  113. package/lib-next/theme/Tag/styles.module.css +70 -0
  114. package/lib-next/theme/TagsListByLetter/index.js +40 -0
  115. package/lib-next/theme/{hooks/styles.css → TagsListByLetter/styles.module.css} +3 -2
  116. package/lib-next/theme/TagsListInline/index.js +31 -0
  117. package/lib-next/theme/TagsListInline/styles.module.css +15 -0
  118. package/lib-next/theme/ThemedImage/index.js +7 -10
  119. package/lib-next/theme/ThemedImage/styles.module.css +2 -2
  120. package/lib-next/theme/prism-include-languages.js +17 -15
  121. package/package.json +31 -31
  122. package/src/admonitions.css +35 -0
  123. package/src/deps.d.ts +13 -0
  124. package/src/getSwizzleConfig.ts +123 -0
  125. package/src/index.ts +39 -61
  126. package/{lib-next/prism-include-languages.js → src/prism-include-languages.ts} +0 -0
  127. package/src/theme/Admonition/index.tsx +106 -0
  128. package/src/theme/AnnouncementBar/index.tsx +9 -15
  129. package/src/theme/AnnouncementBar/styles.module.css +23 -32
  130. package/src/theme/BackToTopButton/index.tsx +143 -0
  131. package/src/theme/BackToTopButton/styles.module.css +44 -0
  132. package/src/theme/BlogArchivePage/index.tsx +91 -0
  133. package/src/theme/BlogLayout/index.tsx +42 -0
  134. package/src/theme/BlogListPage/index.tsx +19 -28
  135. package/src/theme/BlogListPaginator/index.tsx +13 -15
  136. package/src/theme/BlogPostAuthor/index.tsx +54 -0
  137. package/{lib/theme/MDXPage → src/theme/BlogPostAuthor}/styles.module.css +4 -2
  138. package/src/theme/BlogPostAuthors/index.tsx +49 -0
  139. package/src/theme/BlogPostAuthors/styles.module.css +21 -0
  140. package/src/theme/BlogPostItem/index.tsx +84 -90
  141. package/src/theme/BlogPostPage/index.tsx +77 -38
  142. package/src/theme/BlogPostPaginator/index.tsx +12 -18
  143. package/src/theme/BlogSidebar/index.tsx +11 -13
  144. package/src/theme/BlogSidebar/styles.module.css +4 -2
  145. package/src/theme/BlogTagsListPage/index.tsx +15 -60
  146. package/src/theme/BlogTagsPostsPage/index.tsx +32 -40
  147. package/src/theme/CodeBlock/index.tsx +68 -156
  148. package/src/theme/CodeBlock/styles.module.css +17 -9
  149. package/src/theme/ColorModeToggle/index.tsx +92 -0
  150. package/src/theme/ColorModeToggle/styles.module.css +51 -0
  151. package/src/theme/Details/index.tsx +25 -0
  152. package/src/theme/Details/styles.module.css +13 -0
  153. package/src/theme/DocBreadcrumbs/index.tsx +91 -0
  154. package/src/theme/DocBreadcrumbs/styles.module.css +26 -0
  155. package/src/theme/DocCard/index.tsx +109 -0
  156. package/src/theme/DocCard/styles.module.css +43 -0
  157. package/src/theme/DocCardList/index.tsx +27 -0
  158. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +59 -0
  159. package/src/theme/DocCategoryGeneratedIndexPage/styles.module.css +18 -0
  160. package/src/theme/DocItem/index.tsx +56 -58
  161. package/src/theme/DocItem/styles.module.css +6 -10
  162. package/src/theme/DocItemFooter/index.tsx +91 -0
  163. package/{lib/theme/Toggle → src/theme/DocItemFooter}/styles.module.css +9 -8
  164. package/src/theme/DocPage/index.tsx +53 -49
  165. package/src/theme/DocPage/styles.module.css +9 -3
  166. package/src/theme/DocPaginator/index.tsx +15 -23
  167. package/src/theme/DocSidebar/index.tsx +76 -298
  168. package/src/theme/DocSidebar/styles.module.css +5 -22
  169. package/src/theme/DocSidebarItem/index.tsx +283 -0
  170. package/src/theme/DocSidebarItem/styles.module.css +13 -0
  171. package/src/theme/DocSidebarItems/index.tsx +32 -0
  172. package/src/theme/DocTagDocListPage/index.tsx +89 -0
  173. package/src/theme/DocTagsListPage/index.tsx +39 -0
  174. package/src/theme/DocVersionBadge/index.tsx +35 -0
  175. package/src/theme/DocVersionBanner/index.tsx +49 -22
  176. package/src/theme/EditThisPage/index.tsx +6 -1
  177. package/src/theme/ErrorPageContent.tsx +41 -0
  178. package/src/theme/Footer/index.tsx +109 -44
  179. package/src/theme/Footer/styles.module.css +2 -1
  180. package/src/theme/Heading/index.tsx +38 -53
  181. package/src/theme/Heading/styles.module.css +25 -5
  182. package/src/theme/IconArrow/index.tsx +2 -4
  183. package/src/theme/IconClose/index.tsx +26 -0
  184. package/src/theme/IconDarkMode/index.tsx +20 -0
  185. package/src/theme/IconEdit/index.tsx +5 -4
  186. package/src/theme/IconExternalLink/index.tsx +3 -5
  187. package/src/theme/IconLanguage/index.tsx +6 -8
  188. package/src/theme/IconLightMode/index.tsx +20 -0
  189. package/src/theme/IconMenu/index.tsx +3 -5
  190. package/src/theme/LastUpdated/index.tsx +3 -2
  191. package/src/theme/Layout/index.tsx +5 -6
  192. package/src/theme/LayoutHead/index.tsx +26 -25
  193. package/src/theme/LayoutProviders/index.tsx +15 -9
  194. package/src/theme/Logo/index.tsx +21 -19
  195. package/src/theme/MDXComponents/index.tsx +70 -32
  196. package/{lib/theme/IconExternalLink/styles.module.css → src/theme/MDXComponents/styles.css} +7 -4
  197. package/src/theme/MDXPage/index.tsx +10 -12
  198. package/src/theme/Navbar/index.tsx +208 -68
  199. package/src/theme/Navbar/styles.module.css +10 -3
  200. package/src/theme/NavbarItem/DefaultNavbarItem.tsx +37 -207
  201. package/src/theme/NavbarItem/DocNavbarItem.tsx +17 -18
  202. package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +84 -0
  203. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +39 -24
  204. package/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +7 -3
  205. package/src/theme/NavbarItem/DropdownNavbarItem.tsx +181 -0
  206. package/src/theme/NavbarItem/{LocaleDropdownNavbarItem.tsx → LocaleDropdownNavbarItem/index.tsx} +16 -10
  207. package/src/theme/NavbarItem/LocaleDropdownNavbarItem/styles.module.css +11 -0
  208. package/src/theme/NavbarItem/NavbarNavLink.tsx +68 -0
  209. package/src/theme/NavbarItem/index.tsx +41 -18
  210. package/src/theme/NavbarItem/utils.ts +10 -0
  211. package/src/theme/NotFound.tsx +1 -3
  212. package/src/theme/PaginatorNavLink/index.tsx +20 -0
  213. package/src/theme/SearchBar.tsx +2 -1
  214. package/src/theme/SearchMetadata/index.tsx +43 -0
  215. package/src/theme/Seo/index.tsx +7 -4
  216. package/src/theme/SkipToContent/index.tsx +3 -5
  217. package/src/theme/SkipToContent/styles.module.css +7 -0
  218. package/src/theme/TOC/index.tsx +13 -44
  219. package/src/theme/TOC/styles.module.css +1 -1
  220. package/src/theme/TOCCollapsible/index.tsx +58 -0
  221. package/src/theme/TOCCollapsible/styles.module.css +50 -0
  222. package/src/theme/TOCInline/index.tsx +14 -35
  223. package/src/theme/TOCItems/index.tsx +100 -0
  224. package/src/theme/TabItem/index.tsx +5 -3
  225. package/src/theme/Tabs/index.tsx +115 -56
  226. package/src/theme/Tabs/styles.module.css +0 -13
  227. package/src/theme/Tag/index.tsx +29 -0
  228. package/src/theme/Tag/styles.module.css +70 -0
  229. package/src/theme/TagsListByLetter/index.tsx +43 -0
  230. package/src/theme/TagsListByLetter/styles.module.css +11 -0
  231. package/src/theme/TagsListInline/index.tsx +35 -0
  232. package/src/theme/TagsListInline/styles.module.css +15 -0
  233. package/src/theme/ThemedImage/index.tsx +7 -9
  234. package/src/theme/ThemedImage/styles.module.css +2 -2
  235. package/src/theme/prism-include-languages.ts +20 -15
  236. package/src/theme-classic.d.ts +771 -0
  237. package/src/translations.ts +74 -54
  238. package/src/types.d.ts +0 -587
  239. package/src/validateThemeConfig.ts +381 -0
  240. package/babel.config.js +0 -35
  241. package/codeTranslations/README.md +0 -20
  242. package/codeTranslations/ar.json +0 -57
  243. package/codeTranslations/base.json +0 -112
  244. package/codeTranslations/bn.json +0 -56
  245. package/codeTranslations/da.json +0 -57
  246. package/codeTranslations/de.json +0 -57
  247. package/codeTranslations/es.json +0 -57
  248. package/codeTranslations/fa.json +0 -57
  249. package/codeTranslations/fil.json +0 -57
  250. package/codeTranslations/fr.json +0 -57
  251. package/codeTranslations/he.json +0 -57
  252. package/codeTranslations/hi.json +0 -57
  253. package/codeTranslations/ja.json +0 -57
  254. package/codeTranslations/ko.json +0 -57
  255. package/codeTranslations/pl.json +0 -57
  256. package/codeTranslations/pt-BR.json +0 -57
  257. package/codeTranslations/pt-PT.json +0 -57
  258. package/codeTranslations/ru.json +0 -57
  259. package/codeTranslations/tr.json +0 -57
  260. package/codeTranslations/vi.json +0 -57
  261. package/codeTranslations/zh-Hans.json +0 -57
  262. package/codeTranslations/zh-Hant.json +0 -57
  263. package/lib/__tests__/__snapshots__/translations.test.ts.snap +0 -116
  264. package/lib/__tests__/translations.test.js +0 -112
  265. package/lib/__tests__/validateThemeConfig.test.js +0 -333
  266. package/lib/theme/AnnouncementBar/index.js +0 -72
  267. package/lib/theme/AnnouncementBar/styles.module.css +0 -72
  268. package/lib/theme/BlogListPage/index.js +0 -71
  269. package/lib/theme/BlogListPaginator/index.js +0 -63
  270. package/lib/theme/BlogPostItem/index.js +0 -161
  271. package/lib/theme/BlogPostPage/index.js +0 -69
  272. package/lib/theme/BlogPostPaginator/index.js +0 -64
  273. package/lib/theme/BlogSidebar/index.js +0 -51
  274. package/lib/theme/BlogSidebar/styles.module.css +0 -44
  275. package/lib/theme/BlogTagsListPage/index.js +0 -76
  276. package/lib/theme/BlogTagsPostsPage/index.js +0 -100
  277. package/lib/theme/CodeBlock/index.js +0 -253
  278. package/lib/theme/CodeBlock/styles.module.css +0 -68
  279. package/lib/theme/DocItem/index.js +0 -129
  280. package/lib/theme/DocPage/index.js +0 -173
  281. package/lib/theme/DocPage/styles.module.css +0 -80
  282. package/lib/theme/DocPaginator/index.js +0 -63
  283. package/lib/theme/DocSidebar/index.js +0 -309
  284. package/lib/theme/DocSidebar/styles.module.css +0 -124
  285. package/lib/theme/DocVersionBanner/index.js +0 -128
  286. package/lib/theme/EditThisPage/index.js +0 -31
  287. package/lib/theme/Footer/index.js +0 -115
  288. package/lib/theme/Footer/styles.module.css +0 -15
  289. package/lib/theme/Heading/index.js +0 -76
  290. package/lib/theme/Heading/styles.css +0 -23
  291. package/lib/theme/Heading/styles.module.css +0 -15
  292. package/lib/theme/IconArrow/index.js +0 -28
  293. package/lib/theme/IconEdit/index.js +0 -34
  294. package/lib/theme/IconExternalLink/index.js +0 -30
  295. package/lib/theme/IconLanguage/index.js +0 -29
  296. package/lib/theme/IconMenu/index.js +0 -30
  297. package/lib/theme/LastUpdated/index.js +0 -61
  298. package/lib/theme/Layout/index.js +0 -64
  299. package/lib/theme/Layout/styles.css +0 -27
  300. package/lib/theme/LayoutHead/index.js +0 -144
  301. package/lib/theme/LayoutProviders/index.js +0 -36
  302. package/lib/theme/Logo/index.js +0 -60
  303. package/lib/theme/MDXComponents/index.js +0 -65
  304. package/lib/theme/MDXPage/index.js +0 -66
  305. package/lib/theme/Navbar/index.js +0 -147
  306. package/lib/theme/Navbar/styles.module.css +0 -20
  307. package/lib/theme/NavbarItem/DefaultNavbarItem.js +0 -209
  308. package/lib/theme/NavbarItem/DocNavbarItem.js +0 -63
  309. package/lib/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +0 -76
  310. package/lib/theme/NavbarItem/DocsVersionNavbarItem.js +0 -43
  311. package/lib/theme/NavbarItem/LocaleDropdownNavbarItem.js +0 -72
  312. package/lib/theme/NavbarItem/SearchNavbarItem.js +0 -28
  313. package/lib/theme/NavbarItem/index.js +0 -54
  314. package/lib/theme/NotFound.js +0 -57
  315. package/lib/theme/SearchBar.js +0 -15
  316. package/lib/theme/SearchMetadatas/index.js +0 -33
  317. package/lib/theme/Seo/index.js +0 -49
  318. package/lib/theme/SkipToContent/index.js +0 -71
  319. package/lib/theme/SkipToContent/styles.module.css +0 -14
  320. package/lib/theme/TOC/index.js +0 -59
  321. package/lib/theme/TOC/styles.module.css +0 -23
  322. package/lib/theme/TOCInline/index.js +0 -53
  323. package/lib/theme/TOCInline/styles.module.css +0 -12
  324. package/lib/theme/TabItem/index.js +0 -32
  325. package/lib/theme/Tabs/index.js +0 -150
  326. package/lib/theme/Tabs/styles.module.css +0 -23
  327. package/lib/theme/ThemeContext.js +0 -21
  328. package/lib/theme/ThemeProvider/index.js +0 -38
  329. package/lib/theme/ThemedImage/index.js +0 -49
  330. package/lib/theme/ThemedImage/styles.module.css +0 -18
  331. package/lib/theme/Toggle/index.js +0 -94
  332. package/lib/theme/Toggle/styles.css +0 -103
  333. package/lib/theme/UserPreferencesContext.js +0 -18
  334. package/lib/theme/UserPreferencesProvider/index.js +0 -36
  335. package/lib/theme/hooks/useContextualSearchFilters.js +0 -47
  336. package/lib/theme/hooks/useDocs.js +0 -18
  337. package/lib/theme/hooks/useHideableNavbar.js +0 -92
  338. package/lib/theme/hooks/useKeyboardNavigation.js +0 -45
  339. package/lib/theme/hooks/useLocationHash.js +0 -28
  340. package/lib/theme/hooks/useLockBodyScroll.js +0 -26
  341. package/lib/theme/hooks/usePrismTheme.js +0 -36
  342. package/lib/theme/hooks/useScrollPosition.js +0 -49
  343. package/lib/theme/hooks/useTOCHighlight.js +0 -87
  344. package/lib/theme/hooks/useTabGroupChoice.js +0 -51
  345. package/lib/theme/hooks/useTheme.js +0 -99
  346. package/lib/theme/hooks/useThemeContext.js +0 -31
  347. package/lib/theme/hooks/useUserPreferencesContext.js +0 -31
  348. package/lib/theme/hooks/useWindowSize.js +0 -55
  349. package/lib/theme/prism-include-languages.js +0 -39
  350. package/lib-next/__tests__/__snapshots__/translations.test.ts.snap +0 -116
  351. package/lib-next/__tests__/translations.test.js +0 -128
  352. package/lib-next/__tests__/validateThemeConfig.test.js +0 -333
  353. package/lib-next/index.js +0 -221
  354. package/lib-next/theme/Heading/styles.css +0 -23
  355. package/lib-next/theme/SearchMetadatas/index.js +0 -20
  356. package/lib-next/theme/ThemeContext.js +0 -9
  357. package/lib-next/theme/ThemeProvider/index.js +0 -25
  358. package/lib-next/theme/Toggle/index.js +0 -80
  359. package/lib-next/theme/Toggle/styles.css +0 -103
  360. package/lib-next/theme/UserPreferencesProvider/index.js +0 -24
  361. package/lib-next/theme/hooks/useContextualSearchFilters.js +0 -41
  362. package/lib-next/theme/hooks/useDocs.js +0 -10
  363. package/lib-next/theme/hooks/useHideableNavbar.js +0 -79
  364. package/lib-next/theme/hooks/useKeyboardNavigation.js +0 -35
  365. package/lib-next/theme/hooks/useLocationHash.js +0 -20
  366. package/lib-next/theme/hooks/useLockBodyScroll.js +0 -18
  367. package/lib-next/theme/hooks/usePrismTheme.js +0 -20
  368. package/lib-next/theme/hooks/useScrollPosition.js +0 -38
  369. package/lib-next/theme/hooks/useTOCHighlight.js +0 -84
  370. package/lib-next/theme/hooks/useTabGroupChoice.js +0 -39
  371. package/lib-next/theme/hooks/useTheme.js +0 -82
  372. package/lib-next/theme/hooks/useThemeContext.js +0 -22
  373. package/lib-next/theme/hooks/useUserPreferencesContext.js +0 -22
  374. package/lib-next/theme/hooks/useWindowSize.js +0 -45
  375. package/lib-next/translations.js +0 -145
  376. package/lib-next/types.d.ts +0 -598
  377. package/lib-next/validateThemeConfig.js +0 -317
  378. package/src/__tests__/__snapshots__/translations.test.ts.snap +0 -116
  379. package/src/__tests__/translations.test.ts +0 -116
  380. package/src/__tests__/validateThemeConfig.test.js +0 -333
  381. package/src/prism-include-languages.js +0 -11
  382. package/src/theme/Heading/styles.css +0 -23
  383. package/src/theme/SearchMetadatas/index.tsx +0 -28
  384. package/src/theme/ThemeContext.ts +0 -15
  385. package/src/theme/ThemeProvider/index.tsx +0 -24
  386. package/src/theme/Toggle/index.tsx +0 -100
  387. package/src/theme/Toggle/styles.css +0 -103
  388. package/src/theme/UserPreferencesContext.ts +0 -12
  389. package/src/theme/UserPreferencesProvider/index.tsx +0 -27
  390. package/src/theme/hooks/useContextualSearchFilters.ts +0 -52
  391. package/src/theme/hooks/useDocs.ts +0 -11
  392. package/src/theme/hooks/useHideableNavbar.ts +0 -85
  393. package/src/theme/hooks/useKeyboardNavigation.ts +0 -39
  394. package/src/theme/hooks/useLocationHash.ts +0 -25
  395. package/src/theme/hooks/useLockBodyScroll.ts +0 -20
  396. package/src/theme/hooks/usePrismTheme.ts +0 -22
  397. package/src/theme/hooks/useScrollPosition.ts +0 -45
  398. package/src/theme/hooks/useTOCHighlight.ts +0 -98
  399. package/src/theme/hooks/useTabGroupChoice.ts +0 -46
  400. package/src/theme/hooks/useTheme.ts +0 -92
  401. package/src/theme/hooks/useThemeContext.ts +0 -23
  402. package/src/theme/hooks/useUserPreferencesContext.ts +0 -25
  403. package/src/theme/hooks/useWindowSize.ts +0 -51
  404. package/src/validateThemeConfig.js +0 -317
  405. package/tsconfig.json +0 -12
  406. package/update-code-translations.js +0 -240
  407. package/update-code-translations.test.js +0 -33
@@ -7,22 +7,18 @@
7
7
 
8
8
  import React from 'react';
9
9
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
10
- import {useLatestVersion, useActiveDocContext} from '@theme/hooks/useDocs';
10
+ import {
11
+ useLatestVersion,
12
+ useActiveDocContext,
13
+ } from '@docusaurus/plugin-content-docs/client';
11
14
  import clsx from 'clsx';
15
+ import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
12
16
  import type {Props} from '@theme/NavbarItem/DocNavbarItem';
13
- import {useDocsPreferredVersion} from '@docusaurus/theme-common';
14
- import {uniq} from '@docusaurus/utils-common';
15
- import type {
16
- GlobalDataVersion,
17
- GlobalDataDoc,
18
- } from '@docusaurus/plugin-content-docs-types';
19
-
20
- function getDocInVersions(versions: GlobalDataVersion[], docId: string) {
21
- // vanilla-js flatten, TODO replace soon by ES flat() / flatMap()
22
- const allDocs: GlobalDataDoc[] = [].concat(
23
- ...versions.map((version) => version.docs),
24
- );
17
+ import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
18
+ import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
25
19
 
20
+ function getDocInVersions(versions: GlobalVersion[], docId: string) {
21
+ const allDocs = versions.flatMap((version) => version.docs);
26
22
  const doc = allDocs.find((versionDoc) => versionDoc.id === docId);
27
23
  if (!doc) {
28
24
  const docIds = allDocs.map((versionDoc) => versionDoc.id).join('\n- ');
@@ -38,7 +34,6 @@ Available doc ids are:\n- ${docIds}`,
38
34
 
39
35
  export default function DocNavbarItem({
40
36
  docId,
41
- activeSidebarClassName,
42
37
  label: staticLabel,
43
38
  docsPluginId,
44
39
  ...props
@@ -48,19 +43,23 @@ export default function DocNavbarItem({
48
43
  const latestVersion = useLatestVersion(docsPluginId);
49
44
 
50
45
  // Versions used to look for the doc to link to, ordered + no duplicate
51
- const versions: GlobalDataVersion[] = uniq(
52
- [activeVersion, preferredVersion, latestVersion].filter(Boolean),
46
+ const versions = uniq(
47
+ [activeVersion, preferredVersion, latestVersion].filter(
48
+ Boolean,
49
+ ) as GlobalVersion[],
53
50
  );
54
51
  const doc = getDocInVersions(versions, docId);
52
+ const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
55
53
 
56
54
  return (
57
55
  <DefaultNavbarItem
58
56
  exact
59
57
  {...props}
60
58
  className={clsx(props.className, {
61
- [activeSidebarClassName]:
62
- activeDoc && activeDoc.sidebar === doc.sidebar,
59
+ [activeDocInfimaClassName]:
60
+ activeDoc?.sidebar && activeDoc.sidebar === doc.sidebar,
63
61
  })}
62
+ activeClassName={activeDocInfimaClassName}
64
63
  label={staticLabel ?? doc.id}
65
64
  to={doc.path}
66
65
  />
@@ -0,0 +1,84 @@
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 DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
10
+ import {
11
+ useLatestVersion,
12
+ useActiveDocContext,
13
+ } from '@docusaurus/plugin-content-docs/client';
14
+ import clsx from 'clsx';
15
+ import {getInfimaActiveClassName} from '@theme/NavbarItem/utils';
16
+ import {useDocsPreferredVersion, uniq} from '@docusaurus/theme-common';
17
+
18
+ import type {Props} from '@theme/NavbarItem/DocSidebarNavbarItem';
19
+ import type {
20
+ GlobalVersion,
21
+ GlobalSidebar,
22
+ } from '@docusaurus/plugin-content-docs/client';
23
+
24
+ function getSidebarLink(versions: GlobalVersion[], sidebarId: string) {
25
+ const allSidebars = versions
26
+ .flatMap((version) => {
27
+ if (version.sidebars) {
28
+ return Object.entries(version.sidebars);
29
+ }
30
+ return undefined;
31
+ })
32
+ .filter(
33
+ (sidebarItem): sidebarItem is [string, GlobalSidebar] => !!sidebarItem,
34
+ );
35
+ const sidebarEntry = allSidebars.find((sidebar) => sidebar[0] === sidebarId);
36
+ if (!sidebarEntry) {
37
+ throw new Error(
38
+ `DocSidebarNavbarItem: couldn't find any sidebar with id "${sidebarId}" in version${
39
+ versions.length ? 's' : ''
40
+ } ${versions.map((version) => version.name).join(', ')}".
41
+ Available sidebar ids are:
42
+ - ${Object.keys(allSidebars).join('\n- ')}`,
43
+ );
44
+ }
45
+ if (!sidebarEntry[1].link) {
46
+ throw new Error(
47
+ `DocSidebarNavbarItem: couldn't find any document for sidebar with id "${sidebarId}"`,
48
+ );
49
+ }
50
+ return sidebarEntry[1].link;
51
+ }
52
+
53
+ export default function DocSidebarNavbarItem({
54
+ sidebarId,
55
+ label,
56
+ docsPluginId,
57
+ ...props
58
+ }: Props): JSX.Element {
59
+ const {activeVersion, activeDoc} = useActiveDocContext(docsPluginId);
60
+ const {preferredVersion} = useDocsPreferredVersion(docsPluginId);
61
+ const latestVersion = useLatestVersion(docsPluginId);
62
+
63
+ // Versions used to look for the doc to link to, ordered + no duplicate
64
+ const versions = uniq(
65
+ [activeVersion, preferredVersion, latestVersion].filter(
66
+ Boolean,
67
+ ) as GlobalVersion[],
68
+ );
69
+ const sidebarLink = getSidebarLink(versions, sidebarId);
70
+ const activeDocInfimaClassName = getInfimaActiveClassName(props.mobile);
71
+
72
+ return (
73
+ <DefaultNavbarItem
74
+ exact
75
+ {...props}
76
+ className={clsx(props.className, {
77
+ [activeDocInfimaClassName]: activeDoc?.sidebar === sidebarId,
78
+ })}
79
+ activeClassName={activeDocInfimaClassName}
80
+ label={label ?? sidebarLink.label}
81
+ to={sidebarLink.path}
82
+ />
83
+ );
84
+ }
@@ -7,16 +7,20 @@
7
7
 
8
8
  import React from 'react';
9
9
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
10
+ import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
10
11
  import {
11
12
  useVersions,
12
13
  useLatestVersion,
13
14
  useActiveDocContext,
14
- } from '@theme/hooks/useDocs';
15
+ } from '@docusaurus/plugin-content-docs/client';
15
16
  import type {Props} from '@theme/NavbarItem/DocsVersionDropdownNavbarItem';
16
17
  import {useDocsPreferredVersion} from '@docusaurus/theme-common';
18
+ import {translate} from '@docusaurus/Translate';
19
+ import type {GlobalVersion} from '@docusaurus/plugin-content-docs/client';
20
+ import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
17
21
 
18
- const getVersionMainDoc = (version) =>
19
- version.docs.find((doc) => doc.id === version.mainDocId);
22
+ const getVersionMainDoc = (version: GlobalVersion) =>
23
+ version.docs.find((doc) => doc.id === version.mainDocId)!;
20
24
 
21
25
  export default function DocsVersionDropdownNavbarItem({
22
26
  mobile,
@@ -30,11 +34,10 @@ export default function DocsVersionDropdownNavbarItem({
30
34
  const versions = useVersions(docsPluginId);
31
35
  const latestVersion = useLatestVersion(docsPluginId);
32
36
 
33
- const {preferredVersion, savePreferredVersionName} = useDocsPreferredVersion(
34
- docsPluginId,
35
- );
37
+ const {preferredVersion, savePreferredVersionName} =
38
+ useDocsPreferredVersion(docsPluginId);
36
39
 
37
- function getItems() {
40
+ function getItems(): LinkLikeNavbarItemProps[] {
38
41
  const versionLinks = versions.map((version) => {
39
42
  // We try to link to the same doc, in another version
40
43
  // When not possible, fallback to the "main doc" of the version
@@ -52,20 +55,7 @@ export default function DocsVersionDropdownNavbarItem({
52
55
  };
53
56
  });
54
57
 
55
- const items = [
56
- ...dropdownItemsBefore,
57
- ...versionLinks,
58
- ...dropdownItemsAfter,
59
- ];
60
-
61
- // We don't want to render a version dropdown with 0 or 1 item
62
- // If we build the site with a single docs version (onlyIncludeVersions: ['1.0.0'])
63
- // We'd rather render a button instead of a dropdown
64
- if (items.length <= 1) {
65
- return undefined;
66
- }
67
-
68
- return items;
58
+ return [...dropdownItemsBefore, ...versionLinks, ...dropdownItemsAfter];
69
59
  }
70
60
 
71
61
  const items = getItems();
@@ -74,12 +64,37 @@ export default function DocsVersionDropdownNavbarItem({
74
64
  activeDocContext.activeVersion ?? preferredVersion ?? latestVersion;
75
65
 
76
66
  // Mobile dropdown is handled a bit differently
77
- const dropdownLabel = mobile && items ? 'Versions' : dropdownVersion.label;
67
+ const dropdownLabel =
68
+ mobile && items.length > 1
69
+ ? translate({
70
+ id: 'theme.navbar.mobileVersionsDropdown.label',
71
+ message: 'Versions',
72
+ description:
73
+ 'The label for the navbar versions dropdown on mobile view',
74
+ })
75
+ : dropdownVersion.label;
78
76
  const dropdownTo =
79
- mobile && items ? undefined : getVersionMainDoc(dropdownVersion).path;
77
+ mobile && items.length > 1
78
+ ? undefined
79
+ : getVersionMainDoc(dropdownVersion).path;
80
+
81
+ // We don't want to render a version dropdown with 0 or 1 item. If we build
82
+ // the site with a single docs version (onlyIncludeVersions: ['1.0.0']),
83
+ // We'd rather render a button instead of a dropdown
84
+ if (items.length <= 1) {
85
+ return (
86
+ <DefaultNavbarItem
87
+ {...props}
88
+ mobile={mobile}
89
+ label={dropdownLabel}
90
+ to={dropdownTo}
91
+ isActive={dropdownActiveClassDisabled ? () => false : undefined}
92
+ />
93
+ );
94
+ }
80
95
 
81
96
  return (
82
- <DefaultNavbarItem
97
+ <DropdownNavbarItem
83
98
  {...props}
84
99
  mobile={mobile}
85
100
  label={dropdownLabel}
@@ -7,12 +7,16 @@
7
7
 
8
8
  import React from 'react';
9
9
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
10
- import {useActiveVersion, useLatestVersion} from '@theme/hooks/useDocs';
10
+ import {
11
+ useActiveVersion,
12
+ useLatestVersion,
13
+ type GlobalVersion,
14
+ } from '@docusaurus/plugin-content-docs/client';
11
15
  import type {Props} from '@theme/NavbarItem/DocsVersionNavbarItem';
12
16
  import {useDocsPreferredVersion} from '@docusaurus/theme-common';
13
17
 
14
- const getVersionMainDoc = (version) =>
15
- version.docs.find((doc) => doc.id === version.mainDocId);
18
+ const getVersionMainDoc = (version: GlobalVersion) =>
19
+ version.docs.find((doc) => doc.id === version.mainDocId)!;
16
20
 
17
21
  export default function DocsVersionNavbarItem({
18
22
  label: staticLabel,
@@ -0,0 +1,181 @@
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, {useState, useRef, useEffect} from 'react';
9
+ import clsx from 'clsx';
10
+ import {
11
+ isSamePath,
12
+ useCollapsible,
13
+ Collapsible,
14
+ isRegexpStringMatch,
15
+ useLocalPathname,
16
+ } from '@docusaurus/theme-common';
17
+ import type {
18
+ DesktopOrMobileNavBarItemProps,
19
+ Props,
20
+ } from '@theme/NavbarItem/DropdownNavbarItem';
21
+ import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
22
+
23
+ import NavbarNavLink from '@theme/NavbarItem/NavbarNavLink';
24
+ import NavbarItem from '@theme/NavbarItem';
25
+
26
+ const dropdownLinkActiveClass = 'dropdown__link--active';
27
+
28
+ function isItemActive(
29
+ item: LinkLikeNavbarItemProps,
30
+ localPathname: string,
31
+ ): boolean {
32
+ if (isSamePath(item.to, localPathname)) {
33
+ return true;
34
+ }
35
+ if (isRegexpStringMatch(item.activeBaseRegex, localPathname)) {
36
+ return true;
37
+ }
38
+ if (item.activeBasePath && localPathname.startsWith(item.activeBasePath)) {
39
+ return true;
40
+ }
41
+ return false;
42
+ }
43
+
44
+ function containsActiveItems(
45
+ items: readonly LinkLikeNavbarItemProps[],
46
+ localPathname: string,
47
+ ): boolean {
48
+ return items.some((item) => isItemActive(item, localPathname));
49
+ }
50
+
51
+ function DropdownNavbarItemDesktop({
52
+ items,
53
+ position,
54
+ className,
55
+ ...props
56
+ }: DesktopOrMobileNavBarItemProps) {
57
+ const dropdownRef = useRef<HTMLDivElement>(null);
58
+ const [showDropdown, setShowDropdown] = useState(false);
59
+
60
+ useEffect(() => {
61
+ const handleClickOutside = (event: MouseEvent | TouchEvent) => {
62
+ if (
63
+ !dropdownRef.current ||
64
+ dropdownRef.current.contains(event.target as Node)
65
+ ) {
66
+ return;
67
+ }
68
+ setShowDropdown(false);
69
+ };
70
+
71
+ document.addEventListener('mousedown', handleClickOutside);
72
+ document.addEventListener('touchstart', handleClickOutside);
73
+
74
+ return () => {
75
+ document.removeEventListener('mousedown', handleClickOutside);
76
+ document.removeEventListener('touchstart', handleClickOutside);
77
+ };
78
+ }, [dropdownRef]);
79
+
80
+ return (
81
+ <div
82
+ ref={dropdownRef}
83
+ className={clsx('navbar__item', 'dropdown', 'dropdown--hoverable', {
84
+ 'dropdown--right': position === 'right',
85
+ 'dropdown--show': showDropdown,
86
+ })}>
87
+ <NavbarNavLink
88
+ href={props.to ? undefined : '#'}
89
+ className={clsx('navbar__link', className)}
90
+ {...props}
91
+ onClick={props.to ? undefined : (e) => e.preventDefault()}
92
+ onKeyDown={(e) => {
93
+ if (e.key === 'Enter') {
94
+ e.preventDefault();
95
+ setShowDropdown(!showDropdown);
96
+ }
97
+ }}>
98
+ {props.children ?? props.label}
99
+ </NavbarNavLink>
100
+ <ul className="dropdown__menu">
101
+ {items.map((childItemProps, i) => (
102
+ <NavbarItem
103
+ isDropdownItem
104
+ onKeyDown={(e) => {
105
+ if (i === items.length - 1 && e.key === 'Tab') {
106
+ e.preventDefault();
107
+ setShowDropdown(false);
108
+ const nextNavbarItem = dropdownRef.current!.nextElementSibling;
109
+ if (nextNavbarItem) {
110
+ (nextNavbarItem as HTMLElement).focus();
111
+ }
112
+ }
113
+ }}
114
+ activeClassName={dropdownLinkActiveClass}
115
+ {...childItemProps}
116
+ key={i}
117
+ />
118
+ ))}
119
+ </ul>
120
+ </div>
121
+ );
122
+ }
123
+
124
+ function DropdownNavbarItemMobile({
125
+ items,
126
+ className,
127
+ position: _position, // Need to destructure position from props so that it doesn't get passed on.
128
+ ...props
129
+ }: DesktopOrMobileNavBarItemProps) {
130
+ const localPathname = useLocalPathname();
131
+ const containsActive = containsActiveItems(items, localPathname);
132
+
133
+ const {collapsed, toggleCollapsed, setCollapsed} = useCollapsible({
134
+ initialState: () => !containsActive,
135
+ });
136
+
137
+ // Expand/collapse if any item active after a navigation
138
+ useEffect(() => {
139
+ if (containsActive) {
140
+ setCollapsed(!containsActive);
141
+ }
142
+ }, [localPathname, containsActive, setCollapsed]);
143
+
144
+ return (
145
+ <li
146
+ className={clsx('menu__list-item', {
147
+ 'menu__list-item--collapsed': collapsed,
148
+ })}>
149
+ <NavbarNavLink
150
+ role="button"
151
+ className={clsx('menu__link menu__link--sublist', className)}
152
+ {...props}
153
+ onClick={(e) => {
154
+ e.preventDefault();
155
+ toggleCollapsed();
156
+ }}>
157
+ {props.children ?? props.label}
158
+ </NavbarNavLink>
159
+ <Collapsible lazy as="ul" className="menu__list" collapsed={collapsed}>
160
+ {items.map((childItemProps, i) => (
161
+ <NavbarItem
162
+ mobile
163
+ isDropdownItem
164
+ onClick={props.onClick}
165
+ activeClassName="menu__link--active"
166
+ {...childItemProps}
167
+ key={i}
168
+ />
169
+ ))}
170
+ </Collapsible>
171
+ </li>
172
+ );
173
+ }
174
+
175
+ export default function DropdownNavbarItem({
176
+ mobile = false,
177
+ ...props
178
+ }: Props): JSX.Element {
179
+ const Comp = mobile ? DropdownNavbarItemMobile : DropdownNavbarItemDesktop;
180
+ return <Comp {...props} />;
181
+ }
@@ -6,11 +6,15 @@
6
6
  */
7
7
 
8
8
  import React from 'react';
9
- import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
9
+ import DropdownNavbarItem from '@theme/NavbarItem/DropdownNavbarItem';
10
10
  import IconLanguage from '@theme/IconLanguage';
11
11
  import type {Props} from '@theme/NavbarItem/LocaleDropdownNavbarItem';
12
12
  import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
13
13
  import {useAlternatePageUtils} from '@docusaurus/theme-common';
14
+ import {translate} from '@docusaurus/Translate';
15
+ import type {LinkLikeNavbarItemProps} from '@theme/NavbarItem';
16
+
17
+ import styles from './styles.module.css';
14
18
 
15
19
  export default function LocaleDropdownNavbarItem({
16
20
  mobile,
@@ -23,11 +27,11 @@ export default function LocaleDropdownNavbarItem({
23
27
  } = useDocusaurusContext();
24
28
  const alternatePageUtils = useAlternatePageUtils();
25
29
 
26
- function getLocaleLabel(locale) {
30
+ function getLocaleLabel(locale: string) {
27
31
  return localeConfigs[locale].label;
28
32
  }
29
33
 
30
- const localeItems = locales.map((locale) => {
34
+ const localeItems = locales.map((locale): LinkLikeNavbarItemProps => {
31
35
  const to = `pathname://${alternatePageUtils.createUrl({
32
36
  locale,
33
37
  fullyQualified: false,
@@ -39,25 +43,27 @@ export default function LocaleDropdownNavbarItem({
39
43
  target: '_self',
40
44
  autoAddBaseUrl: false,
41
45
  className: locale === currentLocale ? 'dropdown__link--active' : '',
42
- style: {textTransform: 'capitalize'},
43
46
  };
44
47
  });
45
48
 
46
49
  const items = [...dropdownItemsBefore, ...localeItems, ...dropdownItemsAfter];
47
50
 
48
51
  // Mobile is handled a bit differently
49
- const dropdownLabel = mobile ? 'Languages' : getLocaleLabel(currentLocale);
52
+ const dropdownLabel = mobile
53
+ ? translate({
54
+ message: 'Languages',
55
+ id: 'theme.navbar.mobileLanguageDropdown.label',
56
+ description: 'The label for the mobile language switcher dropdown',
57
+ })
58
+ : getLocaleLabel(currentLocale);
50
59
 
51
60
  return (
52
- <DefaultNavbarItem
61
+ <DropdownNavbarItem
53
62
  {...props}
54
- href="#"
55
63
  mobile={mobile}
56
64
  label={
57
65
  <span>
58
- <IconLanguage
59
- style={{verticalAlign: 'text-bottom', marginRight: 5}}
60
- />
66
+ <IconLanguage className={styles.iconLanguage} />
61
67
  <span>{dropdownLabel}</span>
62
68
  </span>
63
69
  }
@@ -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
+
8
+ .iconLanguage {
9
+ vertical-align: text-bottom;
10
+ margin-right: 5px;
11
+ }
@@ -0,0 +1,68 @@
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 useBaseUrl from '@docusaurus/useBaseUrl';
11
+ import type {Props} from '@theme/NavbarItem/NavbarNavLink';
12
+ import IconExternalLink from '@theme/IconExternalLink';
13
+ import isInternalUrl from '@docusaurus/isInternalUrl';
14
+ import {isRegexpStringMatch} from '@docusaurus/theme-common';
15
+
16
+ const dropdownLinkActiveClass = 'dropdown__link--active';
17
+
18
+ export default function NavbarNavLink({
19
+ activeBasePath,
20
+ activeBaseRegex,
21
+ to,
22
+ href,
23
+ label,
24
+ activeClassName = '',
25
+ prependBaseUrlToHref,
26
+ ...props
27
+ }: Props): JSX.Element {
28
+ // TODO all this seems hacky
29
+ // {to: 'version'} should probably be forbidden, in favor of {to: '/version'}
30
+ const toUrl = useBaseUrl(to);
31
+ const activeBaseUrl = useBaseUrl(activeBasePath);
32
+ const normalizedHref = useBaseUrl(href, {forcePrependBaseUrl: true});
33
+ const isExternalLink = label && href && !isInternalUrl(href);
34
+ const isDropdownLink = activeClassName === dropdownLinkActiveClass;
35
+
36
+ return (
37
+ <Link
38
+ {...(href
39
+ ? {
40
+ href: prependBaseUrlToHref ? normalizedHref : href,
41
+ }
42
+ : {
43
+ isNavLink: true,
44
+ activeClassName: !props.className?.includes(activeClassName)
45
+ ? activeClassName
46
+ : '',
47
+ to: toUrl,
48
+ ...(activeBasePath || activeBaseRegex
49
+ ? {
50
+ isActive: (_match, location) =>
51
+ activeBaseRegex
52
+ ? isRegexpStringMatch(activeBaseRegex, location.pathname)
53
+ : location.pathname.startsWith(activeBaseUrl),
54
+ }
55
+ : null),
56
+ })}
57
+ {...props}>
58
+ {isExternalLink ? (
59
+ <span>
60
+ {label}
61
+ <IconExternalLink {...(isDropdownLink && {width: 12, height: 12})} />
62
+ </span>
63
+ ) : (
64
+ label
65
+ )}
66
+ </Link>
67
+ );
68
+ }
@@ -7,39 +7,62 @@
7
7
 
8
8
  import React from 'react';
9
9
  import DefaultNavbarItem from '@theme/NavbarItem/DefaultNavbarItem';
10
+ import DropdownNavbarItem, {
11
+ type Props as DropdownNavbarItemProps,
12
+ } from '@theme/NavbarItem/DropdownNavbarItem';
10
13
  import LocaleDropdownNavbarItem from '@theme/NavbarItem/LocaleDropdownNavbarItem';
11
14
  import SearchNavbarItem from '@theme/NavbarItem/SearchNavbarItem';
12
- import type {Props} from '@theme/NavbarItem';
15
+ import type {Types, Props} from '@theme/NavbarItem';
13
16
 
14
- const NavbarItemComponents = {
17
+ const NavbarItemComponents: Record<
18
+ Exclude<Types, undefined>,
19
+ // Not really worth typing, as we pass all props down immediately
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
21
+ () => (props: any) => JSX.Element
22
+ > = {
15
23
  default: () => DefaultNavbarItem,
16
24
  localeDropdown: () => LocaleDropdownNavbarItem,
17
25
  search: () => SearchNavbarItem,
26
+ dropdown: () => DropdownNavbarItem,
18
27
 
19
- // Need to lazy load these items as we don't know for sure the docs plugin is loaded
20
- // See https://github.com/facebook/docusaurus/issues/3360
21
- docsVersion: () =>
22
- // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
23
- require('@theme/NavbarItem/DocsVersionNavbarItem').default,
28
+ // Need to lazy load these items as we don't know for sure the docs plugin is
29
+ // loaded. See https://github.com/facebook/docusaurus/issues/3360
30
+ /* eslint-disable @typescript-eslint/no-var-requires, global-require */
31
+ docsVersion: () => require('@theme/NavbarItem/DocsVersionNavbarItem').default,
24
32
  docsVersionDropdown: () =>
25
- // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
26
33
  require('@theme/NavbarItem/DocsVersionDropdownNavbarItem').default,
27
- doc: () =>
28
- // eslint-disable-next-line @typescript-eslint/no-var-requires, global-require
29
- require('@theme/NavbarItem/DocNavbarItem').default,
34
+ doc: () => require('@theme/NavbarItem/DocNavbarItem').default,
35
+ docSidebar: () => require('@theme/NavbarItem/DocSidebarNavbarItem').default,
36
+ /* eslint-enable @typescript-eslint/no-var-requires, global-require */
30
37
  } as const;
31
38
 
32
- const getNavbarItemComponent = (
33
- type: keyof typeof NavbarItemComponents = 'default',
34
- ) => {
35
- const navbarItemComponent = NavbarItemComponents[type];
36
- if (!navbarItemComponent) {
39
+ type NavbarItemComponentType = keyof typeof NavbarItemComponents;
40
+
41
+ const getNavbarItemComponent = (type: NavbarItemComponentType) => {
42
+ const navbarItemComponentFn = NavbarItemComponents[type];
43
+ if (!navbarItemComponentFn) {
37
44
  throw new Error(`No NavbarItem component found for type "${type}".`);
38
45
  }
39
- return navbarItemComponent();
46
+ return navbarItemComponentFn();
40
47
  };
41
48
 
49
+ function getComponentType(
50
+ type: Types,
51
+ isDropdown: boolean,
52
+ ): NavbarItemComponentType {
53
+ // Backward compatibility: navbar item with no type set
54
+ // but containing dropdown items should use the type "dropdown"
55
+ if (!type || type === 'default') {
56
+ return isDropdown ? 'dropdown' : 'default';
57
+ }
58
+ return type as NavbarItemComponentType;
59
+ }
60
+
42
61
  export default function NavbarItem({type, ...props}: Props): JSX.Element {
43
- const NavbarItemComponent = getNavbarItemComponent(type);
62
+ const componentType = getComponentType(
63
+ type,
64
+ (props as DropdownNavbarItemProps).items !== undefined,
65
+ );
66
+ const NavbarItemComponent = getNavbarItemComponent(componentType);
44
67
  return <NavbarItemComponent {...props} />;
45
68
  }