@docusaurus/theme-classic 0.0.0-4732 → 0.0.0-4735
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 +7 -3
- package/lib-next/theme/ColorModeToggle/index.js +36 -59
- package/lib-next/theme/ColorModeToggle/styles.module.css +8 -24
- package/lib-next/theme/DocBreadcrumbs/index.js +3 -2
- package/lib-next/theme/DocBreadcrumbs/styles.module.css +2 -17
- package/lib-next/theme/DocItem/index.js +7 -3
- package/lib-next/theme/DocPage/index.js +3 -7
- package/lib-next/theme/LayoutProviders/index.js +4 -1
- package/lib-next/theme/Navbar/index.js +7 -11
- package/lib-next/theme/ThemedImage/index.js +2 -2
- package/package.json +13 -13
- package/src/theme/ColorModeToggle/index.tsx +36 -63
- package/src/theme/ColorModeToggle/styles.module.css +8 -24
- package/src/theme/DocBreadcrumbs/index.tsx +3 -2
- package/src/theme/DocBreadcrumbs/styles.module.css +2 -17
- package/src/theme/DocItem/index.tsx +7 -3
- package/src/theme/DocPage/index.tsx +4 -7
- package/src/theme/LayoutProviders/index.tsx +4 -1
- package/src/theme/Navbar/index.tsx +10 -10
- package/src/theme/ThemedImage/index.tsx +3 -2
- package/src/theme-classic.d.ts +7 -3
package/lib/theme-classic.d.ts
CHANGED
|
@@ -746,12 +746,16 @@ declare module '@theme/TOCCollapsible' {
|
|
|
746
746
|
}
|
|
747
747
|
|
|
748
748
|
declare module '@theme/ColorModeToggle' {
|
|
749
|
-
import type {
|
|
749
|
+
import type {ColorMode} from '@docusaurus/theme-common';
|
|
750
750
|
|
|
751
751
|
export interface Props {
|
|
752
752
|
readonly className?: string;
|
|
753
|
-
readonly
|
|
754
|
-
|
|
753
|
+
readonly value: ColorMode;
|
|
754
|
+
/**
|
|
755
|
+
* The parameter represents the "to-be" value. For example, if currently in
|
|
756
|
+
* dark mode, clicking the button should call `onChange("light")`
|
|
757
|
+
*/
|
|
758
|
+
readonly onChange: (colorMode: ColorMode) => void;
|
|
755
759
|
}
|
|
756
760
|
|
|
757
761
|
export default function Toggle(props: Props): JSX.Element;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
* This source code is licensed under the MIT license found in the
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
|
-
import React
|
|
7
|
+
import React from 'react';
|
|
8
8
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
9
9
|
import {translate} from '@docusaurus/Translate';
|
|
10
10
|
import IconLightMode from '@theme/IconLightMode';
|
|
@@ -12,72 +12,49 @@ import IconDarkMode from '@theme/IconDarkMode';
|
|
|
12
12
|
import clsx from 'clsx';
|
|
13
13
|
import styles from './styles.module.css';
|
|
14
14
|
|
|
15
|
-
function ColorModeToggle({className,
|
|
15
|
+
function ColorModeToggle({className, value, onChange}) {
|
|
16
16
|
const isBrowser = useIsBrowser();
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const title = translate(
|
|
18
|
+
{
|
|
19
|
+
message: 'Switch between dark and light mode (currently {mode})',
|
|
20
|
+
id: 'theme.colorToggle.ariaLabel',
|
|
21
|
+
description: 'The ARIA label for the navbar color mode toggle',
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
mode:
|
|
25
|
+
value === 'dark'
|
|
26
|
+
? translate({
|
|
27
|
+
message: 'dark mode',
|
|
28
|
+
id: 'theme.colorToggle.ariaLabel.mode.dark',
|
|
29
|
+
description: 'The name for the dark color mode',
|
|
30
|
+
})
|
|
31
|
+
: translate({
|
|
32
|
+
message: 'light mode',
|
|
33
|
+
id: 'theme.colorToggle.ariaLabel.mode.light',
|
|
34
|
+
description: 'The name for the light color mode',
|
|
35
|
+
}),
|
|
36
|
+
},
|
|
37
|
+
);
|
|
23
38
|
return (
|
|
24
|
-
<div
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
tabIndex={-1}
|
|
37
|
-
onClick={() => inputRef.current?.click()}>
|
|
39
|
+
<div className={clsx(styles.toggle, className)}>
|
|
40
|
+
<button
|
|
41
|
+
className={clsx(
|
|
42
|
+
'clean-btn',
|
|
43
|
+
styles.toggleButton,
|
|
44
|
+
!isBrowser && styles.toggleButtonDisabled,
|
|
45
|
+
)}
|
|
46
|
+
type="button"
|
|
47
|
+
onClick={() => onChange(value === 'dark' ? 'light' : 'dark')}
|
|
48
|
+
disabled={!isBrowser}
|
|
49
|
+
title={title}
|
|
50
|
+
aria-label={title}>
|
|
38
51
|
<IconLightMode
|
|
39
52
|
className={clsx(styles.toggleIcon, styles.lightToggleIcon)}
|
|
40
53
|
/>
|
|
41
54
|
<IconDarkMode
|
|
42
55
|
className={clsx(styles.toggleIcon, styles.darkToggleIcon)}
|
|
43
56
|
/>
|
|
44
|
-
</
|
|
45
|
-
|
|
46
|
-
<input
|
|
47
|
-
ref={inputRef}
|
|
48
|
-
checked={checked}
|
|
49
|
-
type="checkbox"
|
|
50
|
-
className={styles.toggleScreenReader}
|
|
51
|
-
aria-label={translate(
|
|
52
|
-
{
|
|
53
|
-
message: 'Switch between dark and light mode (currently {mode})',
|
|
54
|
-
id: 'theme.colorToggle.ariaLabel',
|
|
55
|
-
description: 'The ARIA label for the navbar color mode toggle',
|
|
56
|
-
},
|
|
57
|
-
{
|
|
58
|
-
mode: checked
|
|
59
|
-
? translate({
|
|
60
|
-
message: 'dark mode',
|
|
61
|
-
id: 'theme.colorToggle.ariaLabel.mode.dark',
|
|
62
|
-
description: 'The name for the dark color mode',
|
|
63
|
-
})
|
|
64
|
-
: translate({
|
|
65
|
-
message: 'light mode',
|
|
66
|
-
id: 'theme.colorToggle.ariaLabel.mode.light',
|
|
67
|
-
description: 'The name for the light color mode',
|
|
68
|
-
}),
|
|
69
|
-
},
|
|
70
|
-
)}
|
|
71
|
-
onChange={onChange}
|
|
72
|
-
onClick={() => setChecked(!checked)}
|
|
73
|
-
onFocus={() => setFocused(true)}
|
|
74
|
-
onBlur={() => setFocused(false)}
|
|
75
|
-
onKeyDown={(e) => {
|
|
76
|
-
if (e.key === 'Enter') {
|
|
77
|
-
inputRef.current?.click();
|
|
78
|
-
}
|
|
79
|
-
}}
|
|
80
|
-
/>
|
|
57
|
+
</button>
|
|
81
58
|
</div>
|
|
82
59
|
);
|
|
83
60
|
}
|
|
@@ -6,28 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
.toggle {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
height: 32px;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.toggleScreenReader {
|
|
15
|
-
border: 0;
|
|
16
|
-
clip: rect(0 0 0 0);
|
|
17
|
-
height: 1px;
|
|
18
|
-
margin: -1px;
|
|
19
|
-
overflow: hidden;
|
|
20
|
-
position: absolute;
|
|
21
|
-
width: 1px;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.toggleDisabled {
|
|
25
|
-
cursor: not-allowed;
|
|
9
|
+
width: 2rem;
|
|
10
|
+
height: 2rem;
|
|
26
11
|
}
|
|
27
12
|
|
|
28
13
|
.toggleButton {
|
|
29
|
-
cursor: pointer;
|
|
30
|
-
user-select: none;
|
|
31
14
|
-webkit-tap-highlight-color: transparent;
|
|
32
15
|
align-items: center;
|
|
33
16
|
display: flex;
|
|
@@ -35,17 +18,18 @@
|
|
|
35
18
|
width: 100%;
|
|
36
19
|
height: 100%;
|
|
37
20
|
border-radius: 50%;
|
|
21
|
+
transition: background var(--ifm-transition-fast);
|
|
38
22
|
}
|
|
39
23
|
|
|
40
24
|
.toggleButton:hover {
|
|
41
|
-
background-color
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
[data-theme='dark'] .toggleButton:hover {
|
|
45
|
-
background-color: #ffffff20;
|
|
25
|
+
background: var(--ifm-color-emphasis-200);
|
|
46
26
|
}
|
|
47
27
|
|
|
48
28
|
[data-theme='light'] .darkToggleIcon,
|
|
49
29
|
[data-theme='dark'] .lightToggleIcon {
|
|
50
30
|
display: none;
|
|
51
31
|
}
|
|
32
|
+
|
|
33
|
+
.toggleButtonDisabled {
|
|
34
|
+
cursor: not-allowed;
|
|
35
|
+
}
|
|
@@ -16,7 +16,7 @@ import Link from '@docusaurus/Link';
|
|
|
16
16
|
import useBaseUrl from '@docusaurus/useBaseUrl'; // TODO move to design system folder
|
|
17
17
|
|
|
18
18
|
function BreadcrumbsItemLink({children, href}) {
|
|
19
|
-
const className =
|
|
19
|
+
const className = 'breadcrumbs__link';
|
|
20
20
|
return href ? (
|
|
21
21
|
<Link className={className} href={href} itemProp="item">
|
|
22
22
|
<span itemProp="name">{children}</span>
|
|
@@ -81,7 +81,8 @@ export default function DocBreadcrumbs() {
|
|
|
81
81
|
key={idx}
|
|
82
82
|
active={idx === breadcrumbs.length - 1}
|
|
83
83
|
index={idx}>
|
|
84
|
-
<BreadcrumbsItemLink
|
|
84
|
+
<BreadcrumbsItemLink
|
|
85
|
+
href={idx < breadcrumbs.length - 1 ? item.href : undefined}>
|
|
85
86
|
{item.label}
|
|
86
87
|
</BreadcrumbsItemLink>
|
|
87
88
|
</BreadcrumbsItem>
|
|
@@ -6,21 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
.breadcrumbsContainer {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.breadcrumbsItemLink {
|
|
13
|
-
--ifm-breadcrumb-size-multiplier: 0.7 !important;
|
|
14
|
-
margin-bottom: 0.4rem;
|
|
15
|
-
background: var(--ifm-color-gray-100);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
html[data-theme='dark'] .breadcrumbsItemLink {
|
|
19
|
-
background-color: var(--ifm-color-gray-900);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@media (min-width: 997px) {
|
|
23
|
-
.breadcrumbsItemLink {
|
|
24
|
-
--ifm-breadcrumb-size-multiplier: 0.8;
|
|
25
|
-
}
|
|
9
|
+
--ifm-breadcrumb-size-multiplier: 0.8;
|
|
10
|
+
margin-bottom: 0.8rem;
|
|
26
11
|
}
|
|
@@ -15,7 +15,11 @@ import TOC from '@theme/TOC';
|
|
|
15
15
|
import TOCCollapsible from '@theme/TOCCollapsible';
|
|
16
16
|
import Heading from '@theme/Heading';
|
|
17
17
|
import styles from './styles.module.css';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
HtmlClassNameProvider,
|
|
20
|
+
ThemeClassNames,
|
|
21
|
+
useWindowSize,
|
|
22
|
+
} from '@docusaurus/theme-common';
|
|
19
23
|
import DocBreadcrumbs from '@theme/DocBreadcrumbs';
|
|
20
24
|
import MDXContent from '@theme/MDXContent';
|
|
21
25
|
export default function DocItem(props) {
|
|
@@ -41,7 +45,7 @@ export default function DocItem(props) {
|
|
|
41
45
|
const renderTocDesktop =
|
|
42
46
|
canRenderTOC && (windowSize === 'desktop' || windowSize === 'ssr');
|
|
43
47
|
return (
|
|
44
|
-
|
|
48
|
+
<HtmlClassNameProvider className={`docs-doc-id-${metadata.unversionedId}`}>
|
|
45
49
|
<Seo
|
|
46
50
|
{...{
|
|
47
51
|
title,
|
|
@@ -106,6 +110,6 @@ export default function DocItem(props) {
|
|
|
106
110
|
</div>
|
|
107
111
|
)}
|
|
108
112
|
</div>
|
|
109
|
-
|
|
113
|
+
</HtmlClassNameProvider>
|
|
110
114
|
);
|
|
111
115
|
}
|
|
@@ -16,13 +16,13 @@ import {translate} from '@docusaurus/Translate';
|
|
|
16
16
|
import clsx from 'clsx';
|
|
17
17
|
import styles from './styles.module.css';
|
|
18
18
|
import {
|
|
19
|
+
HtmlClassNameProvider,
|
|
19
20
|
ThemeClassNames,
|
|
20
21
|
docVersionSearchTag,
|
|
21
22
|
DocsSidebarProvider,
|
|
22
23
|
useDocsSidebar,
|
|
23
24
|
DocsVersionProvider,
|
|
24
25
|
} from '@docusaurus/theme-common';
|
|
25
|
-
import Head from '@docusaurus/Head';
|
|
26
26
|
|
|
27
27
|
function DocPageContent({
|
|
28
28
|
currentDocRoute,
|
|
@@ -145,11 +145,7 @@ export default function DocPage(props) {
|
|
|
145
145
|
? versionMetadata.docsSidebars[sidebarName]
|
|
146
146
|
: null;
|
|
147
147
|
return (
|
|
148
|
-
|
|
149
|
-
<Head>
|
|
150
|
-
{/* TODO we should add a core addRoute({htmlClassName}) action */}
|
|
151
|
-
<html className={versionMetadata.className} />
|
|
152
|
-
</Head>
|
|
148
|
+
<HtmlClassNameProvider className={versionMetadata.className}>
|
|
153
149
|
<DocsVersionProvider version={versionMetadata}>
|
|
154
150
|
<DocsSidebarProvider sidebar={sidebar ?? null}>
|
|
155
151
|
<DocPageContent
|
|
@@ -162,6 +158,6 @@ export default function DocPage(props) {
|
|
|
162
158
|
</DocPageContent>
|
|
163
159
|
</DocsSidebarProvider>
|
|
164
160
|
</DocsVersionProvider>
|
|
165
|
-
|
|
161
|
+
</HtmlClassNameProvider>
|
|
166
162
|
);
|
|
167
163
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
DocsPreferredVersionContextProvider,
|
|
13
13
|
MobileSecondaryMenuProvider,
|
|
14
14
|
ScrollControllerProvider,
|
|
15
|
+
PluginHtmlClassNameProvider,
|
|
15
16
|
} from '@docusaurus/theme-common';
|
|
16
17
|
export default function LayoutProviders({children}) {
|
|
17
18
|
return (
|
|
@@ -21,7 +22,9 @@ export default function LayoutProviders({children}) {
|
|
|
21
22
|
<ScrollControllerProvider>
|
|
22
23
|
<DocsPreferredVersionContextProvider>
|
|
23
24
|
<MobileSecondaryMenuProvider>
|
|
24
|
-
|
|
25
|
+
<PluginHtmlClassNameProvider>
|
|
26
|
+
{children}
|
|
27
|
+
</PluginHtmlClassNameProvider>
|
|
25
28
|
</MobileSecondaryMenuProvider>
|
|
26
29
|
</DocsPreferredVersionContextProvider>
|
|
27
30
|
</ScrollControllerProvider>
|
|
@@ -84,14 +84,10 @@ function useColorModeToggle() {
|
|
|
84
84
|
const {
|
|
85
85
|
colorMode: {disableSwitch},
|
|
86
86
|
} = useThemeConfig();
|
|
87
|
-
const {
|
|
88
|
-
const toggle = useCallback(
|
|
89
|
-
(e) => (e.target.checked ? setDarkTheme() : setLightTheme()),
|
|
90
|
-
[setLightTheme, setDarkTheme],
|
|
91
|
-
);
|
|
87
|
+
const {colorMode, setColorMode} = useColorMode();
|
|
92
88
|
return {
|
|
93
|
-
|
|
94
|
-
|
|
89
|
+
value: colorMode,
|
|
90
|
+
onChange: setColorMode,
|
|
95
91
|
disabled: disableSwitch,
|
|
96
92
|
};
|
|
97
93
|
}
|
|
@@ -159,8 +155,8 @@ function NavbarMobileSidebar({sidebarShown, toggleSidebar}) {
|
|
|
159
155
|
{!colorModeToggle.disabled && (
|
|
160
156
|
<ColorModeToggle
|
|
161
157
|
className={styles.navbarSidebarToggle}
|
|
162
|
-
|
|
163
|
-
onChange={colorModeToggle.
|
|
158
|
+
value={colorModeToggle.value}
|
|
159
|
+
onChange={colorModeToggle.onChange}
|
|
164
160
|
/>
|
|
165
161
|
)}
|
|
166
162
|
<button
|
|
@@ -262,8 +258,8 @@ export default function Navbar() {
|
|
|
262
258
|
{!colorModeToggle.disabled && (
|
|
263
259
|
<ColorModeToggle
|
|
264
260
|
className={styles.toggle}
|
|
265
|
-
|
|
266
|
-
onChange={colorModeToggle.
|
|
261
|
+
value={colorModeToggle.value}
|
|
262
|
+
onChange={colorModeToggle.onChange}
|
|
267
263
|
/>
|
|
268
264
|
)}
|
|
269
265
|
{!hasSearchNavbarItem && <SearchBar />}
|
|
@@ -11,9 +11,9 @@ import {useColorMode} from '@docusaurus/theme-common';
|
|
|
11
11
|
import styles from './styles.module.css';
|
|
12
12
|
export default function ThemedImage(props) {
|
|
13
13
|
const isBrowser = useIsBrowser();
|
|
14
|
-
const {
|
|
14
|
+
const {colorMode} = useColorMode();
|
|
15
15
|
const {sources, className, alt, ...propsRest} = props;
|
|
16
|
-
const clientThemes =
|
|
16
|
+
const clientThemes = colorMode === 'dark' ? ['dark'] : ['light'];
|
|
17
17
|
const renderedSourceNames = isBrowser
|
|
18
18
|
? clientThemes // We need to render both images on the server to avoid flash
|
|
19
19
|
: // See https://github.com/facebook/docusaurus/pull/3730
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@docusaurus/theme-classic",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-4735",
|
|
4
4
|
"description": "Classic theme for Docusaurus",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "src/theme-classic.d.ts",
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
"format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@docusaurus/core": "0.0.0-
|
|
25
|
-
"@docusaurus/plugin-content-blog": "0.0.0-
|
|
26
|
-
"@docusaurus/plugin-content-docs": "0.0.0-
|
|
27
|
-
"@docusaurus/plugin-content-pages": "0.0.0-
|
|
28
|
-
"@docusaurus/theme-common": "0.0.0-
|
|
29
|
-
"@docusaurus/theme-translations": "0.0.0-
|
|
30
|
-
"@docusaurus/utils": "0.0.0-
|
|
31
|
-
"@docusaurus/utils-common": "0.0.0-
|
|
32
|
-
"@docusaurus/utils-validation": "0.0.0-
|
|
24
|
+
"@docusaurus/core": "0.0.0-4735",
|
|
25
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4735",
|
|
26
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4735",
|
|
27
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4735",
|
|
28
|
+
"@docusaurus/theme-common": "0.0.0-4735",
|
|
29
|
+
"@docusaurus/theme-translations": "0.0.0-4735",
|
|
30
|
+
"@docusaurus/utils": "0.0.0-4735",
|
|
31
|
+
"@docusaurus/utils-common": "0.0.0-4735",
|
|
32
|
+
"@docusaurus/utils-validation": "0.0.0-4735",
|
|
33
33
|
"@mdx-js/react": "^1.6.22",
|
|
34
34
|
"clsx": "^1.1.1",
|
|
35
35
|
"copy-text-to-clipboard": "^3.0.1",
|
|
@@ -42,8 +42,8 @@
|
|
|
42
42
|
"rtlcss": "^3.5.0"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@docusaurus/module-type-aliases": "0.0.0-
|
|
46
|
-
"@docusaurus/types": "0.0.0-
|
|
45
|
+
"@docusaurus/module-type-aliases": "0.0.0-4735",
|
|
46
|
+
"@docusaurus/types": "0.0.0-4735",
|
|
47
47
|
"@types/mdx-js__react": "^1.5.5",
|
|
48
48
|
"@types/prismjs": "^1.26.0",
|
|
49
49
|
"@types/rtlcss": "^3.1.2",
|
|
@@ -59,5 +59,5 @@
|
|
|
59
59
|
"engines": {
|
|
60
60
|
"node": ">=14"
|
|
61
61
|
},
|
|
62
|
-
"gitHead": "
|
|
62
|
+
"gitHead": "0f869a8574293be34dcba878680b8adb519887dd"
|
|
63
63
|
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React
|
|
8
|
+
import React from 'react';
|
|
9
9
|
import type {Props} from '@theme/ColorModeToggle';
|
|
10
10
|
import useIsBrowser from '@docusaurus/useIsBrowser';
|
|
11
11
|
import {translate} from '@docusaurus/Translate';
|
|
@@ -15,78 +15,51 @@ import IconDarkMode from '@theme/IconDarkMode';
|
|
|
15
15
|
import clsx from 'clsx';
|
|
16
16
|
import styles from './styles.module.css';
|
|
17
17
|
|
|
18
|
-
function ColorModeToggle({
|
|
19
|
-
className,
|
|
20
|
-
checked: defaultChecked,
|
|
21
|
-
onChange,
|
|
22
|
-
}: Props): JSX.Element {
|
|
18
|
+
function ColorModeToggle({className, value, onChange}: Props): JSX.Element {
|
|
23
19
|
const isBrowser = useIsBrowser();
|
|
24
|
-
const [checked, setChecked] = useState(defaultChecked);
|
|
25
|
-
const [focused, setFocused] = useState(false);
|
|
26
|
-
const inputRef = useRef<HTMLInputElement>(null);
|
|
27
20
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
const title = translate(
|
|
22
|
+
{
|
|
23
|
+
message: 'Switch between dark and light mode (currently {mode})',
|
|
24
|
+
id: 'theme.colorToggle.ariaLabel',
|
|
25
|
+
description: 'The ARIA label for the navbar color mode toggle',
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
mode:
|
|
29
|
+
value === 'dark'
|
|
30
|
+
? translate({
|
|
31
|
+
message: 'dark mode',
|
|
32
|
+
id: 'theme.colorToggle.ariaLabel.mode.dark',
|
|
33
|
+
description: 'The name for the dark color mode',
|
|
34
|
+
})
|
|
35
|
+
: translate({
|
|
36
|
+
message: 'light mode',
|
|
37
|
+
id: 'theme.colorToggle.ariaLabel.mode.light',
|
|
38
|
+
description: 'The name for the light color mode',
|
|
39
|
+
}),
|
|
40
|
+
},
|
|
41
|
+
);
|
|
31
42
|
|
|
32
43
|
return (
|
|
33
|
-
<div
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
tabIndex={-1}
|
|
46
|
-
onClick={() => inputRef.current?.click()}>
|
|
44
|
+
<div className={clsx(styles.toggle, className)}>
|
|
45
|
+
<button
|
|
46
|
+
className={clsx(
|
|
47
|
+
'clean-btn',
|
|
48
|
+
styles.toggleButton,
|
|
49
|
+
!isBrowser && styles.toggleButtonDisabled,
|
|
50
|
+
)}
|
|
51
|
+
type="button"
|
|
52
|
+
onClick={() => onChange(value === 'dark' ? 'light' : 'dark')}
|
|
53
|
+
disabled={!isBrowser}
|
|
54
|
+
title={title}
|
|
55
|
+
aria-label={title}>
|
|
47
56
|
<IconLightMode
|
|
48
57
|
className={clsx(styles.toggleIcon, styles.lightToggleIcon)}
|
|
49
58
|
/>
|
|
50
59
|
<IconDarkMode
|
|
51
60
|
className={clsx(styles.toggleIcon, styles.darkToggleIcon)}
|
|
52
61
|
/>
|
|
53
|
-
</
|
|
54
|
-
|
|
55
|
-
<input
|
|
56
|
-
ref={inputRef}
|
|
57
|
-
checked={checked}
|
|
58
|
-
type="checkbox"
|
|
59
|
-
className={styles.toggleScreenReader}
|
|
60
|
-
aria-label={translate(
|
|
61
|
-
{
|
|
62
|
-
message: 'Switch between dark and light mode (currently {mode})',
|
|
63
|
-
id: 'theme.colorToggle.ariaLabel',
|
|
64
|
-
description: 'The ARIA label for the navbar color mode toggle',
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
mode: checked
|
|
68
|
-
? translate({
|
|
69
|
-
message: 'dark mode',
|
|
70
|
-
id: 'theme.colorToggle.ariaLabel.mode.dark',
|
|
71
|
-
description: 'The name for the dark color mode',
|
|
72
|
-
})
|
|
73
|
-
: translate({
|
|
74
|
-
message: 'light mode',
|
|
75
|
-
id: 'theme.colorToggle.ariaLabel.mode.light',
|
|
76
|
-
description: 'The name for the light color mode',
|
|
77
|
-
}),
|
|
78
|
-
},
|
|
79
|
-
)}
|
|
80
|
-
onChange={onChange}
|
|
81
|
-
onClick={() => setChecked(!checked)}
|
|
82
|
-
onFocus={() => setFocused(true)}
|
|
83
|
-
onBlur={() => setFocused(false)}
|
|
84
|
-
onKeyDown={(e) => {
|
|
85
|
-
if (e.key === 'Enter') {
|
|
86
|
-
inputRef.current?.click();
|
|
87
|
-
}
|
|
88
|
-
}}
|
|
89
|
-
/>
|
|
62
|
+
</button>
|
|
90
63
|
</div>
|
|
91
64
|
);
|
|
92
65
|
}
|
|
@@ -6,28 +6,11 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
.toggle {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
height: 32px;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
.toggleScreenReader {
|
|
15
|
-
border: 0;
|
|
16
|
-
clip: rect(0 0 0 0);
|
|
17
|
-
height: 1px;
|
|
18
|
-
margin: -1px;
|
|
19
|
-
overflow: hidden;
|
|
20
|
-
position: absolute;
|
|
21
|
-
width: 1px;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.toggleDisabled {
|
|
25
|
-
cursor: not-allowed;
|
|
9
|
+
width: 2rem;
|
|
10
|
+
height: 2rem;
|
|
26
11
|
}
|
|
27
12
|
|
|
28
13
|
.toggleButton {
|
|
29
|
-
cursor: pointer;
|
|
30
|
-
user-select: none;
|
|
31
14
|
-webkit-tap-highlight-color: transparent;
|
|
32
15
|
align-items: center;
|
|
33
16
|
display: flex;
|
|
@@ -35,17 +18,18 @@
|
|
|
35
18
|
width: 100%;
|
|
36
19
|
height: 100%;
|
|
37
20
|
border-radius: 50%;
|
|
21
|
+
transition: background var(--ifm-transition-fast);
|
|
38
22
|
}
|
|
39
23
|
|
|
40
24
|
.toggleButton:hover {
|
|
41
|
-
background-color
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
[data-theme='dark'] .toggleButton:hover {
|
|
45
|
-
background-color: #ffffff20;
|
|
25
|
+
background: var(--ifm-color-emphasis-200);
|
|
46
26
|
}
|
|
47
27
|
|
|
48
28
|
[data-theme='light'] .darkToggleIcon,
|
|
49
29
|
[data-theme='dark'] .lightToggleIcon {
|
|
50
30
|
display: none;
|
|
51
31
|
}
|
|
32
|
+
|
|
33
|
+
.toggleButtonDisabled {
|
|
34
|
+
cursor: not-allowed;
|
|
35
|
+
}
|
|
@@ -24,7 +24,7 @@ function BreadcrumbsItemLink({
|
|
|
24
24
|
children: ReactNode;
|
|
25
25
|
href?: string;
|
|
26
26
|
}): JSX.Element {
|
|
27
|
-
const className =
|
|
27
|
+
const className = 'breadcrumbs__link';
|
|
28
28
|
return href ? (
|
|
29
29
|
<Link className={className} href={href} itemProp="item">
|
|
30
30
|
<span itemProp="name">{children}</span>
|
|
@@ -98,7 +98,8 @@ export default function DocBreadcrumbs(): JSX.Element | null {
|
|
|
98
98
|
key={idx}
|
|
99
99
|
active={idx === breadcrumbs.length - 1}
|
|
100
100
|
index={idx}>
|
|
101
|
-
<BreadcrumbsItemLink
|
|
101
|
+
<BreadcrumbsItemLink
|
|
102
|
+
href={idx < breadcrumbs.length - 1 ? item.href : undefined}>
|
|
102
103
|
{item.label}
|
|
103
104
|
</BreadcrumbsItemLink>
|
|
104
105
|
</BreadcrumbsItem>
|
|
@@ -6,21 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
.breadcrumbsContainer {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
.breadcrumbsItemLink {
|
|
13
|
-
--ifm-breadcrumb-size-multiplier: 0.7 !important;
|
|
14
|
-
margin-bottom: 0.4rem;
|
|
15
|
-
background: var(--ifm-color-gray-100);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
html[data-theme='dark'] .breadcrumbsItemLink {
|
|
19
|
-
background-color: var(--ifm-color-gray-900);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
@media (min-width: 997px) {
|
|
23
|
-
.breadcrumbsItemLink {
|
|
24
|
-
--ifm-breadcrumb-size-multiplier: 0.8;
|
|
25
|
-
}
|
|
9
|
+
--ifm-breadcrumb-size-multiplier: 0.8;
|
|
10
|
+
margin-bottom: 0.8rem;
|
|
26
11
|
}
|
|
@@ -17,7 +17,11 @@ import TOC from '@theme/TOC';
|
|
|
17
17
|
import TOCCollapsible from '@theme/TOCCollapsible';
|
|
18
18
|
import Heading from '@theme/Heading';
|
|
19
19
|
import styles from './styles.module.css';
|
|
20
|
-
import {
|
|
20
|
+
import {
|
|
21
|
+
HtmlClassNameProvider,
|
|
22
|
+
ThemeClassNames,
|
|
23
|
+
useWindowSize,
|
|
24
|
+
} from '@docusaurus/theme-common';
|
|
21
25
|
import DocBreadcrumbs from '@theme/DocBreadcrumbs';
|
|
22
26
|
import MDXContent from '@theme/MDXContent';
|
|
23
27
|
|
|
@@ -49,7 +53,7 @@ export default function DocItem(props: Props): JSX.Element {
|
|
|
49
53
|
canRenderTOC && (windowSize === 'desktop' || windowSize === 'ssr');
|
|
50
54
|
|
|
51
55
|
return (
|
|
52
|
-
|
|
56
|
+
<HtmlClassNameProvider className={`docs-doc-id-${metadata.unversionedId}`}>
|
|
53
57
|
<Seo {...{title, description, keywords, image}} />
|
|
54
58
|
|
|
55
59
|
<div className="row">
|
|
@@ -107,6 +111,6 @@ export default function DocItem(props: Props): JSX.Element {
|
|
|
107
111
|
</div>
|
|
108
112
|
)}
|
|
109
113
|
</div>
|
|
110
|
-
|
|
114
|
+
</HtmlClassNameProvider>
|
|
111
115
|
);
|
|
112
116
|
}
|
|
@@ -20,14 +20,15 @@ import {translate} from '@docusaurus/Translate';
|
|
|
20
20
|
|
|
21
21
|
import clsx from 'clsx';
|
|
22
22
|
import styles from './styles.module.css';
|
|
23
|
+
|
|
23
24
|
import {
|
|
25
|
+
HtmlClassNameProvider,
|
|
24
26
|
ThemeClassNames,
|
|
25
27
|
docVersionSearchTag,
|
|
26
28
|
DocsSidebarProvider,
|
|
27
29
|
useDocsSidebar,
|
|
28
30
|
DocsVersionProvider,
|
|
29
31
|
} from '@docusaurus/theme-common';
|
|
30
|
-
import Head from '@docusaurus/Head';
|
|
31
32
|
|
|
32
33
|
type DocPageContentProps = {
|
|
33
34
|
readonly currentDocRoute: DocumentRoute;
|
|
@@ -160,11 +161,7 @@ export default function DocPage(props: Props): JSX.Element {
|
|
|
160
161
|
: null;
|
|
161
162
|
|
|
162
163
|
return (
|
|
163
|
-
|
|
164
|
-
<Head>
|
|
165
|
-
{/* TODO we should add a core addRoute({htmlClassName}) action */}
|
|
166
|
-
<html className={versionMetadata.className} />
|
|
167
|
-
</Head>
|
|
164
|
+
<HtmlClassNameProvider className={versionMetadata.className}>
|
|
168
165
|
<DocsVersionProvider version={versionMetadata}>
|
|
169
166
|
<DocsSidebarProvider sidebar={sidebar ?? null}>
|
|
170
167
|
<DocPageContent
|
|
@@ -175,6 +172,6 @@ export default function DocPage(props: Props): JSX.Element {
|
|
|
175
172
|
</DocPageContent>
|
|
176
173
|
</DocsSidebarProvider>
|
|
177
174
|
</DocsVersionProvider>
|
|
178
|
-
|
|
175
|
+
</HtmlClassNameProvider>
|
|
179
176
|
);
|
|
180
177
|
}
|
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
DocsPreferredVersionContextProvider,
|
|
14
14
|
MobileSecondaryMenuProvider,
|
|
15
15
|
ScrollControllerProvider,
|
|
16
|
+
PluginHtmlClassNameProvider,
|
|
16
17
|
} from '@docusaurus/theme-common';
|
|
17
18
|
import type {Props} from '@theme/LayoutProviders';
|
|
18
19
|
|
|
@@ -24,7 +25,9 @@ export default function LayoutProviders({children}: Props): JSX.Element {
|
|
|
24
25
|
<ScrollControllerProvider>
|
|
25
26
|
<DocsPreferredVersionContextProvider>
|
|
26
27
|
<MobileSecondaryMenuProvider>
|
|
27
|
-
|
|
28
|
+
<PluginHtmlClassNameProvider>
|
|
29
|
+
{children}
|
|
30
|
+
</PluginHtmlClassNameProvider>
|
|
28
31
|
</MobileSecondaryMenuProvider>
|
|
29
32
|
</DocsPreferredVersionContextProvider>
|
|
30
33
|
</ScrollControllerProvider>
|
|
@@ -88,12 +88,12 @@ function useColorModeToggle() {
|
|
|
88
88
|
const {
|
|
89
89
|
colorMode: {disableSwitch},
|
|
90
90
|
} = useThemeConfig();
|
|
91
|
-
const {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
91
|
+
const {colorMode, setColorMode} = useColorMode();
|
|
92
|
+
return {
|
|
93
|
+
value: colorMode,
|
|
94
|
+
onChange: setColorMode,
|
|
95
|
+
disabled: disableSwitch,
|
|
96
|
+
};
|
|
97
97
|
}
|
|
98
98
|
|
|
99
99
|
function useSecondaryMenu({
|
|
@@ -173,8 +173,8 @@ function NavbarMobileSidebar({
|
|
|
173
173
|
{!colorModeToggle.disabled && (
|
|
174
174
|
<ColorModeToggle
|
|
175
175
|
className={styles.navbarSidebarToggle}
|
|
176
|
-
|
|
177
|
-
onChange={colorModeToggle.
|
|
176
|
+
value={colorModeToggle.value}
|
|
177
|
+
onChange={colorModeToggle.onChange}
|
|
178
178
|
/>
|
|
179
179
|
)}
|
|
180
180
|
<button
|
|
@@ -279,8 +279,8 @@ export default function Navbar(): JSX.Element {
|
|
|
279
279
|
{!colorModeToggle.disabled && (
|
|
280
280
|
<ColorModeToggle
|
|
281
281
|
className={styles.toggle}
|
|
282
|
-
|
|
283
|
-
onChange={colorModeToggle.
|
|
282
|
+
value={colorModeToggle.value}
|
|
283
|
+
onChange={colorModeToggle.onChange}
|
|
284
284
|
/>
|
|
285
285
|
)}
|
|
286
286
|
{!hasSearchNavbarItem && <SearchBar />}
|
|
@@ -16,12 +16,13 @@ import styles from './styles.module.css';
|
|
|
16
16
|
|
|
17
17
|
export default function ThemedImage(props: Props): JSX.Element {
|
|
18
18
|
const isBrowser = useIsBrowser();
|
|
19
|
-
const {
|
|
19
|
+
const {colorMode} = useColorMode();
|
|
20
20
|
const {sources, className, alt, ...propsRest} = props;
|
|
21
21
|
|
|
22
22
|
type SourceName = keyof Props['sources'];
|
|
23
23
|
|
|
24
|
-
const clientThemes: SourceName[] =
|
|
24
|
+
const clientThemes: SourceName[] =
|
|
25
|
+
colorMode === 'dark' ? ['dark'] : ['light'];
|
|
25
26
|
|
|
26
27
|
const renderedSourceNames: SourceName[] = isBrowser
|
|
27
28
|
? clientThemes
|
package/src/theme-classic.d.ts
CHANGED
|
@@ -746,12 +746,16 @@ declare module '@theme/TOCCollapsible' {
|
|
|
746
746
|
}
|
|
747
747
|
|
|
748
748
|
declare module '@theme/ColorModeToggle' {
|
|
749
|
-
import type {
|
|
749
|
+
import type {ColorMode} from '@docusaurus/theme-common';
|
|
750
750
|
|
|
751
751
|
export interface Props {
|
|
752
752
|
readonly className?: string;
|
|
753
|
-
readonly
|
|
754
|
-
|
|
753
|
+
readonly value: ColorMode;
|
|
754
|
+
/**
|
|
755
|
+
* The parameter represents the "to-be" value. For example, if currently in
|
|
756
|
+
* dark mode, clicking the button should call `onChange("light")`
|
|
757
|
+
*/
|
|
758
|
+
readonly onChange: (colorMode: ColorMode) => void;
|
|
755
759
|
}
|
|
756
760
|
|
|
757
761
|
export default function Toggle(props: Props): JSX.Element;
|