Process Steps
Landing section listing how-we-work steps joined by a scroll-driven amber heat rail; step numbers roll and light as the heat reaches them.
pnpm dlx shadcn@latest add @leo/process-stepsProps
| Name | Type | Default | Description |
|---|---|---|---|
| className | string | undefined | - | |
| description | string | undefined | Four steps, and every one leaves you something to see and approve. | |
| eyebrow | string | undefined | Process | |
| reducedMotion | undefined | "respect" | "ignore" | respect | "ignore" keeps the heat rail animating for visitors who prefer reduced motion. |
| steps | ProcessStep[] | undefined | [ { title: "Discover", description: "You send a few lines about what you need. Within a day we reply with the right questions and a clear scope.", }, { title: "Design", description: "You review real screens, not descriptions. Every milestone ships a working demo for you to approve first.", }, { title: "Build", description: "We build in short cycles on a staging link you can open any time, so nothing arrives as a surprise.", }, { title: "Hand over", description: "You receive the source, the accounts, the docs and a backup routine. Want us to keep running it? There is a monthly plan.", }, ] | Designed for 2–5 steps; more get cramped in the md+ row. A row from md up, a column below. Omit for the sample steps. |
| title | string | undefined | How we work | Empty string hides the whole header (eyebrow and description too), for sites that render their own. |
Dependencies
- motion@^12.23.12
Source
"use client";
import { useMotionValueEvent, useScroll } from "motion/react";
import { type CSSProperties, useEffect, useRef, useState } from "react";
import Counter from "@/components/counter";
import { useForgeMotion } from "@/hooks/use-forge-motion";
import { cn } from "@/lib/utils";
export interface ProcessStep {
title: string;
description?: string;
}
export interface ProcessStepsProps {
eyebrow?: string;
/** Empty string hides the whole header (eyebrow and description too), for sites that render their own. */
title?: string;
description?: string;
/** Designed for 2–5 steps; more get cramped in the md+ row. A row from md up, a column below. Omit for the sample steps. */
steps?: ProcessStep[];
/** "ignore" keeps the heat rail animating for visitors who prefer reduced motion. */
reducedMotion?: "respect" | "ignore";
className?: string;
}
const SAMPLE_STEPS: ProcessStep[] = [
{
title: "Discover",
description:
"You send a few lines about what you need. Within a day we reply with the right questions and a clear scope.",
},
{
title: "Design",
description:
"You review real screens, not descriptions. Every milestone ships a working demo for you to approve first.",
},
{
title: "Build",
description:
"We build in short cycles on a staging link you can open any time, so nothing arrives as a surprise.",
},
{
title: "Hand over",
description:
"You receive the source, the accounts, the docs and a backup routine. Want us to keep running it? There is a monthly plan.",
},
];
/** Scroll progress (0..1) at which step `i` of `n` lights. */
export function stepThreshold(i: number, n: number): number {
return i / Math.max(n - 1, 1);
}
/** Number of steps whose threshold the progress has reached; 0 for an empty list. */
export function litCount(progress: number, n: number): number {
let lit = 0;
for (let i = 0; i < n; i++) if (stepThreshold(i, n) <= progress) lit++;
return lit;
}
const clamp01 = (v: number) => Math.min(1, Math.max(0, Number.isFinite(v) ? v : 0));
// One rail per orientation (row from md, column below). The heat line is scaled, so the head is a
// sibling placed at its tip; its glow follows the theme's --forge-glow and fades out on light themes.
function Rail({
vertical,
progress,
head,
}: {
vertical: boolean;
progress: number;
head: boolean;
}) {
return (
<span
aria-hidden="true"
data-rail=""
className={cn(
"pointer-events-none absolute bg-border",
vertical
? // One segment per step, from its number down to the next one (the li height plus the
// gap-10 between items), so the head meets each number as that step lights.
"top-5 left-5 h-[calc(100%+2.5rem)] w-px md:hidden"
: "top-5 right-(--rail-end) left-0 hidden h-px md:block",
)}
>
<span
data-heat=""
style={{ transform: vertical ? `scaleY(${progress})` : `scaleX(${progress})` }}
className={cn(
"absolute inset-0 bg-primary transition-transform duration-300 ease-out motion-reduce:transition-none",
vertical ? "origin-top" : "origin-left",
)}
/>
{head && (
<span
className="absolute size-2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary shadow-[0_0_12px_2px_var(--primary)] transition-[left,top] duration-300 ease-out motion-reduce:transition-none"
style={{
opacity: "var(--forge-glow, 1)",
...(vertical
? { top: `${progress * 100}%`, left: "50%" }
: { left: `${progress * 100}%`, top: "50%" }),
}}
/>
)}
</span>
);
}
// Separate component so useScroll's target ref is attached together with the element.
function StepsList({
steps,
reducedMotion,
}: {
steps: ProcessStep[];
reducedMotion: "respect" | "ignore";
}) {
const stepCount = steps.length;
const listRef = useRef<HTMLDivElement>(null);
// "end end", not "end 0.9": a last-on-page section has under 10% of the viewport below the list, so it could never reach 1.
const { scrollYProgress } = useScroll({ target: listRef, offset: ["start 0.9", "end end"] });
const { hydrated, animate } = useForgeMotion(reducedMotion);
// Furthest progress seen: a lit step stays lit and the heat line never shrinks.
const [maxProgress, setMaxProgress] = useState(0);
useEffect(() => {
// The section may already be in view on load, before any change event fires.
if (hydrated) setMaxProgress((m) => Math.max(m, clamp01(scrollYProgress.get())));
}, [hydrated, scrollYProgress]);
useMotionValueEvent(scrollYProgress, "change", (v) =>
setMaxProgress((m) => Math.max(m, clamp01(v))),
);
const still = hydrated && !animate;
const progress = still ? 1 : hydrated ? maxProgress : 0;
const lit = !hydrated ? 0 : still ? stepCount : litCount(progress, stepCount);
const head = hydrated && !still;
return (
<div
ref={listRef}
className="relative"
// The md+ rail ends at the last step's number: one column plus the gaps short of the full
// width (md:gap-8 is 2rem between each of the n columns).
style={
{
"--rail-end": `calc(${100 / stepCount}% - ${((stepCount - 1) * 2) / stepCount}rem)`,
} as CSSProperties
}
>
{stepCount > 1 && <Rail vertical={false} progress={progress} head={head} />}
{/* biome-ignore lint/a11y/noRedundantRoles: Tailwind's list-style: none makes Safari/VoiceOver drop list semantics; role restores them. */}
<ol role="list" className="relative grid gap-10 md:auto-cols-fr md:grid-flow-col md:gap-8">
{steps.map((step, i) => {
const isLit = i < lit;
const from = stepThreshold(i, stepCount);
const segment = clamp01((progress - from) / (stepThreshold(i + 1, stepCount) - from));
return (
<li
// biome-ignore lint/suspicious/noArrayIndexKey: steps have no id and titles may repeat, so the index is part of the key
key={`${i}-${step.title}`}
className="relative flex gap-5 md:flex-col md:gap-4"
>
{i < stepCount - 1 && (
<Rail vertical progress={segment} head={head && segment > 0 && segment < 1} />
)}
{/* Hidden from assistive tech: the sequence is conveyed by list order, not by this number. */}
<div
aria-hidden="true"
className={cn(
"relative shrink-0 self-start bg-background pr-3 font-mono transition-colors duration-300",
isLit ? "text-primary" : "text-muted-foreground",
)}
>
<span
className="pointer-events-none absolute inset-0"
style={{ opacity: "var(--forge-glow, 1)" }}
>
<span
className={cn(
"absolute inset-0 bg-primary/25 blur-xl transition-opacity duration-500",
isLit ? "opacity-100" : "opacity-0",
)}
/>
</span>
<div className="relative">
<Counter
// Switching to reduced motion remounts the counter at its number, skipping the roll.
key={still ? "static" : "roll"}
value={isLit ? i + 1 : 0}
places={[10, 1]}
fontSize={32}
padding={8}
gap={0}
horizontalPadding={0}
borderRadius={0}
textColor="currentColor"
fontWeight={600}
gradientHeight={6}
gradientFrom="var(--background)"
/>
</div>
</div>
<div className="flex flex-col gap-2">
<h3 className="text-lg font-semibold tracking-tight">{step.title}</h3>
{step.description && (
<p className="text-sm leading-relaxed text-muted-foreground sm:text-base">
{step.description}
</p>
)}
</div>
</li>
);
})}
</ol>
</div>
);
}
export function ProcessSteps({
eyebrow = "Process",
title = "How we work",
description = "Four steps, and every one leaves you something to see and approve.",
steps = SAMPLE_STEPS,
reducedMotion = "respect",
className,
}: ProcessStepsProps) {
return (
<section className={cn("bg-background px-6 py-16 text-foreground sm:py-24", className)}>
<div className="mx-auto max-w-6xl">
{title && (
<header className="mb-12 max-w-2xl">
{eyebrow && (
<p className="font-mono text-xs tracking-widest text-primary uppercase">{eyebrow}</p>
)}
<h2 className="mt-3 text-3xl font-semibold tracking-tight sm:text-4xl">{title}</h2>
{description && <p className="mt-4 text-base text-muted-foreground">{description}</p>}
</header>
)}
{steps.length > 0 && <StepsList steps={steps} reducedMotion={reducedMotion} />}
</div>
</section>
);
}
// A named declaration re-exported as default: docgen names a bare `export default function` after
// the file ("processsteps"), so the exact-name match in gen-props only finds the component this way.
export default ProcessSteps;