Process Steps UI | React & Tailwind CSS
A responsive example that switches from horizontal to vertical — copy the code. Numbered steps stack as a number column and a text column on phones (under 640px) and sit in four columns from 640px up; numbers are joined by a connector at every width, with no stray line after the last step. A switch above the preview compares a Static version (every line and number at equal weight) with a Scroll-linked version, where the connector grows as you scroll and each number fills once the line reaches it. Each step carries a title, a short description and a one-line deliverable, so readers see what they receive at every stage. Built as an <ol> because order matters; plain React + Tailwind CSS with no dependencies, exported as <ProcessSteps steps initialMode showModeSwitch>. prefers-reduced-motion stops the motion and shows every step filled. Step copy is sample text.
Preview
スクロールすると線が伸び、届いた番号が塗りに変わります。
- 01
ヒアリング
目的・ターゲット・現状の課題を整理します。
成果物要件メモ
- 02
設計・提案
構成とデザインの方向性をご提案します。
成果物構成案・ワイヤー
- 03
制作
デザインから実装まで一貫して進めます。
成果物確認用のURL
- 04
公開・改善
公開後もデータを見ながら改善します。
成果物改善レポート
Read the full description
A responsive example that switches from horizontal to vertical — copy the code. Numbered steps stack as a number column and a text column on phones (under 640px) and sit in four columns from 640px up; numbers are joined by a connector at every width, with no stray line after the last step. A switch above the preview compares a Static version (every line and number at equal weight) with a Scroll-linked version, where the connector grows as you scroll and each number fills once the line reaches it. Each step carries a title, a short description and a one-line deliverable, so readers see what they receive at every stage. Built as an <ol> because order matters; plain React + Tailwind CSS with no dependencies, exported as <ProcessSteps steps initialMode showModeSwitch>. prefers-reduced-motion stops the motion and shows every step filled. Step copy is sample text.
- Added:
- 2026-07-23
- Updated:
- 2026-11-01
- Dependencies:
- None
- tags
- #process #steps #step-ui #timeline #responsive #scroll-linked #section #react #tailwind #no-dependency
"use client";
import { useEffect, useRef, useState, type CSSProperties } from "react";
/**
* 制作フローのステップUI(BLK-03)
*
* 番号つきの工程を、640px 未満では「番号列+本文列」の縦並び、640px 以上では4列の横並びで見せる。
* 番号どうしは線でつなぎ、最後の工程の後ろには線を出さない。
*
* 表示は2種類:
* - static: 線と番号をすべて同じ強さで描く静止版
* - scroll: ページのスクロールに合わせて線が伸び、線が届いた番号が塗りに変わる版
*
* 技法メモ:
* - 進み具合は「工程の番号」を単位にした1つの数値 progress(-1 〜 steps.length - 1)にまとめる。
* i 番目の番号は progress >= i で塗り、i → i+1 の線は (progress - i) を 0〜1 に丸めた値で伸ばす。
* - 基準線は画面の上から 65% の位置。縦並びでは各番号の中心が基準線を越えた量から progress を求める。
* 横並びでは番号の高さが揃っているので、番号どうしの間隔を画面の高さの 12% とみなして同じ計算をする。
* - 線の伸びは CSS 変数 --fill を transform(縦は scaleY・横は scaleX)に渡すだけ。レイアウトは動かさない。
* - prefers-reduced-motion: reduce のときは scroll を選んでも全工程を塗った静止表示にする。
*/
export type ProcessStep = {
n: string;
title: string;
body: string;
deliverable: string;
};
const defaultSteps: ProcessStep[] = [
{ n: "01", title: "ヒアリング", body: "目的・ターゲット・現状の課題を整理します。", deliverable: "要件メモ" },
{ n: "02", title: "設計・提案", body: "構成とデザインの方向性をご提案します。", deliverable: "構成案・ワイヤー" },
{ n: "03", title: "制作", body: "デザインから実装まで一貫して進めます。", deliverable: "確認用のURL" },
{ n: "04", title: "公開・改善", body: "公開後もデータを見ながら改善します。", deliverable: "改善レポート" },
];
type Mode = "static" | "scroll";
const READING_LINE = 0.65;
const ROW_GAP_RATIO = 0.12;
function useReducedMotion() {
const [reduced, setReduced] = useState(false);
useEffect(() => {
const mq = window.matchMedia("(prefers-reduced-motion: reduce)");
const update = () => setReduced(mq.matches);
update();
mq.addEventListener("change", update);
return () => mq.removeEventListener("change", update);
}, []);
return reduced;
}
export default function ProcessSteps({
steps = defaultSteps,
initialMode = "scroll",
showModeSwitch = true,
}: {
steps?: ProcessStep[];
initialMode?: Mode;
showModeSwitch?: boolean;
/** ギャラリーの表示枠が渡す見出しの指定。この部品は工程名を h3 で固定するため使わない */
headingTag?: "h1" | "p";
}) {
const [mode, setMode] = useState<Mode>(initialMode);
const [progress, setProgress] = useState(-1);
const reduced = useReducedMotion();
const listRef = useRef<HTMLOListElement>(null);
const animated = mode === "scroll" && !reduced;
useEffect(() => {
if (!animated) return;
const list = listRef.current;
if (!list) return;
let frame = 0;
const measure = () => {
frame = 0;
const markers = Array.from(list.querySelectorAll<HTMLElement>("[data-marker]"));
if (markers.length === 0) return;
const vh = window.innerHeight;
const line = vh * READING_LINE;
let centers = markers.map((m) => {
const r = m.getBoundingClientRect();
return r.top + r.height / 2;
});
// 横並び(中心の高さが揃っている)なら、番号の間隔を画面の高さの一定割合とみなす
if (centers.length > 1 && Math.abs(centers[centers.length - 1] - centers[0]) < 1) {
centers = centers.map((c, i) => c + i * vh * ROW_GAP_RATIO);
}
let next = -1;
if (line >= centers[0]) {
next = centers.length - 1;
for (let i = 0; i < centers.length - 1; i++) {
if (line < centers[i + 1]) {
next = i + (line - centers[i]) / (centers[i + 1] - centers[i]);
break;
}
}
}
next = Math.round(next * 100) / 100;
setProgress((prev) => (prev === next ? prev : next));
};
const schedule = () => {
if (!frame) frame = requestAnimationFrame(measure);
};
measure();
window.addEventListener("scroll", schedule, { passive: true });
window.addEventListener("resize", schedule);
return () => {
window.removeEventListener("scroll", schedule);
window.removeEventListener("resize", schedule);
if (frame) cancelAnimationFrame(frame);
};
}, [animated, steps.length]);
// 静止版は「全部同じ強さ」、動きを減らす設定の scroll は「全部到達済み」で描く
const effective = mode === "static" ? null : animated ? progress : steps.length - 1;
const current = effective === null ? -1 : Math.floor(effective);
return (
<div className="w-full max-w-3xl px-2 sm:px-0">
{showModeSwitch && (
<div className="mb-6 flex flex-wrap items-center gap-x-4 gap-y-2 sm:mb-8">
<div
role="group"
aria-label="表示の切り替え"
className="inline-flex rounded-full border border-gray-200 bg-white p-1"
>
{(
[
{ key: "static", label: "静止" },
{ key: "scroll", label: "スクロール連動" },
] as const
).map((opt) => (
<button
key={opt.key}
type="button"
aria-pressed={mode === opt.key}
onClick={() => setMode(opt.key)}
className={`min-h-11 rounded-full px-4 text-sm font-semibold transition-[background-color,color,transform] duration-150 active:scale-[0.96] focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-amber-600 motion-reduce:transition-none ${
mode === opt.key ? "bg-gray-900 text-white" : "text-gray-600 hover:bg-gray-100"
}`}
>
{opt.label}
</button>
))}
</div>
<p className="text-xs leading-relaxed text-gray-500" aria-live="polite">
{mode === "static"
? "線と番号をすべて同じ強さで表示しています。"
: reduced
? "動きを減らす設定のため、全工程を表示しています。"
: "スクロールすると線が伸び、届いた番号が塗りに変わります。"}
</p>
</div>
)}
<ol ref={listRef} className="grid sm:grid-cols-4 sm:gap-x-6">
{steps.map((step, i) => {
const isLast = i === steps.length - 1;
const reached = effective !== null && effective >= i;
const fill = effective === null ? 1 : Math.min(1, Math.max(0, effective - i));
return (
<li
key={step.n}
className={`relative grid grid-cols-[2rem_minmax(0,1fr)] gap-x-4 sm:block ${isLast ? "" : "pb-8 sm:pb-0"}`}
style={{ "--fill": fill } as CSSProperties}
>
{!isLast && (
<span
className="absolute top-10 bottom-2 left-4 w-px -translate-x-1/2 overflow-hidden bg-gray-200 sm:top-4 sm:right-[-1rem] sm:bottom-auto sm:left-10 sm:h-px sm:w-auto sm:translate-x-0"
aria-hidden="true"
>
{effective !== null && (
<span className="block size-full origin-top bg-amber-500 transition-transform duration-150 ease-out [transform:scaleY(var(--fill))] motion-reduce:transition-none sm:origin-left sm:[transform:scaleX(var(--fill))]" />
)}
</span>
)}
<span
data-marker
className={`relative z-10 inline-flex size-8 items-center justify-center rounded-full border font-mono text-xs font-bold transition-[background-color,border-color,color,box-shadow] duration-300 motion-reduce:transition-none ${
effective === null
? "border-amber-200 bg-amber-50 text-amber-700"
: reached
? "border-amber-500 bg-amber-500 text-white"
: "border-gray-300 bg-white text-gray-400"
} ${i === current && animated && !isLast ? "shadow-[0_0_0_4px_rgb(254_243_199)]" : ""}`}
>
{step.n}
</span>
<div className="min-w-0">
<h3
className={`mt-1.5 text-sm font-bold transition-colors duration-300 motion-reduce:transition-none sm:mt-3 ${
effective !== null && !reached ? "text-gray-400" : "text-gray-900"
}`}
>
{step.title}
</h3>
<p className="mt-1 text-[13px] leading-relaxed text-gray-500">{step.body}</p>
<p className="mt-2 inline-flex max-w-full items-baseline gap-1.5 rounded border border-gray-200 px-2 py-0.5 text-[11px] leading-relaxed text-gray-600">
<span className="shrink-0 font-semibold text-gray-400">成果物</span>
{step.deliverable}
</p>
</div>
</li>
);
})}
</ol>
</div>
);
}
Add to your project via shadcn CLI
npx shadcn@latest add https://designs.first-ch.com/r/process-steps.json