@docusaurus/theme-classic 2.0.0-beta.14 → 2.0.0-beta.15

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 (152) hide show
  1. package/README.md +1 -1
  2. package/lib/index.js +7 -16
  3. package/lib/theme-classic.d.ts +89 -182
  4. package/lib/validateThemeConfig.js +13 -1
  5. package/lib-next/theme/BackToTopButton/styles.module.css +1 -1
  6. package/lib-next/theme/BlogListPaginator/index.js +12 -12
  7. package/lib-next/theme/BlogPostAuthor/index.js +1 -1
  8. package/lib-next/theme/BlogPostAuthors/index.js +12 -2
  9. package/lib-next/theme/BlogPostAuthors/styles.module.css +10 -0
  10. package/lib-next/theme/BlogPostItem/index.js +12 -15
  11. package/lib-next/theme/BlogPostPage/index.js +10 -7
  12. package/lib-next/theme/BlogPostPaginator/index.js +11 -15
  13. package/lib-next/theme/BlogSidebar/styles.module.css +2 -0
  14. package/lib-next/theme/CodeBlock/index.js +44 -9
  15. package/lib-next/theme/CodeBlock/styles.module.css +12 -7
  16. package/lib-next/theme/DocCard/styles.module.css +3 -3
  17. package/lib-next/theme/DocCategoryGeneratedIndexPage/index.js +6 -3
  18. package/lib-next/theme/DocItem/index.js +9 -6
  19. package/lib-next/theme/DocItem/styles.module.css +2 -2
  20. package/lib-next/theme/DocPage/index.js +7 -3
  21. package/lib-next/theme/DocPage/styles.module.css +1 -0
  22. package/lib-next/theme/DocPaginator/index.js +26 -4
  23. package/lib-next/theme/DocSidebar/index.js +2 -2
  24. package/lib-next/theme/DocSidebar/styles.module.css +1 -0
  25. package/lib-next/theme/DocSidebarItem/index.js +43 -21
  26. package/lib-next/theme/DocSidebarItem/styles.module.css +1 -0
  27. package/lib-next/theme/DocSidebarItems/index.js +28 -0
  28. package/{src/theme/hooks/styles.css → lib-next/theme/DocSidebarItems/styles.module.css} +12 -2
  29. package/lib-next/theme/DocVersionBanner/index.js +4 -1
  30. package/lib-next/theme/Footer/styles.module.css +2 -1
  31. package/lib-next/theme/Heading/index.js +39 -42
  32. package/lib-next/theme/Heading/styles.css +1 -1
  33. package/lib-next/theme/Layout/index.js +1 -2
  34. package/lib-next/theme/LayoutHead/index.js +5 -9
  35. package/lib-next/theme/LayoutProviders/index.js +6 -6
  36. package/lib-next/theme/MDXComponents/index.js +18 -31
  37. package/lib-next/theme/MDXComponents/styles.css +4 -0
  38. package/lib-next/theme/MDXPage/index.js +3 -10
  39. package/lib-next/theme/Navbar/index.js +6 -6
  40. package/lib-next/theme/NavbarItem/DefaultNavbarItem.js +4 -66
  41. package/lib-next/theme/NavbarItem/DocNavbarItem.js +5 -2
  42. package/lib-next/theme/NavbarItem/DocSidebarNavbarItem.js +73 -0
  43. package/lib-next/theme/NavbarItem/DocsVersionDropdownNavbarItem.js +5 -3
  44. package/lib-next/theme/NavbarItem/DocsVersionNavbarItem.js +4 -1
  45. package/lib-next/theme/NavbarItem/DropdownNavbarItem.js +5 -5
  46. package/lib-next/theme/NavbarItem/NavbarNavLink.js +70 -0
  47. package/lib-next/theme/NavbarItem/index.js +1 -2
  48. package/lib-next/theme/{hooks/styles.css → NavbarItem/utils.js} +3 -4
  49. package/lib-next/theme/PaginatorNavLink/index.js +20 -0
  50. package/lib-next/theme/SkipToContent/index.js +1 -1
  51. package/lib-next/theme/SkipToContent/styles.module.css +7 -0
  52. package/lib-next/theme/TOCCollapsible/styles.module.css +2 -2
  53. package/lib-next/theme/Tabs/__tests__/index.test.js +8 -6
  54. package/lib-next/theme/Tabs/index.js +6 -3
  55. package/lib-next/theme/Tag/styles.module.css +4 -4
  56. package/lib-next/theme/ThemedImage/index.js +2 -2
  57. package/lib-next/theme/Toggle/styles.module.css +16 -15
  58. package/lib-next/theme/prism-include-languages.js +10 -3
  59. package/package.json +16 -17
  60. package/src/index.ts +10 -21
  61. package/src/theme/Admonition/index.tsx +1 -1
  62. package/src/theme/BackToTopButton/styles.module.css +1 -1
  63. package/src/theme/BlogListPaginator/index.tsx +12 -12
  64. package/src/theme/BlogPostAuthor/index.tsx +1 -1
  65. package/src/theme/BlogPostAuthors/index.tsx +12 -2
  66. package/src/theme/BlogPostAuthors/styles.module.css +10 -0
  67. package/src/theme/BlogPostItem/index.tsx +13 -15
  68. package/src/theme/BlogPostPage/index.tsx +10 -7
  69. package/src/theme/BlogPostPaginator/index.tsx +11 -15
  70. package/src/theme/BlogSidebar/styles.module.css +2 -0
  71. package/src/theme/CodeBlock/index.tsx +45 -10
  72. package/src/theme/CodeBlock/styles.module.css +12 -7
  73. package/src/theme/DocCard/index.tsx +2 -2
  74. package/src/theme/DocCard/styles.module.css +3 -3
  75. package/src/theme/DocCardList/index.tsx +1 -1
  76. package/src/theme/DocCategoryGeneratedIndexPage/index.tsx +7 -3
  77. package/src/theme/DocItem/index.tsx +9 -6
  78. package/src/theme/DocItem/styles.module.css +2 -2
  79. package/src/theme/DocItemFooter/index.tsx +1 -1
  80. package/src/theme/DocPage/index.tsx +8 -4
  81. package/src/theme/DocPage/styles.module.css +1 -0
  82. package/src/theme/DocPaginator/index.tsx +26 -4
  83. package/src/theme/DocSidebar/index.tsx +3 -3
  84. package/src/theme/DocSidebar/styles.module.css +1 -0
  85. package/src/theme/DocSidebarItem/index.tsx +34 -23
  86. package/src/theme/DocSidebarItem/styles.module.css +1 -0
  87. package/src/theme/DocSidebarItems/index.tsx +32 -0
  88. package/src/theme/{UserPreferencesContext.ts → DocSidebarItems/styles.module.css} +11 -3
  89. package/src/theme/DocVersionBanner/index.tsx +3 -3
  90. package/src/theme/Footer/index.tsx +4 -4
  91. package/src/theme/Footer/styles.module.css +2 -1
  92. package/src/theme/Heading/index.tsx +39 -46
  93. package/src/theme/Heading/styles.css +1 -1
  94. package/src/theme/Layout/index.tsx +1 -2
  95. package/src/theme/LayoutHead/index.tsx +4 -8
  96. package/src/theme/LayoutProviders/index.tsx +6 -6
  97. package/src/theme/MDXComponents/index.tsx +26 -37
  98. package/src/theme/MDXComponents/styles.css +4 -0
  99. package/src/theme/MDXPage/index.tsx +3 -11
  100. package/src/theme/Navbar/index.tsx +7 -7
  101. package/src/theme/NavbarItem/DefaultNavbarItem.tsx +6 -62
  102. package/src/theme/NavbarItem/DocNavbarItem.tsx +8 -5
  103. package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +84 -0
  104. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +9 -6
  105. package/src/theme/NavbarItem/DocsVersionNavbarItem.tsx +2 -2
  106. package/src/theme/NavbarItem/DropdownNavbarItem.tsx +5 -5
  107. package/src/theme/NavbarItem/NavbarNavLink.tsx +68 -0
  108. package/src/theme/NavbarItem/index.tsx +3 -5
  109. package/{lib-next/theme/UserPreferencesContext.js → src/theme/NavbarItem/utils.ts} +4 -3
  110. package/src/theme/PaginatorNavLink/index.tsx +22 -0
  111. package/src/theme/SkipToContent/index.tsx +1 -1
  112. package/src/theme/SkipToContent/styles.module.css +7 -0
  113. package/src/theme/TOCCollapsible/styles.module.css +2 -2
  114. package/src/theme/TOCItems/index.tsx +2 -2
  115. package/src/theme/Tabs/index.tsx +7 -4
  116. package/src/theme/Tag/styles.module.css +4 -4
  117. package/src/theme/TagsListByLetter/index.tsx +1 -1
  118. package/src/theme/ThemedImage/index.tsx +2 -2
  119. package/src/theme/Toggle/index.tsx +1 -1
  120. package/src/theme/Toggle/styles.module.css +16 -15
  121. package/src/theme/prism-include-languages.ts +10 -3
  122. package/src/theme-classic.d.ts +89 -182
  123. package/src/translations.ts +2 -2
  124. package/src/validateThemeConfig.ts +16 -0
  125. package/lib-next/theme/DocPaginatorNavLink/index.js +0 -36
  126. package/lib-next/theme/ThemeContext.js +0 -9
  127. package/lib-next/theme/ThemeProvider/index.js +0 -28
  128. package/lib-next/theme/UserPreferencesProvider/index.js +0 -27
  129. package/lib-next/theme/hooks/useDocs.js +0 -10
  130. package/lib-next/theme/hooks/useHideableNavbar.js +0 -66
  131. package/lib-next/theme/hooks/useKeyboardNavigation.js +0 -35
  132. package/lib-next/theme/hooks/useLockBodyScroll.js +0 -18
  133. package/lib-next/theme/hooks/usePrismTheme.js +0 -20
  134. package/lib-next/theme/hooks/useTabGroupChoice.js +0 -39
  135. package/lib-next/theme/hooks/useTheme.js +0 -81
  136. package/lib-next/theme/hooks/useThemeContext.js +0 -22
  137. package/lib-next/theme/hooks/useUserPreferencesContext.js +0 -22
  138. package/lib-next/theme/hooks/useWindowSize.js +0 -59
  139. package/src/theme/DocPaginatorNavLink/index.tsx +0 -38
  140. package/src/theme/ThemeContext.ts +0 -15
  141. package/src/theme/ThemeProvider/index.tsx +0 -28
  142. package/src/theme/UserPreferencesProvider/index.tsx +0 -30
  143. package/src/theme/hooks/useDocs.ts +0 -11
  144. package/src/theme/hooks/useHideableNavbar.ts +0 -72
  145. package/src/theme/hooks/useKeyboardNavigation.ts +0 -39
  146. package/src/theme/hooks/useLockBodyScroll.ts +0 -20
  147. package/src/theme/hooks/usePrismTheme.ts +0 -22
  148. package/src/theme/hooks/useTabGroupChoice.ts +0 -46
  149. package/src/theme/hooks/useTheme.ts +0 -91
  150. package/src/theme/hooks/useThemeContext.ts +0 -23
  151. package/src/theme/hooks/useUserPreferencesContext.ts +0 -25
  152. package/src/theme/hooks/useWindowSize.ts +0 -69
