feat: timeline component

This commit is contained in:
Timi
2026-11-13 14:04:20 +08:00
parent 214263f78f
commit bed8b65092
7 changed files with 199 additions and 0 deletions
+5
View File
@@ -16,6 +16,7 @@ import NotifyView from "./notify-view";
import BottomPopup from "./bottom-popup";
import AttachmentSelector from "./attachment-selector";
import Space from "./space";
import { Timeline, TimelineItem } from "./timeline";
import CardContainer from "./card-container";
import {
AiChatComposer,
@@ -42,6 +43,8 @@ export default [
BottomPopup,
AttachmentSelector,
Space,
Timeline,
TimelineItem,
CardContainer,
AiChatComposer,
AiChatMessageList,
@@ -67,6 +70,8 @@ export {
BottomPopup,
AttachmentSelector,
Space,
Timeline,
TimelineItem,
CardContainer,
AiChatComposer,
AiChatMessageList,
+6
View File
@@ -0,0 +1,6 @@
import { WebToolkit } from "timi-web";
import timeline from "./index.vue";
import item from "./item.vue";
export const Timeline = WebToolkit.withInstall(timeline);
export const TimelineItem = WebToolkit.withInstall(item);
+73
View File
@@ -0,0 +1,73 @@
<template>
<div class="t-timeline" :class="{ horizontal: layout === 'horizontal', reverse }">
<slot />
</div>
</template>
<script setup lang="ts">
defineOptions({ name: "TTimeline" });
withDefaults(defineProps<{ layout?: "vertical" | "horizontal"; reverse?: boolean }>(), {
layout: "vertical",
reverse: false
});
</script>
<style lang="less">
.t-timeline {
display: flex;
flex-direction: column;
&.reverse {
flex-direction: column-reverse;
}
&.horizontal {
flex-direction: row;
&.reverse {
flex-direction: row-reverse;
}
.t-timeline-item {
flex: 1;
padding: var(--t-timeline-horizontal-offset, 1.5rem) var(--t-timeline-horizontal-gap, .75rem) 0 0;
}
.t-timeline-item::before {
top: calc((var(--t-timeline-dot-size, .5rem) - var(--t-timeline-line-width, 2px)) / 2);
left: calc(var(--t-timeline-dot-size, .5rem) + var(--t-timeline-line-gap, .25rem));
width: calc(100% - var(--t-timeline-dot-size, .5rem) - var(--t-timeline-line-gap, .25rem) - var(--t-timeline-line-gap, .25rem));
height: var(--t-timeline-line-width, 2px);
}
.t-timeline-item .dot {
top: 0;
}
}
.t-timeline-item {
position: relative;
padding: 0 0 var(--t-timeline-item-gap, 1rem) var(--t-timeline-content-offset, 1rem);
&::before {
position: absolute;
top: calc(1lh / 2 + var(--t-timeline-dot-size, .5rem) / 2 + var(--t-timeline-line-gap, .25rem));
bottom: calc(var(--t-timeline-dot-size, .5rem) / 2 + var(--t-timeline-line-gap, .25rem) - 1lh / 2);
left: calc((var(--t-timeline-dot-size, .5rem) - var(--t-timeline-line-width, 2px)) / 2);
width: var(--t-timeline-line-width, 2px);
content: "";
background: var(--t-timeline-line-color, var(--td-component-border, #ddd));
}
&:last-child::before {
display: none;
}
}
&.reverse .t-timeline-item:last-child::before {
display: block;
}
&.reverse .t-timeline-item:first-child::before {
display: none;
}
}
</style>
+58
View File
@@ -0,0 +1,58 @@
<template>
<div class="t-timeline-item" @click="onClick">
<span class="dot" :style="{ color: color }">
<slot name="dot" />
</span>
<div v-if="label || $slots.label" class="label">
<slot name="label">
<span v-text="label" />
</slot>
</div>
<div>
<slot name="content">
<slot>
<span v-text="content" />
</slot>
</slot>
</div>
</div>
</template>
<script setup lang="ts">
import { computed } from "vue";
defineOptions({ name: "TTimelineItem" });
const props = withDefaults(defineProps<{
label?: string;
content?: string;
dotColor?: string
}>(), { dotColor: "primary" });
const emit = defineEmits<{ click: [context: { e: MouseEvent; item: typeof props }] }>();
const colors: Record<string, string> = {
primary: "var(--td-brand-color, #0052d9)",
warning: "#ed7b2f",
error: "#d54941",
default: "#bbb"
};
const color = computed(() => colors[props.dotColor] ?? props.dotColor);
function onClick(e: MouseEvent): void {
emit("click", { e, item: props });
}
</script>
<style lang="less" scoped>
.dot {
position: absolute;
top: calc((1lh - var(--t-timeline-dot-size, .5rem)) / 2);
left: 0;
width: var(--t-timeline-dot-size, .5rem);
height: var(--t-timeline-dot-size, .5rem);
border: var(--t-timeline-dot-border-width, 2px) solid currentColor;
box-sizing: border-box;
background: var(--t-timeline-dot-background, var(--td-bg-color-container, #fff));
border-radius: 50%;
}
.label {
color: var(--t-timeline-label-color, var(--td-text-color-secondary, #777));
}
</style>