iter(g174): 时间线支持双侧交替

This commit is contained in:
HIsheR
2026-10-26 16:21:48 +08:00
parent 7084fe1feb
commit 2316445b1e
7 changed files with 63 additions and 12 deletions
+6 -2
View File
@@ -11,10 +11,14 @@ function node(item: TimelineItem, pending: boolean): HTMLElement {
return h('li', { class: `ua-tl-item${pending ? ' is-pending' : ''}` }, dot, h('div', { class: 'ua-tl-body' }, head, body));
}
/*** 时间线:纵向事件流,mode 决定轴线在左还是在右;pending 为真时末尾补一个进行中节点 ***/
/*** 时间线:纵向事件流,mode 决定轴线在左 / 右 / 双侧交替;pending 为真时末尾补一个进行中节点 ***/
export function timeline(props: TimelineProps): HTMLElement {
const rows: TimelineItem[] = [...props.items]; // 复制入参,避免改动调用方数组
if (props.pending) rows.push({ title: '进行中…' }); // 尾部虚节点表示流程尚未结束
const items = rows.map((row, i) => node(row, !!props.pending && i === rows.length - 1));
const items = rows.map((row, i) => {
const el = node(row, !!props.pending && i === rows.length - 1);
if (props.mode === 'alternate') el.classList.add(i % 2 ? 'is-right' : 'is-left'); // 交替排布:奇偶决定左右,轴线由样式表居中
return el;
});
return h('ol', { class: `ua-tl ua-tl-${props.mode ?? 'left'}` }, ...items);
}
+1 -1
View File
@@ -435,7 +435,7 @@ export interface TimelineItem {
/*** 时间线入参 ***/
export interface TimelineProps {
items: TimelineItem[]; // 条目列表,按时间顺序自上而下
mode?: 'left' | 'right'; // 轴线与节点所在侧;缺省 left(内容在右)
mode?: 'left' | 'right' | 'alternate'; // 轴线位置:left / right 单侧,alternate 双侧交替(轴线居中,窄屏自动退回左侧);缺省 left
pending?: boolean; // 末尾追加「进行中」虚线节点,表示流程未结束;缺省 false
}