Page fixes: v1.10.7 to v1.10.10 #21

Merged
ngu-git-admin merged 17 commits from page-fixes into main 2026-10-01 10:53:41 +01:00
2 changed files with 29 additions and 9 deletions
Showing only changes of commit 7f45006253 - Show all commits

View file

@ -121,7 +121,9 @@ const CIRCLE_GAP = 8 + 4;
green and amber their own, teal and deep teal (and any other) teal. */ green and amber their own, teal and deep teal (and any other) teal. */
const circleFamily = (accent?: string) => const circleFamily = (accent?: string) =>
accent === ACCENTS.green ? "green" : accent === ACCENTS.amber ? "amber" : "teal"; accent === ACCENTS.green ? "green" : accent === ACCENTS.amber ? "amber" : "teal";
/* How far left of the list's center the circle sits. */ /* How far left of the list's center the circle sits, at most: never
left of the "On this page" heading's own center, so a list of short
titles keeps it on the heading. */
const CIRCLE_SHIFT = 24; const CIRCLE_SHIFT = 24;
export default function PageShell({ title, intro, sections, sideNav = false }: PageShellProps) { export default function PageShell({ title, intro, sections, sideNav = false }: PageShellProps) {
@ -132,14 +134,20 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
// narrows. // narrows.
const listRef = useRef<HTMLDivElement>(null); const listRef = useRef<HTMLDivElement>(null);
const columnRef = useRef<HTMLElement>(null); const columnRef = useRef<HTMLElement>(null);
const [listBox, setListBox] = useState<{ width: number; height: number } | null>(null); const [listBox, setListBox] = useState<{ width: number; height: number; heading: number } | null>(null);
const [columnWidth, setColumnWidth] = useState(0); const [columnWidth, setColumnWidth] = useState(0);
useEffect(() => { useEffect(() => {
const list = listRef.current; const list = listRef.current;
const column = columnRef.current; const column = columnRef.current;
if (!list || !column) return; if (!list || !column) return;
const ro = new ResizeObserver(() => { const ro = new ResizeObserver(() => {
setListBox({ width: list.offsetWidth, height: list.offsetHeight }); const heading = list.querySelector<HTMLElement>("[data-nav-heading]");
setListBox({
width: list.offsetWidth,
height: list.offsetHeight,
// The heading's center, from the list's left.
heading: heading ? heading.offsetLeft + heading.offsetWidth / 2 : 0,
});
setColumnWidth(column.offsetWidth); setColumnWidth(column.offsetWidth);
}); });
ro.observe(list); ro.observe(list);
@ -147,7 +155,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
return () => ro.disconnect(); return () => ro.disconnect();
}, [sideNav]); }, [sideNav]);
const circle = listBox && circleSize(listBox); const circle = listBox && circleSize(listBox);
const navSections = sideNav ? sections.map((s) => ({ id: s.id, label: s.title })) : []; const navSections = sideNav ? sections.map((s) => ({ id: s.id, label: s.title, accent: s.accent })) : [];
const active = useActiveSection(navSections); const active = useActiveSection(navSections);
const activeAccent = sections.find((s) => s.id === active)?.accent; const activeAccent = sections.find((s) => s.id === active)?.accent;
const listTop = listBox && circle ? Math.max(LIST_TOP, CIRCLE_GAP + circle / 2 - listBox.height / 2) : LIST_TOP; const listTop = listBox && circle ? Math.max(LIST_TOP, CIRCLE_GAP + circle / 2 - listBox.height / 2) : LIST_TOP;
@ -208,7 +216,10 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
style={{ style={{
width: circle, width: circle,
height: circle, height: circle,
left: Math.min(LIST_LEFT + listBox.width / 2 - CIRCLE_SHIFT - circle / 2, columnWidth - circle), left: Math.min(
LIST_LEFT + Math.max(listBox.width / 2 - CIRCLE_SHIFT, listBox.heading) - circle / 2,
columnWidth - circle,
),
top: listTop + listBox.height / 2 - circle / 2, top: listTop + listBox.height / 2 - circle / 2,
}} }}
/> />

View file

@ -18,10 +18,14 @@
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { scrollBehavior } from "../../lib/motion.ts"; import { scrollBehavior } from "../../lib/motion.ts";
import { accentText } from "../../lib/color.ts";
export type EditorSection = { export type EditorSection = {
id: string; id: string;
label: string; label: string;
/** The public pages' section color: its entry takes it when hovered
or lit. Without one (the editors), the link teal. */
accent?: string;
count?: number; count?: number;
hasError?: boolean; hasError?: boolean;
}; };
@ -91,7 +95,7 @@ export function SectionNav({ sections, wrap = false }: { sections: EditorSection
return ( return (
<nav aria-label="Sections" className="hidden max-h-[calc(100vh-8rem)] overflow-y-auto lg:block"> <nav aria-label="Sections" className="hidden max-h-[calc(100vh-8rem)] overflow-y-auto lg:block">
<p className="mb-2 px-3 text-xs font-semibold uppercase tracking-wider text-muted/70"> <p data-nav-heading className="mb-2 w-fit px-3 text-xs font-semibold uppercase tracking-wider text-muted/70">
On this page On this page
</p> </p>
<ul className="space-y-0.5 border-l border-brand/15"> <ul className="space-y-0.5 border-l border-brand/15">
@ -103,8 +107,13 @@ export function SectionNav({ sections, wrap = false }: { sections: EditorSection
type="button" type="button"
onClick={() => jump(section.id)} onClick={() => jump(section.id)}
aria-current={lit ? "location" : undefined} aria-current={lit ? "location" : undefined}
style={section.accent ? ({ "--nav-accent": accentText(section.accent) } as React.CSSProperties) : undefined}
className={`-ml-px flex w-full items-center gap-1.5 border-l-2 px-3 py-1.5 text-left text-sm transition-colors ${ className={`-ml-px flex w-full items-center gap-1.5 border-l-2 px-3 py-1.5 text-left text-sm transition-colors ${
lit section.accent
? lit
? "border-[var(--nav-accent)] font-semibold text-[var(--nav-accent)]"
: "border-transparent text-muted hover:border-[var(--nav-accent)]/40 hover:text-[var(--nav-accent)]"
: lit
? "border-brand font-semibold text-link" ? "border-brand font-semibold text-link"
: "border-transparent text-muted hover:border-brand/40 hover:text-link" : "border-transparent text-muted hover:border-brand/40 hover:text-link"
}`} }`}