Timeline
事件历史记录,包括方向、时间、加载、图标和主题设置。
何时使用
时间线显示相关事件的历史记录以及它们发生的顺序:交付、项目变更或流程日志。它不控制阶段的通过;对于交互式多步骤任务,请使用步骤。
事件和故事顺序
items 包含 title、content 和可选的持久 key。color 设置节点的颜色,icon——它自己的图标。loading 标志着一个等待事件;相反,reverse 视觉顺序,同时保留应用程序的原始数据。
| 问题 | 设置 | 示例 |
|---|---|---|
| 显示序列 | items |
主要故事 |
| 表示期望 | item.loading、reverse |
装载和订购 |
| 交替双方 | mode="alternate" |
交替 |
| 将时间与内容分开 | title、content |
签名 |
| 设置水平轴 | orientation="horizontal" |
水平放置 |
| 添加事件操作 | content 中的片段 |
自有节点 |
loading 标签本身并不加载数据。应用程序在操作结果后添加或更新相应的项目。事件应该有一个文本状态:单一颜色或旋转图标不能解释发生了什么。
轴、侧面和头部空间
orientation 选择 vertical/horizontal。模式:开始/end/交替确定事件相对于线路的一侧;单独的项目可以指定 placement:start/end。逻辑侧遵循接口的方向。
titleSpan 指定到节点中心的空间。 Number 是 24 列网格的分数,line 是 CSS 长度,包括百分比。对于替代,不应用数字 titleSpan。对于较长的水平故事,请保持本地滚动(如示例所示),而不展开整个页面。
变体:轮廓/filled 改变了节点的设计。图标接受文本内容或片段;content 内的本机按钮保留自己的语义和键盘。时间线不会按日期对条目进行排序:提前准备所需的 items 顺序。
语义 DOM 和主题
词根是带有历史元素的 ol。内容可能包括链接、时间和操作;当机器可读的时间对您的应用程序很重要时,请使用清晰的签名和时间。
在整个时间轴语义中,名称都以 item 为前缀:itemTitle/itemContent/itemRail。单个事件使用 title/content/rail。项目 classNames/styles 指定常规设置。styles 包含 CSS 字符串; 语义示例 显示两个级别。
时间线设计令牌(design tokens)通过 theme.components.Timeline 应用并更改行、节点和填充。主题可以独立于事件数组进行更新; bind:nativeElement 在挂载后提供根 ol。此设计不会自动过滤或对故事进行分页。
ConfigProvider.timeline 接受 TimelineConfig:class、styles、classNames 和样式;数据和行为仍然是时间轴的支柱。语义默认支持当前 props 的回调。课程加起来;对于 root,使用提供者的 styles.root、provider style、local styles.root、local style。对于事件,本地 styles 和项目 styles 优先于通用 style。嵌套的 timeline={} 替换整个记录时间轴。 设置示例 显示这些级别。
单独的 ConfigProvider.steps 仅将根 class/样式传递到时间轴:步骤的语义设置不设置时间轴事件的 style。重置 timeline={} 不会禁用 steps.class/style;这也需要 steps={}。
本地 prefixCls 更改根、状态和时间轴节点的命名空间。非空本地前缀优先;空字符串和 undefined 继承 ConfigProvider.prefixCls 并带有 -timeline 后缀,默认为 ant-timeline。内部 Steps 分别继承相同的基本前缀和 -steps 后缀:本地 Timeline.prefixCls 不会影响它。因此, suite 和 Timeline.prefixCls="local-history" 给出了 local-history 和 suite-steps,并且在不设置提供者的情况下,ant-steps 被保存。theme 和语义 API 未重命名。 本地前缀 和 公共 prefix 切换不改变历史记录。
示例
- 项目已创建
- 测试完成
- 版本已发布
基本示例
按时间和节点颜色排列的事件。
<script lang="ts">
import { Timeline } from '@woodger/antd';
</script>
<Timeline aria-label={("主要故事")} items={([
{ key: 'created', content: "项目已创建", color: 'green' },
{ key: 'tested', content: "测试完成", color: 'green' },
{ key: 'published', content: "版本已发布" }
])} />
outlined
- 准备
- 考试
- 准备好
filled
- 准备
- 考试
- 准备好
节点选项
勾勒出 outlined 并 filled。
<script lang="ts">
import { Timeline } from '@woodger/antd';
const items = [{ content: "准备" }, { content: "考试" }, { content: "准备好" }];
</script>
<style>
.examples {
display: grid;
gap: 24px;
}
h4 {
margin: 0 0 16px;
font: inherit;
font-weight: 600;
}
</style>
<div class="examples">
{#each ['outlined', 'filled'] as variant (variant)}
<div><h4>{(variant)}</h4><Timeline
items={(items)}
variant={variant as 'outlined' | 'filled'}
aria-label={("选项 " + String((variant)) + "")}
/></div>
{/each}
</div>
- 组装完成
- 检查已通过
- 发布…
装载和倒序
管理 item.loading 和 reverse。
<script lang="ts">
import { Checkbox, Timeline } from '@woodger/antd';
let reverse = $state(false);
let loading = $state(true);
</script>
<style>
.settings {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 16px;
margin-bottom: 24px;
}
</style>
<div class="settings">
<Checkbox bind:checked={reverse}>{("颠倒顺序")}</Checkbox>
<Checkbox bind:checked={loading}>{("出版继续")}</Checkbox>
</div>
<Timeline aria-label={("出版历史")} {reverse} items={([
{ key: 'build', content: "组装完成" },
{ key: 'checks', content: "检查已通过" },
{ key: 'publish', content: loading ? "发布…" : "已发表", loading }
])} />
- 创建项目
- 代码审查
- 构建包
- 发布
事件交替
start、交替和 end。
<script lang="ts">
import { RadioGroup, Timeline } from '@woodger/antd';
let mode = $state<'start' | 'alternate' | 'end'>('alternate');
</script>
<style>
.settings { margin-bottom: 24px; }
</style>
<div class="settings"><RadioGroup
aria-label={("活动位置")}
value={mode}
options={(['start', 'alternate', 'end'])}
onValueChange={next => { mode = next; }}
/></div>
<Timeline aria-label={("事件交替")} {mode} items={([
{ content: "创建项目" }, { content: "代码审查" },
{ content: "构建包" }, { content: "发布" }
])} />
- 09:00创建
- 10:00考试
- 12:00发布
横向历史
在卡片内滚动。
<script lang="ts">
import { Timeline } from '@woodger/antd';
</script>
<style>
.scroll {
max-width: 100%;
overflow-x: auto;
}
.scroll:focus-visible {
outline: 2px solid var(--ant-color-primary);
outline-offset: 2px;
}
.line { min-width: 520px; }
</style>
<div class="scroll" role="region" aria-label={("滚动历史记录")} tabindex="0">
<div
class="line"
><Timeline
aria-label={("横向历史")}
orientation="horizontal"
items={([
{ title: '09:00', content: "创建" }, { title: '10:00', content: "考试" },
{ title: '12:00', content: "发布" }
])}
/></div>
</div>
- 09:00处理开始
- 09:30
- 等待决定
- 档案准备
图标和动作
内容中的片段图标和按钮。
<script lang="ts">
import { Button, Timeline } from '@woodger/antd';
let accepted = $state(0);
let reverse = $state(false);
</script>
<style>
output {
display: block;
margin-block-start: 12px;
}
.actions {
display: flex;
flex-wrap: wrap;
gap: 8px;
}
.actions :global(.ant-btn) {
max-width: 100%;
height: auto;
min-height: var(--ant-control-height-sm);
white-space: normal;
}
</style>
{#snippet clock()}<svg
width="16"
height="16"
viewBox="0 0 24 24"
fill="none"
aria-hidden="true"
><circle
cx="12"
cy="12"
r="9"
stroke="currentColor"
stroke-width="2"
/><path
d="M12 6v6l4 2"
stroke="currentColor"
stroke-width="2"
/></svg>{/snippet}
{#snippet details()}<div class="actions">
<Button
size="small"
onclick={() => { accepted++; }}
>{("确认验证")}</Button>
<Button
size="small"
onclick={() => { reverse = !reverse; }}
>{("展开故事")}</Button>
</div>{/snippet}
<Timeline
aria-label={("故事与行动")}
{reverse}
titleSpan="60px"
items={([
{ key: 'start', title: '09:00', content: "处理开始", color: 'green' },
{ key: 'review', title: '09:30', content: details, icon: clock, color: 'purple' },
{ key: 'end', content: "等待决定", color: '#d46b08' },
{ key: 'archive', content: "档案准备", color: 'gray' }
])}
/>
<output
aria-label={("时间表确认")}
>{("确认的: ")}{accepted}</output>
- 项目已创建
- 测试完成
- 需要验证
- 发布准备就绪
端边
线路另一边的事件。
<script lang="ts">
import { Timeline } from '@woodger/antd';
</script>
<Timeline aria-label={("活动结束")} mode="end" items={([
{ content: "项目已创建" }, { content: "测试完成", color: 'green' },
{ content: "需要验证", color: 'red' }, { content: "发布准备就绪" }
])} />
- 09:00项目已创建
- 09:30验证完成
- 准备文件
- 12:00版本已发布
时间的痕迹
标题与内容是分开的。
<script lang="ts">
import { Timeline } from '@woodger/antd';
</script>
<Timeline aria-label={("历史与时间")} titleSpan="88px" items={([
{ title: '09:00', content: "项目已创建" },
{ title: '09:30', content: "验证完成" },
{ content: "准备文件" },
{ title: '12:00', content: "版本已发布" }
])} />
100px
- 05:10准备
- 09:03考试
- 集会
- 11:28发布
25%
- 05:10准备
- 09:03考试
- 集会
- 11:28发布
18 列,结束
- 05:10准备
- 09:03考试
- 集会
- 11:28发布
标题缩进
像素、百分比和列。
<script lang="ts">
import { Timeline, type TimelineItem } from '@woodger/antd';
const items: TimelineItem[] = [
{ title: '05:10', content: "准备" }, { title: '09:03', content: "考试" },
{ content: "集会" }, { title: '11:28', content: "发布" }
];
</script>
<style>
.examples {
display: grid;
gap: 24px;
}
h4 {
margin: 0 0 16px;
font: inherit;
font-weight: 600;
}
</style>
<div class="examples">
<div><h4>100px</h4><Timeline items={(items)} titleSpan="100px" aria-label={("缩进 100 像素")} /></div>
<div><h4>25%</h4><Timeline items={(items)} titleSpan="25%" aria-label={("缩进 25%")} /></div>
<div><h4>{("18 列,结束")}</h4><Timeline
items={(items)}
titleSpan={18}
mode="end"
aria-label={("缩进18列")}
/></div>
</div>
- 09:00通用款式
- 10:00单项活动风格
- 协调
- 发布
Semantic DOM
单个事件的对象、功能和样式。
<script lang="ts">
import { Timeline } from '@woodger/antd';
</script>
<style>
.examples {
display: grid;
gap: 24px;
}
</style>
<div class="examples">
<Timeline
aria-label={("按对象设计")}
classNames={{ root: 'timeline-object' }}
styles={{
root: 'padding: 12px',
itemTitle: 'font-weight: 700',
itemContent: 'font-size: 13px'
}}
items={([
{ title: '09:00', content: "通用款式" },
{
title: '10:00', content: "单项活动风格", styles: {
title: 'color: var(--ant-color-primary)',
content: 'font-weight: 600'
}
}
])}
/>
<Timeline aria-label={("按功能设计")} mode="end"
classNames={() => ({ root: 'timeline-function' })}
styles={({ props }) => ({ itemContent: `font-weight: ${props.mode === 'end' ? 700 : 400}` })}
items={([{ content: "协调" }, { content: "发布" }])} />
</div>
- 09:00准备
- 10:00考试
- 11:00准备好
组件代币
六个本地时间线标记。
<script lang="ts">
import { ConfigProvider, Timeline } from '@woodger/antd';
</script>
<ConfigProvider theme={{
components: {
Timeline: {
tailColor: '#d3adf7', tailWidth: 4, dotBorderWidth: 3,
dotSize: 14, dotBg: '#fff7e6', itemPaddingBottom: 32
}
}
}}>
<Timeline aria-label={("本地时间线主题")} titleSpan="64px" items={([
{ title: '09:00', content: "准备" }, { title: '10:00', content: "考试" },
{ title: '11:00', content: "准备好" }
])} />
</ConfigProvider>
- 09:00准备
- 10:00发布
从右到左
direction 和拍号。
<script lang="ts">
import { ConfigProvider, Timeline } from '@woodger/antd';
</script>
<ConfigProvider direction="rtl">
<Timeline aria-label={("历史从右到左")} titleSpan="64px" items={([
{ title: '09:00', content: "准备" }, { title: '10:00', content: "发布" }
])} />
</ConfigProvider>
- 09:10订单已创建
- 09:15付款已确认
- 10:30已交付交付
- 预计交货
来自评论的订单历史记录
reverse 并 loading 上一个事件的状态。
<script lang="ts">
import { Timeline } from '@woodger/antd';
let reverse = $state(false);
let loading = $state(true);
</script>
<style>
.controls {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.controls label {
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 8px;
}
</style>
<div class="controls">
<label><input
type="checkbox"
bind:checked={reverse}
/>{(" 颠倒事件顺序")}</label>
<label><input type="checkbox" bind:checked={loading} />{(" 等待下一次活动")}</label>
</div>
<Timeline
aria-label={("订单历史")}
{reverse}
titleSpan="72px"
items={([
{ key: 'created', title: '09:10', content: "订单已创建", color: 'green' },
{ key: 'paid', title: '09:15', content: "付款已确认", color: 'green' },
{ key: 'sent', title: '10:30', content: "已交付交付" },
...(loading ? [{ key: 'delivery', content: "预计交货", loading: true }] : [])
])}
/>
- 09:00申请已收到
- 10:00申请已验证
- 09:00申请已收到
- 10:00申请已验证
- 09:00申请已收到
- 10:00申请已验证
<script lang="ts">
import { Checkbox, ConfigProvider, Timeline } from '@woodger/antd';
let emphasized = $state(true);
const items = [
{ title: '09:00', content: "申请已收到" },
{ title: '10:00', content: "申请已验证" }
];
</script>
<style>
.example, .examples {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<Checkbox bind:checked={emphasized}>{("时间线标题重点")}</Checkbox>
<ConfigProvider
steps={({
class: 'history-steps', style: 'border-radius: 12px',
styles: { itemTitle: 'letter-spacing: 8px' }
})}
timeline={{
class: 'shared-timeline', style: 'padding: 12px',
classNames: { itemTitle: 'shared-timeline-title' },
styles: ({ props }) => ({
itemTitle: props.orientation === 'vertical' && emphasized
? 'font-weight: 700'
: 'font-weight: 400'
})
}}>
<div class="examples">
<Timeline aria-label={("具有默认值的历史记录")} items={(items)} />
<Timeline
aria-label={("历史与当地风格")}
style="padding: 20px"
classNames={{ itemTitle: 'local-timeline-title' }}
styles={{ itemTitle: 'font-weight: 400' }}
items={([items[0], { ...items[1], styles: { title: 'font-weight: 800' } }])}
/>
<ConfigProvider timeline={{}}>
<Timeline aria-label={("没有默认时间线的历史")} items={(items)} />
</ConfigProvider>
</div>
</ConfigProvider>
</div>
- 09:00创建项目
- 10:00项目发布
- 09:00创建项目
- 10:00项目发布
<script lang="ts">
import { Checkbox, Timeline } from '@woodger/antd';
let alternate = $state(false);
const items = [
{ title: '09:00', content: "创建项目" },
{ title: '10:00', content: "项目发布" }
];
</script>
<style>
.example {
display: grid;
gap: 24px;
}
</style>
<div class="example">
<Checkbox bind:checked={alternate}>{("另一个时间轴前缀")}</Checkbox>
<Timeline prefixCls={alternate ? 'woodger-history' : 'woodger-timeline'}
aria-label={("带有前缀的历史记录")} items={(items)} />
<Timeline aria-label={("标准故事")} items={(items)} />
</div>
API
针对 11 个 ant.design 6.7.0 主题和已安装的 Svelte 包的公共 variant 进行了验证。outlined/filled 的变体已发布。 Props 的完整定义位于库中。
| 主题 | 示例或限制 |
|---|---|
| Basic | 事件和颜色的顺序。 |
| Variant | 从当前第 6.7 页 outlined 和 filled。 |
| Loading and Reversing | item.loading 和逆序。 |
| Alternate | start、交替和 end。 |
| Horizontal | 具有本地滚动的水平历史记录。 |
| Custom | 图标和动作作为片段。 |
| End alternate | 与末端边缘对齐。 |
| Title | 时间与内容是分开的。 |
| Title Offset | 100px、25% 和数字列。 |
| Semantic Sample | 一般风格和个人活动风格。 |
| Custom semantic dom styling | 带有道具的对象和功能。 |
| Component config | ConfigProvider.timeline 和 Steps 设置边界。 |
| Local CSS prefix | 命名空间时间线,保留内部步骤类。 |
Timeline
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
prefixCls | 完整的本地时间轴 CSS 前缀。空字符串继承公共前缀; ant-timeline 无需配置即可使用。内部Steps单独继承ConfigProvider.prefixCls,独立于本地 Timeline.prefixCls。 | string | ConfigProvider + -timeline |
items | 具有稳定 key、标题、内容和图标的事件。 | readonly TimelineItem[] | [] |
mode | 事件相对于线路的位置:start、交替或 end。 | start | alternate | end | start |
orientation | 时间线方向。 | vertical | horizontal | vertical |
variant | 节点的设计。由公共 Svelte API 支持。 | outlined | filled | outlined |
titleSpan | 24 列的数量或 CSS 长度:例如 100px 或 25%。 | number | string | 12 |
reverse | 颠倒事件的视觉顺序。 | boolean | false |
styles | CSS 行 root 和项目槽;对象或函数。 | TimelineSlots | callback | ConfigProvider.timeline |
classNames | 语义槽类。 | TimelineSlots | callback | ConfigProvider.timeline |
TimelineItem
| 属性 | 描述 | 类型 | 默认 |
|---|---|---|---|
title | 拍号或标题;支持片段。 | TimelineContent | — |
content | 包含事件内容的文本或片段。 | TimelineContent | — |
icon | 一个图标而不是常规节点。 | TimelineContent | 圆圈 |
loading | 未完成事件的指示器。 | boolean | false |
placement | 特定事件的位置。 | start | end | 按模式 |
color | 预设或自定义 CSS 节点颜色。 | string | blue |
styles | 本地 root/wrapper/icon/部分/title/header/content/rail。 | StepsItemSlots | — |
ReactNode 替换为值和 Snippet,CSSProperties 替换为 CSS 字符串。活动使用 title/content/icon/placement; item.loading 指定挂起状态。
ConfigProvider.timeline 接受 TimelineConfig:class、styles、classNames 和 styles。语义默认值支持具有当前属性的对象或回调。本地 style 优先;嵌套的 timeline={} 替换整个记录。项目 styles 优先。仅根 class/style 继承自 ConfigProvider.steps;语义步骤设置是隔离的。
Semantic DOM
时间轴输出 ol 和 li。普通槽位使用item前缀;个人活动风格 - 简称 title/content/rail 目。装饰图标在辅助功能树中隐藏;content 内的按钮可通过键盘访问。
| Slot | 目的 |
|---|---|
root | 已排序的列表。 |
item | 事件。 |
itemWrapper | 事件包装器。 |
itemIcon | 节点图标。 |
itemSection | 活动区。 |
itemHeader | 标头区域。 |
itemTitle | 标题或时间。 |
itemContent | 内容。 |
itemRail | 连接线。 |
注册令牌
theme.components.Timeline 指定节点的线条、大小和背景,以及事件之间的距离。在该示例中,所有六个标记均已更改。内联 styles 阐明了本地设计。
| 代币 | 目的 |
|---|---|
tailColor | 线条颜色。 |
tailWidth | 线条粗细。 |
dotBorderWidth | 节点轮廓的厚度。 |
dotSize | 结尺寸。 |
dotBg | 节点背景。 |
itemPaddingBottom | 事件之间的间隔。 |
| 代币 | 意义 |
|---|---|
colorPrimary | #2f54eb |
colorError | #ff4d4f |
colorSuccess | #52c41a |
colorText | rgba(0,0,0,0.88) |
colorTextDisabled | rgba(0,0,0,0.25) |
fontSize | 14 |
lineHeight | 1.5714285714285714 |
paddingXS | 8 |
FAQ
如何表示等待?
将 loading 传递给所需的事件。该事件的添加和删除由应用程序控制。
如何在事件中放置按钮?
将代码片段传递给 content 并使用本机按钮。它的处理程序仍然是应用程序的一部分。
事件样式和时间轴样式有什么区别?
一般槽称为 itemTitle/itemContent/itemRail,本地槽称为 title/content/rail。地方价值观澄清了一般价值观。
titleSpan 是什么意思?
数字是 24 列网格的分数,线条是 CSS 长度。或者,不使用数值。