feat(webui): refine composer action feedback (#6419)

* feat(webui): refine composer action feedback

* fix(webui): preserve composer hit targets and ring previews
This commit is contained in:
chengyongru authored and GitHub committed 2026-10-24 02:50:47 +08:00
1 parent 03e9b5430b
commit 6d4add200b
20 files changed
+351 -48

No files matched your search

+2 -18
View File
@@ -49,6 +49,7 @@ import {
import { MAX_WORKBENCH_PANES } from "@/components/workbench/workbench-model";
import { SidebarTopicRename } from "@/components/SidebarTopicRename";
import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus";
import { LoadingRing } from "@/components/ui/loading-ring";
import {
SIDEBAR_SELECTION_ITEM_CLASS,
SidebarSelectionHighlight,
@@ -1880,12 +1881,6 @@ function ChatsFoldFooter({
);
}
function synchronizeRunningRing(element: SVGCircleElement | null) {
if (!element) return;
// Align pending animations before their first frame, not only after animationstart.
for (const animation of element.getAnimations()) animation.startTime = 0;
}
function SessionActivityIndicator({
state,
}: {
@@ -1919,18 +1914,7 @@ function SessionActivityIndicator({
aria-label={label}
className="grid h-4 w-4 shrink-0 place-items-center"
>
<svg
className="h-3 w-3 text-sidebar-muted-foreground"
viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" aria-hidden="true"
>
<circle cx="12" cy="12" r="10" opacity="0.2" />
<circle
cx="12" cy="12" r="10" strokeDasharray="16 46.8" strokeLinecap="round"
className="sidebar-running-ring"
ref={synchronizeRunningRing}
onAnimationStart={(event) => synchronizeRunningRing(event.currentTarget)}
/>
</svg>
<LoadingRing className="h-3 w-3 text-sidebar-muted-foreground" />
</span>
</HoverHint>
);
@@ -0,0 +1,37 @@
import { ModelsIcon, StopIcon } from "@/components/icons/product-icons";
import { LoadingRing } from "@/components/ui/loading-ring";
export type ComposerActionState = "voice" | "recording" | "busy" | "stop" | "setup" | "send";
export function ComposerActionIcon({ state }: { state: ComposerActionState }) {
return (
<span className="composer-action-icons pointer-events-none relative block h-7 w-7 shrink-0" data-state={state} aria-hidden="true">
<span className="composer-action-glyph" data-action-icon="voice" data-active={state === "voice" || undefined}>
<svg className="h-6 w-6" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<rect x="9.5" y="4.75" width="5" height="9.5" rx="2.5" fill="currentColor" />
<path d="M7 11.25v.5a5 5 0 0 0 10 0v-.5M12 16.75v2.5" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
</svg>
</span>
<span className="composer-action-glyph" data-action-icon="send" data-active={state === "send" || undefined}>
<svg className="h-6 w-6" viewBox="0 0 24 24" fill="none" aria-hidden="true">
<path d="m8.25 10.25 3.75-3.75 3.75 3.75M12 7v10.5" stroke="currentColor" strokeWidth="1.75" strokeLinecap="round" strokeLinejoin="round" />
</svg>
</span>
<span className="composer-action-glyph" data-action-icon="stop" data-active={state === "stop" || undefined}>
<LoadingRing track={false} strokeDasharray="12 50.8" className="absolute h-6 w-6 text-foreground/50" strokeWidth="1.5" />
<svg className="h-6 w-6" viewBox="0 0 24 24" fill="currentColor" aria-hidden="true">
<rect x="8" y="8" width="8" height="8" rx="1.75" />
</svg>
</span>
<span className="composer-action-glyph" data-action-icon="recording" data-active={state === "recording" || undefined}>
<StopIcon className="h-3.5 w-3.5" fill="currentColor" />
</span>
<span className="composer-action-glyph" data-action-icon="busy" data-active={state === "busy" || undefined}>
<LoadingRing className="h-4 w-4" />
</span>
<span className="composer-action-glyph" data-action-icon="setup" data-active={state === "setup" || undefined}>
<ModelsIcon className="h-4 w-4" />
</span>
</span>
);
}
+13 -24
View File
@@ -16,7 +16,6 @@ import {
HelpIcon,
HistoryIcon,
ConversationIcon,
VoiceIcon,
AttachIcon,
RestartIcon,
RestrictedAccessIcon,
@@ -53,7 +52,6 @@ import {
} from "@/lib/composer-mention-text";
import { INLINE_TOKEN_HIGHLIGHT_COLOR } from "@/components/InlineTokenHighlight";
import {
ArrowUp,
ChevronDown,
ChevronUp,
CornerDownRight,
@@ -69,6 +67,7 @@ import {
import { useTranslation } from "react-i18next";
import { Button } from "@/components/ui/button";
import { ComposerActionIcon, type ComposerActionState } from "@/components/thread/ComposerActionIcon";
import {
floatingItemClassName,
floatingItemFocusClassName,
@@ -2480,6 +2479,9 @@ export function ThreadComposer({
: t("thread.composer.voice.hint");
// Touch users need an explicit send action; keep Stop while sending is unavailable.
const showStopButton = isStreaming && !!onStop && !canSend;
const actionState: ComposerActionState = showVoiceButton
? voiceRecorder.state === "transcribing" ? "busy" : voiceRecorder.isRecording ? "recording" : "voice"
: showStopButton ? "stop" : modelNeedsSetup ? "setup" : canSend || !isStreaming ? "send" : "busy";
const relaxedHeroInput = isHero && images.length === 0 && !isStreaming;
const compactIdle = compactWhenIdle && !compactControls && !isHero && !composerFocused
&& value.length === 0 && images.length === 0 && !inlineError
@@ -2864,31 +2866,18 @@ export function ThreadComposer({
}}
onClick={showVoiceButton ? voiceRecorder.handleClick : showStopButton ? handleStop : modelNeedsSetup ? onModelBadgeClick : undefined}
className={cn(
"thread-composer-action thread-composer-round-action touch-target rounded-full",
showStopButton && !showVoiceButton
? "border border-border/70 bg-card text-foreground/85 hover:text-foreground disabled:text-muted-foreground/50"
: "border border-foreground bg-foreground text-background disabled:border-foreground disabled:bg-foreground disabled:text-background",
showVoiceButton && voiceRecorder.isRecording && "border-red-500 bg-red-500 text-white hover:bg-red-500 hover:text-white",
"composer-primary-action thread-composer-action thread-composer-round-action touch-target rounded-full bg-clip-padding",
actionState === "stop"
? "border border-transparent bg-foreground/[0.045] text-foreground/85 hover:bg-foreground/[0.08] hover:text-foreground disabled:text-muted-foreground/50"
: actionState === "voice"
? "border border-transparent bg-foreground/75 text-background hover:bg-foreground/[0.85] hover:text-background disabled:bg-foreground/[0.12] disabled:text-muted-foreground"
: "border border-transparent bg-foreground text-background hover:bg-foreground/90 hover:text-background disabled:border-foreground disabled:bg-foreground disabled:text-background",
actionState === "send" && "disabled:border-transparent disabled:bg-foreground/[0.12] disabled:text-muted-foreground",
showVoiceButton && voiceRecorder.isRecording && "border-transparent bg-red-500 text-white hover:bg-red-500 hover:text-white",
isHero ? "h-8 w-8" : "h-9 w-9",
)}
>
{showVoiceButton ? (
voiceRecorder.state === "transcribing" ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : voiceRecorder.isRecording ? (
<StopIcon className="h-3.5 w-3.5" fill="currentColor" />
) : (
<VoiceIcon className="h-4 w-4" />
)
) : showStopButton ? (
<StopIcon className={cn("fill-current stroke-current", isHero ? "h-3 w-3" : "h-3.5 w-3.5")} />
) : modelNeedsSetup ? (
<ModelsIcon className="h-4 w-4" />
) : canSend || !isStreaming ? (
<ArrowUp className="h-4 w-4" />
) : (
<Loader2 className="h-4 w-4 animate-spin" />
)}
<ComposerActionIcon state={actionState} />
</Button>
</TooltipTrigger>
{showVoiceButton ? (
+21
View File
@@ -0,0 +1,21 @@
import type { SVGProps } from "react";
function synchronizeRing(element: SVGCircleElement | null) {
if (!element) return;
// Align the first frame and animations restarted by a live motion preference change.
for (const animation of element.getAnimations()) animation.startTime = 0;
}
export function LoadingRing({ track = true, strokeDasharray = "16 46.8", ...props }: SVGProps<SVGSVGElement> & { track?: boolean }) {
return (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.5" aria-hidden="true" {...props}>
{track ? <circle cx="12" cy="12" r="10" opacity="0.2" /> : null}
<circle
cx="12" cy="12" r="10" strokeDasharray={strokeDasharray} strokeLinecap="round"
className="loading-ring-arc"
ref={synchronizeRing}
onAnimationStart={(event) => synchronizeRing(event.currentTarget)}
/>
</svg>
);
}