mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-11-23 06:04:32 +01:00
solid navbar
This commit is contained in:
5 files changed
+39
-27
No files matched your search
@@ -17,7 +17,7 @@ const { locale } = Astro.props;
|
|||||||
const strings = await api.strings(locale);
|
const strings = await api.strings(locale);
|
||||||
|
|
||||||
export const filtered = Object.values(tools).filter(
|
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 { api } from "../api/dynamic";
|
||||||
import { Logo } from "../icons/Logo";
|
import { Logo } from "../icons/Logo";
|
||||||
import { LinkI18nWrapper } from "./LinkI18nWrapper";
|
import { LinkI18nWrapper } from "./LinkI18nWrapper";
|
||||||
|
import type { Props as NavbarDesktopProps } from "./NavbarDesktop.astro";
|
||||||
import { filtered } from "./NavbarDesktop.astro";
|
import { filtered } from "./NavbarDesktop.astro";
|
||||||
|
import NavbarMobileAutoHide from "./NavbarMobileAutoHide.astro";
|
||||||
import { Scroller, ScrollerOrientation } from "./Scroller";
|
import { Scroller, ScrollerOrientation } from "./Scroller";
|
||||||
import { Text } from "./Text";
|
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);
|
const strings = await api.strings(locale);
|
||||||
---
|
---
|
||||||
@@ -175,27 +180,6 @@ const strings = await api.strings(locale);
|
|||||||
const navbar = document.getElementById("navbar-mobile")!;
|
const navbar = document.getElementById("navbar-mobile")!;
|
||||||
const tool = document.getElementById("current-tool")!;
|
const tool = document.getElementById("current-tool")!;
|
||||||
const overlay = document.getElementById("navbar-mobile-overlay")!;
|
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", () => {
|
tool.addEventListener("click", () => {
|
||||||
navbar.dataset.expanded = `${navbar.dataset.expanded !== "true"}`;
|
navbar.dataset.expanded = `${navbar.dataset.expanded !== "true"}`;
|
||||||
@@ -261,3 +245,5 @@ const strings = await api.strings(locale);
|
|||||||
</nav>
|
</nav>
|
||||||
|
|
||||||
<div id="navbar-mobile-overlay" />
|
<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 & {
|
type Props = LocaleAcceptorProps & {
|
||||||
accent: Color;
|
accent: Color;
|
||||||
|
solidNavbar?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const { locale, accent } = Astro.props;
|
const { locale, accent, solidNavbar = false } = Astro.props;
|
||||||
|
|
||||||
const tool = tools.tanks;
|
const tool = tools.tanks;
|
||||||
---
|
---
|
||||||
@@ -53,6 +54,7 @@ const tool = tools.tanks;
|
|||||||
|
|
||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
min-height: 100dvh;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
||||||
@@ -74,7 +76,7 @@ const tool = tools.tanks;
|
|||||||
|
|
||||||
<body>
|
<body>
|
||||||
<NavbarDesktop {locale} {tool} />
|
<NavbarDesktop {locale} {tool} />
|
||||||
<NavbarMobile {locale} {tool} />
|
<NavbarMobile {locale} {tool} solid={solidNavbar} />
|
||||||
|
|
||||||
<main class="main">
|
<main class="main">
|
||||||
<slot />
|
<slot />
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export { getStaticPaths } from "../index.astro";
|
|||||||
const { locale } = Astro.props;
|
const { locale } = Astro.props;
|
||||||
---
|
---
|
||||||
|
|
||||||
<BaseLayout accent="blue" {locale}>
|
<BaseLayout accent="blue" {locale} solidNavbar>
|
||||||
<ColorScale color="red" />
|
<ColorScale color="red" />
|
||||||
|
|
||||||
<Page {locale} client:only="react">
|
<Page {locale} client:only="react">
|
||||||
|
|||||||
Reference in new issue
Block a user