@docusaurus/theme-classic 0.0.0-4376 → 0.0.0-4383

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 (53) hide show
  1. package/lib/theme-classic.d.ts +16 -137
  2. package/lib-next/theme/CodeBlock/index.js +1 -1
  3. package/lib-next/theme/DocItem/index.js +1 -2
  4. package/lib-next/theme/DocSidebar/index.js +1 -1
  5. package/lib-next/theme/Layout/index.js +1 -2
  6. package/lib-next/theme/LayoutProviders/index.js +6 -6
  7. package/lib-next/theme/Navbar/index.js +5 -5
  8. package/lib-next/theme/SkipToContent/index.js +1 -1
  9. package/lib-next/theme/Tabs/__tests__/index.test.js +8 -6
  10. package/lib-next/theme/Tabs/index.js +6 -3
  11. package/lib-next/theme/ThemedImage/index.js +2 -2
  12. package/package.json +12 -12
  13. package/src/theme/CodeBlock/index.tsx +1 -1
  14. package/src/theme/DocItem/index.tsx +1 -2
  15. package/src/theme/DocSidebar/index.tsx +1 -1
  16. package/src/theme/Layout/index.tsx +1 -2
  17. package/src/theme/LayoutProviders/index.tsx +6 -6
  18. package/src/theme/Navbar/index.tsx +5 -5
  19. package/src/theme/NavbarItem/DocNavbarItem.tsx +3 -3
  20. package/src/theme/NavbarItem/DocSidebarNavbarItem.tsx +6 -7
  21. package/src/theme/NavbarItem/DocsVersionDropdownNavbarItem.tsx +2 -2
  22. package/src/theme/SkipToContent/index.tsx +1 -1
  23. package/src/theme/Tabs/index.tsx +6 -3
  24. package/src/theme/ThemedImage/index.tsx +2 -2
  25. package/src/theme-classic.d.ts +16 -137
  26. package/lib-next/theme/ThemeContext.js +0 -9
  27. package/lib-next/theme/ThemeProvider/index.js +0 -28
  28. package/lib-next/theme/UserPreferencesContext.js +0 -9
  29. package/lib-next/theme/UserPreferencesProvider/index.js +0 -27
  30. package/lib-next/theme/hooks/styles.css +0 -10
  31. package/lib-next/theme/hooks/useHideableNavbar.js +0 -66
  32. package/lib-next/theme/hooks/useKeyboardNavigation.js +0 -35
  33. package/lib-next/theme/hooks/useLockBodyScroll.js +0 -18
  34. package/lib-next/theme/hooks/usePrismTheme.js +0 -20
  35. package/lib-next/theme/hooks/useTabGroupChoice.js +0 -39
  36. package/lib-next/theme/hooks/useTheme.js +0 -81
  37. package/lib-next/theme/hooks/useThemeContext.js +0 -22
  38. package/lib-next/theme/hooks/useUserPreferencesContext.js +0 -22
  39. package/lib-next/theme/hooks/useWindowSize.js +0 -59
  40. package/src/theme/ThemeContext.ts +0 -15
  41. package/src/theme/ThemeProvider/index.tsx +0 -28
  42. package/src/theme/UserPreferencesContext.ts +0 -12
  43. package/src/theme/UserPreferencesProvider/index.tsx +0 -30
  44. package/src/theme/hooks/styles.css +0 -10
  45. package/src/theme/hooks/useHideableNavbar.ts +0 -72
  46. package/src/theme/hooks/useKeyboardNavigation.ts +0 -39
  47. package/src/theme/hooks/useLockBodyScroll.ts +0 -20
  48. package/src/theme/hooks/usePrismTheme.ts +0 -22
  49. package/src/theme/hooks/useTabGroupChoice.ts +0 -46
  50. package/src/theme/hooks/useTheme.ts +0 -91
  51. package/src/theme/hooks/useThemeContext.ts +0 -23
  52. package/src/theme/hooks/useUserPreferencesContext.ts +0 -25
  53. package/src/theme/hooks/useWindowSize.ts +0 -69
@@ -13,8 +13,11 @@ import React, {
13
13
  type ReactElement,
14
14
  } from 'react';
15
15
  import useIsBrowser from '@docusaurus/useIsBrowser';
16
- import useUserPreferencesContext from '@theme/hooks/useUserPreferencesContext';
17
- import {useScrollPositionBlocker, duplicates} from '@docusaurus/theme-common';
16
+ import {
17
+ useScrollPositionBlocker,
18
+ duplicates,
19
+ useTabGroupChoice,
20
+ } from '@docusaurus/theme-common';
18
21
  import type {Props} from '@theme/Tabs';
