-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🧭 Move collapsed top-bar to primary sidebar on small screens (#444)
- Loading branch information
Showing
19 changed files
with
405 additions
and
193 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
'@myst-theme/frontmatter': patch | ||
'@myst-theme/site': patch | ||
'@myst-theme/book': patch | ||
--- | ||
|
||
Some alignment fixes, leaving more control over content top alignment to the theme |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@myst-theme/site': patch | ||
'@myst-theme/book': patch | ||
--- | ||
|
||
Renamed `Navigation` component and split for re-use in different (composed/multi-site) themes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'@myst-theme/site': minor | ||
'@myst-theme/book': patch | ||
--- | ||
|
||
Rework TOC to PrimarySidebar |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@myst-theme/common': patch | ||
--- | ||
|
||
Modified `getProjectHeadings` to work with plain `projectSlugs` to support custom theme routes that use `baseurl` but have no separate project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
packages/site/src/components/Navigation/InlineTableOfContents.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { useSiteManifest } from '@myst-theme/providers'; | ||
import { getProjectHeadings } from '@myst-theme/common'; | ||
import { Toc } from './TableOfContentsItems.js'; | ||
|
||
export const InlineTableOfContents = ({ | ||
projectSlug, | ||
sidebarRef, | ||
className = 'flex-grow overflow-y-auto max-w-[350px]', | ||
}: { | ||
projectSlug?: string; | ||
className?: string; | ||
sidebarRef?: React.RefObject<HTMLElement>; | ||
}) => { | ||
const config = useSiteManifest(); | ||
if (!config) return null; | ||
const headings = getProjectHeadings(config, projectSlug, { | ||
addGroups: false, | ||
}); | ||
if (!headings) return null; | ||
return ( | ||
<nav aria-label="Table of Contents" className={className} ref={sidebarRef}> | ||
<Toc headings={headings} /> | ||
</nav> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import { useLinkProvider, useNavLinkProvider } from '@myst-theme/providers'; | ||
|
||
export function ExternalOrInternalLink({ | ||
to, | ||
className, | ||
children, | ||
nav, | ||
onClick, | ||
prefetch = 'intent', | ||
}: { | ||
to: string; | ||
className?: string | ((props: { isActive: boolean }) => string); | ||
children: React.ReactNode; | ||
nav?: boolean; | ||
onClick?: () => void; | ||
prefetch?: 'intent' | 'render' | 'none'; | ||
}) { | ||
const Link = useLinkProvider(); | ||
const NavLink = useNavLinkProvider(); | ||
const staticClass = typeof className === 'function' ? className({ isActive: false }) : className; | ||
if (to.startsWith('http') || to.startsWith('mailto:')) { | ||
return ( | ||
<a | ||
href={to} | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
className={staticClass} | ||
onClick={onClick} | ||
> | ||
{children} | ||
</a> | ||
); | ||
} | ||
if (nav) { | ||
return ( | ||
<NavLink prefetch={prefetch} to={to} className={className} onClick={onClick}> | ||
{children} | ||
</NavLink> | ||
); | ||
} | ||
return ( | ||
<Link prefetch={prefetch} to={to} className={staticClass} onClick={onClick}> | ||
{children} | ||
</Link> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,106 @@ | ||
import { useNavOpen, useThemeTop } from '@myst-theme/providers'; | ||
import { TableOfContents } from './TableOfContents.js'; | ||
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'; | ||
|
||
export function Navigation({ | ||
/** | ||
* PrimaryNavigation will load nav links and headers from the site manifest and display | ||
* them in a mobile-friendly format. | ||
*/ | ||
export const PrimaryNavigation = ({ | ||
children, | ||
projectSlug, | ||
tocRef, | ||
sidebarRef, | ||
hide_toc, | ||
mobileOnly, | ||
footer, | ||
}: { | ||
children?: React.ReactNode; | ||
projectSlug?: string; | ||
tocRef?: React.RefObject<HTMLDivElement>; | ||
sidebarRef?: React.RefObject<HTMLDivElement>; | ||
hide_toc?: boolean; | ||
mobileOnly?: boolean; | ||
footer?: React.ReactNode; | ||
}) { | ||
}) => { | ||
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} | ||
/> | ||
); | ||
}; | ||
|
||
/** | ||
@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, | ||
}: { | ||
children?: React.ReactNode; | ||
sidebarRef?: React.RefObject<HTMLDivElement>; | ||
hide_toc?: boolean; | ||
mobileOnly?: boolean; | ||
nav?: SiteManifest['nav']; | ||
headings?: Heading[]; | ||
footer?: React.ReactNode; | ||
}) => { | ||
const [open, setOpen] = useNavOpen(); | ||
const top = useThemeTop(); | ||
|
||
if (children) | ||
console.warn( | ||
`Including children in Navigation can break keyboard accessbility 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 (hide_toc) return children ? null : <>{children}</>; | ||
|
||
return ( | ||
<> | ||
{open && ( | ||
{open && !mobileOnly && headings && ( | ||
<div | ||
className="fixed inset-0 z-30 bg-black opacity-50" | ||
style={{ marginTop: top }} | ||
onClick={() => setOpen(false)} | ||
></div> | ||
)} | ||
<TableOfContents tocRef={tocRef} projectSlug={projectSlug} footer={footer} /> | ||
<PrimarySidebar | ||
sidebarRef={sidebarRef} | ||
nav={nav} | ||
headings={headings} | ||
footer={footer} | ||
mobileOnly={mobileOnly} | ||
/> | ||
{children} | ||
</> | ||
); | ||
} | ||
}; |
Oops, something went wrong.