feat(webui): streamline contextual message controls (#5831)
This commit is contained in:
1 parent
99a7ec256f
commit
920efd00b8
24 files changed
+1776
-955
No files matched your search
@@ -1,133 +1,117 @@
|
||||
import { ChevronDown } from "lucide-react";
|
||||
import { useState, type ReactNode, type Ref } from "react";
|
||||
import { useId, useState, type ReactNode } from "react";
|
||||
import { Activity } from "lucide-react";
|
||||
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
interface ThinkingReasoningShellProps {
|
||||
active: boolean;
|
||||
expanded: boolean;
|
||||
contextual?: boolean;
|
||||
showHeader?: boolean;
|
||||
collapseLabel?: string;
|
||||
contentId?: string;
|
||||
label: string;
|
||||
children: ReactNode;
|
||||
viewportRef: Ref<HTMLDivElement>;
|
||||
contentRef: Ref<HTMLDivElement>;
|
||||
fadeTop: boolean;
|
||||
fadeBottom: boolean;
|
||||
hasDetails?: boolean;
|
||||
onToggle: () => void;
|
||||
onScroll: () => void;
|
||||
}
|
||||
|
||||
export function ThinkingReasoningShell({
|
||||
active,
|
||||
expanded,
|
||||
contextual = false,
|
||||
showHeader = true,
|
||||
collapseLabel,
|
||||
contentId: providedContentId,
|
||||
label,
|
||||
children,
|
||||
viewportRef,
|
||||
contentRef,
|
||||
fadeTop,
|
||||
fadeBottom,
|
||||
hasDetails = true,
|
||||
onToggle,
|
||||
onScroll,
|
||||
}: ThinkingReasoningShellProps) {
|
||||
const generatedContentId = useId();
|
||||
const contentId = providedContentId ?? generatedContentId;
|
||||
const [hasExpanded, setHasExpanded] = useState(expanded);
|
||||
if (expanded && !hasExpanded) setHasExpanded(true);
|
||||
const headerClassName = "touch-target inline-flex h-7 min-w-0 items-center gap-1.5 rounded-md px-1.5";
|
||||
const headerContent = (
|
||||
<>
|
||||
<Activity className="h-3.5 w-3.5 shrink-0" strokeWidth={1.5} aria-hidden />
|
||||
<span
|
||||
className={cn(
|
||||
"min-w-0 truncate text-[12px] font-normal leading-4 text-muted-foreground/65",
|
||||
active && "animate-pulse motion-reduce:animate-none",
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
</>
|
||||
);
|
||||
return (
|
||||
<div
|
||||
className="flex w-full max-w-[45rem] animate-in flex-col fade-in duration-300 motion-reduce:animate-none"
|
||||
data-state={active ? "thinking" : "done"}
|
||||
data-contextual-activity={contextual || undefined}
|
||||
data-block-context-rail={contextual && showHeader || undefined}
|
||||
data-block-context-expanded={contextual && expanded ? true : undefined}
|
||||
>
|
||||
{hasDetails ? (
|
||||
<button
|
||||
type="button"
|
||||
data-thread-disclosure=""
|
||||
className="group inline-flex min-h-5 items-center self-start gap-1.5 bg-transparent p-0"
|
||||
onClick={onToggle}
|
||||
aria-expanded={expanded}
|
||||
aria-label={label}
|
||||
aria-live={active ? "polite" : undefined}
|
||||
>
|
||||
<span
|
||||
{showHeader ? <div className="flex min-h-7 items-center gap-1.5">
|
||||
{hasDetails ? (
|
||||
<button
|
||||
type="button"
|
||||
data-thread-disclosure=""
|
||||
data-contextual-activity-disclosure
|
||||
data-contextual-activity-collapse={expanded || undefined}
|
||||
className={cn(
|
||||
"min-w-0 truncate text-[13px] font-medium leading-[18px] text-muted-foreground/70",
|
||||
active && "animate-pulse motion-reduce:animate-none",
|
||||
headerClassName,
|
||||
"bg-transparent transition-colors hover:bg-muted/60 hover:text-foreground",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
onClick={onToggle}
|
||||
aria-expanded={expanded}
|
||||
aria-controls={contentId}
|
||||
aria-label={expanded && collapseLabel ? `${label} · ${collapseLabel}` : label}
|
||||
aria-live={active ? "polite" : undefined}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
<span
|
||||
className={cn(
|
||||
"inline-flex shrink-0 transition-transform [transition-duration:220ms] ease-out",
|
||||
"motion-reduce:transition-none",
|
||||
expanded && "rotate-180",
|
||||
)}
|
||||
{headerContent}
|
||||
</button>
|
||||
) : (
|
||||
<div
|
||||
className={headerClassName}
|
||||
role="status"
|
||||
aria-label={label}
|
||||
aria-live={active ? "polite" : undefined}
|
||||
>
|
||||
<ChevronDown
|
||||
className={cn(
|
||||
"h-3 w-3 text-muted-foreground/60 transition-colors duration-200",
|
||||
"group-hover:text-muted-foreground motion-reduce:transition-none",
|
||||
)}
|
||||
strokeWidth={1.8}
|
||||
aria-hidden
|
||||
/>
|
||||
</span>
|
||||
</button>
|
||||
) : (
|
||||
<div
|
||||
className="inline-flex min-h-5 items-center self-start"
|
||||
role="status"
|
||||
aria-label={label}
|
||||
aria-live={active ? "polite" : undefined}
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"min-w-0 truncate text-[13px] font-medium leading-[18px] text-muted-foreground/70",
|
||||
active && "animate-pulse motion-reduce:animate-none",
|
||||
)}
|
||||
>
|
||||
{label}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
{headerContent}
|
||||
</div>
|
||||
)}
|
||||
</div> : null}
|
||||
|
||||
{hasDetails ? (
|
||||
<div
|
||||
id={contentId}
|
||||
{...(!expanded ? { inert: "" } : {})}
|
||||
aria-hidden={!expanded}
|
||||
className={cn(
|
||||
"grid transition-[grid-template-rows,opacity] [transition-duration:220ms] ease-out motion-reduce:transition-none",
|
||||
"grid transition-[grid-template-rows,opacity] duration-150 ease-out motion-reduce:transition-none",
|
||||
expanded
|
||||
? "grid-rows-[1fr] opacity-100"
|
||||
: "pointer-events-none grid-rows-[0fr] opacity-0",
|
||||
)}
|
||||
>
|
||||
<div className="relative min-h-0 overflow-hidden">
|
||||
{expanded ? (
|
||||
<span
|
||||
data-contextual-activity-guide
|
||||
aria-hidden
|
||||
className="pointer-events-none absolute inset-y-1 start-[13px] w-px rounded-full bg-border"
|
||||
/>
|
||||
) : null}
|
||||
<div
|
||||
ref={viewportRef}
|
||||
data-testid={expanded ? "agent-activity-scroll" : undefined}
|
||||
data-fade-top={fadeTop}
|
||||
data-fade-bottom={fadeBottom}
|
||||
onScroll={onScroll}
|
||||
className="mt-1.5 max-h-[180px] overflow-y-auto pr-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
||||
data-testid={expanded ? "agent-activity-content" : undefined}
|
||||
className="mt-1 flex flex-col gap-0.5 pe-1 ps-6"
|
||||
>
|
||||
<div ref={contentRef} className="flex flex-col gap-0.5">
|
||||
{hasExpanded ? children : null}
|
||||
</div>
|
||||
{hasExpanded ? children : null}
|
||||
</div>
|
||||
{fadeTop ? (
|
||||
<span
|
||||
data-testid="activity-scroll-fade-top"
|
||||
className="pointer-events-none absolute inset-x-0 top-1.5 z-10 h-3.5 bg-gradient-to-b from-background to-transparent"
|
||||
aria-hidden
|
||||
/>
|
||||
) : null}
|
||||
{fadeBottom ? (
|
||||
<span
|
||||
data-testid="activity-scroll-fade-bottom"
|
||||
className="pointer-events-none absolute inset-x-0 bottom-0 z-10 h-3.5 bg-gradient-to-t from-background to-transparent"
|
||||
aria-hidden
|
||||
/>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
Reference in new issue
Block a user