Skip to content

Timeline 时间轴 ​

按时间或流程顺序展示一组事件节点。

何时使用 ​

  • 操作记录、审批流、发布历史和物流轨迹。
  • 需要事件之间的轴线关系时使用;简单步骤导航用 Steps 步骤条。

在线体验 ​

Timeline 时间轴 · 在线体验真实 Go 组件
在独立页面打开 ↗

查看此场景的 Go 源码 ↗

基本用法 ​

go
import "github.com/tangoui/tango/ui"

func page(c *ui.Context) {
    ui.Timeline(c, []ui.TimelineItem{
        {Content: "创建项目", Time: "09:00", Color: "success"},
        {Content: "提交审核", Time: "10:30", Color: "processing"},
        {Content: "等待发布", Time: "进行中", Hollow: true},
    }).Show()
}

常见用法 ​

交替布局 ​

go
func alternate(c *ui.Context, items []ui.TimelineItem) {
    ui.Timeline(c, items).Mode("alternate").Reverse().Show()
}

横向时间轴 ​

go
func horizontal(c *ui.Context) {
    ui.Timeline(c, []ui.TimelineItem{{Content: "开始"}, {Content: "完成"}}).Horizontal().Show()
}

自定义节点和待处理项 ​

Body 或 Dot 可构建自定义内容,Pending 在末尾追加旋转中的节点。

go
func pending(c *ui.Context) {
    ui.Timeline(c, []ui.TimelineItem{{Content: "已完成"}}).Pending("下一步处理中").Show()
}

主题与样式 ​

Mode 支持 left、right、alternate、start、end;默认键为 mode 和 reverse。颜色状态和空心节点由 Timeline 令牌统一适配三套主题。

注意事项 ​

事件数组顺序就是渲染顺序;实时数据到达时替换外部数组。时间文本要与内容形成可读的语义,不要只用颜色区分状态。

示例代码 ​

以下是上方在线演示运行的 Go 源码(来自官方 gallery),点击标题展开。函数接收的 c *ui.Context 由窗口的 UI 循环每帧传入,接入方式见 Go GUI 入门。

Timeline 时间轴

gallery 演示 Timeline 的 Render 函数,源码 page_data_timeline.go#L11。

加载中…

Timeline v6:标题列、单项位置、加载与实心点

gallery 演示 TimelineAlign 的 Render 函数,源码 page_b2h.go#L81。

加载中…

API ​

签名与说明由 site/tools/compdoc 从 Go 源码和文档注释提取;点击名称跳到 Go API 参考 的对应条目。

入口函数 ​

ui.Timeline ​

go
func Timeline(c *Context, items []TimelineItem) *TimelineW

Timeline starts a timeline; finish with Show.

ConfigProvider.Defaults("Timeline", ...) keys: "mode" ("start" | "end" | "alternate" | "alternate-reverse"; "left" / "right" are the deprecated names of start / end), "reverse" (bool), "orientation" ("vertical" | "horizontal"), "variant" ("outlined" | "filled").

返回 *TimelineW,可链式调用的方法见 TimelineW 方法。

TimelineW 方法 ​

ui.TimelineW:TimelineW shows events along a vertical axis.

方法说明签名
HorizontalHorizontal lays the events out along a horizontal axis (Ant v6 orientation="horizontal"): every event takes an equal share of the width with its dot on the axis.Horizontal() *TimelineW
LayoutLayout applies layout options to the timeline (call after Show).Layout(o ...layout.Option) *TimelineW
ModeMode places the content: "start" (axis at the inline start, content after it; default), "end" (axis at the inline end), "alternate" (content alternates around a centered axis, the first item after it) or "alternate-reverse" (Element: the first item before it).Mode(m string) *TimelineW
OrientationOrientation lays the events out "vertical" (default) or "horizontal" (Ant v6 orientation; same as Horizontal).Orientation(o string) *TimelineW
PendingPending appends a "still in progress" item with a spinning dot.Pending(label string) *TimelineW
ReverseReverse lists the items in reverse order.Reverse() *TimelineW
ShowShow builds the timeline.Show() *TimelineW
TitleSpanTitleSpan sets the share of the width, in 24ths, taken by the titles of a vertical timeline whose items have a Title (Ant titleSpan; default 12, the axis in the middle).TitleSpan(span float32) *TimelineW
VariantVariant sets the dots: "outlined" (a ring, Ant's default) or "filled" (a solid dot, the Element and shadcn default).Variant(v string) *TimelineW

TimelineItem 参数类型 ​

ui.TimelineItem:TimelineItem is one event of a Timeline.

字段说明类型
Contentmain text (Ant v6 content)string
Bodycustom content (replaces Content)func()
TitleTitle is the text on the opposite side of the axis (Ant v6 title); any item with a Title centers the axis of a vertical timeline.string
LabelDeprecated: use Title.string
TimeElement: timestamp under (or above) the contentstring
TimeTopput Time above the contentbool
ColorColor is a status ("primary", "success", "warning", "error", "info", "gray") or a hex color; empty uses the theme default.string
DotIconicon instead of the circle*icon.Icon
Dotfully custom dot nodefunc()
HollowElement: hollow dotbool
LargeElement: larger dotbool
PlacementPlacement puts this item's content at the "start" or "end" side, overriding the Mode (Ant v6 items[].placement).string
LoadingLoading shows a spinning dot (Ant v6 items[].loading); the axis entering it (leaving it under Reverse) is dotted where the theme's TimelineToken.BusyTailDashed says so.bool
CenterCenter centers the dot vertically on the item (Element center).bool

相关链接 ​

以 MIT 许可发布