solid navbar

This commit is contained in:
tresabhi committed 2026-11-19 11:11:20 -06:00
1 parent 94ec7cfb6f
commit 73917b46d8
5 files changed
+39 -27

No files matched your search

@@ -17,7 +17,7 @@ const { locale } = Astro.props;
const strings = await api.strings(locale);
export const filtered = Object.values(tools).filter(
(tool) => !tool.href && (tool.navbar ?? true),
(tool) => !tool.href && (tool.navbar ?? true) && !tool.disabled,
);
---
@@ -4,12 +4,17 @@ import { CaretUpIcon, GearIcon } from "@radix-ui/react-icons";
import { api } from "../api/dynamic";
import { Logo } from "../icons/Logo";
import { LinkI18nWrapper } from "./LinkI18nWrapper";
import type { Props as NavbarDesktopProps } from "./NavbarDesktop.astro";
import { filtered } from "./NavbarDesktop.astro";
import NavbarMobileAutoHide from "./NavbarMobileAutoHide.astro";
import { Scroller, ScrollerOrientation } from "./Scroller";
import { Text } from "./Text";
export { type Props } from "./NavbarDesktop.astro";
const { locale, tool } = Astro.props;
export type Props = NavbarDesktopProps & {
solid?: boolean;
};
const { locale, tool, solid = false } = Astro.props;
const strings = await api.strings(locale);
---
@@ -175,27 +180,6 @@ const strings = await api.strings(locale);
const navbar = document.getElementById("navbar-mobile")!;
const tool = document.getElementById("current-tool")!;
const overlay = document.getElementById("navbar-mobile-overlay")!;
const lastScrollTops = new WeakMap<Element, number>();
// Scroll doesn't bubble, so capturing also catches nested scrollers like tables
document.addEventListener(
"scroll",
(event) => {
const target =
event.target instanceof Element
? event.target
: document.scrollingElement!;
const scrollTop = target.scrollTop;
const lastScrollTop = lastScrollTops.get(target) ?? 0;
// Horizontal scrolling leaves scrollTop unchanged, so it's ignored
if (scrollTop === lastScrollTop) return;
navbar.dataset.visible = `${scrollTop < lastScrollTop}`;
lastScrollTops.set(target, scrollTop);
},
{ capture: true, passive: true },
);
tool.addEventListener("click", () => {
navbar.dataset.expanded = `${navbar.dataset.expanded !== "true"}`;
@@ -261,3 +245,5 @@ const strings = await api.strings(locale);
</nav>
<div id="navbar-mobile-overlay" />
{!solid && <NavbarMobileAutoHide />}
@@ -0,0 +1,24 @@
<script>
const navbar = document.getElementById("navbar-mobile")!;
const lastScrollTops = new WeakMap<Element, number>();
// Scroll doesn't bubble, so capturing also catches nested scrollers like tables
document.addEventListener(
"scroll",
(event) => {
const target =
event.target instanceof Element
? event.target
: document.scrollingElement!;
const scrollTop = target.scrollTop;
const lastScrollTop = lastScrollTops.get(target) ?? 0;
// Horizontal scrolling leaves scrollTop unchanged, so it's ignored
if (scrollTop === lastScrollTop) return;
navbar.dataset.visible = `${scrollTop < lastScrollTop}`;
lastScrollTops.set(target, scrollTop);
},
{ capture: true, passive: true },
);
</script>
@@ -12,9 +12,10 @@ import type { Color } from "../ui/color";
type Props = LocaleAcceptorProps & {
accent: Color;
solidNavbar?: boolean;
};
const { locale, accent } = Astro.props;
const { locale, accent, solidNavbar = false } = Astro.props;
const tool = tools.tanks;
---
@@ -53,6 +54,7 @@ const tool = tools.tanks;
body {
margin: 0;
min-height: 100dvh;
display: flex;
@@ -74,7 +76,7 @@ const tool = tools.tanks;
<body>
<NavbarDesktop {locale} {tool} />
<NavbarMobile {locale} {tool} />
<NavbarMobile {locale} {tool} solid={solidNavbar} />
<main class="main">
<slot />
@@ -8,7 +8,7 @@ export { getStaticPaths } from "../index.astro";
const { locale } = Astro.props;
---
<BaseLayout accent="blue" {locale}>
<BaseLayout accent="blue" {locale} solidNavbar>
<ColorScale color="red" />
<Page {locale} client:only="react">