PD03▸📊 Data Display · 資料展示▸時序
Timeline
時間軸
難度 ★★★★★標籤 timeline · 歷史 · 事件3 min read
模式簡述
Timeline:時序事件展示。Git history、changelog、訂單追蹤都會用到。
Frontend Lab 上線
2026-05-14
Deploy 到 Cloudflare
2026-05-13
修復 variant 切換 bug
2026-05-12
初版 commit
2026-05-10
Claude Code Prompt
參考:PD03 timeline 組件:Timeline.tsx Timeline:時序事件展示。Git history、changelog、訂單追蹤都會用到。 限制: - 節點和文字沒對齊 - 沒區分時間層級 - 手機端視覺破碎
完整程式碼
"use client";
import { GitCommit, Rocket, Bug, Sparkles } from "lucide-react";
type State = "simple" | "detailed" | "live";
const EVENTS = [
{ icon: Sparkles, title: "Frontend Lab 上線", time: "2026-05-14", desc: "118 個前端 UI 模式" },
{ icon: Rocket, title: "Deploy 到 Cloudflare", time: "2026-05-13" },
{ icon: Bug, title: "修復 variant 切換 bug", time: "2026-05-12" },
{ icon: GitCommit, title: "初版 commit", time: "2026-05-10" },
];
export function Timeline({ state = "detailed" }: { state?: State }) {
const simple = state === "simple";
return (
<ol className="relative w-full max-w-md space-y-4 border-l-2 border-border pl-6">
{EVENTS.map((e, i) => {
const isLive = state === "live" && i === 0;
return (
<li key={i} className="relative">
<span
className={`absolute -left-[31px] grid h-5 w-5 place-items-center rounded-full ${isLive ? "bg-lab-accent" : "bg-background border border-border"}`}
>
{isLive && (
<span className="absolute inset-0 animate-ping rounded-full bg-lab-accent" />
)}
<e.icon
className={`h-3 w-3 ${isLive ? "text-background" : "text-muted-foreground"}`}
/>
</span>
<p className="text-sm font-medium text-foreground">{e.title}</p>
<p className="font-mono text-[10px] uppercase tracking-wider text-muted-foreground/70">
{e.time}
</p>
{!simple && e.desc && (
<p
className="mt-1 text-xs text-muted-foreground"
style={{ fontFamily: "var(--font-zh)" }}
>
{e.desc}
</p>
)}
</li>
);
})}
</ol>
);
}何時用
- ✅ 訂單/包裹追蹤
- ✅ Changelog、版本更新
- ✅ 個人 / 公司歷程展示
何時別用
- ❌ 事件超過 50 條(虛擬捲動或分頁)
- ❌ 事件無時間屬性(不是 timeline)
- ❌ 需要對齊比較不同 timeline(改用 gantt)
我踩過的坑
-
節點和文字沒對齊:每個節點要垂直置中對齊文字第一行,不是 box 中間。
-
沒區分時間層級:所有事件大小一樣,重要的看不出。highlight + 加粗區隔重要事件。
-
手機端視覺破碎:考慮改成垂直堆疊,左側 timeline 不變、文字往右走。
相關模式
- PC04
- PA03