Side nav entries take their section's color; the circle stays on the "On this page" heading
Hovered and lit entries use their section's accent (as heading text), the editors' nav keeping the link teal. The circle's leftward shift stops at the heading's center, so short titles no longer pull it off the heading. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
37c555a7b8
commit
7f45006253
2 changed files with 29 additions and 9 deletions
|
|
@ -121,7 +121,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 +134,20 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
// narrows.
|
||||
const listRef = useRef<HTMLDivElement>(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);
|
||||
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<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);
|
||||
});
|
||||
ro.observe(list);
|
||||
|
|
@ -147,7 +155,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;
|
||||
|
|
@ -208,7 +216,10 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
style={{
|
||||
width: 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,
|
||||
}}
|
||||
/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue