Keep a short set of destinations within reach on a small screen. Place the trigger beside the site title in a flex header. Give each menu its own popover ID and mark the current destination with current. The first preview uses sample destinations. The second uses the documentation site’s book button and chapter picker.
Mobile main navigation
Example.jsx
import { BookOpen, Layers, Palette } from "@lucide/icons";
import { SiteMenu } from "./ui/site-menu";
import "./example.css";
export default function Example() {
return (
<section class="sample journal-preview">
<header class="split">
<h2>Studio journal</h2>
<SiteMenu id="studio-destinations" label="Journal navigation" links={[
{ label: "Engineering notes", href: "#preview-fierst-dev-notes", icon: BookOpen },
{ label: "Components", href: "#preview-docs-components", icon: Layers },
{ label: "Themes", href: "#preview-docs-themes", icon: Palette },
]} />
</header>
<article>
<small>Editor's desk</small>
<h3>Inside the component library</h3>
<p>Open the menu to browse the collection or read the engineering notes behind it.</p>
</article>
</section>
);
}
example.css
@media screen and (prefers-reduced-motion: no-preference) {
#example button:is(.v-primary, .v-secondary):enabled {
transition: transform 120ms ease-out;
}
#example button:is(.v-primary, .v-secondary):enabled:active {
transform: scale(0.98);
}
}
@media (prefers-reduced-motion: reduce) {
#example button:is(.v-primary, .v-secondary):enabled:active {
transition: none;
transform: none;
}
}
* {
box-sizing: border-box;
}
:root {
--example-seed: var(--blokd-primary);
--example-secondary-text: var(--blokd-on-surface-subtle);
}
body {
--blokd-primary: color-mix(in srgb, var(--example-seed) 84%, var(--blokd-on-surface));
--blokd-on-surface-subtle: color-mix(in srgb, var(--example-secondary-text) 84%, var(--blokd-on-surface));
--blokd-input-border: color-mix(in srgb, var(--blokd-on-surface) 55%, var(--blokd-surface));
margin: 0;
padding: clamp(0.8rem, 4vw, 1.5rem);
color: var(--blokd-on-surface);
background: var(--blokd-surface-muted);
font: 1rem/1.5 var(--blokd-font-sans);
}
#example {
display: grid;
gap: 0.8rem;
min-width: 0;
align-content: start;
}
#example > button,
.sample > button {
justify-self: start;
}
.sample,
.tile {
background: var(--blokd-surface);
border: 1px solid var(--blokd-border);
border-radius: var(--blokd-radius-lg);
}
.sample {
display: grid;
gap: 0.8rem;
padding: clamp(0.85rem, 3vw, 1.35rem);
box-shadow: var(--blokd-shadow-xs);
min-width: 0;
}
.tile {
padding: 1rem;
min-width: 0;
}
h2,
h3,
p,
dl,
ul {
margin-block: 0;
}
h2,
h3 {
letter-spacing: -0.025em;
line-height: 1.2;
}
h2 {
font-size: 1.25rem;
}
h3 {
font-size: 1rem;
}
.sample > header:not(.split),
.identity > div,
.receipt {
display: grid;
gap: 0.25rem;
}
.sample > header p,
.tile p,
small {
color: var(--blokd-on-surface-muted);
}
small {
font-size: 0.82rem;
}
.split,
.actions,
.identity {
display: flex;
align-items: center;
gap: 0.65rem;
flex-wrap: wrap;
}
.split {
justify-content: space-between;
padding-block: 0.4rem;
border-bottom: 1px solid var(--blokd-border);
}
.split:last-child {
border-bottom: 0;
}
.metric {
font-size: 2rem;
letter-spacing: -0.06em;
}
.facts {
display: grid;
grid-template-columns: max-content 1fr;
gap: 0.45rem 1rem;
}
.facts dt {
color: var(--blokd-on-surface-muted);
}
.facts dd {
margin: 0;
font-weight: 600;
}
.type-sample {
font:
2rem/1.2 Georgia,
serif;
}
.listing {
padding-inline-start: 1.25rem;
}
.ink-strip {
height: 1.2rem;
background: var(--blokd-primary);
border-radius: var(--blokd-radius-sm);
}
.ink-proof {
display: grid;
gap: 0.15rem;
border-left: 0.6rem solid;
padding-left: 0.8rem;
}
.ink-proof strong {
font-size: 1.25rem;
letter-spacing: 0.06em;
}
.glyph {
display: inline-grid;
place-items: center;
width: 2rem;
height: 2rem;
border-radius: var(--blokd-radius-sm);
color: var(--blokd-on-primary-subtle);
background: var(--blokd-primary-subtle);
}
.cover-box {
width: min(100%, 18rem);
}
.cover {
display: flex;
min-height: 7.5rem;
height: 100%;
padding: 1rem 1.25rem;
flex-direction: column;
justify-content: space-between;
gap: 1.6rem;
color: #fff;
background: repeating-linear-gradient(150deg, transparent 0 8px, #fff2 8px 9px), #204a48;
}
.cover strong {
font:
italic 2.45rem/1 Georgia,
serif;
}
.cover span {
font: 0.78rem var(--blokd-font-mono);
}
.cover.grove {
background-color: #3d4b27;
}
.cover.dune {
background-color: #7c4428;
}
button:not([class]),
.entry {
font: inherit;
font-size: 0.875rem;
padding: 0.45rem 0.8rem;
border: 1px solid var(--blokd-border-strong);
border-radius: var(--blokd-radius-control);
background: var(--blokd-surface);
color: var(--blokd-on-surface);
}
button:not([class]) {
cursor: pointer;
font-weight: 600;
}
button:not([class]):hover:enabled {
background: var(--blokd-primary-subtle);
}
button:disabled {
cursor: default;
}
:focus-visible {
outline: 2px solid var(--blokd-primary);
outline-offset: 3px;
}
output:not(:empty) {
display: block;
color: var(--blokd-on-primary-subtle);
font-weight: 600;
font-size: 0.9rem;
}
#example, .sample { grid-template-columns: minmax(0, 1fr); }
.sample > header.split { gap: .75rem; flex-wrap: nowrap; }
.journal-preview { width: min(100%, 26rem); margin-inline: auto; }
.journal-preview header { padding-block: 0 .75rem; }
.journal-preview article { display: grid; gap: .45rem; padding-block: .45rem; }
.journal-preview article p { color: var(--blokd-on-surface-muted); }
Site-owned component source and scoped styles
src/ui/site-menu
import './theme.css';
import { scope } from '@fierst/blokd';
import { ChevronRight, ExternalLink } from '@lucide/icons';
import { Icon, type LucideIconInput } from './icon';
import { Popover } from './popover';
const menuScope = scope`
:scope { display: inline-flex; color: var(--blokd-on-surface); }
.trigger { width: 44px; height: 44px; display: grid; place-items: center; color: inherit; background: var(--blokd-surface); border: 1px solid var(--blokd-border); border-radius: var(--blokd-radius-control); cursor:pointer; }
.bars { position: relative; width: 18px; height: 2px; background: currentColor; }
.bars::before, .bars::after { content: ''; position: absolute; inset: 0; background: currentColor; transform: translateY(-6px); }
.bars::after { transform: translateY(6px); }
:scope:has(:popover-open) .bars { background: transparent; transform: rotate(180deg); }
:scope:has(:popover-open) .bars::before { transform: rotate(45deg); }
:scope:has(:popover-open) .bars::after { transform: rotate(-45deg); }
@media(prefers-reduced-motion:no-preference){ .bars, .bars::before, .bars::after { transition: transform 190ms ease-in-out; } }
.destinations { box-sizing: border-box; min-width: 0; width: min(18.5rem, calc(100% - 24px)); padding: .4rem 0; border-radius: 1.25rem .55rem 1.75rem .75rem; }
nav { display: grid; }
nav:has(.symbol) { background: linear-gradient(to right, var(--blokd-surface-muted) 0 3rem, transparent 3rem); }
.symbol { display: grid; place-items: center; flex: 0 0 3rem; }
a:has(.symbol) { padding-inline-start: 0; }
a { display: flex; align-items: center; gap: .75rem; min-height: 48px; padding: .35rem 1rem; color: inherit; text-decoration: none; overflow-wrap: anywhere; }
.direction { margin-inline-start: auto; flex: none; }
a:hover, a[aria-current] { background: var(--blokd-surface-muted); }
a:focus-visible, button:focus-visible { outline:2px solid currentColor; outline-offset:-2px; }
`;
export function SiteMenu({
id,
label = 'Site menu',
links,
}: {
id: string;
label?: string;
links: readonly { href: string; label: string; icon?: LucideIconInput; current?: boolean }[];
}) {
return (
<div class={menuScope}>
<button type="button" class="trigger" aria-label={label} popovertarget={id}>
<span class="bars" aria-hidden="true" />
</button>
<Popover id={id} align="end" class="destinations">
<nav aria-label={label}>
{links.map((link) => (
<a
key={link.href}
href={link.href}
aria-current={link.current ? 'page' : undefined}
onClick={(event: MouseEvent) =>
(event.currentTarget as HTMLElement)
.closest<HTMLElement>('[popover]')
?.hidePopover()
}
>
{link.icon && <span class="symbol"><Icon icon={link.icon} size={18} /></span>}
<span>{link.label}</span>
<Icon class="direction" icon={link.href.startsWith("https://") ? ExternalLink : ChevronRight} size={14} />
</a>
))}
</nav>
</Popover>
</div>
);
}
Mobile documentation menu
Try the field guide at phone width. Browse chapters or search, then scroll the page to reach the floating book button.
Example.jsx
import "../docs/reader.css";
import "./documentation-menu.css";
const chapters = [
["site-menu", "Site menu", "Keep the main destinations together in the header. The trigger stays beside the publication title, even on a narrow screen."],
["chapters", "Chapter navigation", "Group related pages under a short heading. Open the book to move through the guide without losing your place."],
["reading", "Reading mode", "Once the chapter list scrolls away, the book sits within thumb's reach. Open it again to jump back to an earlier section."],
];
export default function Example() {
return <div class="field-guide">
<header data-docs-mast="">Field guide</header>
<aside class="sidebar"><details class="mobile-nav" open>
<summary>Browse documentation</summary>
<div class="nav-inner">
<label for="find">Find a chapter</label><input id="find" type="search" />
<div id="matches" hidden></div>
<div id="chapters"><nav><section><h2>Chapters</h2>
{chapters.map(([id, title]) => <a href={"#chapter-" + id}>{title}</a>)}
</section></nav></div>
</div>
</details></aside>
{chapters.map(([id, title, text]) => <section id={"chapter-" + id} tabIndex={-1}>
<h2>{title}</h2><p>{text}</p>
</section>)}
</div>;
}
export async function setup() {
await import("../src/docs-navigation.jsx");
const search = document.querySelector("#find");
const results = document.querySelector("#matches");
search.addEventListener("input", () => {
const query = search.value.trim().toLowerCase();
document.querySelector("#chapters").hidden = Boolean(query);
results.hidden = !query;
results.replaceChildren();
for (const [id, title] of chapters.filter(([, title]) => title.toLowerCase().includes(query))) {
const link = document.createElement("a");
link.href = "#chapter-" + id;
link.textContent = title;
results.append(link);
}
if (!results.childElementCount) results.textContent = "No matching chapters.";
});
}
documentation-menu.css
:root {
--ink: var(--blokd-on-surface); --paper: var(--blokd-surface);
--surface: var(--blokd-surface); --line: var(--blokd-border);
--accent: var(--blokd-primary); --tint: var(--blokd-surface-muted); --muted: var(--blokd-on-surface-muted);
color: var(--ink); background: var(--paper);
}
.field-guide { padding: 1rem; }
.field-guide > header { padding: .35rem 0 .8rem; border-bottom: 1px solid var(--line); font-weight: 700; }
.field-guide .sidebar { padding: .75rem 0; }
.field-guide > section { min-height: 53vh; padding: 1.5rem 0; border-bottom: 1px solid var(--line); }
.field-guide > section h2 { margin: 0 0 .5rem; }
.field-guide > section p { margin: 0; color: var(--muted); }
src/docs-navigation.jsx
import { render } from "@fierst/blokd";
import { BookOpen, X, Layers, CodeXml, Compass } from "@lucide/icons";
import { Icon } from "../examples/ui/icon";
import { SidebarNav } from "../examples/ui/sidebar-nav";
const rail = document.querySelector(".mobile-nav");
const content = rail.querySelector(".nav-inner");
const chapters = content.querySelector("#chapters");
function chapterIcon(path) {
if (path.startsWith("/docs/components/")) return Layers;
if (path.includes("/api") || path.includes("/architecture") || path.includes("/examples")) return CodeXml;
if (path.includes("/guides/")) return Compass;
return BookOpen;
}
const items = (links) =>
Array.from(links, (link) => ({
label: link.textContent.trim(),
icon: chapterIcon(link.pathname),
href: link.getAttribute("href"),
active: link.matches("[aria-current=page]"),
}));
const groups = [];
for (const section of chapters.firstElementChild.children) {
const categories = section.querySelectorAll(".component-group");
if (categories.length) {
for (const category of categories) {
groups.push({
id: category.querySelector("a").pathname,
label:
category.querySelector("summary").firstChild.textContent.trim() +
" (" +
category.querySelector("small").textContent +
")",
items: items(category.querySelectorAll("a")),
defaultOpen: category.open,
});
}
} else {
const title = section.querySelector("h2").textContent;
groups.push({ id: title, label: title, items: items(section.querySelectorAll("a")) });
}
}
const narrow = matchMedia("(max-width: 760px)");
function NavigationMenu() {
return (
<div>
<button id="docs-menu" type="button" aria-label="Browse documentation"
title="Browse documentation" aria-controls="docs-panel" aria-expanded="false">
<span class="docs-menu-icon" aria-hidden="true">
<Icon icon={BookOpen} class="docs-book" size={20} />
<Icon icon={X} class="docs-close" size={20} />
</span>
<span class="docs-menu-label">Browse documentation</span>
</button>
<section id="docs-panel" aria-label="Documentation" hidden></section>
</div>
);
}
const host = document.createElement("div");
host.className = "docs-menu-anchor";
rail.before(host);
render(<NavigationMenu />, host);
const panel = host.querySelector("#docs-panel");
const trigger = host.querySelector("#docs-menu");
const label = trigger.querySelector(".docs-menu-label");
function setOpen(open) {
panel.hidden = !open;
trigger.setAttribute("aria-expanded", String(open));
const name = open ? "Close documentation" : "Browse documentation";
trigger.setAttribute("aria-label", name);
trigger.title = name;
label.textContent = name;
}
trigger.addEventListener("click", () => setOpen(panel.hidden));
document.addEventListener("click", event => {
if (!panel.hidden && (!host.contains(event.target) || event.target.closest("a"))) setOpen(false);
});
document.addEventListener("focusin", event => {
if (!host.contains(event.target) && !panel.hidden) setOpen(false);
});
document.addEventListener("keydown", event => {
if (event.key === "Escape" && !event.defaultPrevented && !panel.hidden) {
event.preventDefault();
setOpen(false);
trigger.focus({ preventScroll: true });
}
});
// Observe the original row so moving the button never shifts the threshold.
const mast = document.querySelector("body > header, [data-docs-mast]");
let observer;
function observeMenuRow() {
observer?.disconnect();
host.classList.remove("is-reading");
if (!narrow.matches) return;
observer = new IntersectionObserver(([entry]) => {
host.classList.toggle("is-reading", !entry.isIntersecting && entry.boundingClientRect.bottom <= entry.rootBounds.top);
}, { rootMargin: "-" + mast.offsetHeight + "px 0px 0px" });
observer.observe(host);
}
new ResizeObserver(observeMenuRow).observe(mast);
chapters.replaceChildren();
render(<SidebarNav groups={groups} />, chapters);
function placeNavigation() {
if (!narrow.matches) setOpen(false);
(narrow.matches ? panel : rail).append(content);
rail.open = true;
observeMenuRow();
}
placeNavigation();
narrow.addEventListener("change", placeNavigation);
document.documentElement.classList.add("docs-nav-ready");
document.addEventListener("docs-search", () => {
if (narrow.matches) setOpen(true);
requestAnimationFrame(() => content.querySelector("#find").focus());
});
Install
sh
npx @fierst/blokd-ui@1.1.0 add site-menuRegistry dependencies: theme, icon, popover. Package dependencies: @lucide/icons.
Exports from ./ui/site-menu: SiteMenu.
Download the registry source for site-menu 1.1.0.
API contracts
ts
export function SiteMenu({
id,
label = 'Site menu',
links,
}: {
id: string;
label?: string;
links: readonly { href: string; label: string; icon?: LucideIconInput; current?: boolean }[];
})