Side nav circle shows above the first divider, sits further left, and slides left rather than being cut at the content
The nav column clipped on every side, cutting the circle off above the first section line; it clips sideways only now. The circle keeps its right edge inside the column, so a narrower window moves it off the screen's left edge instead of cutting it at the content. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
ac794d5ff1
commit
a5c4e365cd
1 changed files with 30 additions and 17 deletions
|
|
@ -111,21 +111,32 @@ const circleSize = (box: { width: number; height: number }) =>
|
||||||
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;
|
||||||
|
/* 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) {
|
export default function PageShell({ title, intro, sections, sideNav = false }: PageShellProps) {
|
||||||
// The list's measured box, so its circle can center on it from a
|
// The list's measured box, so its circle can center on it from a
|
||||||
// layer of its own (below).
|
// layer of its own (below).
|
||||||
|
// The column's width too: the circle keeps its right edge inside
|
||||||
|
// it, sliding off the screen's left edge instead when the window
|
||||||
|
// narrows.
|
||||||
const listRef = useRef<HTMLDivElement>(null);
|
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 } | null>(null);
|
||||||
|
const [columnWidth, setColumnWidth] = useState(0);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const el = listRef.current;
|
const list = listRef.current;
|
||||||
if (!el) return;
|
const column = columnRef.current;
|
||||||
const ro = new ResizeObserver(([entry]) =>
|
if (!list || !column) return;
|
||||||
setListBox({ width: entry.borderBoxSize[0].inlineSize, height: entry.borderBoxSize[0].blockSize }),
|
const ro = new ResizeObserver(() => {
|
||||||
);
|
setListBox({ width: list.offsetWidth, height: list.offsetHeight });
|
||||||
ro.observe(el);
|
setColumnWidth(column.offsetWidth);
|
||||||
|
});
|
||||||
|
ro.observe(list);
|
||||||
|
ro.observe(column);
|
||||||
return () => ro.disconnect();
|
return () => ro.disconnect();
|
||||||
}, [sideNav]);
|
}, [sideNav]);
|
||||||
|
const circle = listBox && circleSize(listBox);
|
||||||
|
|
||||||
// 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
|
||||||
|
|
@ -160,12 +171,14 @@ 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 anything wider so the circle never reaches the
|
clipping sideways only (the circle shows above and below
|
||||||
content. clip, not hidden: hidden would make it a scroll
|
the list, past the column's top), so nothing reaches the
|
||||||
container, and the sticky layers in it would stop
|
content or the screen's edge. clip, not hidden: hidden
|
||||||
sticking. */}
|
would make it a scroll container, and the sticky layers in
|
||||||
|
it would stop sticking. */}
|
||||||
<aside
|
<aside
|
||||||
className="absolute inset-y-0 left-0 hidden overflow-clip min-[88rem]:block"
|
ref={columnRef}
|
||||||
|
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 tint the
|
{/* A solid circle centered on the list, in the tint the
|
||||||
|
|
@ -175,19 +188,19 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
||||||
section lines, and after the page backdrop (also -1)
|
section lines, and after the page backdrop (also -1)
|
||||||
so in front of that. Height 0, so the list's layer
|
so in front of that. Height 0, so the list's layer
|
||||||
below starts, and sticks, at the same place. */}
|
below starts, and sticks, at the same place. */}
|
||||||
{listBox && (
|
{listBox && circle ? (
|
||||||
<div aria-hidden="true" className="pointer-events-none sticky h-0" style={{ top: STICK, zIndex: -1 }}>
|
<div aria-hidden="true" className="pointer-events-none sticky h-0" style={{ top: STICK, zIndex: -1 }}>
|
||||||
<div
|
<div
|
||||||
className="absolute rounded-full bg-tint"
|
className="absolute rounded-full bg-tint"
|
||||||
style={{
|
style={{
|
||||||
width: circleSize(listBox),
|
width: circle,
|
||||||
height: circleSize(listBox),
|
height: circle,
|
||||||
left: LIST_LEFT + listBox.width / 2 - circleSize(listBox) / 2,
|
left: Math.min(LIST_LEFT + listBox.width / 2 - CIRCLE_SHIFT - circle / 2, columnWidth - circle),
|
||||||
top: LIST_TOP + listBox.height / 2 - circleSize(listBox) / 2,
|
top: LIST_TOP + listBox.height / 2 - circle / 2,
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
) : null}
|
||||||
{/* The list, in front of the section lines. */}
|
{/* The list, in front of the section lines. */}
|
||||||
<div className="sticky z-10 pt-8 pl-4 pr-2" style={{ top: STICK }}>
|
<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">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue