@docusaurus/theme-classic 0.0.0-4734 → 0.0.0-4737
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 +66 -4
- package/lib-next/theme/ColorModeToggle/index.js +36 -59
- package/lib-next/theme/ColorModeToggle/styles.module.css +8 -24
- package/lib-next/theme/DocSidebar/Mobile/index.js +24 -20
- package/lib-next/theme/LayoutProviders/index.js +4 -6
- package/lib-next/theme/Navbar/ColorModeToggle/index.js +25 -0
- package/lib-next/theme/Navbar/Content/index.js +70 -0
- package/lib-next/theme/Navbar/Content/styles.module.css +15 -0
- package/lib-next/theme/Navbar/Layout/index.js +54 -0
- package/lib-next/theme/Navbar/{styles.module.css → Layout/styles.module.css} +0 -13
- package/lib-next/theme/Navbar/Logo/index.js +17 -0
- package/lib-next/theme/Navbar/MobileSidebar/Header/index.js +33 -0
- package/lib-next/theme/Navbar/MobileSidebar/Layout/index.js +28 -0
- package/lib-next/theme/Navbar/MobileSidebar/PrimaryMenu/index.js +33 -0
- package/lib-next/theme/Navbar/MobileSidebar/SecondaryMenu/index.js +36 -0
- package/lib-next/theme/Navbar/MobileSidebar/Toggle/index.js +23 -0
- package/lib-next/theme/Navbar/MobileSidebar/index.js +31 -0
- package/lib-next/theme/Navbar/index.js +6 -277
- 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/DocSidebar/Mobile/index.tsx +26 -23
- package/src/theme/LayoutProviders/index.tsx +4 -6
- package/src/theme/Navbar/ColorModeToggle/index.tsx +30 -0
- package/src/theme/Navbar/Content/index.tsx +81 -0
- package/src/theme/Navbar/Content/styles.module.css +15 -0
- package/src/theme/Navbar/Layout/index.tsx +57 -0
- package/src/theme/Navbar/{styles.module.css → Layout/styles.module.css} +0 -13
- package/src/theme/Navbar/Logo/index.tsx +19 -0
- package/src/theme/Navbar/MobileSidebar/Header/index.tsx +34 -0
- package/src/theme/Navbar/MobileSidebar/Layout/index.tsx +31 -0
- package/src/theme/Navbar/MobileSidebar/PrimaryMenu/index.tsx +38 -0
- package/src/theme/Navbar/MobileSidebar/SecondaryMenu/index.tsx +38 -0
- package/src/theme/Navbar/MobileSidebar/Toggle/index.tsx +25 -0
- package/src/theme/Navbar/MobileSidebar/index.tsx +33 -0
- package/src/theme/Navbar/index.tsx +6 -292
- package/src/theme/ThemedImage/index.tsx +3 -2
- package/src/theme-classic.d.ts +66 -4
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
import {useNavbarSecondaryMenu, useThemeConfig} from '@docusaurus/theme-common';
|
|
9
|
+
import Translate from '@docusaurus/Translate';
|
|
10
|
+
|
|
11
|
+
function SecondaryMenuBackButton(props) {
|
|
12
|
+
return (
|
|
13
|
+
<button {...props} type="button" className="clean-btn navbar-sidebar__back">
|
|
14
|
+
<Translate
|
|
15
|
+
id="theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel"
|
|
16
|
+
description="The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)">
|
|
17
|
+
← Back to main menu
|
|
18
|
+
</Translate>
|
|
19
|
+
</button>
|
|
20
|
+
);
|
|
21
|
+
} // The secondary menu slides from the right and shows contextual information
|
|
22
|
+
// such as the docs sidebar
|
|
23
|
+
|
|
24
|
+
export default function NavbarMobileSidebarSecondaryMenu() {
|
|
25
|
+
const isPrimaryMenuEmpty = useThemeConfig().navbar.items.length === 0;
|
|
26
|
+
const secondaryMenu = useNavbarSecondaryMenu();
|
|
27
|
+
return (
|
|
28
|
+
<>
|
|
29
|
+
{/* edge-case: prevent returning to the primaryMenu when it's empty */}
|
|
30
|
+
{!isPrimaryMenuEmpty && (
|
|
31
|
+
<SecondaryMenuBackButton onClick={() => secondaryMenu.hide()} />
|
|
32
|
+
)}
|
|
33
|
+
{secondaryMenu.content}
|
|
34
|
+
</>
|
|
35
|
+
);
|
|
36
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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
|
+
import IconMenu from '@theme/IconMenu';
|
|
9
|
+
import {useNavbarMobileSidebar} from '@docusaurus/theme-common';
|
|
10
|
+
export default function MobileSidebarToggle() {
|
|
11
|
+
const mobileSidebar = useNavbarMobileSidebar();
|
|
12
|
+
return (
|
|
13
|
+
<button
|
|
14
|
+
onClick={mobileSidebar.toggle}
|
|
15
|
+
onKeyDown={mobileSidebar.toggle}
|
|
16
|
+
aria-label="Navigation bar toggle"
|
|
17
|
+
className="navbar__toggle clean-btn"
|
|
18
|
+
type="button"
|
|
19
|
+
tabIndex={0}>
|
|
20
|
+
<IconMenu />
|
|
21
|
+
</button>
|
|
22
|
+
);
|
|
23
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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
|
+
import NavbarMobileSidebarLayout from '@theme/Navbar/MobileSidebar/Layout';
|
|
9
|
+
import NavbarMobileSidebarHeader from '@theme/Navbar/MobileSidebar/Header';
|
|
10
|
+
import {
|
|
11
|
+
useLockBodyScroll,
|
|
12
|
+
useNavbarMobileSidebar,
|
|
13
|
+
} from '@docusaurus/theme-common';
|
|
14
|
+
import NavbarMobileSidebarPrimaryMenu from '@theme/Navbar/MobileSidebar/PrimaryMenu';
|
|
15
|
+
import NavbarMobileSidebarSecondaryMenu from '@theme/Navbar/MobileSidebar/SecondaryMenu';
|
|
16
|
+
export default function NavbarMobileSidebar() {
|
|
17
|
+
const mobileSidebar = useNavbarMobileSidebar();
|
|
18
|
+
useLockBodyScroll(mobileSidebar.shown);
|
|
19
|
+
|
|
20
|
+
if (!mobileSidebar.shouldRender) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return (
|
|
25
|
+
<NavbarMobileSidebarLayout
|
|
26
|
+
header={<NavbarMobileSidebarHeader />}
|
|
27
|
+
primaryMenu={<NavbarMobileSidebarPrimaryMenu />}
|
|
28
|
+
secondaryMenu={<NavbarMobileSidebarSecondaryMenu />}
|
|
29
|
+
/>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -4,284 +4,13 @@
|
|
|
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
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
import SearchBar from '@theme/SearchBar';
|
|
11
|
-
import ColorModeToggle from '@theme/ColorModeToggle';
|
|
12
|
-
import {
|
|
13
|
-
useThemeConfig,
|
|
14
|
-
useMobileSecondaryMenuRenderer,
|
|
15
|
-
usePrevious,
|
|
16
|
-
useHistoryPopHandler,
|
|
17
|
-
useHideableNavbar,
|
|
18
|
-
useLockBodyScroll,
|
|
19
|
-
useWindowSize,
|
|
20
|
-
useColorMode,
|
|
21
|
-
} from '@docusaurus/theme-common';
|
|
22
|
-
import {useActivePlugin} from '@docusaurus/plugin-content-docs/client';
|
|
23
|
-
import NavbarItem from '@theme/NavbarItem';
|
|
24
|
-
import Logo from '@theme/Logo';
|
|
25
|
-
import IconMenu from '@theme/IconMenu';
|
|
26
|
-
import IconClose from '@theme/IconClose';
|
|
27
|
-
import styles from './styles.module.css'; // retrocompatible with v1
|
|
28
|
-
|
|
29
|
-
const DefaultNavItemPosition = 'right';
|
|
30
|
-
|
|
31
|
-
function useNavbarItems() {
|
|
32
|
-
// TODO temporary casting until ThemeConfig type is improved
|
|
33
|
-
return useThemeConfig().navbar.items;
|
|
34
|
-
} // If split links by left/right
|
|
35
|
-
// if position is unspecified, fallback to right (as v1)
|
|
36
|
-
|
|
37
|
-
function splitNavItemsByPosition(items) {
|
|
38
|
-
const leftItems = items.filter(
|
|
39
|
-
(item) => (item.position ?? DefaultNavItemPosition) === 'left',
|
|
40
|
-
);
|
|
41
|
-
const rightItems = items.filter(
|
|
42
|
-
(item) => (item.position ?? DefaultNavItemPosition) === 'right',
|
|
43
|
-
);
|
|
44
|
-
return {
|
|
45
|
-
leftItems,
|
|
46
|
-
rightItems,
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function useMobileSidebar() {
|
|
51
|
-
const windowSize = useWindowSize(); // Mobile sidebar not visible on hydration: can avoid SSR rendering
|
|
52
|
-
|
|
53
|
-
const shouldRender = windowSize === 'mobile'; // || windowSize === 'ssr';
|
|
54
|
-
|
|
55
|
-
const [shown, setShown] = useState(false); // Close mobile sidebar on navigation pop
|
|
56
|
-
// Most likely firing when using the Android back button (but not only)
|
|
57
|
-
|
|
58
|
-
useHistoryPopHandler(() => {
|
|
59
|
-
if (shown) {
|
|
60
|
-
setShown(false); // Should we prevent the navigation here?
|
|
61
|
-
// See https://github.com/facebook/docusaurus/pull/5462#issuecomment-911699846
|
|
62
|
-
|
|
63
|
-
return false; // prevent pop navigation
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return undefined;
|
|
67
|
-
});
|
|
68
|
-
const toggle = useCallback(() => {
|
|
69
|
-
setShown((s) => !s);
|
|
70
|
-
}, []);
|
|
71
|
-
useEffect(() => {
|
|
72
|
-
if (windowSize === 'desktop') {
|
|
73
|
-
setShown(false);
|
|
74
|
-
}
|
|
75
|
-
}, [windowSize]);
|
|
76
|
-
return {
|
|
77
|
-
shouldRender,
|
|
78
|
-
toggle,
|
|
79
|
-
shown,
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function useColorModeToggle() {
|
|
84
|
-
const {
|
|
85
|
-
colorMode: {disableSwitch},
|
|
86
|
-
} = useThemeConfig();
|
|
87
|
-
const {isDarkTheme, setLightTheme, setDarkTheme} = useColorMode();
|
|
88
|
-
const toggle = useCallback(
|
|
89
|
-
(e) => (e.target.checked ? setDarkTheme() : setLightTheme()),
|
|
90
|
-
[setLightTheme, setDarkTheme],
|
|
91
|
-
);
|
|
92
|
-
return {
|
|
93
|
-
isDarkTheme,
|
|
94
|
-
toggle,
|
|
95
|
-
disabled: disableSwitch,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function useSecondaryMenu({sidebarShown, toggleSidebar}) {
|
|
100
|
-
const content = useMobileSecondaryMenuRenderer()?.({
|
|
101
|
-
toggleSidebar,
|
|
102
|
-
});
|
|
103
|
-
const previousContent = usePrevious(content);
|
|
104
|
-
const [shown, setShown] = useState(
|
|
105
|
-
() =>
|
|
106
|
-
// /!\ content is set with useEffect,
|
|
107
|
-
// so it's not available on mount anyway
|
|
108
|
-
// "return !!content" => always returns false
|
|
109
|
-
false,
|
|
110
|
-
); // When content is become available for the first time (set in useEffect)
|
|
111
|
-
// we set this content to be shown!
|
|
112
|
-
|
|
113
|
-
useEffect(() => {
|
|
114
|
-
const contentBecameAvailable = content && !previousContent;
|
|
115
|
-
|
|
116
|
-
if (contentBecameAvailable) {
|
|
117
|
-
setShown(true);
|
|
118
|
-
}
|
|
119
|
-
}, [content, previousContent]);
|
|
120
|
-
const hasContent = !!content; // On sidebar close, secondary menu is set to be shown on next re-opening
|
|
121
|
-
// (if any secondary menu content available)
|
|
122
|
-
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
if (!hasContent) {
|
|
125
|
-
setShown(false);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
if (!sidebarShown) {
|
|
130
|
-
setShown(true);
|
|
131
|
-
}
|
|
132
|
-
}, [sidebarShown, hasContent]);
|
|
133
|
-
const hide = useCallback(() => {
|
|
134
|
-
setShown(false);
|
|
135
|
-
}, []);
|
|
136
|
-
return {
|
|
137
|
-
shown,
|
|
138
|
-
hide,
|
|
139
|
-
content,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function NavbarMobileSidebar({sidebarShown, toggleSidebar}) {
|
|
144
|
-
useLockBodyScroll(sidebarShown);
|
|
145
|
-
const items = useNavbarItems();
|
|
146
|
-
const colorModeToggle = useColorModeToggle();
|
|
147
|
-
const secondaryMenu = useSecondaryMenu({
|
|
148
|
-
sidebarShown,
|
|
149
|
-
toggleSidebar,
|
|
150
|
-
});
|
|
151
|
-
return (
|
|
152
|
-
<div className="navbar-sidebar">
|
|
153
|
-
<div className="navbar-sidebar__brand">
|
|
154
|
-
<Logo
|
|
155
|
-
className="navbar__brand"
|
|
156
|
-
imageClassName="navbar__logo"
|
|
157
|
-
titleClassName="navbar__title"
|
|
158
|
-
/>
|
|
159
|
-
{!colorModeToggle.disabled && (
|
|
160
|
-
<ColorModeToggle
|
|
161
|
-
className={styles.navbarSidebarToggle}
|
|
162
|
-
checked={colorModeToggle.isDarkTheme}
|
|
163
|
-
onChange={colorModeToggle.toggle}
|
|
164
|
-
/>
|
|
165
|
-
)}
|
|
166
|
-
<button
|
|
167
|
-
type="button"
|
|
168
|
-
className="clean-btn navbar-sidebar__close"
|
|
169
|
-
onClick={toggleSidebar}>
|
|
170
|
-
<IconClose
|
|
171
|
-
color="var(--ifm-color-emphasis-600)"
|
|
172
|
-
className={styles.navbarSidebarCloseSvg}
|
|
173
|
-
/>
|
|
174
|
-
</button>
|
|
175
|
-
</div>
|
|
176
|
-
|
|
177
|
-
<div
|
|
178
|
-
className={clsx('navbar-sidebar__items', {
|
|
179
|
-
'navbar-sidebar__items--show-secondary': secondaryMenu.shown,
|
|
180
|
-
})}>
|
|
181
|
-
<div className="navbar-sidebar__item menu">
|
|
182
|
-
<ul className="menu__list">
|
|
183
|
-
{items.map((item, i) => (
|
|
184
|
-
<NavbarItem mobile {...item} onClick={toggleSidebar} key={i} />
|
|
185
|
-
))}
|
|
186
|
-
</ul>
|
|
187
|
-
</div>
|
|
188
|
-
|
|
189
|
-
<div className="navbar-sidebar__item menu">
|
|
190
|
-
{items.length > 0 && (
|
|
191
|
-
<button
|
|
192
|
-
type="button"
|
|
193
|
-
className="clean-btn navbar-sidebar__back"
|
|
194
|
-
onClick={secondaryMenu.hide}>
|
|
195
|
-
<Translate
|
|
196
|
-
id="theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel"
|
|
197
|
-
description="The label of the back button to return to main menu, inside the mobile navbar sidebar secondary menu (notably used to display the docs sidebar)">
|
|
198
|
-
← Back to main menu
|
|
199
|
-
</Translate>
|
|
200
|
-
</button>
|
|
201
|
-
)}
|
|
202
|
-
{secondaryMenu.content}
|
|
203
|
-
</div>
|
|
204
|
-
</div>
|
|
205
|
-
</div>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
|
|
7
|
+
import React from 'react';
|
|
8
|
+
import NavbarLayout from '@theme/Navbar/Layout';
|
|
9
|
+
import NavbarContent from '@theme/Navbar/Content';
|
|
209
10
|
export default function Navbar() {
|
|
210
|
-
const {
|
|
211
|
-
navbar: {hideOnScroll, style},
|
|
212
|
-
} = useThemeConfig();
|
|
213
|
-
const mobileSidebar = useMobileSidebar();
|
|
214
|
-
const colorModeToggle = useColorModeToggle();
|
|
215
|
-
const activeDocPlugin = useActivePlugin();
|
|
216
|
-
const {navbarRef, isNavbarVisible} = useHideableNavbar(hideOnScroll);
|
|
217
|
-
const items = useNavbarItems();
|
|
218
|
-
const hasSearchNavbarItem = items.some((item) => item.type === 'search');
|
|
219
|
-
const {leftItems, rightItems} = splitNavItemsByPosition(items);
|
|
220
11
|
return (
|
|
221
|
-
<
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
'navbar',
|
|
225
|
-
'navbar--fixed-top',
|
|
226
|
-
hideOnScroll && [
|
|
227
|
-
styles.navbarHideable,
|
|
228
|
-
!isNavbarVisible && styles.navbarHidden,
|
|
229
|
-
],
|
|
230
|
-
{
|
|
231
|
-
'navbar--dark': style === 'dark',
|
|
232
|
-
'navbar--primary': style === 'primary',
|
|
233
|
-
'navbar-sidebar--show': mobileSidebar.shown,
|
|
234
|
-
},
|
|
235
|
-
)}>
|
|
236
|
-
<div className="navbar__inner">
|
|
237
|
-
<div className="navbar__items">
|
|
238
|
-
{(items?.length > 0 || activeDocPlugin) && (
|
|
239
|
-
<button
|
|
240
|
-
aria-label="Navigation bar toggle"
|
|
241
|
-
className="navbar__toggle clean-btn"
|
|
242
|
-
type="button"
|
|
243
|
-
tabIndex={0}
|
|
244
|
-
onClick={mobileSidebar.toggle}
|
|
245
|
-
onKeyDown={mobileSidebar.toggle}>
|
|
246
|
-
<IconMenu />
|
|
247
|
-
</button>
|
|
248
|
-
)}
|
|
249
|
-
<Logo
|
|
250
|
-
className="navbar__brand"
|
|
251
|
-
imageClassName="navbar__logo"
|
|
252
|
-
titleClassName="navbar__title"
|
|
253
|
-
/>
|
|
254
|
-
{leftItems.map((item, i) => (
|
|
255
|
-
<NavbarItem {...item} key={i} />
|
|
256
|
-
))}
|
|
257
|
-
</div>
|
|
258
|
-
<div className="navbar__items navbar__items--right">
|
|
259
|
-
{rightItems.map((item, i) => (
|
|
260
|
-
<NavbarItem {...item} key={i} />
|
|
261
|
-
))}
|
|
262
|
-
{!colorModeToggle.disabled && (
|
|
263
|
-
<ColorModeToggle
|
|
264
|
-
className={styles.toggle}
|
|
265
|
-
checked={colorModeToggle.isDarkTheme}
|
|
266
|
-
onChange={colorModeToggle.toggle}
|
|
267
|
-
/>
|
|
268
|
-
)}
|
|
269
|
-
{!hasSearchNavbarItem && <SearchBar />}
|
|
270
|
-
</div>
|
|
271
|
-
</div>
|
|
272
|
-
|
|
273
|
-
<div
|
|
274
|
-
role="presentation"
|
|
275
|
-
className="navbar-sidebar__backdrop"
|
|
276
|
-
onClick={mobileSidebar.toggle}
|
|
277
|
-
/>
|
|
278
|
-
|
|
279
|
-
{mobileSidebar.shouldRender && (
|
|
280
|
-
<NavbarMobileSidebar
|
|
281
|
-
sidebarShown={mobileSidebar.shown}
|
|
282
|
-
toggleSidebar={mobileSidebar.toggle}
|
|
283
|
-
/>
|
|
284
|
-
)}
|
|
285
|
-
</nav>
|
|
12
|
+
<NavbarLayout>
|
|
13
|
+
<NavbarContent />
|
|
14
|
+
</NavbarLayout>
|
|
286
15
|
);
|
|
287
16
|
}
|
|
@@ -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-4737",
|
|
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-4737",
|
|
25
|
+
"@docusaurus/plugin-content-blog": "0.0.0-4737",
|
|
26
|
+
"@docusaurus/plugin-content-docs": "0.0.0-4737",
|
|
27
|
+
"@docusaurus/plugin-content-pages": "0.0.0-4737",
|
|
28
|
+
"@docusaurus/theme-common": "0.0.0-4737",
|
|
29
|
+
"@docusaurus/theme-translations": "0.0.0-4737",
|
|
30
|
+
"@docusaurus/utils": "0.0.0-4737",
|
|
31
|
+
"@docusaurus/utils-common": "0.0.0-4737",
|
|
32
|
+
"@docusaurus/utils-validation": "0.0.0-4737",
|
|
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-4737",
|
|
46
|
+
"@docusaurus/types": "0.0.0-4737",
|
|
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": "ac3069f091cfe3cfa175cac034df8cccd000c85b"
|
|
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
|
+
}
|