# Timeline

> 展示审批、操作历史与协作动态，支持状态节点、时间侧列、逆序和内容组合。

网页来源：/components/timeline

版本：@quirekit/ui 0.3.1；源码修订：d79a6b48d00e+worktree。此文档对应当前源码构建，接入方式以开始使用为准。

接入前置：[开始使用](/raw/components/getting-started.md)（Vue、样式、主题与图标 Provider）。

按时间阅读一组记录。`items` 中每项提供唯一 `key` 和 `title`，`description` 补充说明。事件排序、时间格式化和业务操作由调用方处理；需要引导用户完成可切换步骤时使用 [Steps](/raw/components/steps.md)。

## 基本用法

默认按 `items` 顺序展示纵向记录，`label` 为有序列表提供可访问名称。省略状态时使用中性空心圆环，文字和图片内容均可自然撑开条目。

### 示例：timeline/basic

文件：`basic.vue`

```vue
<script setup lang="ts">
import { QuireTimeline } from '@quirekit/ui/vue';
import { records } from './data';
</script>

<template>
  <div class="p-qk-surface" data-timeline-basic>
    <QuireTimeline :items="records" label="项目计划操作历史" />
  </div>
</template>
```

文件：`data.ts`

```ts
import type { QuireKitTimelineItem } from '@quirekit/ui/vue';

/** Stable example records; display labels and machine-readable times are host-owned. */
export const records: readonly QuireKitTimelineItem[] = [
  { key: 'created', title: '创建项目计划', time: '09:10', dateTime: '2026-09-12T09:10:00+08:00', description: '林溪创建了项目计划，整理交付范围和里程碑。' },
  { key: 'updated', title: '更新评审内容', time: '10:25', dateTime: '2026-09-12T10:25:00+08:00', description: '补充了协作分工与验收标准。' },
  { key: 'shared', title: '分享给项目组', time: '11:40', dateTime: '2026-09-12T11:40:00+08:00', description: '项目成员可以查看和批注。' }
];
```

## 状态与审批记录

`status` 支持 `neutral`、`info`、`success`、`warning`、`danger`，同时提供状态图形与文字；`statusLabel` 替换为“审核中”“待修改”等实际文案。传入空字符串可隐藏状态标签，此时标题或说明应表达完整含义。

下面的按钮由页面更新审批数据，Timeline 展示结果。它不会发送请求或把记录当作可点击步骤。

### 示例：timeline/status

文件：`status.vue`

```vue
<script setup lang="ts">
import { computed, ref } from 'vue';
import { QuireButton, QuireTimeline, type QuireKitTimelineItem } from '@quirekit/ui/vue';

const decision = ref<'pending' | 'approved' | 'returned'>('pending');
const items = computed<QuireKitTimelineItem[]>(() => [
  { key: 'submit', title: '林溪提交发布申请', time: '09:10', status: 'success', statusLabel: '已提交' },
  { key: 'supplement', title: '校验发现附件缺失', time: '09:30', status: 'warning', statusLabel: '需补充', description: '当时缺少验收记录，申请人补齐后进入下一次评审。' },
  { key: 'review', title: '陈宇审核发布内容', time: '10:00', status: decision.value === 'pending' ? 'info' : 'success', icon: decision.value === 'pending' ? 'clock' : 'check',
    statusLabel: decision.value === 'pending' ? '审核中' : '已审核', description: '核对发布范围、附件和成员权限。' },
  ...(decision.value === 'pending' ? [] : [{ key: 'result', title: decision.value === 'approved' ? '发布申请通过' : '发布申请退回',
    time: '10:15', status: decision.value === 'approved' ? 'success' as const : 'danger' as const,
    statusLabel: decision.value === 'approved' ? '已通过' : '待修改',
    description: decision.value === 'approved' ? '项目计划已向团队开放。' : '请补充发布说明，再次提交评审。' }])
]);
</script>

<template>
  <div class="grid gap-qk-group p-qk-surface" data-timeline-status>
    <QuireTimeline :items="items" label="项目计划发布审批记录" />
    <div class="flex flex-wrap gap-qk-inline">
      <QuireButton variant="solid" color="primary" @click="decision = 'approved'">通过申请</QuireButton>
      <QuireButton variant="outline" @click="decision = 'returned'">退回修改</QuireButton>
      <QuireButton variant="outline" @click="decision = 'pending'">重置示例</QuireButton>
    </div>
    <p class="m-0 text-qk-helper text-qk-text-secondary" role="status">{{ decision === 'pending' ? '等待审核结果' : decision === 'approved' ? '已记录通过结果' : '已记录退回原因' }}</p>
  </div>
</template>
```

