Compare commits
No commits in common. "37c555a7b879005902ea80d3506ca4ff5bfe8b43" and "a5c4e365cdf847f9c73129fcfa6afb6d7e9613df" have entirely different histories.
37c555a7b8
...
a5c4e365cd
3 changed files with 19 additions and 69 deletions
|
|
@ -1,37 +0,0 @@
|
||||||
/* 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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -41,9 +41,8 @@
|
||||||
import { useEffect, useRef, useState, type ReactNode } from "react";
|
import { useEffect, useRef, useState, type ReactNode } from "react";
|
||||||
|
|
||||||
import { documentTitle } from "../lib/site.ts";
|
import { documentTitle } from "../lib/site.ts";
|
||||||
import { accentText, ACCENTS, BRAND } from '../lib/color.ts'
|
import { accentText, BRAND } from '../lib/color.ts'
|
||||||
import { SectionNav, useActiveSection } from "./admin/SectionNav.tsx";
|
import { SectionNav } from "./admin/SectionNav.tsx";
|
||||||
import "./PageShell.css";
|
|
||||||
|
|
||||||
|
|
||||||
export type ShellSection = {
|
export type ShellSection = {
|
||||||
|
|
@ -108,19 +107,10 @@ const circleSize = (box: { width: number; height: number }) =>
|
||||||
Math.min(Math.max(box.width * 1.5, box.height * 1.1), 22 * 16);
|
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
|
/* 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
|
column's top and left (pt-8, pl-4): the circle centers on that. */
|
||||||
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 STICK = "calc(var(--header-h, 5rem) + 1rem)";
|
||||||
const LIST_TOP = 32;
|
const LIST_TOP = 32;
|
||||||
const LIST_LEFT = 16;
|
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. */
|
/* How far left of the list's center the circle sits. */
|
||||||
const CIRCLE_SHIFT = 24;
|
const CIRCLE_SHIFT = 24;
|
||||||
|
|
||||||
|
|
@ -147,10 +137,6 @@ 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 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
|
// 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
|
// comes from the server (pageMeta.js), which also sets the page's
|
||||||
|
|
@ -185,7 +171,8 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
||||||
{sideNav ? (
|
{sideNav ? (
|
||||||
<div className="relative">
|
<div className="relative">
|
||||||
{/* The margin left of the content (72rem, its text 1.5rem in),
|
{/* The margin left of the content (72rem, its text 1.5rem in),
|
||||||
clipping sideways only, so nothing reaches the
|
clipping sideways only (the circle shows above and below
|
||||||
|
the list, past the column's top), so nothing reaches the
|
||||||
content or the screen's edge. clip, not hidden: hidden
|
content or the screen's edge. clip, not hidden: hidden
|
||||||
would make it a scroll container, and the sticky layers in
|
would make it a scroll container, and the sticky layers in
|
||||||
it would stop sticking. */}
|
it would stop sticking. */}
|
||||||
|
|
@ -194,30 +181,30 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
||||||
className="absolute inset-y-0 left-0 hidden overflow-x-clip min-[88rem]:block"
|
className="absolute inset-y-0 left-0 hidden overflow-x-clip min-[88rem]:block"
|
||||||
style={{ width: "calc((100% - 72rem) / 2 + 1rem)" }}
|
style={{ width: "calc((100% - 72rem) / 2 + 1rem)" }}
|
||||||
>
|
>
|
||||||
{/* A solid circle centered on the list, in the light shade
|
{/* A solid circle centered on the list, in the tint the
|
||||||
of the section being read (PageShell.css): a sticky layer of
|
nav's text reads on in either mode. Its own sticky layer
|
||||||
its own, in front of the section lines like the list,
|
(a sticky box is a layer of its own, so it couldn't sit
|
||||||
which comes after it and so draws over it. Height 0, so
|
inside the list's): z-index -1 puts it behind the
|
||||||
the list's layer below starts, and sticks, at the same
|
section lines, and after the page backdrop (also -1)
|
||||||
place. */}
|
so in front of that. Height 0, so the list's layer
|
||||||
|
below starts, and sticks, at the same place. */}
|
||||||
{listBox && circle ? (
|
{listBox && circle ? (
|
||||||
<div aria-hidden="true" className="pointer-events-none sticky z-10 h-0" style={{ top: STICK }}>
|
<div aria-hidden="true" className="pointer-events-none sticky h-0" style={{ top: STICK, zIndex: -1 }}>
|
||||||
<div
|
<div
|
||||||
className="side-nav-circle absolute rounded-full"
|
className="absolute rounded-full bg-tint"
|
||||||
data-family={circleFamily(activeAccent)}
|
|
||||||
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 + listBox.width / 2 - CIRCLE_SHIFT - circle / 2, columnWidth - circle),
|
||||||
top: listTop + listBox.height / 2 - circle / 2,
|
top: LIST_TOP + listBox.height / 2 - circle / 2,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
) : null}
|
) : null}
|
||||||
{/* The list, in front of the section lines and its circle. */}
|
{/* The list, in front of the section lines. */}
|
||||||
<div className="sticky z-10 pl-4 pr-2" style={{ top: STICK, paddingTop: listTop }}>
|
<div className="sticky z-10 pt-8 pl-4 pr-2" style={{ top: STICK }}>
|
||||||
<div ref={listRef} className="w-fit max-w-full">
|
<div ref={listRef} className="w-fit max-w-full">
|
||||||
<SectionNav sections={navSections} wrap />
|
<SectionNav sections={sections.map((s) => ({ id: s.id, label: s.title }))} wrap />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</aside>
|
</aside>
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ export type EditorSection = {
|
||||||
|
|
||||||
const ACTIVE_LINE = 140;
|
const ACTIVE_LINE = 140;
|
||||||
|
|
||||||
export function useActiveSection(sections: EditorSection[]) {
|
function useActiveSection(sections: EditorSection[]) {
|
||||||
const [active, setActive] = useState<string | null>(sections[0]?.id ?? null);
|
const [active, setActive] = useState<string | null>(sections[0]?.id ?? null);
|
||||||
const ids = sections.map((section) => section.id).join("|");
|
const ids = sections.map((section) => section.id).join("|");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue