Skip to content

Commit

Permalink
🔧 Fix positioning of secondary sidebar when scrolling (#417)
Browse files Browse the repository at this point in the history
* fix: positioning of secondary sidebar

* chore: add changeset

* 📐align to top content, leave room at top on scroll

* 📏 position tweaks

* ✨ 2px

---------

Co-authored-by: stevejpurves <[email protected]>
  • Loading branch information
agoose77 and stevejpurves authored Jul 3, 2024
1 parent de79758 commit 6309593
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/afraid-plants-kiss.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@myst-theme/article': patch
'@myst-theme/book': patch
---

Fix position of secondary sidebar during scrolling
12 changes: 9 additions & 3 deletions themes/article/app/components/Article.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
} from '@myst-theme/site';
import { ErrorTray, NotebookToolbar, useComputeOptions } from '@myst-theme/jupyter';
import { FrontmatterBlock } from '@myst-theme/frontmatter';
import { ReferencesProvider } from '@myst-theme/providers';
import { ReferencesProvider, useThemeTop } from '@myst-theme/providers';
import type { GenericParent } from 'myst-common';
import { copyNode } from 'myst-common';
import { BusyScopeProvider, ConnectionStatusTray, ExecuteScopeProvider } from '@myst-theme/jupyter';
import { SourceFileKind } from 'myst-spec-ext';

const TOP_OFFSET = 24;

export function Article({
article,
hideKeywords,
Expand All @@ -35,6 +37,7 @@ export function Article({
const parts = extractKnownParts(tree);
const { title, subtitle } = article.frontmatter;
const compute = useComputeOptions();
const top = useThemeTop();

return (
<ReferencesProvider
Expand All @@ -45,8 +48,11 @@ export function Article({
<ExecuteScopeProvider enable={compute?.enabled ?? false} contents={article}>
{!hideTitle && <FrontmatterBlock frontmatter={{ title, subtitle }} className="mb-5" />}
{!hideOutline && (
<div className="block my-10 lg:sticky lg:top-0 lg:z-10 lg:h-0 lg:pt-2 lg:my-0 lg:ml-10 lg:col-margin-right">
<DocumentOutline className="relative" maxdepth={outlineMaxDepth}>
<div
className="block my-10 lg:sticky lg:top-0 lg:z-10 lg:h-0 lg:pt-0 lg:my-0 lg:ml-10 lg:col-margin-right"
style={{ top: top + TOP_OFFSET }}
>
<DocumentOutline className="relative pt-[2px]" maxdepth={outlineMaxDepth}>
<SupportingDocuments />
</DocumentOutline>
</div>
Expand Down
16 changes: 14 additions & 2 deletions themes/book/app/components/ArticlePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
import React from 'react';
import { ReferencesProvider, useProjectManifest, useSiteManifest } from '@myst-theme/providers';
import {
ReferencesProvider,
useProjectManifest,
useSiteManifest,
useThemeTop,
} from '@myst-theme/providers';
import {
Bibliography,
ContentBlocks,
Expand All @@ -9,6 +14,7 @@ import {
DocumentOutline,
extractKnownParts,
Footnotes,
DEFAULT_NAV_HEIGHT,
} from '@myst-theme/site';
import type { SiteManifest } from 'myst-config';
import type { PageLoader } from '@myst-theme/common';
Expand Down Expand Up @@ -43,6 +49,8 @@ function combineDownloads(
return pageFrontmatter.exports;
}

const TOP_OFFSET = 33;

export const ArticlePage = React.memo(function ({
article,
hide_all_footer_links,
Expand All @@ -54,6 +62,7 @@ export const ArticlePage = React.memo(function ({
}) {
const manifest = useProjectManifest();
const compute = useComputeOptions();
const top = useThemeTop();

const pageDesign: TemplateOptions = (article.frontmatter as any)?.options ?? {};
const siteDesign: TemplateOptions =
Expand Down Expand Up @@ -82,7 +91,10 @@ export const ArticlePage = React.memo(function ({
/>
)}
{!hide_outline && (
<div className="block my-10 lg:sticky lg:top-0 lg:z-10 lg:h-0 lg:pt-2 lg:my-0 lg:ml-10 lg:col-margin-right">
<div
className="block my-10 lg:sticky lg:top-0 lg:z-10 lg:h-0 lg:pt-0 lg:my-0 lg:ml-10 lg:col-margin-right"
style={{ top: top + TOP_OFFSET }}
>
<DocumentOutline className="relative" maxdepth={outline_maxdepth} />
</div>
)}
Expand Down

0 comments on commit 6309593

Please sign in to comment.