## 时间位置与密度

`time` 是已格式化的显示文案；`dateTime` 可选，填写带时区的 ISO 时间或合法的 HTML 日期值，生成原生 `<time datetime>`。“刚刚”“待安排”等文案可只传 `time`，不会自动解析。

`timePosition="aside"` 在容器达到 32rem 时将时间放到侧列，窄容器自动回到标题上方。`timeWidth` 设置侧列宽度，最大占容器 30%；`density="compact"` 收紧记录间距与字阶，内部按钮继续使用自己的尺寸。文字方向继承容器的 `dir`。

### 示例：timeline/time

文件：`time.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireButton, QuireTimeline } from '@quirekit/ui/vue';
import { records } from './data';

const compact = ref(false);
const narrow = ref(false);
const rtl = ref(false);
const items = records.map(item => ({
  ...item,
  time: `2026-09-12 ${item.time}`,
  icon: item.key === 'updated' ? 'edit' : undefined
}));
</script>

<template>
  <div class="grid gap-qk-group p-qk-surface" data-timeline-time>
    <div class="flex flex-wrap gap-qk-inline">
      <QuireButton variant="outline" :aria-pressed="compact" @click="compact = !compact">{{ compact ? '常规密度' : '紧凑密度' }}</QuireButton>
      <QuireButton variant="outline" :aria-pressed="narrow" @click="narrow = !narrow">{{ narrow ? '恢复宽容器' : '使用窄容器' }}</QuireButton>
      <QuireButton variant="outline" :aria-pressed="rtl" @click="rtl = !rtl">{{ rtl ? '从左向右' : '从右向左' }}</QuireButton>
    </div>
    <div :style="{ maxWidth: narrow ? '300px' : undefined }" :dir="rtl ? 'rtl' : 'ltr'" data-timeline-container>
      <QuireTimeline :items="items" label="按时间查看项目记录" time-position="aside" time-width="11em" :density="compact ? 'compact' : 'regular'" />
    </div>
  </div>
</template>
```

文件：`data.ts`

```ts
import type { QuireKitTimelineItem } from '@quirekit/ui/vue';

/** Stable example records; display labels and machine-readable times are host-owned. */
export const records: readonly QuireKitTimelineItem[] = [
  { key: 'created', title: '创建项目计划', time: '09:10', dateTime: '2026-09-12T09:10:00+08:00', description: '林溪创建了项目计划，整理交付范围和里程碑。' },
  { key: 'updated', title: '更新评审内容', time: '10:25', dateTime: '2026-09-12T10:25:00+08:00', description: '补充了协作分工与验收标准。' },
  { key: 'shared', title: '分享给项目组', time: '11:40', dateTime: '2026-09-12T11:40:00+08:00', description: '项目成员可以查看和批注。' }
];
```

## 自定义节点与内容

`icon` 使用已注册图标。`indicator` 插槽使用 24px 的节点区域，可放 `size="xs"` 的 [Avatar](/raw/components/avatar.md) 或同尺寸的装饰节点，让连接线与图形保持间距。交互操作放入 `content` 插槽，保留正常的按钮焦点与键盘行为。`time`、`title`、`description` 插槽分别定制对应区域，所有条目插槽提供 `item` 和原数组 `index`。

### 示例：timeline/content

