-
-
Notifications
You must be signed in to change notification settings - Fork 9.9k
Expand file tree
/
Copy pathindex.tsx
More file actions
77 lines (73 loc) · 2.2 KB
/
index.tsx
File metadata and controls
77 lines (73 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import React, {version, type ReactNode} from 'react';
import clsx from 'clsx';
import {translate} from '@docusaurus/Translate';
import {useNavbarSecondaryMenu} from '@docusaurus/theme-common/internal';
import {ThemeClassNames} from '@docusaurus/theme-common';
import type {Props} from '@theme/Navbar/MobileSidebar/Layout';
// TODO Docusaurus v4: remove temporary inert workaround
// See https://github.com/facebook/react/issues/17157
// See https://github.com/radix-ui/themes/pull/509
function inertProps(inert: boolean) {
const isBeforeReact19 = parseInt(version!.split('.')[0]!, 10) < 19;
if (isBeforeReact19) {
// TODO Docusaurus v4: remove temporary inert workaround
return {inert: inert ? '' : undefined} as unknown as {inert: boolean};
}
return {inert};
}
function NavbarMobileSidebarPanel({
children,
inert,
}: {
children: ReactNode;
inert: boolean;
}) {
return (
<div
className={clsx(
ThemeClassNames.layout.navbar.mobileSidebar.panel,
'navbar-sidebar__item menu',
)}
{...inertProps(inert)}>
{children}
</div>
);
}
export default function NavbarMobileSidebarLayout({
header,
primaryMenu,
secondaryMenu,
}: Props): ReactNode {
const {shown: secondaryMenuShown} = useNavbarSecondaryMenu();
return (
<nav
aria-label={translate({
id: 'theme.navbar.mobileSidebarAriaLabel',
message: 'Navigation bar',
description: 'The ARIA label for the mobile sidebar navigation',
})}
className={clsx(
ThemeClassNames.layout.navbar.mobileSidebar.container,
'navbar-sidebar',
)}>
{header}
<div
className={clsx('navbar-sidebar__items', {
'navbar-sidebar__items--show-secondary': secondaryMenuShown,
})}>
<NavbarMobileSidebarPanel inert={secondaryMenuShown}>
{primaryMenu}
</NavbarMobileSidebarPanel>
<NavbarMobileSidebarPanel inert={!secondaryMenuShown}>
{secondaryMenu}
</NavbarMobileSidebarPanel>
</div>
</nav>
);
}