Kits
TaskList
Floating agent task progress pill above the composer that expands into the full task list.
Composition
Expandable task progress
Trigger and item children can be omitted to use their built-in content.
- <TaskList>
- <TaskListTrigger>
- <TaskListIndicator />
- <TaskListProgress />
- <TaskListLabel />
- <TaskListContent>
- <TaskListItem>
- <TaskListIndicator />
- <TaskListItem>
- <TaskListTrigger>
Installation
Use this command to install the component.
npx shadcn@latest add https://control-ui.dev/r/task-list.jsonUsage
"use client";
import { useChat } from "@mastra/react";
import { TaskList, TaskListContent, TaskListItem, TaskListTrigger } from "@/components/control-ui/task-list";
export function Example({ agentId }: { agentId: string }) { const { tasks } = useChat({ agentId });
return ( <TaskList defaultOpen={false}> <TaskListTrigger /> <TaskListContent> {tasks.map((task) => ( <TaskListItem key={task.id} label={task.status === "in_progress" ? task.activeForm : task.content} status={task.status === "in_progress" ? "active" : task.status} /> ))} </TaskListContent> </TaskList> );}
Dependencies
Effects
src/registry/sources/control-ui/effects.css
Support
Collapsible
collapsible
Component
Live status
live-status
Component
Raw code
Installed component source and support files
"use client";
import { ChevronRight, CircleCheck, CircleDashed, Loader2 } from "lucide-react";import type { ComponentProps, CSSProperties, ReactNode } from "react";import { createContext, useContext, useEffect, useId, useRef, useState } from "react";import type { TaskListKnobStyle } from "@/components/control-ui/knob-contracts/task-list-knobs";import { cn } from "@/components/control-ui/lib/cn";import type { SkinIconComponent, SkinIconName } from "@/components/control-ui/skin";import { useSkinIcon } from "@/components/control-ui/skin-provider";import type { CollapsibleProps } from "@/components/control-ui/ui/collapsible";import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/control-ui/ui/collapsible";import { LiveStatus } from "@/components/control-ui/ui/live-status";
export type TaskStatus = "pending" | "active" | "completed";
export type TaskStatusLabels = Record<TaskStatus, string>;
export const taskStatusLabels: TaskStatusLabels = { pending: "Pending", active: "In progress", completed: "Done" };
export type TaskListProps = Omit<CollapsibleProps, "style"> & { statusLabels?: Partial<TaskStatusLabels>; /** Announced once every task is done. */ completedLabel?: string; style?: CSSProperties & TaskListKnobStyle;};
type TaskListStyleProps<Props, Style> = Omit<Props, "style"> & { style?: CSSProperties & Style };
type TaskEntry = { key: string; status: TaskStatus; label: string; node: HTMLElement | null;};
type TaskListRegistrationContextValue = { registerTask: (entry: TaskEntry) => void; unregisterTask: (key: string) => void;};
type TaskListContextValue = { total: number; current?: TaskEntry; /** 1-based position rendered as "Task 3 of 5"; 0 while no task is registered. */ currentNumber: number; allCompleted: boolean; statusLabels: TaskStatusLabels;};
const TaskListContext = createContext<TaskListContextValue | null>(null);
const TaskListRegistrationContext = createContext<TaskListRegistrationContextValue | null>(null);
function useTaskListContext() { const context = useContext(TaskListContext); if (!context) throw new Error("TaskList compound components must be rendered inside <TaskList>."); return context;}
function useTaskListRegistrationContext() { const context = useContext(TaskListRegistrationContext); if (!context) throw new Error("TaskList items must be rendered inside <TaskList>."); return context;}
function upsert(entries: TaskEntry[], entry: TaskEntry) { const index = entries.findIndex((existing) => existing.key === entry.key); if (index === -1) return [...entries, entry]; const next = [...entries]; next[index] = entry; return next;}
function compareDocumentOrder(a: TaskEntry, b: TaskEntry) { if (!a.node || !b.node) return 0; const position = a.node.compareDocumentPosition(b.node); if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1; if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1; return 0;}
// Items register in mount order, so one inserted mid-list would count as the last task.// Returns the input array when it is already ordered so a state update can bail out.function inDocumentOrder(entries: TaskEntry[]) { const sorted = [...entries].sort(compareDocumentOrder); return sorted.every((entry, index) => entry === entries[index]) ? entries : sorted;}
function currentTaskIndex(tasks: TaskEntry[]) { const active = tasks.findIndex((task) => task.status === "active"); if (active !== -1) return active; const pending = tasks.findIndex((task) => task.status === "pending"); if (pending !== -1) return pending; return tasks.length - 1;}
export function TaskList({ statusLabels, completedLabel = "All tasks completed", className, children, ...props }: TaskListProps) { const [tasks, setTasks] = useState<TaskEntry[]>([]); const [hasProgressed, setHasProgressed] = useState(false); // register upserts in place so status change never reorders, and unregister runs only at item unmount — // combined effect cleanup would move every updated item to end const [registration] = useState<TaskListRegistrationContextValue>(() => ({ registerTask(entry) { setTasks((previous) => inDocumentOrder(upsert(previous, entry))); }, unregisterTask(key) { setTasks((previous) => previous.filter((task) => task.key !== key)); }, })); // A keyed reorder re-renders no item, so nothing re-registers. useEffect(() => setTasks(inDocumentOrder));
const total = tasks.length; const currentIndex = currentTaskIndex(tasks); const current = tasks[currentIndex]; const allCompleted = total > 0 && tasks.every((task) => task.status === "completed"); const labels = { ...taskStatusLabels, ...statusLabels }; // A list that mounts already finished (history) stays silent; only a completion that happens while mounted is announced. if (!hasProgressed && total > 0 && !allCompleted) setHasProgressed(true); const completedStatus = allCompleted && hasProgressed ? completedLabel : ""; const progressStatus = current?.status === "active" ? `${current.label}: ${labels.active}` : completedStatus;
return ( <TaskListRegistrationContext.Provider value={registration}> <TaskListContext.Provider value={{ total, current, currentNumber: total === 0 ? 0 : currentIndex + 1, allCompleted, statusLabels: labels }} > <Collapsible data-control-ui="task-list" data-control-family="task-list" data-slot="root" data-surface="panel" className={cn("w-full overflow-hidden", className)} {...props} > {children} <LiveStatus message={progressStatus} /> </Collapsible> </TaskListContext.Provider> </TaskListRegistrationContext.Provider> );}
export type TaskListTriggerProps = TaskListStyleProps<ComponentProps<"button">, TaskListKnobStyle>;
export function TaskListTrigger({ className, children, ...props }: TaskListTriggerProps) { const ChevronRightGlyph = useSkinIcon("chevronRight", ChevronRight); const { current } = useTaskListContext();
return ( <CollapsibleTrigger data-control-ui="task-list" data-control-family="task-list" data-slot="trigger" className={cn("flex w-full items-center", className)} {...props} > {children ?? ( <> <TaskListIndicator status={current?.status ?? "pending"} /> <TaskListProgress /> <ChevronRightGlyph aria-hidden="true" data-icon-dir="inline" data-control-ui="task-list" data-control-family="task-list" data-slot="chevron" className="shrink-0" /> {/* expanded list already shows current task, so pill's preview hides while open */} <TaskListLabel className="in-data-[state=open]:hidden" /> </> )} </CollapsibleTrigger> );}
export type TaskListProgressProps = TaskListStyleProps<ComponentProps<"span">, TaskListKnobStyle> & { /** Formats the 1-based position of the current task; `children` replaces it entirely. */ label?: (current: number, total: number) => string;};
function taskProgressLabel(current: number, total: number) { return `Task ${current} of ${total}`;}
export function TaskListProgress({ label = taskProgressLabel, className, children, ...props }: TaskListProgressProps) { const { currentNumber, total } = useTaskListContext();
return ( <span data-control-ui="task-list" data-control-family="task-list" data-slot="progress" className={cn("shrink-0", className)} {...props}> {children ?? label(currentNumber, total)} </span> );}
export type TaskListLabelProps = TaskListStyleProps<ComponentProps<"span">, TaskListKnobStyle>;
export function TaskListLabel({ className, children, ...props }: TaskListLabelProps) { const { current } = useTaskListContext(); const text = children ?? current?.label;
return ( <span data-control-ui="task-list" data-control-family="task-list" data-slot="label" title={typeof text === "string" ? text : undefined} className={cn("min-w-0 flex-1 truncate", className)} {...props} > {text} </span> );}
export type TaskListContentProps = ComponentProps<"ol"> & { style?: CSSProperties & TaskListKnobStyle };
export function TaskListContent({ className, children, ...props }: TaskListContentProps) { return ( // closed items must stay registered — collapsed pill derives "Task 3 of 5" from them <CollapsibleContent keepMounted> <ol // biome-ignore lint/a11y/noRedundantRoles: Safari drops list semantics when list-style is none. role="list" data-control-ui="task-list" data-control-family="task-list" data-slot="items" className={cn("flex flex-col", className)} {...props} > {children} </ol> </CollapsibleContent> );}
export type TaskListItemProps = TaskListStyleProps<Omit<ComponentProps<"li">, "children">, TaskListKnobStyle> & { label: string; status?: TaskStatus; children?: ReactNode;};
export function TaskListItem({ label, status = "pending", className, children, ref, ...props }: TaskListItemProps) { const { registerTask, unregisterTask } = useTaskListRegistrationContext(); const key = useId(); const itemRef = useRef<HTMLLIElement>(null);
useEffect(() => registerTask({ key, status, label, node: itemRef.current }), [registerTask, key, status, label]); useEffect(() => () => unregisterTask(key), [unregisterTask, key]);
return ( <li ref={(node) => { itemRef.current = node; if (typeof ref === "function") ref(node); else if (ref) ref.current = node; }} data-control-ui="task-list" data-control-family="task-list" data-slot="item" data-status={status} className={cn("flex items-center", className)} {...props} > <TaskListIndicator status={status} /> <span className="min-w-0 flex-1 text-pretty">{children ?? label}</span> </li> );}
const indicatorIcons = { pending: { name: "pending", fallback: CircleDashed }, active: { name: "spinner", fallback: Loader2 }, completed: { name: "success", fallback: CircleCheck },} satisfies Record<TaskStatus, { name: SkinIconName; fallback: SkinIconComponent }>;
export type TaskListIndicatorProps = TaskListStyleProps<ComponentProps<"span">, TaskListKnobStyle> & { status?: TaskStatus;};
export function TaskListIndicator({ status = "pending", className, ...props }: TaskListIndicatorProps) { const indicatorIcon = indicatorIcons[status]; const IndicatorGlyph = useSkinIcon(indicatorIcon.name, indicatorIcon.fallback); const statusLabels = useContext(TaskListContext)?.statusLabels ?? taskStatusLabels;
return ( <span data-control-ui="task-list" data-control-family="task-list" data-slot="item-indicator" data-status={status} className={cn("inline-flex shrink-0 items-center justify-center", className)} {...props} > <IndicatorGlyph aria-hidden="true" data-motion-essential={status === "active" ? "" : undefined} /> <span className="sr-only">{statusLabels[status]}</span> </span> );}
Knobs
Typed custom properties the recipe paints with. Set one on the root — style, a utility class, or a skin — and every slot inherits it.
| Knob | Syntax | Default |
|---|---|---|
--cui-task-list-radius | <length-percentage> | var(--radius-field) |
--cui-task-list-ring-color | <color> | oklch(from var(--foreground) l c h / 0.04) |
--cui-task-list-items-padding | <length-percentage> | calc(var(--spacing) * 2) |
--cui-task-list-item-radius | <length-percentage> | max(
var(--radius-sm),
min(var(--radius-popup-item-fit), calc(var(--cui-task-list-radius) - var(--cui-task-list-items-padding)))
) |
--cui-task-list-trigger-hover-background | <color> | var(--hover-fill) |
--cui-task-list-background | <color> | oklch(from var(--card) l c h / 0.9) |
--cui-task-list-foreground | <color> | var(--foreground) |
--cui-task-list-border-color | <color> | var(--border) |
--cui-task-list-border-width | <length> | var(--control-rim-width) |
--cui-task-list-shadow | * | var(--shadow-md) |
--cui-task-list-item-foreground | <color> | var(--foreground) |
--cui-task-list-item-pending-foreground | <color> | var(--muted-foreground) |
--cui-task-list-indicator-foreground | <color> | var(--muted-foreground) |
--cui-task-list-indicator-active-foreground | <color> | var(--primary-text) |