文件：`content.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireAvatar, QuireButton, QuireTimeline, type QuireKitTimelineItem } from '@quirekit/ui/vue';

const expanded = ref(false);
const items: readonly QuireKitTimelineItem[] = [
  { key: 'lin', title: '林溪上传了评审稿', time: '昨天 14:20', description: '项目计划 · 第二版' },
  { key: 'chen', title: '陈宇添加了评审意见', time: '今天 09:30', description: '补充了交付节奏与验收要求。' }
];
</script>

<template>
  <div class="p-qk-surface" data-timeline-content>
    <QuireTimeline :items="items" label="团队协作动态">
      <template #indicator="{ item }"><QuireAvatar :name="item.key === 'lin' ? '林溪' : '陈宇'" size="xs" /></template>
      <template #content="{ item }">
        <div v-if="item.key === 'chen'" class="grid justify-items-start gap-qk-inline">
          <QuireButton variant="outline" :aria-expanded="expanded" @click="expanded = !expanded">{{ expanded ? '收起评审意见' : '查看评审意见' }}</QuireButton>
          <p v-if="expanded" class="m-0 text-qk-text-secondary">建议先明确试点团队的反馈窗口，再安排正式发布，避免验收与上线时间重叠。</p>
        </div>
      </template>
    </QuireTimeline>
  </div>
</template>
```

## 逆序、长内容与空数据

`reverse` 反转展示和读屏顺序，不修改传入数组。连续字符和长说明会换行。空数组显示跟随 [Locale Provider](/raw/components/locale-provider.md) 语言的空状态文案，也可通过 `empty` 插槽组合 [EmptyState](/raw/components/empty-state.md)；不会生成虚构节点。

### 示例：timeline/order

文件：`order.vue`

```vue
<script setup lang="ts">
import { ref } from 'vue';
import { QuireButton, QuireEmptyState, QuireTimeline } from '@quirekit/ui/vue';
import { records } from './data';

const reverse = ref(true);
const empty = ref(false);
const items = [...records, { key: 'literal', title: '<document status="review" />', time: '待安排',
  description: 'document-review-2026-09-12-team-product-design-engineering-quality-assurance-final-record', icon: 'fileText' }];
</script>

<template>
  <div class="grid gap-qk-group p-qk-surface" data-timeline-order>
    <div class="flex flex-wrap gap-qk-inline">
      <QuireButton variant="outline" :aria-pressed="reverse" @click="reverse = !reverse">{{ reverse ? '最早记录在前' : '最新记录在前' }}</QuireButton>
      <QuireButton variant="outline" @click="empty = !empty">{{ empty ? '恢复记录' : '清空记录' }}</QuireButton>
    </div>
    <QuireTimeline :items="empty ? [] : items" :reverse="reverse" label="完整操作记录">
      <template #empty><QuireEmptyState title="暂无操作记录" description="此文档产生操作后，记录会显示在这里。" /></template>
    </QuireTimeline>
  </div>
</template>
```

文件：`data.ts`

```ts
import type { QuireKitTimelineItem } from '@quirekit/ui/vue';

/** Stable example records; display labels and machine-readable times are host-owned. */
export const records: readonly QuireKitTimelineItem[] = [
  { key: 'created', title: '创建项目计划', time: '09:10', dateTime: '2026-09-12T09:10:00+08:00', description: '林溪创建了项目计划，整理交付范围和里程碑。' },
  { key: 'updated', title: '更新评审内容', time: '10:25', dateTime: '2026-09-12T10:25:00+08:00', description: '补充了协作分工与验收标准。' },
  { key: 'shared', title: '分享给项目组', time: '11:40', dateTime: '2026-09-12T11:40:00+08:00', description: '项目成员可以查看和批注。' }
];
```

## API

### QuireTimeline

#### Props

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| items | 是 | — | Events in the order chosen by the host. |
| label | 否 | — | Accessible name of the event list; defaults to the language pack. |
| reverse | 否 | false | Reverse the rendered and accessible reading order without mutating items. |
| density | 否 | "regular" | Record spacing and typography, independent of nested control size. Defaults to regular. |
| timePosition | 否 | "inline" | Place time above the title or in a separate column when the container is at least 32rem. |
| timeWidth | 否 | "9em" | Preferred aside time width, capped at 30% of the container. Defaults to 9em. |

**items**

```ts
readonly QuireKitTimelineItem[]
```

```ts
readonly ({
  /** Unique identity retained when records are inserted or reordered. */
  key: string;
  /** Human-readable event heading. */
  title: string;
  /** Supporting detail, rendered as literal text. */
  description?: undefined | string;
  /** Already formatted time label; the component does not choose a locale or time zone. */
  time?: string | undefined;
  /** Valid HTML datetime value, supplied separately from the display label. */
  dateTime?: string | undefined;
  /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
  status?: undefined | "neutral" | "info" | "success" | "warning" | "danger";
  /** Override the status text; an empty string intentionally hides it. */
  statusLabel?: string | undefined;
  /** Registered decorative icon name; the indicator slot takes precedence. */
  icon?: string | undefined;
})[]
```

**label**

```ts
string | undefined
```

```ts
undefined | string
```

**reverse**

```ts
boolean | undefined
```

**density**

```ts
"regular" | "compact" | undefined
```

```ts
undefined | "regular" | "compact"
```

**timePosition**

```ts
"inline" | "aside" | undefined
```

```ts
undefined | "inline" | "aside"
```

**timeWidth**

```ts
string | undefined
```

```ts
undefined | string
```

#### Events

无。

#### Slots

| 名称 | 必填 | 默认值 | 说明 |
| --- | --- | --- | --- |
| indicator | 否 | — | Decorative content for the 24px node area, such as an xs Avatar; keep interactive controls in content. |
| time | 否 | — | Display label within the native time element when dateTime is provided. |
| title | 否 | — | Event heading content. |
| description | 否 | — | Supporting event description. |
| content | 否 | — | Additional details and host-owned actions below the description. |
| empty | 否 | — | Empty-list content; no fake event is inserted. |

**indicator**

```ts
QuireKitTimelineItemContext
```

```ts
{
  /** Original event object. */
  item: {
    /** Unique identity retained when records are inserted or reordered. */
    key: string;
    /** Human-readable event heading. */
    title: string;
    /** Supporting detail, rendered as literal text. */
    description?: undefined | string;
    /** Already formatted time label; the component does not choose a locale or time zone. */
    time?: string | undefined;
    /** Valid HTML datetime value, supplied separately from the display label. */
    dateTime?: string | undefined;
    /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
    status?: undefined | "neutral" | "info" | "success" | "warning" | "danger";
    /** Override the status text; an empty string intentionally hides it. */
    statusLabel?: string | undefined;
    /** Registered decorative icon name; the indicator slot takes precedence. */
    icon?: string | undefined;
  };
  /** Index in the original items array. */
  index: number;
}
```

**time**

```ts
QuireKitTimelineItemContext
```

```ts
{
  /** Original event object. */
  item: {
    /** Unique identity retained when records are inserted or reordered. */
    key: string;
    /** Human-readable event heading. */
    title: string;
    /** Supporting detail, rendered as literal text. */
    description?: undefined | string;
    /** Already formatted time label; the component does not choose a locale or time zone. */
    time?: string | undefined;
    /** Valid HTML datetime value, supplied separately from the display label. */
    dateTime?: string | undefined;
    /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
    status?: undefined | "neutral" | "info" | "success" | "warning" | "danger";
    /** Override the status text; an empty string intentionally hides it. */
    statusLabel?: string | undefined;
    /** Registered decorative icon name; the indicator slot takes precedence. */
    icon?: string | undefined;
  };
  /** Index in the original items array. */
  index: number;
}
```

**title**

```ts
QuireKitTimelineItemContext
```

