diff --git a/src/components/PageShell.tsx b/src/components/PageShell.tsx index dc43ba6..6a2f1c8 100644 --- a/src/components/PageShell.tsx +++ b/src/components/PageShell.tsx @@ -107,13 +107,19 @@ export function Section({ section }: { section: ShellSection }) { const circleSize = (box: { width: number; height: number }) => Math.min(Math.max(box.width * 1.5, box.height * 1.1), 22 * 16); -/* Where the side nav sticks, and how far its list sits in from the - column's top and left: the circle centers on that. The list sits - at least LIST_TOP down, and lower if its circle needs the room to - start CIRCLE_GAP below the first section line (h-2, 8px), rather - than over it. */ -const STICK = "calc(var(--header-h, 5rem) + 1rem)"; -const LIST_TOP = 32; +/* How far the list sits in from the column's top and left: the + circle centers on that. LIST_TOP puts "On this page" level with + the first section's title: the line (h-2, 8px), the section's + py-20 (80px), then half the difference between the title's 40px + line (md:text-4xl) and the heading's 16px one. Lower still if its + circle needs the room to start CIRCLE_GAP below that first line + rather than over it. + + The nav sticks STUCK_TOP below the header, as it always has; its + sticky offset takes back whatever the list sits lower than that. */ +const LIST_TOP = 8 + 80 + (40 - 16) / 2; +const STUCK_TOP = 32; +const stickAt = (listTop: number) => `calc(var(--header-h, 5rem) + 1rem + ${STUCK_TOP - listTop}px)`; const LIST_LEFT = 16; const CIRCLE_GAP = 8 + 4; @@ -121,7 +127,9 @@ const CIRCLE_GAP = 8 + 4; green and amber their own, teal and deep teal (and any other) teal. */ const circleFamily = (accent?: string) => 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; export default function PageShell({ title, intro, sections, sideNav = false }: PageShellProps) { @@ -132,14 +140,20 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P // narrows. const listRef = useRef(null); const columnRef = useRef(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); useEffect(() => { const list = listRef.current; const column = columnRef.current; if (!list || !column) return; const ro = new ResizeObserver(() => { - setListBox({ width: list.offsetWidth, height: list.offsetHeight }); + const heading = list.querySelector("[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); }); ro.observe(list); @@ -147,7 +161,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P return () => ro.disconnect(); }, [sideNav]); 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 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; @@ -201,21 +215,24 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P the list's layer below starts, and sticks, at the same place. */} {listBox && circle ? ( -