Skip to content
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

feat(nx-dev): display toc for smaller viewport sizes #16061

Merged
merged 1 commit into from
Apr 3, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions nx-dev/feature-doc-viewer/src/lib/doc-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Breadcrumbs, Footer } from '@nrwl/nx-dev/ui-common';
import { renderMarkdown } from '@nrwl/nx-dev/ui-markdoc';
import { NextSeo } from 'next-seo';
import { useRouter } from 'next/router';
import { cx } from 'nx-dev/ui-primitives';
import { useRef } from 'react';
import { collectHeadings, TableOfContents } from './table-of-contents';

Expand All @@ -19,6 +20,7 @@ export function DocViewer({
relatedDocuments: RelatedDocument[];
}): JSX.Element {
const router = useRouter();
const isIntro = router.asPath.includes('/getting-started/intro');
const ref = useRef<HTMLDivElement | null>(null);

const { metadata, node, treeNode } = renderMarkdown(
Expand Down Expand Up @@ -86,17 +88,26 @@ export function DocViewer({
<div
ref={ref}
data-document="main"
className="prose prose-slate dark:prose-invert w-full max-w-none 2xl:max-w-4xl"
className={cx(
'prose prose-slate dark:prose-invert w-full max-w-none 2xl:max-w-4xl',
{ 'xl:max-w-2xl': !isIntro }
)}
>
{vm.content}
</div>
<div className="fixed top-36 right-[max(4rem,calc(50%-55rem))] z-20 hidden w-60 overflow-y-auto bg-white py-10 text-sm dark:bg-slate-900 2xl:block">
<TableOfContents
elementRef={ref}
path={router.basePath}
headings={vm.tableOfContent}
/>
</div>
{!isIntro && (
<div
className={cx(
'fixed top-36 right-[max(4rem,calc(50%-55rem))] z-20 hidden w-60 overflow-y-auto bg-white py-10 text-sm dark:bg-slate-900 xl:block'
)}
>
<TableOfContents
elementRef={ref}
path={router.basePath}
headings={vm.tableOfContent}
/>
</div>
)}
</div>
{/*RELATED CONTENT*/}
<div
Expand Down