19
22
  import type {Props as TabItemProps} from '@theme/TabItem';
20
23
 
@@ -83,7 +86,7 @@ function TabsComponent(props: Props): JSX.Element {
83
86
  );
84
87
  }
85
88
 
86
- const {tabGroupChoices, setTabGroupChoices} = useUserPreferencesContext();
89
+ const {tabGroupChoices, setTabGroupChoices} = useTabGroupChoice();
87
90
  const [selectedValue, setSelectedValue] = useState(defaultValue);
88
91
  const tabRefs: (HTMLLIElement | null)[] = [];
89
92
  const {blockElementScrollPositionUntilNextRender} =
@@ -9,14 +9,14 @@ import React from 'react';
9
9
  import clsx from 'clsx';
10
10
 
11
11
  import useIsBrowser from '@docusaurus/useIsBrowser';
12
- import useThemeContext from '@theme/hooks/useThemeContext';
12
+ import {useColorMode} from '@docusaurus/theme-common';
13
13
  import type {Props} from '@theme/ThemedImage';
14
14
 
15
15
  import styles from './styles.module.css';
16
16
 
17
17
  function ThemedImage(props: Props): JSX.Element {
18
18
  const isBrowser = useIsBrowser();
19
- const {isDarkTheme} = useThemeContext();
19
+ const {isDarkTheme} = useColorMode();
20
20
  const {sources, className, alt = '', ...propsRest} = props;
21
21
 
22
22
  type SourceName = keyof Props['sources'];
@@ -44,7 +44,8 @@ declare module '@theme/BlogListPaginator' {
44
44
  }
45
45
 
46
46
  declare module '@theme/BlogPostItem' {
47
- import type {FrontMatter, Assets, Metadata} from '@theme/BlogPostPage';
47
+ import type {FrontMatter, Metadata} from '@theme/BlogPostPage';
48
+ import type {Assets} from '@docusaurus/plugin-content-blog';
48
49
 
49
50
  export interface Props {
50
51
  readonly frontMatter: FrontMatter;
@@ -70,7 +71,8 @@ declare module '@theme/BlogPostAuthor' {
70
71
  }
71
72
 
72
73
  declare module '@theme/BlogPostAuthors' {
73
- import type {Metadata, Assets} from '@theme/BlogPostPage';
74
+ import type {Metadata} from '@theme/BlogPostPage';
75
+ import type {Assets} from '@docusaurus/plugin-content-blog';
74
76
 
75
77
  export interface Props {
76
78
  readonly authors: Metadata['authors'];
@@ -215,86 +217,6 @@ declare module '@theme/Heading' {
215
217
  export default function Heading(props: Props): JSX.Element;
216
218
  }
217
219
 
218
- declare module '@theme/hooks/useHideableNavbar' {
219
- export type useHideableNavbarReturns = {
220
- readonly navbarRef: (node: HTMLElement | null) => void;
221
- readonly isNavbarVisible: boolean;
222
- };
223
-
224
- const useHideableNavbar: (hideOnScroll: boolean) => useHideableNavbarReturns;
225
- export default useHideableNavbar;
226
- }
227
-
228
- declare module '@theme/hooks/useLockBodyScroll' {
229
- const useLockBodyScroll: (lock?: boolean) => void;
230
- export default useLockBodyScroll;
231
- }
232
-
233
- declare module '@theme/hooks/usePrismTheme' {
234
- import type defaultTheme from 'prism-react-renderer/themes/palenight';
235
-
236
- const usePrismTheme: () => typeof defaultTheme;
237
- export default usePrismTheme;
238
- }
239
-
240
- declare module '@theme/hooks/useTabGroupChoice' {
241
- export type useTabGroupChoiceReturns = {
242
- readonly tabGroupChoices: {readonly [groupId: string]: string};
243
- readonly setTabGroupChoices: (groupId: string, newChoice: string) => void;
244
- };
245
-
246
- const useTabGroupChoice: () => useTabGroupChoiceReturns;
247
- export default useTabGroupChoice;
248
- }
249
-
250
- declare module '@theme/hooks/useTheme' {
251
- export type useThemeReturns = {
252
- readonly isDarkTheme: boolean;
253
- readonly setLightTheme: () => void;
254
- readonly setDarkTheme: () => void;
255
- };
256
-
257
- const useTheme: () => useThemeReturns;
258
- export default useTheme;
259
- }
260
-
261
- declare module '@theme/hooks/useThemeContext' {
262
- export type ThemeContextProps = {
263
- isDarkTheme: boolean;
264
- setLightTheme: () => void;
265
- setDarkTheme: () => void;
266
- };
267
-
268
- export default function useThemeContext(): ThemeContextProps;
269
- }
270
-
271
- declare module '@theme/hooks/useUserPreferencesContext' {
272
- export type UserPreferencesContextProps = {
273
- tabGroupChoices: {readonly [groupId: string]: string};
274
- setTabGroupChoices: (groupId: string, newChoice: string) => void;
275
- };
276
-
277
- export default function useUserPreferencesContext(): UserPreferencesContextProps;
278
- }
279
-
280
- declare module '@theme/hooks/useWindowSize' {
281
- export const windowSizes: {
282
- desktop: 'desktop';
283
- mobile: 'mobile';
284
- ssr: 'ssr';
285
- };
286
-
287
- export type WindowSize = keyof typeof windowSizes;
288
-
289
- export default function useWindowSize(): WindowSize;
290
- }
291
-
292
- declare module '@theme/hooks/useKeyboardNavigation' {
293
- const useKeyboardNavigation: () => void;
294
-
295
- export default useKeyboardNavigation;
296
- }
297
-
298
220
  declare module '@theme/Layout' {
299
221
  import type {ReactNode} from 'react';
300
222
 
@@ -314,8 +236,7 @@ declare module '@theme/Layout' {
314
236
  };
315
237
  }
316
238
 
317
- const Layout: (props: Props) => JSX.Element;
318
- export default Layout;
239
+ export default function Layout(props: Props): JSX.Element;
319
240
  }
320
241
 
321
242
  declare module '@theme/LayoutHead' {
@@ -323,8 +244,17 @@ declare module '@theme/LayoutHead' {
323
244
 
324
245
  export interface Props extends Omit<LayoutProps, 'children'> {}
325
246
 
326
- const LayoutHead: (props: Props) => JSX.Element;
327
- export default LayoutHead;
247
+ export default function LayoutHead(props: Props): JSX.Element;
248
+ }
249
+
250
+ declare module '@theme/LayoutProviders' {
251
+ import type {ReactNode} from 'react';
252
+
253
+ export interface Props {
254
+ readonly children: ReactNode;
255
+ }
256
+
257
+ export default function LayoutProviders(props: Props): JSX.Element;
328
258
  }
329
259
 
330
260
  declare module '@theme/SearchMetadata' {
@@ -621,17 +551,6 @@ declare module '@theme/Details' {
621
551
  export default Details;
622
552
  }
623
553
 
624
- declare module '@theme/ThemeProvider' {
625
- import type {ReactNode} from 'react';
626
-
627
- export interface Props {
628
- readonly children: ReactNode;
629
- }
630
-
631
- const ThemeProvider: (props: Props) => JSX.Element;
632
- export default ThemeProvider;
633
- }
634
-
635
554
  declare module '@theme/TOCItems' {
636
555
  import type {TOCItem} from '@docusaurus/types';
637
556
 
@@ -712,46 +631,6 @@ declare module '@theme/Toggle' {
712
631
  export default Toggle;
713
632
  }
714
633
 
715
- declare module '@theme/UserPreferencesProvider' {
716
- import type {ReactNode} from 'react';
717
-
718
- export interface Props {
719
- readonly children: ReactNode;
720
- }
721
-
722
- const UserPreferencesProvider: (props: Props) => JSX.Element;
723
- export default UserPreferencesProvider;
724
- }
725
-
726
- declare module '@theme/LayoutProviders' {
727
- import type {ReactNode} from 'react';
728
-
729
- export interface Props {
730
- readonly children: ReactNode;
731
- }
732
-
733
- const LayoutProviders: (props: Props) => JSX.Element;
734
- export default LayoutProviders;
735
- }
736
-
737
- declare module '@theme/ThemeContext' {
738
- import type {Context} from 'react';
739
- import type {ThemeContextProps} from '@theme/hooks/useThemeContext';
740
-
741
- const ThemeContext: Context<ThemeContextProps | undefined>;
742
- export default ThemeContext;
743
- }
744
-
745
- declare module '@theme/UserPreferencesContext' {
746
- import type {Context} from 'react';
747
- import type {UserPreferencesContextProps} from '@theme/hooks/useUserPreferencesContext';
748
-
749
- const UserPreferencesContext: Context<
750
- UserPreferencesContextProps | undefined
751
- >;
752
- export default UserPreferencesContext;
753
- }
754
-
755
634
  declare module '@theme/Logo' {
756
635
  import type {ComponentProps} from 'react';
757
636
 
@@ -1,9 +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 React from 'react';
8
- const ThemeContext = React.createContext(undefined);
9
- 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
- import React, {useMemo} from 'react';
8
- import useTheme from '@theme/hooks/useTheme';
9
- import ThemeContext from '@theme/ThemeContext';
10
-
11
- function ThemeProvider(props) {
12
- const {isDarkTheme, setLightTheme, setDarkTheme} = useTheme();
13
- const contextValue = useMemo(
14
- () => ({
15
- isDarkTheme,
16
- setLightTheme,
17
- setDarkTheme,
18
- }),
19
- [isDarkTheme, setLightTheme, setDarkTheme],
20
- );
21
- return (
22
- <ThemeContext.Provider value={contextValue}>
23
- {props.children}
24
- </ThemeContext.Provider>
25
- );
26
- }
27
-
28
- export default ThemeProvider;
@@ -1,9 +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 {createContext} from 'react';
8
- const UserPreferencesContext = createContext(undefined);
9
- export default UserPreferencesContext;
@@ -1,27 +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 React, {useMemo} from 'react';
8
- import useTabGroupChoice from '@theme/hooks/useTabGroupChoice';
9
- import UserPreferencesContext from '@theme/UserPreferencesContext';
10
-
11
- function UserPreferencesProvider(props) {
12
- const {tabGroupChoices, setTabGroupChoices} = useTabGroupChoice();
13
- const contextValue = useMemo(
14
- () => ({
15
- tabGroupChoices,
16
- setTabGroupChoices,
17
- }),
18
- [tabGroupChoices, setTabGroupChoices],
19
- );
20
- return (
21
- <UserPreferencesContext.Provider value={contextValue}>
22
- {props.children}
23
- </UserPreferencesContext.Provider>
24
- );
25
- }
26
-
27
- export default UserPreferencesProvider;
@@ -1,10 +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
- body:not(.navigation-with-keyboard) *:not(input):focus {
9
- outline: none;
10
- }
@@ -1,66 +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, useRef} from 'react';
8
- import {useLocationChange, useScrollPosition} from '@docusaurus/theme-common';
9
-
10
- const useHideableNavbar = (hideOnScroll) => {
11
- const [isNavbarVisible, setIsNavbarVisible] = useState(hideOnScroll);
12
- const isFocusedAnchor = useRef(false);
13
- const navbarHeight = useRef(0);
14
- const navbarRef = useCallback((node) => {
15
- if (node !== null) {
16
- navbarHeight.current = node.getBoundingClientRect().height;
17
- }
18
- }, []);
19
- useScrollPosition((currentPosition, lastPosition) => {
20
- if (!hideOnScroll) {
21
- return;
22
- }
23
-
24
- const scrollTop = currentPosition.scrollY; // It needed for mostly to handle rubber band scrolling
25
-
26
- if (scrollTop < navbarHeight.current) {
27
- setIsNavbarVisible(true);
28
- return;
29
- }
30
-
31
- if (isFocusedAnchor.current) {
32
- isFocusedAnchor.current = false;
33
- return;
34
- }
35
-
36
- const lastScrollTop = lastPosition?.scrollY;
37
- const documentHeight =
38
- document.documentElement.scrollHeight - navbarHeight.current;
39
- const windowHeight = window.innerHeight;
40
-
41
- if (lastScrollTop && scrollTop >= lastScrollTop) {
42
- setIsNavbarVisible(false);
43
- } else if (scrollTop + windowHeight < documentHeight) {
44
- setIsNavbarVisible(true);
45
- }
46
- });
47
- useLocationChange((locationChangeEvent) => {
48
- if (!hideOnScroll) {
49
- return;
50
- }
51
-
52
- if (locationChangeEvent.location.hash) {
53
- isFocusedAnchor.current = true;
54
- setIsNavbarVisible(false);
55
- return;
56
- }
57
-
58
- setIsNavbarVisible(true);
59
- });
60
- return {
61
- navbarRef,
62
- isNavbarVisible,
63
- };
64
- };
65
-
66
- export default useHideableNavbar;
@@ -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;