```ts
{
  /** Original event object. */
  item: {
    /** Unique identity retained when records are inserted or reordered. */
    key: string;
    /** Human-readable event heading. */
    title: string;
    /** Supporting detail, rendered as literal text. */
    description?: undefined | string;
    /** Already formatted time label; the component does not choose a locale or time zone. */
    time?: string | undefined;
    /** Valid HTML datetime value, supplied separately from the display label. */
    dateTime?: string | undefined;
    /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
    status?: undefined | "neutral" | "info" | "success" | "warning" | "danger";
    /** Override the status text; an empty string intentionally hides it. */
    statusLabel?: string | undefined;
    /** Registered decorative icon name; the indicator slot takes precedence. */
    icon?: string | undefined;
  };
  /** Index in the original items array. */
  index: number;
}
```

**description**

```ts
QuireKitTimelineItemContext
```

```ts
{
  /** Original event object. */
  item: {
    /** Unique identity retained when records are inserted or reordered. */
    key: string;
    /** Human-readable event heading. */
    title: string;
    /** Supporting detail, rendered as literal text. */
    description?: undefined | string;
    /** Already formatted time label; the component does not choose a locale or time zone. */
    time?: string | undefined;
    /** Valid HTML datetime value, supplied separately from the display label. */
    dateTime?: string | undefined;
    /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
    status?: undefined | "neutral" | "info" | "success" | "warning" | "danger";
    /** Override the status text; an empty string intentionally hides it. */
    statusLabel?: string | undefined;
    /** Registered decorative icon name; the indicator slot takes precedence. */
    icon?: string | undefined;
  };
  /** Index in the original items array. */
  index: number;
}
```

**content**

```ts
QuireKitTimelineItemContext
```

```ts
{
  /** Original event object. */
  item: {
    /** Unique identity retained when records are inserted or reordered. */
    key: string;
    /** Human-readable event heading. */
    title: string;
    /** Supporting detail, rendered as literal text. */
    description?: undefined | string;
    /** Already formatted time label; the component does not choose a locale or time zone. */
    time?: string | undefined;
    /** Valid HTML datetime value, supplied separately from the display label. */
    dateTime?: string | undefined;
    /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
    status?: undefined | "neutral" | "info" | "success" | "warning" | "danger";
    /** Override the status text; an empty string intentionally hides it. */
    statusLabel?: string | undefined;
    /** Registered decorative icon name; the indicator slot takes precedence. */
    icon?: string | undefined;
  };
  /** Index in the original items array. */
  index: number;
}
```

**empty**

```ts
any
```

#### 公开实例成员

无。

#### 相关类型

```ts
type QuireKitTimelineItem = {
  /** Unique identity retained when records are inserted or reordered. */
  key: string;
  /** Human-readable event heading. */
  title: string;
  /** Supporting detail, rendered as literal text. */
  description?: undefined | string;
  /** Already formatted time label; the component does not choose a locale or time zone. */
  time?: string | undefined;
  /** Valid HTML datetime value, supplied separately from the display label. */
  dateTime?: string | undefined;
  /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
  status?: undefined | "neutral" | "info" | "success" | "warning" | "danger";
  /** Override the status text; an empty string intentionally hides it. */
  statusLabel?: string | undefined;
  /** Registered decorative icon name; the indicator slot takes precedence. */
  icon?: string | undefined;
};
```

```ts
type QuireKitTimelineItemContext = {
  /** Original event object. */
  item: {
    /** Unique identity retained when records are inserted or reordered. */
    key: string;
    /** Human-readable event heading. */
    title: string;
    /** Supporting detail, rendered as literal text. */
    description?: string | undefined;
    /** Already formatted time label; the component does not choose a locale or time zone. */
    time?: string | undefined;
    /** Valid HTML datetime value, supplied separately from the display label. */
    dateTime?: string | undefined;
    /** Semantic indicator and default status label; omission renders a neutral ring without a label. */
    status?: QuireKitTimelineStatus | undefined;
    /** Override the status text; an empty string intentionally hides it. */
    statusLabel?: string | undefined;
    /** Registered decorative icon name; the indicator slot takes precedence. */
    icon?: string | undefined;
  };
  /** Index in the original items array. */
  index: number;
};
```
