@docusaurus/theme-classic 0.0.0-4733 → 0.0.0-4736
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/DocItem/index.js +7 -3
- package/lib-next/theme/DocPage/index.js +3 -7
- package/lib-next/theme/DocSidebar/Mobile/index.js +24 -20
- package/lib-next/theme/LayoutProviders/index.js +5 -4
- 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/DocItem/index.tsx +7 -3
- package/src/theme/DocPage/index.tsx +4 -7
- package/src/theme/DocSidebar/Mobile/index.tsx +26 -23
- package/src/theme/LayoutProviders/index.tsx +5 -4
- 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
|
@@ -5,300 +5,14 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import React
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import SearchBar from '@theme/SearchBar';
|
|
12
|
-
import ColorModeToggle from '@theme/ColorModeToggle';
|
|
13
|
-
import {
|
|
14
|
-
useThemeConfig,
|
|
15
|
-
useMobileSecondaryMenuRenderer,
|
|
16
|
-
usePrevious,
|
|
17
|
-
useHistoryPopHandler,
|
|
18
|
-
useHideableNavbar,
|
|
19
|
-
useLockBodyScroll,
|
|
20
|
-
useWindowSize,
|
|
21
|
-
useColorMode,
|
|
22
|
-
} from '@docusaurus/theme-common';
|
|
23
|
-
import {useActivePlugin} from '@docusaurus/plugin-content-docs/client';
|
|
24
|
-
import NavbarItem, {type Props as NavbarItemConfig} from '@theme/NavbarItem';
|
|
25
|
-
import Logo from '@theme/Logo';
|
|
26
|
-
import IconMenu from '@theme/IconMenu';
|
|
27
|
-
import IconClose from '@theme/IconClose';
|
|
28
|
-
|
|
29
|
-
import styles from './styles.module.css';
|
|
30
|
-
|
|
31
|
-
// retrocompatible with v1
|
|
32
|
-
const DefaultNavItemPosition = 'right';
|
|
33
|
-
|
|
34
|
-
function useNavbarItems() {
|
|
35
|
-
// TODO temporary casting until ThemeConfig type is improved
|
|
36
|
-
return useThemeConfig().navbar.items as NavbarItemConfig[];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// If split links by left/right
|
|
40
|
-
// if position is unspecified, fallback to right (as v1)
|
|
41
|
-
function splitNavItemsByPosition(items: NavbarItemConfig[]) {
|
|
42
|
-
const leftItems = items.filter(
|
|
43
|
-
(item) => (item.position ?? DefaultNavItemPosition) === 'left',
|
|
44
|
-
);
|
|
45
|
-
const rightItems = items.filter(
|
|
46
|
-
(item) => (item.position ?? DefaultNavItemPosition) === 'right',
|
|
47
|
-
);
|
|
48
|
-
return {
|
|
49
|
-
leftItems,
|
|
50
|
-
rightItems,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function useMobileSidebar() {
|
|
55
|
-
const windowSize = useWindowSize();
|
|
56
|
-
|
|
57
|
-
// Mobile sidebar not visible on hydration: can avoid SSR rendering
|
|
58
|
-
const shouldRender = windowSize === 'mobile'; // || windowSize === 'ssr';
|
|
59
|
-
|
|
60
|
-
const [shown, setShown] = useState(false);
|
|
61
|
-
|
|
62
|
-
// Close mobile sidebar on navigation pop
|
|
63
|
-
// Most likely firing when using the Android back button (but not only)
|
|
64
|
-
useHistoryPopHandler(() => {
|
|
65
|
-
if (shown) {
|
|
66
|
-
setShown(false);
|
|
67
|
-
// Should we prevent the navigation here?
|
|
68
|
-
// See https://github.com/facebook/docusaurus/pull/5462#issuecomment-911699846
|
|
69
|
-
return false; // prevent pop navigation
|
|
70
|
-
}
|
|
71
|
-
return undefined;
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
const toggle = useCallback(() => {
|
|
75
|
-
setShown((s) => !s);
|
|
76
|
-
}, []);
|
|
77
|
-
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
if (windowSize === 'desktop') {
|
|
80
|
-
setShown(false);
|
|
81
|
-
}
|
|
82
|
-
}, [windowSize]);
|
|
83
|
-
|
|
84
|
-
return {shouldRender, toggle, shown};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function useColorModeToggle() {
|
|
88
|
-
const {
|
|
89
|
-
colorMode: {disableSwitch},
|
|
90
|
-
} = useThemeConfig();
|
|
91
|
-
const {isDarkTheme, setLightTheme, setDarkTheme} = useColorMode();
|
|
92
|
-
const toggle = useCallback(
|
|
93
|
-
(e) => (e.target.checked ? setDarkTheme() : setLightTheme()),
|
|
94
|
-
[setLightTheme, setDarkTheme],
|
|
95
|
-
);
|
|
96
|
-
return {isDarkTheme, toggle, disabled: disableSwitch};
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function useSecondaryMenu({
|
|
100
|
-
sidebarShown,
|
|
101
|
-
toggleSidebar,
|
|
102
|
-
}: NavbarMobileSidebarProps) {
|
|
103
|
-
const content = useMobileSecondaryMenuRenderer()?.({
|
|
104
|
-
toggleSidebar,
|
|
105
|
-
});
|
|
106
|
-
const previousContent = usePrevious(content);
|
|
107
|
-
|
|
108
|
-
const [shown, setShown] = useState<boolean>(
|
|
109
|
-
() =>
|
|
110
|
-
// /!\ content is set with useEffect,
|
|
111
|
-
// so it's not available on mount anyway
|
|
112
|
-
// "return !!content" => always returns false
|
|
113
|
-
false,
|
|
114
|
-
);
|
|
115
|
-
|
|
116
|
-
// When content is become available for the first time (set in useEffect)
|
|
117
|
-
// we set this content to be shown!
|
|
118
|
-
useEffect(() => {
|
|
119
|
-
const contentBecameAvailable = content && !previousContent;
|
|
120
|
-
if (contentBecameAvailable) {
|
|
121
|
-
setShown(true);
|
|
122
|
-
}
|
|
123
|
-
}, [content, previousContent]);
|
|
124
|
-
|
|
125
|
-
const hasContent = !!content;
|
|
126
|
-
|
|
127
|
-
// On sidebar close, secondary menu is set to be shown on next re-opening
|
|
128
|
-
// (if any secondary menu content available)
|
|
129
|
-
useEffect(() => {
|
|
130
|
-
if (!hasContent) {
|
|
131
|
-
setShown(false);
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
if (!sidebarShown) {
|
|
135
|
-
setShown(true);
|
|
136
|
-
}
|
|
137
|
-
}, [sidebarShown, hasContent]);
|
|
138
|
-
|
|
139
|
-
const hide = useCallback(() => {
|
|
140
|
-
setShown(false);
|
|
141
|
-
}, []);
|
|
142
|
-
|
|
143
|
-
return {shown, hide, content};
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
type NavbarMobileSidebarProps = {
|
|
147
|
-
sidebarShown: boolean;
|
|
148
|
-
toggleSidebar: () => void;
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
function NavbarMobileSidebar({
|
|
152
|
-
sidebarShown,
|
|
153
|
-
toggleSidebar,
|
|
154
|
-
}: NavbarMobileSidebarProps) {
|
|
155
|
-
useLockBodyScroll(sidebarShown);
|
|
156
|
-
const items = useNavbarItems();
|
|
157
|
-
|
|
158
|
-
const colorModeToggle = useColorModeToggle();
|
|
159
|
-
|
|
160
|
-
const secondaryMenu = useSecondaryMenu({
|
|
161
|
-
sidebarShown,
|
|
162
|
-
toggleSidebar,
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
return (
|
|
166
|
-
<div className="navbar-sidebar">
|
|
167
|
-
<div className="navbar-sidebar__brand">
|
|
168
|
-
<Logo
|
|
169
|
-
className="navbar__brand"
|
|
170
|
-
imageClassName="navbar__logo"
|
|
171
|
-
titleClassName="navbar__title"
|
|
172
|
-
/>
|
|
173
|
-
{!colorModeToggle.disabled && (
|
|
174
|
-
<ColorModeToggle
|
|
175
|
-
className={styles.navbarSidebarToggle}
|
|
176
|
-
checked={colorModeToggle.isDarkTheme}
|
|
177
|
-
onChange={colorModeToggle.toggle}
|
|
178
|
-
/>
|
|
179
|
-
)}
|
|
180
|
-
<button
|
|
181
|
-
type="button"
|
|
182
|
-
className="clean-btn navbar-sidebar__close"
|
|
183
|
-
onClick={toggleSidebar}>
|
|
184
|
-
<IconClose
|
|
185
|
-
color="var(--ifm-color-emphasis-600)"
|
|
186
|
-
className={styles.navbarSidebarCloseSvg}
|
|
187
|
-
/>
|
|
188
|
-
</button>
|
|
189
|
-
</div>
|
|
190
|
-
|
|
191
|
-
<div
|
|
192
|
-
className={clsx('navbar-sidebar__items', {
|
|
193
|
-
'navbar-sidebar__items--show-secondary': secondaryMenu.shown,
|
|
194
|
-
})}>
|
|
195
|
-
<div className="navbar-sidebar__item menu">
|
|
196
|
-
<ul className="menu__list">
|
|
197
|
-
{items.map((item, i) => (
|
|
198
|
-
<NavbarItem mobile {...item} onClick={toggleSidebar} key={i} />
|
|
199
|
-
))}
|
|
200
|
-
</ul>
|
|
201
|
-
</div>
|
|
202
|
-
|
|
203
|
-
<div className="navbar-sidebar__item menu">
|
|
204
|
-
{items.length > 0 && (
|
|
205
|
-
<button
|
|
206
|
-
type="button"
|
|
207
|
-
className="clean-btn navbar-sidebar__back"
|
|
208
|
-
onClick={secondaryMenu.hide}>
|
|
209
|
-
<Translate
|
|
210
|
-
id="theme.navbar.mobileSidebarSecondaryMenu.backButtonLabel"
|
|
211
|
-
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)">
|
|
212
|
-
← Back to main menu
|
|
213
|
-
</Translate>
|
|
214
|
-
</button>
|
|
215
|
-
)}
|
|
216
|
-
{secondaryMenu.content}
|
|
217
|
-
</div>
|
|
218
|
-
</div>
|
|
219
|
-
</div>
|
|
220
|
-
);
|
|
221
|
-
}
|
|
8
|
+
import React from 'react';
|
|
9
|
+
import NavbarLayout from '@theme/Navbar/Layout';
|
|
10
|
+
import NavbarContent from '@theme/Navbar/Content';
|
|
222
11
|
|
|
223
12
|
export default function Navbar(): JSX.Element {
|
|
224
|
-
const {
|
|
225
|
-
navbar: {hideOnScroll, style},
|
|
226
|
-
} = useThemeConfig();
|
|
227
|
-
|
|
228
|
-
const mobileSidebar = useMobileSidebar();
|
|
229
|
-
const colorModeToggle = useColorModeToggle();
|
|
230
|
-
const activeDocPlugin = useActivePlugin();
|
|
231
|
-
const {navbarRef, isNavbarVisible} = useHideableNavbar(hideOnScroll);
|
|
232
|
-
|
|
233
|
-
const items = useNavbarItems();
|
|
234
|
-
const hasSearchNavbarItem = items.some((item) => item.type === 'search');
|
|
235
|
-
const {leftItems, rightItems} = splitNavItemsByPosition(items);
|
|
236
|
-
|
|
237
13
|
return (
|
|
238
|
-
<
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
'navbar',
|
|
242
|
-
'navbar--fixed-top',
|
|
243
|
-
hideOnScroll && [
|
|
244
|
-
styles.navbarHideable,
|
|
245
|
-
!isNavbarVisible && styles.navbarHidden,
|
|
246
|
-
],
|
|
247
|
-
{
|
|
248
|
-
'navbar--dark': style === 'dark',
|
|
249
|
-
'navbar--primary': style === 'primary',
|
|
250
|
-
'navbar-sidebar--show': mobileSidebar.shown,
|
|
251
|
-
},
|
|
252
|
-
)}>
|
|
253
|
-
<div className="navbar__inner">
|
|
254
|
-
<div className="navbar__items">
|
|
255
|
-
{(items?.length > 0 || activeDocPlugin) && (
|
|
256
|
-
<button
|
|
257
|
-
aria-label="Navigation bar toggle"
|
|
258
|
-
className="navbar__toggle clean-btn"
|
|
259
|
-
type="button"
|
|
260
|
-
tabIndex={0}
|
|
261
|
-
onClick={mobileSidebar.toggle}
|
|
262
|
-
onKeyDown={mobileSidebar.toggle}>
|
|
263
|
-
<IconMenu />
|
|
264
|
-
</button>
|
|
265
|
-
)}
|
|
266
|
-
<Logo
|
|
267
|
-
className="navbar__brand"
|
|
268
|
-
imageClassName="navbar__logo"
|
|
269
|
-
titleClassName="navbar__title"
|
|
270
|
-
/>
|
|
271
|
-
{leftItems.map((item, i) => (
|
|
272
|
-
<NavbarItem {...item} key={i} />
|
|
273
|
-
))}
|
|
274
|
-
</div>
|
|
275
|
-
<div className="navbar__items navbar__items--right">
|
|
276
|
-
{rightItems.map((item, i) => (
|
|
277
|
-
<NavbarItem {...item} key={i} />
|
|
278
|
-
))}
|
|
279
|
-
{!colorModeToggle.disabled && (
|
|
280
|
-
<ColorModeToggle
|
|
281
|
-
className={styles.toggle}
|
|
282
|
-
checked={colorModeToggle.isDarkTheme}
|
|
283
|
-
onChange={colorModeToggle.toggle}
|
|
284
|
-
/>
|
|
285
|
-
)}
|
|
286
|
-
{!hasSearchNavbarItem && <SearchBar />}
|
|
287
|
-
</div>
|
|
288
|
-
</div>
|
|
289
|
-
|
|
290
|
-
<div
|
|
291
|
-
role="presentation"
|
|
292
|
-
className="navbar-sidebar__backdrop"
|
|
293
|
-
onClick={mobileSidebar.toggle}
|
|
294
|
-
/>
|
|
295
|
-
|
|
296
|
-
{mobileSidebar.shouldRender && (
|
|
297
|
-
<NavbarMobileSidebar
|
|
298
|
-
sidebarShown={mobileSidebar.shown}
|
|
299
|
-
toggleSidebar={mobileSidebar.toggle}
|
|
300
|
-
/>
|
|
301
|
-
)}
|
|
302
|
-
</nav>
|
|
14
|
+
<NavbarLayout>
|
|
15
|
+
<NavbarContent />
|
|
16
|
+
</NavbarLayout>
|
|
303
17
|
);
|
|
304
18
|
}
|
|
@@ -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
|
@@ -460,6 +460,64 @@ declare module '@theme/Navbar' {
|
|
|
460
460
|
export default function Navbar(): JSX.Element;
|
|
461
461
|
}
|
|
462
462
|
|
|
463
|
+
declare module '@theme/Navbar/ColorModeToggle' {
|
|
464
|
+
export interface Props {
|
|
465
|
+
readonly className?: string;
|
|
466
|
+
}
|
|
467
|
+
|
|
468
|
+
export default function NavbarColorModeToggle(
|
|
469
|
+
props: Props,
|
|
470
|
+
): JSX.Element | null;
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
declare module '@theme/Navbar/Logo' {
|
|
474
|
+
export default function NavbarLogo(): JSX.Element;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
declare module '@theme/Navbar/Content' {
|
|
478
|
+
export default function NavbarContent(): JSX.Element;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
declare module '@theme/Navbar/Layout' {
|
|
482
|
+
export interface Props {
|
|
483
|
+
children: React.ReactNode;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
export default function NavbarLayout(props: Props): JSX.Element;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
declare module '@theme/Navbar/MobileSidebar' {
|
|
490
|
+
export default function NavbarMobileSidebar(): JSX.Element;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
declare module '@theme/Navbar/MobileSidebar/Layout' {
|
|
494
|
+
import type {ReactNode} from 'react';
|
|
495
|
+
|
|
496
|
+
interface Props {
|
|
497
|
+
header: ReactNode;
|
|
498
|
+
primaryMenu: ReactNode;
|
|
499
|
+
secondaryMenu: ReactNode;
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
export default function NavbarMobileSidebarLayout(props: Props): JSX.Element;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
declare module '@theme/Navbar/MobileSidebar/Toggle' {
|
|
506
|
+
export default function NavbarMobileSidebarToggle(): JSX.Element;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
declare module '@theme/Navbar/MobileSidebar/PrimaryMenu' {
|
|
510
|
+
export default function NavbarMobileSidebarPrimaryMenu(): JSX.Element;
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
declare module '@theme/Navbar/MobileSidebar/SecondaryMenu' {
|
|
514
|
+
export default function NavbarMobileSidebarSecondaryMenu(): JSX.Element;
|
|
515
|
+
}
|
|
516
|
+
|
|
517
|
+
declare module '@theme/Navbar/MobileSidebar/Header' {
|
|
518
|
+
export default function NavbarMobileSidebarHeader(): JSX.Element;
|
|
519
|
+
}
|
|
520
|
+
|
|
463
521
|
declare module '@theme/NavbarItem/DefaultNavbarItem' {
|
|
464
522
|
import type {Props as NavbarNavLinkProps} from '@theme/NavbarItem/NavbarNavLink';
|
|
465
523
|
|
|
@@ -746,15 +804,19 @@ declare module '@theme/TOCCollapsible' {
|
|
|
746
804
|
}
|
|
747
805
|
|
|
748
806
|
declare module '@theme/ColorModeToggle' {
|
|
749
|
-
import type {
|
|
807
|
+
import type {ColorMode} from '@docusaurus/theme-common';
|
|
750
808
|
|
|
751
809
|
export interface Props {
|
|
752
810
|
readonly className?: string;
|
|
753
|
-
readonly
|
|
754
|
-
|
|
811
|
+
readonly value: ColorMode;
|
|
812
|
+
/**
|
|
813
|
+
* The parameter represents the "to-be" value. For example, if currently in
|
|
814
|
+
* dark mode, clicking the button should call `onChange("light")`
|
|
815
|
+
*/
|
|
816
|
+
readonly onChange: (colorMode: ColorMode) => void;
|
|
755
817
|
}
|
|
756
818
|
|
|
757
|
-
export default function
|
|
819
|
+
export default function ColorModeToggle(props: Props): JSX.Element;
|
|
758
820
|
}
|
|
759
821
|
|
|
760
822
|
declare module '@theme/Logo' {
|