forked from graphql/graphql.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
learn — restyled left sidebar #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
23a2db9
Ignore Lucide in autoImport
hasparus 6aa124e
Add scroll-into-view-if-needed
hasparus 9fb0acf
Eject Sidebar from Nextra
hasparus 3c6c5e1
Replace Nextra MDX Wrapper and restyle TOC
hasparus 629037c
Fix type error in a patch
hasparus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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,54 @@ | ||
/** | ||
* @file BackToTop component extracted from Nextra | ||
*/ | ||
|
||
import { clsx } from "clsx" | ||
import { Button } from "nextra/components" | ||
import { ArrowRightIcon } from "nextra/icons" | ||
import type { ComponentProps, ReactElement, ReactNode } from "react" | ||
|
||
const SCROLL_TO_OPTIONS = { top: 0, behavior: "smooth" } as const | ||
|
||
const scrollToTop: ComponentProps<"button">["onClick"] = event => { | ||
const buttonElement = event.currentTarget | ||
const tocElement = buttonElement.parentElement!.parentElement! | ||
|
||
window.scrollTo(SCROLL_TO_OPTIONS) | ||
tocElement.scrollTo(SCROLL_TO_OPTIONS) | ||
|
||
// Fixes https://github.com/facebook/react/issues/20770 | ||
// Fixes https://github.com/shuding/nextra/issues/2917 | ||
buttonElement.disabled = true | ||
} | ||
|
||
export function BackToTop({ | ||
children, | ||
className, | ||
hidden, | ||
}: { | ||
children: ReactNode | ||
className?: string | ||
hidden: boolean | ||
}): ReactElement { | ||
return ( | ||
<Button | ||
// elements with `aria-hidden: true` must not be focusable or contain focusable elements | ||
aria-hidden={hidden ? "true" : undefined} | ||
onClick={scrollToTop} | ||
disabled={hidden} | ||
className={({ disabled }) => | ||
clsx( | ||
"flex items-center gap-1.5", | ||
disabled ? "opacity-0" : "opacity-100", | ||
className, | ||
) | ||
} | ||
> | ||
{children} | ||
<ArrowRightIcon | ||
height="16" | ||
className="-rotate-90 rounded-full border border-current" | ||
/> | ||
</Button> | ||
) | ||
} |
This file contains hidden or 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,155 @@ | ||
import type { ReactElement, ReactNode } from "react" | ||
import { useMounted } from "nextra/hooks" | ||
import { Heading } from "nextra" | ||
import { | ||
useConfig, | ||
useThemeConfig, | ||
SkipNavContent, | ||
Breadcrumb, | ||
NavLinks, | ||
} from "nextra-theme-docs" | ||
import { clsx } from "clsx" | ||
|
||
import { Sidebar } from "./sidebar" | ||
import { renderComponent } from "./utils" | ||
import { TableOfContents } from "./table-of-contents" | ||
|
||
const classes = { | ||
toc: clsx("nextra-toc order-last max-xl:hidden w-64 shrink-0 print:hidden"), | ||
main: clsx("w-full break-words"), | ||
} | ||
|
||
export interface NextraMdxWrapperProps { | ||
toc?: Heading[] | ||
children?: React.ReactNode | ||
} | ||
|
||
export function NextraMdxWrapper({ | ||
toc = [], | ||
children, | ||
}: NextraMdxWrapperProps) { | ||
const config = useConfig() | ||
const { | ||
activeType, | ||
activeThemeContext: themeContext, | ||
docsDirectories, | ||
directories, | ||
} = config.normalizePagesResult | ||
|
||
const tocEl = | ||
activeType === "page" || | ||
!themeContext.toc || | ||
themeContext.layout !== "default" ? ( | ||
themeContext.layout !== "full" && | ||
themeContext.layout !== "raw" && ( | ||
<nav className={classes.toc} aria-label="table of contents" /> | ||
) | ||
) : ( | ||
<nav className={classes.toc} aria-label="table of contents"> | ||
<TableOfContents toc={toc} filePath={config.filePath} /> | ||
</nav> | ||
) | ||
return ( | ||
<div | ||
className={clsx( | ||
"mx-auto flex", | ||
themeContext.layout !== "raw" && "max-w-[90rem]", | ||
)} | ||
> | ||
<Sidebar | ||
docsDirectories={docsDirectories} | ||
fullDirectories={directories} | ||
toc={toc} | ||
asPopover={config.hideSidebar} | ||
includePlaceholder={themeContext.layout === "default"} | ||
/> | ||
{tocEl} | ||
<SkipNavContent /> | ||
<Body>{children}</Body> | ||
</div> | ||
) | ||
} | ||
|
||
function Body({ children }: { children: ReactNode }): ReactElement { | ||
const config = useConfig() | ||
const themeConfig = useThemeConfig() | ||
const mounted = useMounted() | ||
const { | ||
activeThemeContext: themeContext, | ||
activeType, | ||
activeIndex, | ||
flatDocsDirectories, | ||
activePath, | ||
} = config.normalizePagesResult | ||
|
||
if (themeContext.layout === "raw") { | ||
return <div className={classes.main}>{children}</div> | ||
} | ||
|
||
const date = | ||
themeContext.timestamp && themeConfig.gitTimestamp && config.timestamp | ||
? new Date(config.timestamp) | ||
: null | ||
|
||
const gitTimestampEl = | ||
// Because a user's time zone may be different from the server page | ||
mounted && date ? ( | ||
<div className="mb-8 mt-12 block text-xs text-neu-500 ltr:text-right rtl:text-left"> | ||
{renderComponent(themeConfig.gitTimestamp, { timestamp: date })} | ||
</div> | ||
) : ( | ||
<div className="mt-16" /> | ||
) | ||
|
||
const content = ( | ||
<> | ||
{renderComponent(themeContext.topContent)} | ||
{children} | ||
{gitTimestampEl} | ||
{renderComponent(themeContext.bottomContent)} | ||
{activeType !== "page" && themeContext.pagination && ( | ||
<NavLinks | ||
flatDocsDirectories={flatDocsDirectories} | ||
currentIndex={activeIndex} | ||
/> | ||
)} | ||
</> | ||
) | ||
|
||
const body = themeConfig.main ? ( | ||
<themeConfig.main>{content}</themeConfig.main> | ||
) : ( | ||
content | ||
) | ||
|
||
if (themeContext.layout === "full") { | ||
return ( | ||
<article | ||
className={clsx( | ||
classes.main, | ||
"nextra-content min-h-[calc(100vh-var(--nextra-navbar-height))] pl-[max(env(safe-area-inset-left),1.5rem)] pr-[max(env(safe-area-inset-right),1.5rem)]", | ||
)} | ||
> | ||
{body} | ||
</article> | ||
) | ||
} | ||
|
||
return ( | ||
<article | ||
className={clsx( | ||
classes.main, | ||
"nextra-content flex min-h-[calc(100vh-var(--nextra-navbar-height))] min-w-0 justify-center pb-8 pr-[calc(env(safe-area-inset-right)-1.5rem)]", | ||
themeContext.typesetting === "article" && | ||
"nextra-body-typesetting-article", | ||
)} | ||
> | ||
<main className="w-full min-w-0 max-w-6xl px-6 pt-4 md:px-12"> | ||
{activeType !== "page" && themeContext.breadcrumb && ( | ||
<Breadcrumb activePath={activePath} /> | ||
)} | ||
{body} | ||
</main> | ||
</article> | ||
) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
memoize this? usually creating
new Date
causes re-renders