Compare commits
No commits in common. "f7b9af710154fabd962e6cb39ee77d17de025506" and "37c555a7b879005902ea80d3506ca4ff5bfe8b43" have entirely different histories.
f7b9af7101
...
37c555a7b8
2 changed files with 18 additions and 44 deletions
|
|
@ -107,19 +107,13 @@ 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);
|
||||
|
||||
/* 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)`;
|
||||
/* 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;
|
||||
const LIST_LEFT = 16;
|
||||
const CIRCLE_GAP = 8 + 4;
|
||||
|
||||
|
|
@ -127,9 +121,7 @@ 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, at most: never
|
||||
left of the "On this page" heading's own center, so a list of short
|
||||
titles keeps it on the heading. */
|
||||
/* How far left of the list's center the circle sits. */
|
||||
const CIRCLE_SHIFT = 24;
|
||||
|
||||
export default function PageShell({ title, intro, sections, sideNav = false }: PageShellProps) {
|
||||
|
|
@ -140,20 +132,14 @@ 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; heading: number } | null>(null);
|
||||
const [listBox, setListBox] = useState<{ width: number; height: 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(() => {
|
||||
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,
|
||||
});
|
||||
setListBox({ width: list.offsetWidth, height: list.offsetHeight });
|
||||
setColumnWidth(column.offsetWidth);
|
||||
});
|
||||
ro.observe(list);
|
||||
|
|
@ -161,7 +147,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, accent: s.accent })) : [];
|
||||
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;
|
||||
|
|
@ -215,24 +201,21 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
|||
the list's layer below starts, and sticks, at the same
|
||||
place. */}
|
||||
{listBox && circle ? (
|
||||
<div aria-hidden="true" className="pointer-events-none sticky z-10 h-0" style={{ top: stickAt(listTop) }}>
|
||||
<div aria-hidden="true" className="pointer-events-none sticky z-10 h-0" style={{ top: STICK }}>
|
||||
<div
|
||||
className="side-nav-circle absolute rounded-full"
|
||||
data-family={circleFamily(activeAccent)}
|
||||
style={{
|
||||
width: circle,
|
||||
height: circle,
|
||||
left: Math.min(
|
||||
LIST_LEFT + Math.max(listBox.width / 2 - CIRCLE_SHIFT, listBox.heading) - 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,
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{/* The list, in front of the section lines and its circle. */}
|
||||
<div className="sticky z-10 pl-4 pr-2" style={{ top: stickAt(listTop), paddingTop: listTop }}>
|
||||
<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={navSections} wrap />
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -18,14 +18,10 @@
|
|||
|
||||
import { useEffect, useState } from "react";
|
||||
import { scrollBehavior } from "../../lib/motion.ts";
|
||||
import { accentText } from "../../lib/color.ts";
|
||||
|
||||
export type EditorSection = {
|
||||
id: string;
|
||||
label: string;
|
||||
/** The public pages' section color: its entry takes it when hovered
|
||||
or lit. Without one (the editors), the link teal. */
|
||||
accent?: string;
|
||||
count?: number;
|
||||
hasError?: boolean;
|
||||
};
|
||||
|
|
@ -95,7 +91,7 @@ export function SectionNav({ sections, wrap = false }: { sections: EditorSection
|
|||
|
||||
return (
|
||||
<nav aria-label="Sections" className="hidden max-h-[calc(100vh-8rem)] overflow-y-auto lg:block">
|
||||
<p data-nav-heading className="mb-2 w-fit px-3 text-xs font-semibold uppercase tracking-wider text-muted/70">
|
||||
<p className="mb-2 px-3 text-xs font-semibold uppercase tracking-wider text-muted/70">
|
||||
On this page
|
||||
</p>
|
||||
<ul className="space-y-0.5 border-l border-brand/15">
|
||||
|
|
@ -107,13 +103,8 @@ export function SectionNav({ sections, wrap = false }: { sections: EditorSection
|
|||
type="button"
|
||||
onClick={() => jump(section.id)}
|
||||
aria-current={lit ? "location" : undefined}
|
||||
style={section.accent ? ({ "--nav-accent": accentText(section.accent) } as React.CSSProperties) : undefined}
|
||||
className={`-ml-px flex w-full items-center gap-1.5 border-l-2 px-3 py-1.5 text-left text-sm transition-colors ${
|
||||
section.accent
|
||||
? lit
|
||||
? "border-[var(--nav-accent)] font-semibold text-[var(--nav-accent)]"
|
||||
: "border-transparent text-muted hover:border-[var(--nav-accent)]/40 hover:text-[var(--nav-accent)]"
|
||||
: lit
|
||||
lit
|
||||
? "border-brand font-semibold text-link"
|
||||
: "border-transparent text-muted hover:border-brand/40 hover:text-link"
|
||||
}`}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue