2026-10-06 00:46:38 +08:00
|
|
|
import { useRef, useState, type CSSProperties, type ReactNode } from "react";
|
2026-05-30 23:45:26 +08:00
|
|
|
import type { LucideIcon } from "lucide-react";
|
|
|
|
|
|
|
|
|
|
import { StreamingLabelSheen } from "@/components/MessageBubble";
|
2026-09-08 16:00:54 +08:00
|
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
|
2026-05-30 23:45:26 +08:00
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
|
|
|
|
|
export type ActivityStepTone = "neutral" | "active" | "success" | "error";
|
|
|
|
|
|
|
|
|
|
export interface ActivityStepProps {
|
|
|
|
|
icon?: LucideIcon;
|
|
|
|
|
marker?: ReactNode;
|
2026-09-10 15:21:15 +08:00
|
|
|
showMarker?: boolean;
|
2026-05-30 23:45:26 +08:00
|
|
|
label: ReactNode;
|
2026-10-07 15:19:55 +08:00
|
|
|
detail?: string;
|
|
|
|
|
detailClassName?: string;
|
2026-09-11 13:10:18 +08:00
|
|
|
tooltipContent?: ReactNode;
|
2026-07-22 22:35:39 +08:00
|
|
|
ariaLabel?: string;
|
2026-05-30 23:45:26 +08:00
|
|
|
active?: boolean;
|
2026-09-11 13:10:18 +08:00
|
|
|
animateLabel?: boolean;
|
2026-05-30 23:45:26 +08:00
|
|
|
tone?: ActivityStepTone;
|
|
|
|
|
className?: string;
|
|
|
|
|
contentClassName?: string;
|
2026-07-22 22:35:39 +08:00
|
|
|
labelClassName?: string;
|
2026-05-30 23:45:26 +08:00
|
|
|
markerClassName?: string;
|
|
|
|
|
style?: CSSProperties;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ActivityStep({
|
|
|
|
|
icon: Icon,
|
|
|
|
|
marker,
|
2026-09-10 15:21:15 +08:00
|
|
|
showMarker = true,
|
2026-05-30 23:45:26 +08:00
|
|
|
label,
|
2026-10-07 15:19:55 +08:00
|
|
|
detail,
|
|
|
|
|
detailClassName,
|
2026-09-11 13:10:18 +08:00
|
|
|
tooltipContent,
|
2026-07-22 22:35:39 +08:00
|
|
|
ariaLabel,
|
2026-05-30 23:45:26 +08:00
|
|
|
active = false,
|
2026-09-11 13:10:18 +08:00
|
|
|
animateLabel = true,
|
2026-05-30 23:45:26 +08:00
|
|
|
tone = active ? "active" : "neutral",
|
|
|
|
|
className,
|
|
|
|
|
contentClassName,
|
2026-07-22 22:35:39 +08:00
|
|
|
labelClassName,
|
2026-05-30 23:45:26 +08:00
|
|
|
markerClassName,
|
|
|
|
|
style,
|
|
|
|
|
}: ActivityStepProps) {
|
2026-10-06 00:46:38 +08:00
|
|
|
const lineRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const [hintOpen, setHintOpen] = useState(false);
|
2026-10-07 15:19:55 +08:00
|
|
|
const textLabel = typeof label === "string" ? [label, detail].filter(Boolean).join("\n") : undefined;
|
2026-09-08 16:00:54 +08:00
|
|
|
const line = (
|
|
|
|
|
<div
|
2026-10-06 00:46:38 +08:00
|
|
|
ref={lineRef}
|
2026-09-08 16:00:54 +08:00
|
|
|
data-testid="activity-line"
|
|
|
|
|
tabIndex={typeof label === "string" ? 0 : undefined}
|
2026-10-07 15:19:55 +08:00
|
|
|
aria-label={detail && typeof label === "string" ? `${label}, ${detail}` : undefined}
|
2026-09-08 16:00:54 +08:00
|
|
|
className="flex min-w-0 items-center gap-1.5 overflow-hidden whitespace-nowrap"
|
|
|
|
|
>
|
|
|
|
|
<StreamingLabelSheen
|
2026-09-11 13:10:18 +08:00
|
|
|
active={active && animateLabel}
|
2026-09-08 16:00:54 +08:00
|
|
|
className={cn(
|
|
|
|
|
"min-w-0 flex-1 truncate font-medium",
|
2026-10-06 00:46:38 +08:00
|
|
|
tone === "error" ? "text-destructive/[0.78]" : "text-muted-foreground",
|
2026-09-08 16:00:54 +08:00
|
|
|
labelClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
2026-10-07 15:19:55 +08:00
|
|
|
{detail ? (
|
|
|
|
|
<span className="flex min-w-0 items-baseline gap-2">
|
|
|
|
|
<span className="max-w-[70%] shrink-0 truncate">{label}</span>{" "}
|
|
|
|
|
<span className={cn("min-w-0 flex-1 truncate font-normal text-muted-foreground", detailClassName)}>{detail}</span>
|
|
|
|
|
</span>
|
|
|
|
|
) : label}
|
2026-09-08 16:00:54 +08:00
|
|
|
</StreamingLabelSheen>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
|
2026-05-30 23:45:26 +08:00
|
|
|
return (
|
2026-07-22 22:35:39 +08:00
|
|
|
<div
|
|
|
|
|
data-testid="activity-step"
|
|
|
|
|
aria-label={ariaLabel}
|
2026-05-30 23:45:26 +08:00
|
|
|
className={cn(
|
2026-09-10 15:21:15 +08:00
|
|
|
"relative grid min-w-0 py-0.5 text-[13px] leading-5",
|
|
|
|
|
showMarker ? "grid-cols-[1.125rem_minmax(0,1fr)] gap-2" : "grid-cols-1",
|
2026-05-30 23:45:26 +08:00
|
|
|
className,
|
|
|
|
|
)}
|
|
|
|
|
style={style}
|
|
|
|
|
>
|
2026-09-10 15:21:15 +08:00
|
|
|
{showMarker ? (
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
|
|
|
|
"flex h-5 w-[1.125rem] shrink-0 items-start justify-center pt-[3px]",
|
|
|
|
|
)}
|
|
|
|
|
aria-hidden
|
|
|
|
|
>
|
|
|
|
|
{marker ?? (
|
|
|
|
|
<span
|
|
|
|
|
className={cn(
|
2026-10-06 00:46:38 +08:00
|
|
|
"grid h-3.5 w-3.5 place-items-center transition-colors",
|
|
|
|
|
tone === "error" ? "text-destructive/[0.78]" : "text-muted-foreground",
|
2026-09-10 15:21:15 +08:00
|
|
|
markerClassName,
|
|
|
|
|
)}
|
|
|
|
|
>
|
2026-10-06 00:46:38 +08:00
|
|
|
{Icon ? <Icon className="h-3.5 w-3.5" strokeWidth={1.75} /> : null}
|
2026-09-10 15:21:15 +08:00
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
) : null}
|
2026-05-30 23:45:26 +08:00
|
|
|
<div className={cn("min-w-0", contentClassName)}>
|
2026-09-08 16:00:54 +08:00
|
|
|
{typeof label === "string" ? (
|
2026-09-10 11:10:51 +08:00
|
|
|
<TooltipProvider>
|
2026-10-06 00:46:38 +08:00
|
|
|
<Tooltip open={hintOpen} onOpenChange={(open) => {
|
|
|
|
|
const truncated = Array.from(lineRef.current?.querySelectorAll<HTMLElement>(".truncate") ?? [])
|
|
|
|
|
.some((element) => element.scrollWidth > element.clientWidth);
|
2026-10-07 15:19:55 +08:00
|
|
|
setHintOpen(open && (truncated || tooltipContent !== undefined && tooltipContent !== textLabel));
|
2026-10-06 00:46:38 +08:00
|
|
|
}}>
|
2026-09-08 16:00:54 +08:00
|
|
|
<TooltipTrigger asChild>{line}</TooltipTrigger>
|
|
|
|
|
<TooltipContent side="top" className="max-w-[min(32rem,calc(100vw-2rem))] whitespace-pre-wrap break-words">
|
2026-10-07 15:19:55 +08:00
|
|
|
{tooltipContent ?? textLabel}
|
2026-09-08 16:00:54 +08:00
|
|
|
</TooltipContent>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</TooltipProvider>
|
|
|
|
|
) : line}
|
2026-05-30 23:45:26 +08:00
|
|
|
</div>
|
2026-07-22 22:35:39 +08:00
|
|
|
</div>
|
2026-05-30 23:45:26 +08:00
|
|
|
);
|
|
|
|
|
}
|