Todo List
展示带展开详情和明确任务状态的工作条目序列。
适用场景
- 当界面需要以下行为时使用 Todo List:展示带展开详情和明确任务状态的工作条目序列。
安装
选择安装方式,用法示例将同步更新导入路径。
$ bunx --bun shadcn-vue@2.8.2 add https://orvui.efu.me/r/todo-list.json
首次使用时,将安装的 src/components/orvui/styles.css 导入项目样式入口。
示例
预览
packages/vue/src/agents/todo-list/demo.vue
<script setup lang="ts">
import { onBeforeUnmount, onMounted, ref, computed } from "vue";
import { RotateCcw } from "lucide-vue-next";
import { TodoList, type TodoItem } from "@/components/orvui/agents/todo-list";
const tasks = [
"Inspect the current data flow",
"Update the response schema",
"Add coverage for edge cases",
"Run checks and prepare the result",
];
const step = ref(0),
run = ref(0);
const items = computed<TodoItem[]>(() =>
tasks.map((title, index) => {
const progress = step.value - index * 4;
const active = progress >= 0 && progress < 4;
return {
id: `task-${index}`,
title,
status: progress >= 4 ? "completed" : active ? "in-progress" : "pending",
progress: active ? (progress + 1) * 25 : undefined,
detail: active ? `${(progress + 1) * 25}%` : undefined,
};
}),
);
let epoch = 0;
const scheduledTasks = new Set<ReturnType<typeof setTimeout>>();
function cancel() {
epoch++;
scheduledTasks.forEach(clearTimeout);
scheduledTasks.clear();
}
function later(milliseconds: number, task: () => void) {
const version = epoch;
const handle = setTimeout(() => {
scheduledTasks.delete(handle);
if (version === epoch) task();
}, milliseconds);
scheduledTasks.add(handle);
}
onBeforeUnmount(cancel);
function replay() {
cancel();
run.value++;
step.value = 0;
for (let tick = 1; tick <= tasks.length * 4; tick++)
later(tick * 280, () => {
step.value = tick;
});
}
onMounted(replay);
</script>
<template>
<div class="relative h-[330px] w-full max-w-lg">
<TodoList :key="run" :items="items" title="Implementation plan" /><button
type="button"
@click="replay"
class="absolute bottom-0 left-0 inline-flex items-center gap-1.5 rounded-full px-2 py-1 text-xs font-medium text-muted-foreground outline-none transition-colors hover:bg-muted hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring"
>
<RotateCcw class="size-3" />Replay
</button>
</div>
</template>
packages/vue/src/agents/todo-list/src/TodoList.vue
组合结构
使用公开部件 TodoList 组合 Todo List,并从该组件的公开入口导入。
Message
└── MessageContent
└── TodoList说明: Agent Activity 将持续变化的助手活动组织为可展开步骤与完成摘要。 Agent Loading States 通过进度、推理和微光显示传达助手工作仍在进行。 Tool Result 在同一表面呈现工具调用状态、摘要与可展开结果。
工作方式
展示带展开详情和明确任务状态的工作条目序列。
状态与事件
需要由表单、路由或父组件管理时,绑定下列状态并接收对应更新。v-model 是属性与 update 事件的简写;值的类型应与 API 一致。
| 组件 | Vue 绑定 | 更新事件 |
|---|---|---|
TodoList | v-model:openboolean | update:open |
可选受控属性未传入时,按组件文档的默认行为工作;不要用固定的 false 或空值代替未传入。异步请求和持久化在应用中处理,再把结果传回组件。
API 参考
itemsTodoItem[]—title?boolean | null | string | number | void | VNode<RendererNode, RendererElement, { [key: string]: any; }> | VNodeArrayChildren | ComponentOptions<any, any, any, ComputedOptions, MethodOptions, any, any, any, string, {}, {}, string, {}, {}, {}, string, ComponentProvideOptions> | FunctionalComponent<any, {}, any, {}> | ComponentPublicInstanceConstructor<any, any, any, any, ComputedOptions, MethodOptions>"To-dos"open?booleanundefineddefaultOpen?booleantruecollapseOnComplete?booleantruemaxHeight?number248事件
update:open[open: boolean]@update:openopenChange[open: boolean]@openChange无障碍
为交互控件提供明确的无障碍名称。保留文档中的键盘路径、可见焦点与减少动态效果状态;自定义插槽应继续保留所替代部件的语义。
常见问题
- 如何配置 Todo List?
- 通过 items、title、open、defaultOpen、collapseOnComplete、maxHeight 配置 Todo List;API 表列出其类型与默认值。
- 如何连接到应用状态?
- 监听 update:open、openChange,将组件连接到应用状态。
- 可以在服务端渲染吗?
- 可以在 Vue SSR 应用中正常渲染。服务端与客户端的初始 props 应保持一致;浏览器测量与交互资源在挂载后启动。
更新于
来源与许可 ↗MIT · 0.1.1