2024-09-15 14:51:01 -05:00
|
|
|
---
|
2026-11-18 23:38:52 -06:00
|
|
|
import { alias } from "@blitzkit/core";
|
2026-11-17 23:48:31 -06:00
|
|
|
import { GearIcon } from "@radix-ui/react-icons";
|
|
|
|
|
import { api } from "../api/dynamic";
|
2026-11-28 15:42:45 -06:00
|
|
|
import { toolGroups, tools } from "../config/tools";
|
2026-11-22 13:58:17 -06:00
|
|
|
import { getLocaleOptions } from "../core/i18n/getLocaleOptions";
|
2026-11-17 23:48:31 -06:00
|
|
|
import type { LocaleAcceptorProps } from "../hooks/useLocale";
|
|
|
|
|
import { Logo } from "../icons/Logo";
|
|
|
|
|
import { LinkI18nWrapper } from "./LinkI18nWrapper";
|
2026-11-22 13:58:17 -06:00
|
|
|
import { SettingsDialog } from "./SettingsDialog";
|
2026-11-17 23:48:31 -06:00
|
|
|
import { Text } from "./Text";
|
2024-09-15 14:51:01 -05:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
export type Props = LocaleAcceptorProps;
|
2025-05-06 21:30:35 -05:00
|
|
|
|
2025-10-22 17:52:01 -05:00
|
|
|
const { locale } = Astro.props;
|
2026-11-17 23:48:31 -06:00
|
|
|
|
|
|
|
|
const strings = await api.strings(locale);
|
2026-11-22 13:58:17 -06:00
|
|
|
const localeOptions = await getLocaleOptions();
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
// TODO: restore filtering out disabled tools and empty groups after testing
|
|
|
|
|
const groups = toolGroups.map((group) => {
|
|
|
|
|
const name = strings.home[group.id as keyof typeof strings.home];
|
|
|
|
|
const fallback = tools[group.default];
|
|
|
|
|
const href = `/${fallback.slug ?? fallback.id}`;
|
|
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
...group,
|
|
|
|
|
|
|
|
|
|
name,
|
|
|
|
|
href,
|
|
|
|
|
tools: group.tools.map((id) => tools[id]),
|
|
|
|
|
};
|
|
|
|
|
});
|
2024-09-15 14:51:01 -05:00
|
|
|
---
|
|
|
|
|
|
|
|
|
|
<style>
|
2026-11-28 16:18:11 -06:00
|
|
|
#navbar-big {
|
2026-11-17 23:48:31 -06:00
|
|
|
--icon-size: 1.5rem;
|
2026-11-28 15:42:45 -06:00
|
|
|
--padding: var(--space-4);
|
2026-11-28 16:12:35 -06:00
|
|
|
--content-inset: max(var(--page-padding), (100% - var(--page-width)) / 2);
|
2025-05-06 13:29:40 -05:00
|
|
|
|
2026-11-28 16:18:11 -06:00
|
|
|
display: var(--navbar-big-display);
|
2026-11-18 22:31:10 -06:00
|
|
|
|
|
|
|
|
position: sticky;
|
|
|
|
|
top: 0;
|
|
|
|
|
z-index: 1;
|
2025-05-06 13:29:40 -05:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
.bar {
|
2026-11-17 23:48:31 -06:00
|
|
|
display: flex;
|
2026-11-28 15:42:45 -06:00
|
|
|
align-items: center;
|
2026-11-17 23:48:31 -06:00
|
|
|
justify-content: space-between;
|
2026-11-28 15:42:45 -06:00
|
|
|
gap: var(--space-4);
|
2025-10-20 22:13:14 -05:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
padding: var(--padding) var(--content-inset);
|
|
|
|
|
|
|
|
|
|
background-color: var(--black-a9);
|
|
|
|
|
backdrop-filter: var(--blur-tint);
|
|
|
|
|
border-bottom: var(--space-0) solid var(--white-a1);
|
2025-10-20 22:13:14 -05:00
|
|
|
|
2026-11-17 23:48:31 -06:00
|
|
|
transition-duration: var(--duration-brief);
|
2025-10-20 22:13:14 -05:00
|
|
|
|
2026-11-28 16:18:11 -06:00
|
|
|
#navbar-big[data-open="true"] & {
|
2026-11-28 15:42:45 -06:00
|
|
|
border-bottom-color: transparent;
|
2026-11-17 23:48:31 -06:00
|
|
|
}
|
|
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
.icon {
|
|
|
|
|
display: block;
|
|
|
|
|
|
2026-11-17 23:48:31 -06:00
|
|
|
width: var(--icon-size);
|
|
|
|
|
height: var(--icon-size);
|
2026-11-28 15:42:45 -06:00
|
|
|
|
|
|
|
|
color: var(--gray-11);
|
|
|
|
|
|
|
|
|
|
transition-duration: var(--duration-brief);
|
|
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
|
color: var(--gray-12);
|
|
|
|
|
}
|
2026-11-17 23:48:31 -06:00
|
|
|
}
|
|
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
.trigger {
|
|
|
|
|
.name {
|
2026-11-17 23:48:31 -06:00
|
|
|
color: var(--gray-11);
|
|
|
|
|
|
|
|
|
|
transition-duration: var(--duration-brief);
|
2026-11-28 15:42:45 -06:00
|
|
|
}
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
&:hover .name,
|
|
|
|
|
&[data-open="true"] .name {
|
|
|
|
|
color: var(--gray-12);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.flyout {
|
|
|
|
|
position: absolute;
|
|
|
|
|
top: 100%;
|
|
|
|
|
left: 0;
|
|
|
|
|
right: 0;
|
|
|
|
|
|
|
|
|
|
overflow: hidden;
|
|
|
|
|
|
|
|
|
|
height: 0;
|
|
|
|
|
|
|
|
|
|
background-color: var(--black-a9);
|
|
|
|
|
backdrop-filter: var(--blur-tint);
|
|
|
|
|
border-bottom: 0 solid var(--white-a1);
|
|
|
|
|
|
|
|
|
|
transition-property: height, border-bottom-width;
|
|
|
|
|
|
2026-11-28 16:18:11 -06:00
|
|
|
#navbar-big[data-open="true"] & {
|
2026-11-28 15:42:45 -06:00
|
|
|
border-bottom-width: var(--space-0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.panel {
|
|
|
|
|
display: none;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
gap: var(--space-4);
|
|
|
|
|
|
|
|
|
|
padding: var(--space-5) var(--content-inset) var(--space-6);
|
|
|
|
|
|
|
|
|
|
&[data-active="true"] {
|
|
|
|
|
display: flex;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.header,
|
|
|
|
|
.tool {
|
|
|
|
|
transition-duration: var(--duration-brief);
|
|
|
|
|
transition-delay: calc(var(--index, 0) * var(--duration-stagger));
|
|
|
|
|
|
|
|
|
|
@starting-style {
|
|
|
|
|
opacity: 0;
|
|
|
|
|
translate: 0 calc(-1 * var(--space-2));
|
2026-11-17 23:48:31 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
.tools {
|
2026-11-17 23:48:31 -06:00
|
|
|
display: flex;
|
2026-11-28 15:42:45 -06:00
|
|
|
flex-direction: column;
|
2026-11-17 23:48:31 -06:00
|
|
|
gap: var(--space-3);
|
|
|
|
|
|
2026-11-28 16:12:35 -06:00
|
|
|
.entry[data-disabled="true"] {
|
|
|
|
|
opacity: calc(1 / 4);
|
|
|
|
|
cursor: not-allowed;
|
|
|
|
|
|
|
|
|
|
.tool {
|
|
|
|
|
pointer-events: none;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
.tool {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
gap: var(--space-3);
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
.thumbnail {
|
|
|
|
|
flex-shrink: 0;
|
2026-11-17 23:48:31 -06:00
|
|
|
|
|
|
|
|
width: calc(2 * var(--icon-size));
|
2026-11-28 15:42:45 -06:00
|
|
|
height: var(--icon-size);
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
background-size: cover;
|
|
|
|
|
background-position: center;
|
|
|
|
|
|
|
|
|
|
border-radius: var(--radius-max);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
.name {
|
|
|
|
|
color: var(--gray-12);
|
2026-11-17 23:48:31 -06:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-11-28 15:42:45 -06:00
|
|
|
}
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 16:18:11 -06:00
|
|
|
#navbar-big-curtain {
|
2026-11-28 15:42:45 -06:00
|
|
|
position: fixed;
|
|
|
|
|
inset: 0;
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
z-index: 1;
|
|
|
|
|
pointer-events: none;
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
background-color: transparent;
|
|
|
|
|
backdrop-filter: blur(0);
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
transition-duration: var(--duration-brief);
|
2026-11-17 23:48:31 -06:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
&[data-open="true"] {
|
|
|
|
|
pointer-events: auto;
|
|
|
|
|
|
|
|
|
|
background-color: var(--black-a8);
|
|
|
|
|
backdrop-filter: blur(var(--space-3));
|
2026-11-17 23:48:31 -06:00
|
|
|
}
|
2024-09-15 14:51:01 -05:00
|
|
|
}
|
|
|
|
|
</style>
|
|
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
<script>
|
|
|
|
|
// Mirrors apple.com's global nav: hover intent before opening, and a
|
|
|
|
|
// collapse duration that scales with the flyout's height
|
|
|
|
|
const HOVER_DELAY = 120;
|
|
|
|
|
const MIN_DURATION = 240;
|
|
|
|
|
const MAX_DURATION = 480;
|
2024-09-15 14:51:01 -05:00
|
|
|
|
2026-11-28 16:18:11 -06:00
|
|
|
const navbar = document.getElementById("navbar-big")!;
|
|
|
|
|
const curtain = document.getElementById("navbar-big-curtain")!;
|
2026-11-28 15:42:45 -06:00
|
|
|
const flyout = navbar.querySelector<HTMLElement>(".flyout")!;
|
|
|
|
|
const triggers = navbar.querySelectorAll<HTMLElement>(".trigger");
|
|
|
|
|
const panels = navbar.querySelectorAll<HTMLElement>(".panel");
|
|
|
|
|
const icons = navbar.querySelectorAll<HTMLElement>(".bar .icon");
|
2026-11-28 16:05:47 -06:00
|
|
|
const bar = navbar.querySelector<HTMLElement>(".bar")!;
|
2026-11-28 16:18:11 -06:00
|
|
|
const coarse = window.matchMedia("(pointer: coarse)");
|
2026-11-28 15:42:45 -06:00
|
|
|
|
|
|
|
|
let hoverTimeout: number | undefined;
|
|
|
|
|
|
2026-11-28 16:05:47 -06:00
|
|
|
// Lets sticky page elements sit below the bar instead of behind it
|
|
|
|
|
new ResizeObserver(() => {
|
|
|
|
|
document.documentElement.style.setProperty(
|
2026-11-28 16:18:11 -06:00
|
|
|
"--navbar-big-height",
|
2026-11-28 16:05:47 -06:00
|
|
|
`${bar.offsetHeight}px`,
|
|
|
|
|
);
|
|
|
|
|
}).observe(bar);
|
|
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
function resize(height: number) {
|
|
|
|
|
const duration = Math.min(MAX_DURATION, Math.max(MIN_DURATION, height / 2));
|
|
|
|
|
|
|
|
|
|
flyout.style.transitionDuration = `${duration}ms`;
|
|
|
|
|
flyout.style.height = `${height}px`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function open(group: string) {
|
|
|
|
|
let height = 0;
|
|
|
|
|
|
|
|
|
|
navbar.dataset.open = "true";
|
|
|
|
|
curtain.dataset.open = "true";
|
|
|
|
|
|
|
|
|
|
for (const trigger of triggers) {
|
|
|
|
|
trigger.dataset.open = `${trigger.dataset.group === group}`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const panel of panels) {
|
|
|
|
|
const active = panel.dataset.group === group;
|
|
|
|
|
|
|
|
|
|
panel.dataset.active = `${active}`;
|
|
|
|
|
if (active) height = panel.offsetHeight;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
resize(height);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function close() {
|
|
|
|
|
clearTimeout(hoverTimeout);
|
|
|
|
|
|
|
|
|
|
if (navbar.dataset.open !== "true") return;
|
|
|
|
|
|
|
|
|
|
navbar.dataset.open = "false";
|
|
|
|
|
curtain.dataset.open = "false";
|
|
|
|
|
|
|
|
|
|
for (const trigger of triggers) trigger.dataset.open = "false";
|
|
|
|
|
|
|
|
|
|
resize(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const trigger of triggers) {
|
|
|
|
|
const group = trigger.dataset.group!;
|
|
|
|
|
|
|
|
|
|
trigger.addEventListener("mouseenter", () => {
|
|
|
|
|
clearTimeout(hoverTimeout);
|
|
|
|
|
hoverTimeout = window.setTimeout(() => open(group), HOVER_DELAY);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
trigger.addEventListener("mouseleave", () => {
|
|
|
|
|
clearTimeout(hoverTimeout);
|
|
|
|
|
});
|
2026-11-28 16:18:11 -06:00
|
|
|
|
|
|
|
|
// Touch has no hover, so a tap toggles the flyout instead of following
|
|
|
|
|
// the link
|
|
|
|
|
trigger.closest("a")!.addEventListener("click", (event) => {
|
|
|
|
|
if (!coarse.matches) return;
|
|
|
|
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
|
|
|
|
if (trigger.dataset.open === "true") close();
|
|
|
|
|
else open(group);
|
|
|
|
|
});
|
2026-11-28 15:42:45 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (const icon of icons) {
|
|
|
|
|
icon.addEventListener("mouseenter", () => {
|
|
|
|
|
clearTimeout(hoverTimeout);
|
|
|
|
|
hoverTimeout = window.setTimeout(close, HOVER_DELAY);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Panels stay mounted while collapsing; unmount them after so the next
|
|
|
|
|
// open replays the staggered fade in
|
|
|
|
|
flyout.addEventListener("transitionend", (event) => {
|
|
|
|
|
if (event.target !== flyout || navbar.dataset.open === "true") return;
|
|
|
|
|
|
|
|
|
|
for (const panel of panels) panel.dataset.active = "false";
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
navbar.addEventListener("mouseleave", close);
|
|
|
|
|
curtain.addEventListener("pointerdown", close);
|
|
|
|
|
window.addEventListener("scroll", close, { passive: true });
|
|
|
|
|
|
|
|
|
|
navbar.addEventListener("focusout", (event) => {
|
|
|
|
|
if (navbar.contains(event.relatedTarget as Node | null)) return;
|
|
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
document.addEventListener("keydown", (event) => {
|
|
|
|
|
if (event.key !== "Escape" || navbar.dataset.open !== "true") return;
|
|
|
|
|
|
|
|
|
|
const trigger = navbar.querySelector<HTMLElement>(
|
|
|
|
|
'.trigger[data-open="true"]',
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
trigger!.closest("a")!.focus();
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
2026-11-28 16:18:11 -06:00
|
|
|
<div id="navbar-big-curtain" data-open="false"></div>
|
2026-11-28 15:42:45 -06:00
|
|
|
|
2026-11-28 16:18:11 -06:00
|
|
|
<nav id="navbar-big" data-open="false">
|
2026-11-28 15:42:45 -06:00
|
|
|
<div class="bar">
|
2026-11-18 23:43:07 -06:00
|
|
|
<LinkI18nWrapper {locale} href="/">
|
2026-11-28 15:42:45 -06:00
|
|
|
<Logo className="icon" />
|
2026-11-17 23:48:31 -06:00
|
|
|
</LinkI18nWrapper>
|
2024-09-15 14:51:01 -05:00
|
|
|
|
2026-11-28 15:42:45 -06:00
|
|
|
{groups.map((group) => (
|
|
|
|
|
<LinkI18nWrapper {locale} href={group.href}>
|
|
|
|
|
<span class="trigger" data-group={group.id} data-open="false">
|
|
|
|
|
<Text size="minor" className="name">
|
|
|
|
|
{group.name}
|
|
|
|
|
</Text>
|
|
|
|
|
</span>
|
|
|
|
|
</LinkI18nWrapper>
|
|
|
|
|
))}
|
|
|
|
|
|
|
|
|
|
<SettingsDialog {locale} {localeOptions} client:load>
|
|
|
|
|
<GearIcon className="icon" />
|
|
|
|
|
</SettingsDialog>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="flyout">
|
|
|
|
|
{groups.map((group) => (
|
|
|
|
|
<div class="panel" data-group={group.id} data-active="false">
|
|
|
|
|
<Text size="minor" lowContrast className="header">
|
|
|
|
|
{group.name}
|
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
|
|
<div class="tools">
|
|
|
|
|
{group.tools.map((tool, index) => (
|
2026-11-28 16:12:35 -06:00
|
|
|
<div class="entry" data-disabled={String(tool.disabled ?? false)}>
|
|
|
|
|
<LinkI18nWrapper {locale} href={`/${tool.slug ?? tool.id}`}>
|
|
|
|
|
<div class="tool" style={`--index: ${index + 1}`}>
|
|
|
|
|
<div
|
|
|
|
|
class="thumbnail"
|
|
|
|
|
style={`background-image: url(${alias(
|
|
|
|
|
"api",
|
2026-11-28 17:26:21 -06:00
|
|
|
`tools/${tool.id}/banners/thumbnail.webp`,
|
2026-11-28 16:12:35 -06:00
|
|
|
)})`}
|
|
|
|
|
/>
|
2024-09-15 14:51:01 -05:00
|
|
|
|
2026-11-28 16:12:35 -06:00
|
|
|
<Text size="major" weight="medium" className="name">
|
|
|
|
|
{strings.tools[tool.id as keyof typeof strings.tools]}
|
|
|
|
|
</Text>
|
|
|
|
|
</div>
|
|
|
|
|
</LinkI18nWrapper>
|
|
|
|
|
</div>
|
2026-11-28 15:42:45 -06:00
|
|
|
))}
|
|
|
|
|
</div>
|
2026-11-17 23:48:31 -06:00
|
|
|
</div>
|
2026-11-28 15:42:45 -06:00
|
|
|
))}
|
2026-11-17 23:48:31 -06:00
|
|
|
</div>
|
|
|
|
|
</nav>
|