@docusaurus/theme-classic 0.0.0-4376 → 0.0.0-4377
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.
- package/lib/theme-classic.d.ts +12 -135
- package/lib-next/theme/CodeBlock/index.js +1 -1
- package/lib-next/theme/DocItem/index.js +1 -2
- package/lib-next/theme/DocSidebar/index.js +1 -1
- package/lib-next/theme/Layout/index.js +1 -2
- package/lib-next/theme/LayoutProviders/index.js +6 -6
- package/lib-next/theme/Navbar/index.js +5 -5
- package/lib-next/theme/Tabs/__tests__/index.test.js +8 -6
- package/lib-next/theme/Tabs/index.js +6 -3
- package/lib-next/theme/ThemedImage/index.js +2 -2
- package/package.json +12 -12
- package/src/theme/CodeBlock/index.tsx +1 -1
- package/src/theme/DocItem/index.tsx +1 -2
- package/src/theme/DocSidebar/index.tsx +1 -1
- package/src/theme/Layout/index.tsx +1 -2
- package/src/theme/LayoutProviders/index.tsx +6 -6
- package/src/theme/Navbar/index.tsx +5 -5
- package/src/theme/Tabs/index.tsx +6 -3
- package/src/theme/ThemedImage/index.tsx +2 -2
- package/src/theme-classic.d.ts +12 -135
- package/lib-next/theme/ThemeContext.js +0 -9
- package/lib-next/theme/ThemeProvider/index.js +0 -28
- package/lib-next/theme/UserPreferencesContext.js +0 -9
- package/lib-next/theme/UserPreferencesProvider/index.js +0 -27
- package/lib-next/theme/hooks/styles.css +0 -10
- package/lib-next/theme/hooks/useHideableNavbar.js +0 -66
- package/lib-next/theme/hooks/useKeyboardNavigation.js +0 -35
- package/lib-next/theme/hooks/useLockBodyScroll.js +0 -18
- package/lib-next/theme/hooks/usePrismTheme.js +0 -20
- package/lib-next/theme/hooks/useTabGroupChoice.js +0 -39
- package/lib-next/theme/hooks/useTheme.js +0 -81
- package/lib-next/theme/hooks/useThemeContext.js +0 -22
- package/lib-next/theme/hooks/useUserPreferencesContext.js +0 -22
- package/lib-next/theme/hooks/useWindowSize.js +0 -59
- package/src/theme/ThemeContext.ts +0 -15
- package/src/theme/ThemeProvider/index.tsx +0 -28
- package/src/theme/UserPreferencesContext.ts +0 -12
- package/src/theme/UserPreferencesProvider/index.tsx +0 -30
- package/src/theme/hooks/styles.css +0 -10
- package/src/theme/hooks/useHideableNavbar.ts +0 -72
- package/src/theme/hooks/useKeyboardNavigation.ts +0 -39
- package/src/theme/hooks/useLockBodyScroll.ts +0 -20
- package/src/theme/hooks/usePrismTheme.ts +0 -22
- package/src/theme/hooks/useTabGroupChoice.ts +0 -46
- package/src/theme/hooks/useTheme.ts +0 -91
- package/src/theme/hooks/useThemeContext.ts +0 -23
- package/src/theme/hooks/useUserPreferencesContext.ts +0 -25
- package/src/theme/hooks/useWindowSize.ts +0 -69
package/src/theme-classic.d.ts
CHANGED
|
@@ -215,86 +215,6 @@ declare module '@theme/Heading' {
|
|
|
215
215
|
export default function Heading(props: Props): JSX.Element;
|
|
216
216
|
}
|
|
217
217
|
|
|
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
218
|
declare module '@theme/Layout' {
|
|
299
219
|
import type {ReactNode} from 'react';
|
|
300
220
|
|
|
@@ -314,8 +234,7 @@ declare module '@theme/Layout' {
|
|
|
314
234
|
};
|
|
315
235
|
}
|
|
316
236
|
|
|
317
|
-
|
|
318
|
-
export default Layout;
|
|
237
|
+
export default function Layout(props: Props): JSX.Element;
|
|
319
238
|
}
|
|
320
239
|
|
|
321
240
|
declare module '@theme/LayoutHead' {
|
|
@@ -323,8 +242,17 @@ declare module '@theme/LayoutHead' {
|
|
|
323
242
|
|
|
324
243
|
export interface Props extends Omit<LayoutProps, 'children'> {}
|
|
325
244
|
|
|
326
|
-
|
|
327
|
-
|
|
245
|
+
export default function LayoutHead(props: Props): JSX.Element;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
declare module '@theme/LayoutProviders' {
|
|
249
|
+
import type {ReactNode} from 'react';
|
|
250
|
+
|
|
251
|
+
export interface Props {
|
|
252
|
+
readonly children: ReactNode;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export default function LayoutProviders(props: Props): JSX.Element;
|
|
328
256
|
}
|
|
329
257
|
|
|
330
258
|
declare module '@theme/SearchMetadata' {
|
|
@@ -621,17 +549,6 @@ declare module '@theme/Details' {
|
|
|
621
549
|
export default Details;
|
|
622
550
|
}
|
|
623
551
|
|
|
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
552
|
declare module '@theme/TOCItems' {
|
|
636
553
|
import type {TOCItem} from '@docusaurus/types';
|
|
637
554
|
|
|
@@ -712,46 +629,6 @@ declare module '@theme/Toggle' {
|
|
|
712
629
|
export default Toggle;
|
|
713
630
|
}
|
|
714
631
|
|
|
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
632
|
declare module '@theme/Logo' {
|
|
756
633
|
import type {ComponentProps} from 'react';
|
|
757
634
|
|
|
@@ -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;
|
|
@@ -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,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;
|