Page fixes: v1.10.7 to v1.10.10 #21
2 changed files with 62 additions and 10 deletions
|
|
@ -1,11 +1,19 @@
|
||||||
/* The side nav's circle (PageShell.tsx): the light fill of the color
|
/* The side nav's circle (PageShell.tsx), a sun in the corner once
|
||||||
|
the nav sticks: the light fill of the color
|
||||||
family of the section being read (its darkest in dark mode), the
|
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
|
palette shades every text color reads on at 4.5:1 or better, as
|
||||||
on the page backdrop (PageBackdrop.css). */
|
on the page backdrop (PageBackdrop.css). */
|
||||||
|
|
||||||
.side-nav-circle {
|
.side-nav-circle {
|
||||||
background: #d6f5fa;
|
background: #d6f5fa;
|
||||||
transition: background-color 0.8s ease-in-out;
|
/* Color by section; size and place between centered on the list
|
||||||
|
and the corner sun once it sticks. */
|
||||||
|
transition:
|
||||||
|
background-color 0.8s ease-in-out,
|
||||||
|
width 0.6s ease-in-out,
|
||||||
|
height 0.6s ease-in-out,
|
||||||
|
left 0.6s ease-in-out,
|
||||||
|
top 0.6s ease-in-out;
|
||||||
}
|
}
|
||||||
.side-nav-circle[data-family="green"] {
|
.side-nav-circle[data-family="green"] {
|
||||||
background: #e6f0dd;
|
background: #e6f0dd;
|
||||||
|
|
|
||||||
|
|
@ -168,6 +168,53 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
||||||
const activeAccent = sections.find((s) => s.id === active)?.accent;
|
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;
|
const listTop = listBox && circle ? Math.max(LIST_TOP, CIRCLE_GAP + circle / 2 - listBox.height / 2) : LIST_TOP;
|
||||||
|
|
||||||
|
// Stuck: the page has scrolled the list up to its place under the
|
||||||
|
// header. The circle then becomes the corner sun (below).
|
||||||
|
const [stuck, setStuck] = useState(false);
|
||||||
|
useEffect(() => {
|
||||||
|
const column = columnRef.current;
|
||||||
|
if (!sideNav || !column) return;
|
||||||
|
let frame = 0;
|
||||||
|
const measure = () => {
|
||||||
|
frame = 0;
|
||||||
|
const header = parseFloat(getComputedStyle(column).getPropertyValue("--header-h")) || 80;
|
||||||
|
setStuck(column.getBoundingClientRect().top + listTop <= header + STUCK_TOP + 1);
|
||||||
|
};
|
||||||
|
const onScroll = () => {
|
||||||
|
if (!frame) frame = requestAnimationFrame(measure);
|
||||||
|
};
|
||||||
|
measure();
|
||||||
|
window.addEventListener("scroll", onScroll, { passive: true });
|
||||||
|
window.addEventListener("resize", onScroll);
|
||||||
|
return () => {
|
||||||
|
window.removeEventListener("scroll", onScroll);
|
||||||
|
window.removeEventListener("resize", onScroll);
|
||||||
|
if (frame) cancelAnimationFrame(frame);
|
||||||
|
};
|
||||||
|
}, [sideNav, listTop]);
|
||||||
|
|
||||||
|
// The circle's box, from its layer's top left (which sticks with
|
||||||
|
// the list). Before sticking: centered on the list. Stuck: a sun in
|
||||||
|
// the corner, centered on the header's bottom left so the header
|
||||||
|
// and the screen's edge hide three quarters of it, big enough to
|
||||||
|
// reach past the list's far corner, but never wider than the column
|
||||||
|
// (it'd show a cut edge at the content).
|
||||||
|
const circleBox = (() => {
|
||||||
|
if (!listBox || !circle) return null;
|
||||||
|
if (stuck) {
|
||||||
|
const radius = Math.min(
|
||||||
|
Math.hypot(LIST_LEFT + listBox.width + 24, STUCK_TOP + listBox.height + 24),
|
||||||
|
columnWidth - 8,
|
||||||
|
);
|
||||||
|
return { size: radius * 2, left: -radius, top: listTop - STUCK_TOP - radius };
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
size: circle,
|
||||||
|
left: Math.min(LIST_LEFT + Math.max(listBox.width / 2 - CIRCLE_SHIFT, listBox.heading) - circle / 2, columnWidth - circle),
|
||||||
|
top: listTop + listBox.height / 2 - circle / 2,
|
||||||
|
};
|
||||||
|
})();
|
||||||
|
|
||||||
// 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
|
||||||
// description and preview for search and link sharing.
|
// description and preview for search and link sharing.
|
||||||
|
|
@ -216,19 +263,16 @@ export default function PageShell({ title, intro, sections, sideNav = false }: P
|
||||||
which comes after it and so draws over it. Height 0, so
|
which comes after it and so draws over it. Height 0, so
|
||||||
the list's layer below starts, and sticks, at the same
|
the list's layer below starts, and sticks, at the same
|
||||||
place. */}
|
place. */}
|
||||||
{listBox && circle ? (
|
{circleBox ? (
|
||||||
<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: stickAt(listTop) }}>
|
||||||
<div
|
<div
|
||||||
className="side-nav-circle absolute rounded-full"
|
className="side-nav-circle absolute rounded-full"
|
||||||
data-family={circleFamily(activeAccent)}
|
data-family={circleFamily(activeAccent)}
|
||||||
style={{
|
style={{
|
||||||
width: circle,
|
width: circleBox.size,
|
||||||
height: circle,
|
height: circleBox.size,
|
||||||
left: Math.min(
|
left: circleBox.left,
|
||||||
LIST_LEFT + Math.max(listBox.width / 2 - CIRCLE_SHIFT, listBox.heading) - circle / 2,
|
top: circleBox.top,
|
||||||
columnWidth - circle,
|
|
||||||
),
|
|
||||||
top: listTop + listBox.height / 2 - circle / 2,
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue