import { useRef, useState, type CSSProperties, type ReactNode } from "react"; import type { LucideIcon } from "lucide-react"; import { StreamingLabelSheen } from "@/components/ui/streaming-label-sheen"; import { formControlFocusClassName } from "@/components/ui/form-control"; import { HoverHint, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; import { cn } from "@/lib/utils"; export type ActivityStepTone = "neutral" | "active" | "success" | "error"; export interface ActivityStepProps { icon?: LucideIcon; marker?: ReactNode; markerLabel?: string; showMarker?: boolean; label: ReactNode; detail?: string; detailClassName?: string; tooltipContent?: ReactNode; ariaLabel?: string; active?: boolean; animateLabel?: boolean; tone?: ActivityStepTone; className?: string; contentClassName?: string; labelClassName?: string; markerClassName?: string; style?: CSSProperties; } export function ActivityStep({ icon: Icon, marker, markerLabel, showMarker = true, label, detail, detailClassName, tooltipContent, ariaLabel, active = false, animateLabel = true, tone = active ? "active" : "neutral", className, contentClassName, labelClassName, markerClassName, style, }: ActivityStepProps) { const lineRef = useRef(null); const [hintOpen, setHintOpen] = useState(false); const textLabel = typeof label === "string" ? [label, detail].filter(Boolean).join("\n") : undefined; const activityMarker = ( {marker ?? ( {Icon ? : null} )} ); const line = (
{label} {detail ? ( <> {" "} {detail} ) : null}
); return (
{showMarker ? markerLabel ? ( {activityMarker} ) : activityMarker : null}
{typeof label === "string" ? ( { const truncated = Array.from(lineRef.current?.querySelectorAll(".truncate") ?? []) .some((element) => element.scrollWidth > element.clientWidth); setHintOpen(open && (truncated || tooltipContent !== undefined && tooltipContent !== textLabel)); }}> {line} {tooltipContent ?? textLabel} ) : line}
); }