diff --git a/.changeset/sticky-navigation-bar.md b/.changeset/sticky-navigation-bar.md new file mode 100644 index 00000000..fd4dedfc --- /dev/null +++ b/.changeset/sticky-navigation-bar.md @@ -0,0 +1,5 @@ +--- +'@node-core/doc-kit': minor +--- + +Make the web top navigation bar sticky while scrolling, and offset the sticky meta bar, anchor scrolling, and Radix popups so they are not covered by it diff --git a/packages/core/src/generators/web/ui/components/MetaBar/index.jsx b/packages/core/src/generators/web/ui/components/MetaBar/index.jsx index 261498ea..6ddf4643 100644 --- a/packages/core/src/generators/web/ui/components/MetaBar/index.jsx +++ b/packages/core/src/generators/web/ui/components/MetaBar/index.jsx @@ -62,6 +62,11 @@ export default ({ metadata, headings = [], readingTime }) => { return ( ({ ...heading, diff --git a/packages/core/src/generators/web/ui/components/NavBar.jsx b/packages/core/src/generators/web/ui/components/NavBar.jsx index c0484e80..c0f8b8f9 100644 --- a/packages/core/src/generators/web/ui/components/NavBar.jsx +++ b/packages/core/src/generators/web/ui/components/NavBar.jsx @@ -16,23 +16,25 @@ export default ({ metadata }) => { const [themePreference, setThemePreference] = useTheme(); return ( - - {showSearchBox && } - - + - - - + {showSearchBox && } + + + + + + ); }; diff --git a/packages/core/src/generators/web/ui/index.css b/packages/core/src/generators/web/ui/index.css index 1b375458..e053f252 100644 --- a/packages/core/src/generators/web/ui/index.css +++ b/packages/core/src/generators/web/ui/index.css @@ -10,6 +10,28 @@ --font-ibm-plex-mono: 'IBM Plex Mono', monospace; } +/* Keep the top navigation bar visible while scrolling. The hidden sidebar + toggler checkbox inside the NavBar is translated above the bar, so clip it: + inside this stacking context it would otherwise cover the banner above */ +.nav-bar-sticky { + position: sticky; + top: 0; + z-index: 40; + overflow: hidden; +} + +/* Radix popups (theme switcher, selects) must paint above the sticky + navigation bar; they render in a portal and slightly overlap the bar. + `!important` is needed because Radix sets an inline `z-index: auto` */ +[data-radix-popper-content-wrapper] { + z-index: 50 !important; +} + +/* Keep anchored headings below the sticky navigation bar */ +main [id] { + scroll-margin-top: calc(var(--header-height, 4rem) + 1rem); +} + main { /* Code should inherit its font size */ code {