@@ -1,35 +0,0 @@
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 {useEffect} from 'react';
8
- import './styles.css'; // This hook detect keyboard focus indicator to not show outline for mouse users
9
- // Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
10
-
11
- function useKeyboardNavigation() {
12
- useEffect(() => {
13
- const keyboardFocusedClassName = 'navigation-with-keyboard';
14
-
15
- function handleOutlineStyles(e) {
16
- if (e.type === 'keydown' && e.key === 'Tab') {
17
- document.body.classList.add(keyboardFocusedClassName);
18
- }
19
-
20
- if (e.type === 'mousedown') {
21
- document.body.classList.remove(keyboardFocusedClassName);
22
- }
23
- }
24
-
25
- document.addEventListener('keydown', handleOutlineStyles);
26
- document.addEventListener('mousedown', handleOutlineStyles);
27
- return () => {
28
- document.body.classList.remove(keyboardFocusedClassName);
29
- document.removeEventListener('keydown', handleOutlineStyles);
30
- document.removeEventListener('mousedown', handleOutlineStyles);
31
- };
32
- }, []);
33
- }
34
-
35
- export default useKeyboardNavigation;
@@ -1,18 +0,0 @@
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 {useEffect} from 'react';
8
-
9
- function useLockBodyScroll(lock = true) {
10
- useEffect(() => {
11
- document.body.style.overflow = lock ? 'hidden' : 'visible';
12
- return () => {
13
- document.body.style.overflow = 'visible';
14
- };
15
- }, [lock]);
16
- }
17
-
18
- export default useLockBodyScroll;
@@ -1,20 +0,0 @@
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 defaultTheme from 'prism-react-renderer/themes/palenight';
8
- import useThemeContext from '@theme/hooks/useThemeContext';
9
- import {useThemeConfig} from '@docusaurus/theme-common';
10
-
11
- const usePrismTheme = () => {
12
- const {prism} = useThemeConfig();
13
- const {isDarkTheme} = useThemeContext();
14
- const lightModeTheme = prism.theme || defaultTheme;
15
- const darkModeTheme = prism.darkTheme || lightModeTheme;
16
- const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
17
- return prismTheme;
18
- };
19
-
20
- export default usePrismTheme;
@@ -1,39 +0,0 @@
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 {useState, useCallback, useEffect} from 'react';
8
- import {createStorageSlot, listStorageKeys} from '@docusaurus/theme-common';
9
- const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
10
-
11
- const useTabGroupChoice = () => {
12
- const [tabGroupChoices, setChoices] = useState({});
13
- const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => {
14
- createStorageSlot(`${TAB_CHOICE_PREFIX}${groupId}`).set(newChoice);
15
- }, []);
16
- useEffect(() => {
17
- try {
18
- const localStorageChoices = {};
19
- listStorageKeys().forEach((storageKey) => {
20
- if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
21
- const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
22
- localStorageChoices[groupId] = createStorageSlot(storageKey).get();
23
- }
24
- });
25
- setChoices(localStorageChoices);
26
- } catch (err) {
27
- console.error(err);
28
- }
29
- }, []);
30
- return {
31
- tabGroupChoices,
32
- setTabGroupChoices: (groupId, newChoice) => {
33
- setChoices((oldChoices) => ({...oldChoices, [groupId]: newChoice}));
34
- setChoiceSyncWithLocalStorage(groupId, newChoice);
35
- },
36
- };
37
- };
38
-
39
- export default useTabGroupChoice;
@@ -1,81 +0,0 @@
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 {useState, useCallback, useEffect} from 'react';
8
- import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
- import {useThemeConfig, createStorageSlot} from '@docusaurus/theme-common';
10
- const ThemeStorage = createStorageSlot('theme');
11
- const themes = {
12
- light: 'light',
13
- dark: 'dark',
14
- };
15
-
16
- // Ensure to always return a valid theme even if input is invalid
17
- const coerceToTheme = (theme) =>
18
- theme === themes.dark ? themes.dark : themes.light;
19
-
20
- const getInitialTheme = (defaultMode) => {
21
- if (!ExecutionEnvironment.canUseDOM) {
22
- return coerceToTheme(defaultMode);
23
- }
24
-
25
- return coerceToTheme(document.documentElement.getAttribute('data-theme'));
26
- };
27
-
28
- const storeTheme = (newTheme) => {
29
- createStorageSlot('theme').set(coerceToTheme(newTheme));
30
- };
31
-
32
- const useTheme = () => {
33
- const {
34
- colorMode: {defaultMode, disableSwitch, respectPrefersColorScheme},
35
- } = useThemeConfig();
36
- const [theme, setTheme] = useState(getInitialTheme(defaultMode));
37
- const setLightTheme = useCallback(() => {
38
- setTheme(themes.light);
39
- storeTheme(themes.light);
40
- }, []);
41
- const setDarkTheme = useCallback(() => {
42
- setTheme(themes.dark);
43
- storeTheme(themes.dark);
44
- }, []);
45
- useEffect(() => {
46
- document.documentElement.setAttribute('data-theme', coerceToTheme(theme));
47
- }, [theme]);
48
- useEffect(() => {
49
- if (disableSwitch) {
50
- return;
51
- }
52
-
53
- try {
54
- const storedTheme = ThemeStorage.get();
55
-
56
- if (storedTheme !== null) {
57
- setTheme(coerceToTheme(storedTheme));
58
- }
59
- } catch (err) {
60
- console.error(err);
61
- }
62
- }, [disableSwitch, setTheme]);
63
- useEffect(() => {
64
- if (disableSwitch && !respectPrefersColorScheme) {
65
- return;
66
- }
67
-
68
- window
69
- .matchMedia('(prefers-color-scheme: dark)')
70
- .addListener(({matches}) => {
71
- setTheme(matches ? themes.dark : themes.light);
72
- });
73
- }, [disableSwitch, respectPrefersColorScheme]);
74
- return {
75
- isDarkTheme: theme === themes.dark,
76
- setLightTheme,
77
- setDarkTheme,
78
- };
79
- };
80
-
81
- export default useTheme;
@@ -1,22 +0,0 @@
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 {useContext} from 'react';
8
- import ThemeContext from '@theme/ThemeContext';
9
-
10
- function useThemeContext() {
11
- const context = useContext(ThemeContext);
12
-
13
- if (context == null) {
14
- throw new Error(
15
- '"useThemeContext" is used outside of "Layout" component. Please see https://docusaurus.io/docs/api/themes/configuration#usethemecontext.',
16
- );
17
- }
18
-
19
- return context;
20
- }
21
-
22
- export default useThemeContext;
@@ -1,22 +0,0 @@
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 {useContext} from 'react';
8
- import UserPreferencesContext from '@theme/UserPreferencesContext';
9
-
10
- function useUserPreferencesContext() {
11
- const context = useContext(UserPreferencesContext);
12
-
13
- if (context == null) {
14
- throw new Error(
15
- '"useUserPreferencesContext" is used outside of "Layout" component.',
16
- );
17
- }
18
-
19
- return context;
20
- }
21
-
22
- export default useUserPreferencesContext;
@@ -1,59 +0,0 @@
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 {useEffect, useState} from 'react';
8
- import ExecutionEnvironment from '@docusaurus/ExecutionEnvironment';
9
- const windowSizes = {
10
- desktop: 'desktop',
11
- mobile: 'mobile',
12
- // This "ssr" value is very important to handle hydration FOUC / layout shifts
13
- // You have to handle server-rendering explicitly on the call-site
14
- // On the server, you may need to render BOTH the mobile/desktop elements (and hide one of them with mediaquery)
15
- // We don't return "undefined" on purpose, to make it more explicit
16
- ssr: 'ssr',
17
- };
18
- const DesktopThresholdWidth = 996;
19
-
20
- function getWindowSize() {
21
- if (!ExecutionEnvironment.canUseDOM) {
22
- return windowSizes.ssr;
23
- }
24
-
25
- return window.innerWidth > DesktopThresholdWidth
26
- ? windowSizes.desktop
27
- : windowSizes.mobile;
28
- } // Simulate the SSR window size in dev, so that potential hydration FOUC/layout shift problems can be seen in dev too!
29
-
30
- const DevSimulateSSR = process.env.NODE_ENV === 'development' && true; // This hook returns an enum value on purpose!
31
- // We don't want it to return the actual width value, for resize perf reasons
32
- // We only want to re-render once a breakpoint is crossed
33
-
34
- function useWindowSize() {
35
- const [windowSize, setWindowSize] = useState(() => {
36
- if (DevSimulateSSR) {
37
- return 'ssr';
38
- }
39
-
40
- return getWindowSize();
41
- });
42
- useEffect(() => {
43
- function updateWindowSize() {
44
- setWindowSize(getWindowSize());
45
- }
46
-
47
- const timeout = DevSimulateSSR
48
- ? window.setTimeout(updateWindowSize, 1000)
49
- : undefined;
50
- window.addEventListener('resize', updateWindowSize);
51
- return () => {
52
- window.removeEventListener('resize', updateWindowSize);
53
- clearTimeout(timeout);
54
- };
55
- }, []);
56
- return windowSize;
57
- }
58
-
59
- export default useWindowSize;
@@ -1,38 +0,0 @@
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 Link from '@docusaurus/Link';
11
- import Translate from '@docusaurus/Translate';
12
- import type {Props} from '@theme/DocPaginatorNavLink';
13
-
14
- function DocPaginatorNavLink(props: Props): JSX.Element {
15
- const {navLink, next} = props;
16
- return (
17
- <Link className={clsx('pagination-nav__link')} to={navLink.permalink}>
18
- <div className="pagination-nav__sublabel">
19
- {next ? (
20
- <Translate
21
- id="theme.docs.paginator.next"
22
- description="The label used to navigate to the next doc">
23
- Next
24
- </Translate>
25
- ) : (
26
- <Translate
27
- id="theme.docs.paginator.previous"
28
- description="The label used to navigate to the previous doc">
29
- Previous
30
- </Translate>
31
- )}
32
- </div>
33
- <div className="pagination-nav__label">{navLink.title}</div>
34
- </Link>
35
- );
36
- }
37
-
38
- export default DocPaginatorNavLink;
@@ -1,15 +0,0 @@
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 {ThemeContextProps} from '@theme/hooks/useThemeContext';
10
-
11
- const ThemeContext = React.createContext<ThemeContextProps | undefined>(
12
- undefined,
13
- );
14
-
15
- export default ThemeContext;
@@ -1,28 +0,0 @@
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, {useMemo} from 'react';
9
-
10
- import useTheme from '@theme/hooks/useTheme';
11
- import ThemeContext from '@theme/ThemeContext';
12
- import type {Props} from '@theme/ThemeProvider';
13
-
14
- function ThemeProvider(props: Props): JSX.Element {
15
- const {isDarkTheme, setLightTheme, setDarkTheme} = useTheme();
16
- const contextValue = useMemo(
17
- () => ({isDarkTheme, setLightTheme, setDarkTheme}),
18
- [isDarkTheme, setLightTheme, setDarkTheme],
19
- );
20
-
21
- return (
22
- <ThemeContext.Provider value={contextValue}>
23
- {props.children}
24
- </ThemeContext.Provider>
25
- );
26
- }
27
-
28
- export default ThemeProvider;
@@ -1,30 +0,0 @@
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, {useMemo} from 'react';
9
-
10
- import useTabGroupChoice from '@theme/hooks/useTabGroupChoice';
11
- import UserPreferencesContext from '@theme/UserPreferencesContext';
12
- import type {Props} from '@theme/UserPreferencesProvider';
13
-
14
- function UserPreferencesProvider(props: Props): JSX.Element {
15
- const {tabGroupChoices, setTabGroupChoices} = useTabGroupChoice();
16
- const contextValue = useMemo(
17
- () => ({
18
- tabGroupChoices,
19
- setTabGroupChoices,
20
- }),
21
- [tabGroupChoices, setTabGroupChoices],
22
- );
23
- return (
24
- <UserPreferencesContext.Provider value={contextValue}>
25
- {props.children}
26
- </UserPreferencesContext.Provider>
27
- );
28
- }
29
-
30
- export default UserPreferencesProvider;
@@ -1,11 +0,0 @@
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
- // Re-expose useDocs
9
- // Ensure it's always statically available even if user is not using the docs plugin
10
- // Problem reported for the blog-only mode: https://github.com/facebook/docusaurus/issues/3360
11
- export * from '@docusaurus/plugin-content-docs/lib/theme/hooks/useDocs';
@@ -1,72 +0,0 @@
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 {useState, useCallback, useRef} from 'react';
9
- import {useLocationChange, useScrollPosition} from '@docusaurus/theme-common';
10
- import type {useHideableNavbarReturns} from '@theme/hooks/useHideableNavbar';
11
-
12
- const useHideableNavbar = (hideOnScroll: boolean): useHideableNavbarReturns => {
13
- const [isNavbarVisible, setIsNavbarVisible] = useState(hideOnScroll);
14
- const isFocusedAnchor = useRef(false);
15
- const navbarHeight = useRef(0);
16
- const navbarRef = useCallback((node: HTMLElement | null) => {
17
- if (node !== null) {
18
- navbarHeight.current = node.getBoundingClientRect().height;
19
- }
20
- }, []);
21
-
22
- useScrollPosition((currentPosition, lastPosition) => {
23
- if (!hideOnScroll) {
24
- return;
25
- }
26
-
27
- const scrollTop = currentPosition.scrollY;
28
-
29
- // It needed for mostly to handle rubber band scrolling
30
- if (scrollTop < navbarHeight.current) {
31
- setIsNavbarVisible(true);
32
- return;
33
- }
34
-
35
- if (isFocusedAnchor.current) {
36
- isFocusedAnchor.current = false;
37
- return;
38
- }
39
-
40
- const lastScrollTop = lastPosition?.scrollY;
41
- const documentHeight =
42
- document.documentElement.scrollHeight - navbarHeight.current;
43
- const windowHeight = window.innerHeight;
44
-
45
- if (lastScrollTop && scrollTop >= lastScrollTop) {
46
- setIsNavbarVisible(false);
47
- } else if (scrollTop + windowHeight < documentHeight) {
48
- setIsNavbarVisible(true);
49
- }
50
- });
51
-
52
- useLocationChange((locationChangeEvent) => {
53
- if (!hideOnScroll) {
54
- return;
55
- }
56
-
57
- if (locationChangeEvent.location.hash) {
58
- isFocusedAnchor.current = true;
59
- setIsNavbarVisible(false);
60
- return;
61
- }
62
-
63
- setIsNavbarVisible(true);
64
- });
65
-
66
- return {
67
- navbarRef,
68
- isNavbarVisible,
69
- };
70
- };
71
-
72
- export default useHideableNavbar;
@@ -1,39 +0,0 @@
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 {useEffect} from 'react';
9
-
10
- import './styles.css';
11
-
12
- // This hook detect keyboard focus indicator to not show outline for mouse users
13
- // Inspired by https://hackernoon.com/removing-that-ugly-focus-ring-and-keeping-it-too-6c8727fefcd2
14
- function useKeyboardNavigation(): void {
15
- useEffect(() => {
16
- const keyboardFocusedClassName = 'navigation-with-keyboard';
17
-
18
- function handleOutlineStyles(e: MouseEvent | KeyboardEvent) {
19
- if (e.type === 'keydown' && (e as KeyboardEvent).key === 'Tab') {
20
- document.body.classList.add(keyboardFocusedClassName);
21
- }
22
-
23
- if (e.type === 'mousedown') {
24
- document.body.classList.remove(keyboardFocusedClassName);
25
- }
26
- }
27
-
28
- document.addEventListener('keydown', handleOutlineStyles);
29
- document.addEventListener('mousedown', handleOutlineStyles);
30
-
31
- return () => {
32
- document.body.classList.remove(keyboardFocusedClassName);
33
- document.removeEventListener('keydown', handleOutlineStyles);
34
- document.removeEventListener('mousedown', handleOutlineStyles);
35
- };
36
- }, []);
37
- }
38
-
39
- export default useKeyboardNavigation;
@@ -1,20 +0,0 @@
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 {useEffect} from 'react';
9
-
10
- function useLockBodyScroll(lock: boolean = true): void {
11
- useEffect(() => {
12
- document.body.style.overflow = lock ? 'hidden' : 'visible';
13
-
14
- return () => {
15
- document.body.style.overflow = 'visible';
16
- };
17
- }, [lock]);
18
- }
19
-
20
- export default useLockBodyScroll;
@@ -1,22 +0,0 @@
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 defaultTheme from 'prism-react-renderer/themes/palenight';
9
- import useThemeContext from '@theme/hooks/useThemeContext';
10
- import {useThemeConfig} from '@docusaurus/theme-common';
11
-
12
- const usePrismTheme = (): typeof defaultTheme => {
13
- const {prism} = useThemeConfig();
14
- const {isDarkTheme} = useThemeContext();
15
- const lightModeTheme = prism.theme || defaultTheme;
16
- const darkModeTheme = prism.darkTheme || lightModeTheme;
17
- const prismTheme = isDarkTheme ? darkModeTheme : lightModeTheme;
18
-
19
- return prismTheme;
20
- };
21
-
22
- export default usePrismTheme;
@@ -1,46 +0,0 @@
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 {useState, useCallback, useEffect} from 'react';
9
- import type {useTabGroupChoiceReturns} from '@theme/hooks/useTabGroupChoice';
10
- import {createStorageSlot, listStorageKeys} from '@docusaurus/theme-common';
11
-
12
- const TAB_CHOICE_PREFIX = 'docusaurus.tab.';
13
-
14
- const useTabGroupChoice = (): useTabGroupChoiceReturns => {
15
- const [tabGroupChoices, setChoices] = useState<{
16
- readonly [groupId: string]: string;
17
- }>({});
18
- const setChoiceSyncWithLocalStorage = useCallback((groupId, newChoice) => {
19
- createStorageSlot(`${TAB_CHOICE_PREFIX}${groupId}`).set(newChoice);
20
- }, []);
21
-
22
- useEffect(() => {
23
- try {
24
- const localStorageChoices: Record<string, string> = {};
25
- listStorageKeys().forEach((storageKey) => {
26
- if (storageKey.startsWith(TAB_CHOICE_PREFIX)) {
27
- const groupId = storageKey.substring(TAB_CHOICE_PREFIX.length);
28
- localStorageChoices[groupId] = createStorageSlot(storageKey).get()!;
29
- }
30
- });
31
- setChoices(localStorageChoices);
32
- } catch (err) {
33
- console.error(err);
34
- }
35
- }, []);
36
-
37
- return {
38
- tabGroupChoices,
39
- setTabGroupChoices: (groupId: string, newChoice: string) => {
40
- setChoices((oldChoices) => ({...oldChoices, [groupId]: newChoice}));
41
- setChoiceSyncWithLocalStorage(groupId, newChoice);
42
- },
43
- };
44
- };
45
-
46
- export default useTabGroupChoice;