Number 39: Timeline with a line that fills
Specification
- Catalogue
- No. 39 of 110
- Section
- Page sections
- Interaction
- Scroll
- Preview
- Live component
- Imports
- react 19.3.1
- Added
Notes
Dated milestones with a plain line beside them that fills as the reader goes down.
A project, a story or a process told in order, with the reader's place marked by a line that follows the scroll exactly. Dates stay in view while their entry is read.
Fill is scaleY of a 2px rule, tied to scroll progress with no easing. Full before script runs and under reduced motion. Dates are sticky beside their entry; under 420px they sit above it and nothing sticks. Here it scrolls inside its own frame; on a full page the progress reads the window. Changed from the library: a plain rule instead of the glowing gradient beam.
The names, figures and pictures in the demo are sample content; a real build uses the client's own.
Code
React and plain CSS"use client";
import { useRef, type CSSProperties, type ReactNode, type RefObject } from "react";
import { useFrameProgress } from "@/components/pieces/motion-helpers";
import { useSafeReducedMotion } from "@/components/pieces/kit/use-safe-reduced-motion";
import type { LivePreviewProps } from "@/components/live/types";
import { PieceStage } from "@/components/pieces/stage/PieceStage";
import type { Tour } from "@/components/pieces/stage/tour";
import "@/components/pieces/styles/scroll-frame.css";
import "./timeline.css";
function Frame({ label, frame, children, hint }: { label: string; frame: RefObject<HTMLDivElement | null>; children: ReactNode; hint: string }) {
return (
<div className="dm dm-scroll">
<div ref={frame} className="sf" tabIndex={0} role="region" aria-label={`${label}. Scroll inside this frame`}>
{children}
</div>
<p className="dm-hint">{hint}</p>
</div>
);
}
const MILESTONES = [
{ date: "3 Nov", title: "Survey", body: "Measured up, services checked, the old units' condition noted." },
{ date: "10 Nov", title: "Design signed off", body: "Layout and oak finish agreed, with the order placed the same day." },
{ date: "24 Nov", title: "Fitting starts", body: "Old kitchen out, first fix of pipes and wiring, plastering." },
{ date: "5 Dec", title: "Handover", body: "Worktops, splashback and lights in. Walked through together." },
];
function TimelineDemo() {
const frame = useRef<HTMLDivElement>(null);
const track = useRef<HTMLDivElement>(null);
const reduced = useSafeReducedMotion();
const p = useFrameProgress(frame, track);
return (
<Frame label="A kitchen fit, week by week" frame={frame} hint="Scroll inside: the line fills as you read">
<div className="tl">
<p className="ss-intro">A kitchen fit, week by week</p>
<div ref={track} className="tl-track" style={{ "--p": reduced ? 1 : p } as CSSProperties}>
<span className="tl-rule" aria-hidden="true">
<i />
</span>
<ol>
{MILESTONES.map((m) => (
<li key={m.date} className="tl-item">
<p className="tl-date">{m.date}</p>
<div className="tl-text">
<h3>{m.title}</h3>
<p>{m.body}</p>
</div>
</li>
))}
</ol>
</div>
<p className="ss-outro">Sample project</p>
</div>
</Frame>
);
}
// What a hovered card shows: the piece used the way a visitor would.
const TOUR: Tour = [
{ scroll: ".sf", to: 1, ms: 3600, wait: 1000 },
{ scroll: ".sf", to: 0, ms: 900, wait: 400 },
];
export default function TimelineEntry(props: LivePreviewProps) {
return (
<PieceStage {...props} label="Timeline with a line that fills" sample tour={TOUR}>
<TimelineDemo />
</PieceStage>
);
}