forked from jupyter-book/myst-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNavigation.tsx
More file actions
118 lines (109 loc) · 2.99 KB
/
Navigation.tsx
File metadata and controls
118 lines (109 loc) · 2.99 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import { useNavOpen, useSiteManifest, useThemeTop } from '@myst-theme/providers';
import { PrimarySidebar } from './PrimarySidebar.js';
import type { Heading } from '@myst-theme/common';
import { getProjectHeadings } from '@myst-theme/common';
import type { SiteManifest } from 'myst-config';
import type { GenericParent } from 'myst-common';
/**
* PrimaryNavigation will load nav links and headers from the site manifest and display
* them in a mobile-friendly format.
*/
export const PrimaryNavigation = ({
children,
projectSlug,
sidebarRef,
hide_toc,
mobileOnly,
footer,
navbarEnd,
}: {
children?: React.ReactNode;
projectSlug?: string;
sidebarRef?: React.RefObject<HTMLDivElement>;
hide_toc?: boolean;
mobileOnly?: boolean;
footer?: React.ReactNode;
navbarEnd?: GenericParent;
}) => {
const config = useSiteManifest();
if (!config) return null;
const headings = getProjectHeadings(config, projectSlug, {
addGroups: false,
});
const { nav } = config;
return (
<ConfigurablePrimaryNavigation
children={children}
sidebarRef={sidebarRef}
hide_toc={hide_toc}
mobileOnly={mobileOnly}
nav={nav}
headings={headings}
footer={footer}
navbarEnd={navbarEnd}
/>
);
};
/**
@deprecated use PrimaryNavigation instead
*/
export const Navigation = PrimaryNavigation;
/**
* ConfigurablePrimaryNavigation will display a mobile-friendly navigation sidebar based on the
* nav, headings, and footer provided by the caller. Use this in situations where the PrimaryNavigation
* component may pick up the wrong SiteManifest.
*/
export const ConfigurablePrimaryNavigation = ({
children,
sidebarRef,
hide_toc,
mobileOnly,
nav,
headings,
footer,
navbarEnd,
}: {
children?: React.ReactNode;
sidebarRef?: React.RefObject<HTMLDivElement>;
hide_toc?: boolean;
mobileOnly?: boolean;
nav?: SiteManifest['nav'];
headings?: Heading[];
footer?: React.ReactNode;
navbarEnd?: GenericParent;
}) => {
const [open, setOpen] = useNavOpen();
const top = useThemeTop();
if (children)
console.warn(
`Including children in Navigation can break keyboard accessibility and is deprecated. Please move children to the page component.`,
);
// the logic on the following line looks wrong, this will return `null` or `<></>`
// we should just return `null` if `hide_toc` is true?
if (!nav && hide_toc) return children ? null : <>{children}</>;
if (nav && hide_toc) {
headings = undefined;
footer = null;
}
return (
<>
{open && !mobileOnly && headings && (
<div
className="myst-navigation-overlay fixed inset-0 z-30 bg-black opacity-50"
style={{ marginTop: top }}
onClick={() => setOpen(false)}
></div>
)}
<PrimarySidebar
sidebarRef={sidebarRef}
nav={nav}
headings={headings}
footer={footer}
navbarEnd={navbarEnd}
hide_toc={hide_toc}
mobileOnly={mobileOnly}
/>
{children}
</>
);
};