diff --git a/src/components/PageShell.css b/src/components/PageShell.css new file mode 100644 index 0000000..779797d --- /dev/null +++ b/src/components/PageShell.css @@ -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; + } +} diff --git a/src/components/PageShell.tsx b/src/components/PageShell.tsx index 8951eaf..dc43ba6 100644 --- a/src/components/PageShell.tsx +++ b/src/components/PageShell.tsx @@ -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 = { @@ -107,10 +108,19 @@ 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 (pt-8, pl-4): the circle centers on that. */ + 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; 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; @@ -137,6 +147,10 @@ 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 // comes from the server (pageMeta.js), which also sets the page's @@ -171,8 +185,7 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P {sideNav ? (