Side nav circle takes the color of the section being read

Green and amber sections give it their palette's lightest shade, teal
and deep teal the teal one (the darkest in dark mode), the shades the
nav's text reads on, easing between them as the reader scrolls.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Zaldimmar 2026-10-01 03:56:33 -05:00
parent 1db18a8f91
commit 37c555a7b8
3 changed files with 54 additions and 7 deletions

View file

@ -0,0 +1,37 @@
/* The side nav's circle (PageShell.tsx): the light fill of the color
family of the section being read (its darkest in dark mode), the
palette shades every text color reads on at 4.5:1 or better, as
on the page backdrop (PageBackdrop.css). */
.side-nav-circle {
background: #d6f5fa;
transition: background-color 0.8s ease-in-out;
}
.side-nav-circle[data-family="green"] {
background: #e6f0dd;
}
.side-nav-circle[data-family="amber"] {
background: #fdf1d6;
}
/* Dark mode: the toggle's choice, or the system's when there is none. */
:root[data-theme="dark"] .side-nav-circle {
background: #003a45;
}
:root[data-theme="dark"] .side-nav-circle[data-family="green"] {
background: #23361a;
}
:root[data-theme="dark"] .side-nav-circle[data-family="amber"] {
background: #4a2e00;
}
@media (prefers-color-scheme: dark) {
:root:not([data-theme="light"]) .side-nav-circle {
background: #003a45;
}
:root:not([data-theme="light"]) .side-nav-circle[data-family="green"] {
background: #23361a;
}
:root:not([data-theme="light"]) .side-nav-circle[data-family="amber"] {
background: #4a2e00;
}
}

View file

@ -41,8 +41,9 @@
import { useEffect, useRef, useState, type ReactNode } from "react";
import { documentTitle } from "../lib/site.ts";
import { accentText, BRAND } from '../lib/color.ts'
import { SectionNav } from "./admin/SectionNav.tsx";
import { accentText, ACCENTS, BRAND } from '../lib/color.ts'
import { SectionNav, useActiveSection } from "./admin/SectionNav.tsx";
import "./PageShell.css";
export type ShellSection = {
@ -115,6 +116,11 @@ const STICK = "calc(var(--header-h, 5rem) + 1rem)";
const LIST_TOP = 32;
const LIST_LEFT = 16;
const CIRCLE_GAP = 8 + 4;
/* The circle's color family for a section's accent (PageShell.css):
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. */
const CIRCLE_SHIFT = 24;
@ -141,6 +147,9 @@ 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 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;
// The tab's title as the visitor moves around. The first load's
@ -185,8 +194,8 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
className="absolute inset-y-0 left-0 hidden overflow-x-clip min-[88rem]:block"
style={{ width: "calc((100% - 72rem) / 2 + 1rem)" }}
>
{/* A solid circle centered on the list, in the tint the
nav's text reads on in either mode: a sticky layer of
{/* A solid circle centered on the list, in the light shade
of the section being read (PageShell.css): a sticky layer of
its own, in front of the section lines like the list,
which comes after it and so draws over it. Height 0, so
the list's layer below starts, and sticks, at the same
@ -194,7 +203,8 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
{listBox && circle ? (
<div aria-hidden="true" className="pointer-events-none sticky z-10 h-0" style={{ top: STICK }}>
<div
className="absolute rounded-full bg-tint"
className="side-nav-circle absolute rounded-full"
data-family={circleFamily(activeAccent)}
style={{
width: circle,
height: circle,
@ -207,7 +217,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
{/* The list, in front of the section lines and its circle. */}
<div className="sticky z-10 pl-4 pr-2" style={{ top: STICK, paddingTop: listTop }}>
<div ref={listRef} className="w-fit max-w-full">
<SectionNav sections={sections.map((s) => ({ id: s.id, label: s.title }))} wrap />
<SectionNav sections={navSections} wrap />
</div>
</div>
</aside>

View file

@ -28,7 +28,7 @@ export type EditorSection = {
const ACTIVE_LINE = 140;
function useActiveSection(sections: EditorSection[]) {
export function useActiveSection(sections: EditorSection[]) {
const [active, setActive] = useState<string | null>(sections[0]?.id ?? null);
const ids = sections.map((section) => section.id).join("|");