Timeline 时间线
可视化地呈现时间流信息。
基础用法
Timeline 可拆分成多个按照时间戳排列的活动,时间戳是其区分于其他控件的重要特征,使用时注意与 Steps 步骤条等区分。
export function TimelineBasic() { return ( <ElTimeline> {activities.map((activity) => ( <ElTimelineItem key={activity.timestamp} timestamp={activity.timestamp}> {activity.content} </ElTimelineItem> ))} </ElTimeline> );}
Mode 2.13.1
使用 mode 来控制时间线与内容的相对位置。
在 2.13.1 之后,el-timeline 显式设置了内边距样式。如果您在项目中覆盖了 ul 标签的填充样式,请检查以确保布局正确。
export function TimelineMode() { const [mode, setMode] = useState<TimelineMode>("start"); return ( <div> <ElRadioGroup type="button" value={mode} onChange={(value) => setMode(value as TimelineMode)} > <ElRadio value="start">start</ElRadio> <ElRadio value="alternate">alternate</ElRadio> <ElRadio value="alternate-reverse">alternate-reverse</ElRadio> <ElRadio value="end">end</ElRadio> </ElRadioGroup> <ElTimeline mode={mode} style={timelineSpacing}> {activities.map((activity) => ( <ElTimelineItem key={activity.timestamp} timestamp={activity.timestamp}> {activity.content} </ElTimelineItem> ))} </ElTimeline> </div> );}
⾃定义节点样式
可根据实际场景⾃定义节点尺⼨、颜⾊,或直接使⽤图标。
Custom icon
2018-04-12 20:46
Custom color
2018-04-03 20:46
Custom size
2018-04-03 20:46
Custom hollow
2018-04-03 20:46
Default node
2018-04-03 20:46
export function TimelineCustomNode() { return ( <ElTimeline> {customActivities.map((activity) => ( <ElTimelineItem key={activity.content} timestamp={activity.timestamp} icon={activity.icon} type={activity.type} color={activity.color} size={activity.size} hollow={activity.hollow} > {activity.content} </ElTimelineItem> ))} </ElTimeline> );}
⾃定义时间戳
当内容在垂直⽅向上过⾼时,可将时间戳置于内容之上。
2018/4/12
Update Github template
Tom committed 2018/4/12 20:46
2018/4/3
Update Github template
Tom committed 2018/4/3 20:46
2018/4/2
Update Github template
Tom committed 2018/4/2 20:46
export function TimelineCustomTimestamp() { return ( <ElTimeline> {[ { timestamp: "2018/4/12", name: "Tom committed 2018/4/12 20:46" }, { timestamp: "2018/4/3", name: "Tom committed 2018/4/3 20:46" }, { timestamp: "2018/4/2", name: "Tom committed 2018/4/2 20:46" }, ].map((item) => ( <ElTimelineItem key={item.timestamp} timestamp={item.timestamp} placement="top"> <ElCard> <h4 style={cardTitle}>Update Github template</h4> <p style={cardBody}>{item.name}</p> </ElCard> </ElTimelineItem> ))} </ElTimeline> );}
垂直居中
2018/4/12
Update Github template
Tom committed 2018/4/12 20:46
2018/4/3
Update Github template
Tom committed 2018/4/3 20:46
export function TimelineCenter() { return ( <ElTimeline> <ElTimelineItem center timestamp="2018/4/12" placement="top"> <ElCard> <h4 style={cardTitle}>Update Github template</h4> <p style={cardBody}>Tom committed 2018/4/12 20:46</p> </ElCard> </ElTimelineItem> <ElTimelineItem timestamp="2018/4/3" placement="top"> <ElCard> <h4 style={cardTitle}>Update Github template</h4> <p style={cardBody}>Tom committed 2018/4/3 20:46</p> </ElCard> </ElTimelineItem> <ElTimelineItem center timestamp="2018/4/2" placement="top"> Event start </ElTimelineItem> <ElTimelineItem timestamp="2018/4/2" placement="top"> Event end </ElTimelineItem> </ElTimeline> );}
反向 2.11.9
export function TimelineReverse() { const [reverse, setReverse] = useState(true); return ( <div> <ElSwitch checked={reverse} activeText="reverse" onCheckedChange={setReverse} /> <ElTimeline reverse={reverse} style={{ marginTop: 8 }}> {activities.map((activity) => ( <ElTimelineItem key={activity.timestamp} timestamp={activity.timestamp}> {activity.content} </ElTimelineItem> ))} </ElTimeline> </div> );}
Timeline API
Timeline Attributes
| 属性名 | 说明 | 类型 | 默认值 |
|---|
| mode | 时间线与内容的相对位置 | enum | start |
| reverse | 是否反向排列子项 | boolean | false |
| className / style | 根节点类名与样式 | string / CSSProperties | — |
Timeline Events
无。
Timeline Slots
| 插槽名 | 说明 | React 写法 |
|---|
| default | 时间线子项 | children(ElTimelineItem 集合) |
Exposes
无。
Timeline-Item API
Timeline-Item Attributes
| 属性名 | 说明 | 类型 | 默认值 |
|---|
| timestamp | 时间戳内容 | ReactNode | '' |
| hideTimestamp | 是否隐藏时间戳 | boolean | false |
| center | 内容是否居中 | boolean | false |
| placement | 时间戳相对内容的位置 | enum | bottom |
| type | 节点类型 | enum | '' |
| color | 节点颜色,传入后覆盖 type 的配色 | string | '' |
| size | 节点尺寸 | enum | normal |
| icon | 自定义节点图标(渲染在 node 内) | ReactNode | — |
| dot | 完全自定义节点内容,等价官方 dot 插槽 | ReactNode | — |
| hollow | 是否空心节点 | boolean | false |
| className | 自定义类名 | string | — |
Timeline-Item Events
无。
Timeline-Item Slots
| 插槽名 | 说明 | React 写法 |
|---|
| default | 自定义内容 | children |
| dot | 自定义节点 | dot 属性 |
Exposes
无。