fix(webui): simplify mobile composer controls and context sheet
This commit is contained in:
1 parent
3a14935eb1
commit
827dbe137b
7 files changed
+395
-219
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { Fragment, useMemo, useRef } from "react";
|
||||
import { Fragment, useMemo, useRef, type ReactNode } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
import {
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
PopoverContent,
|
||||
PopoverTrigger,
|
||||
} from "@/components/ui/popover";
|
||||
import { Sheet, SheetContent, SheetTitle, SheetTrigger } from "@/components/ui/sheet";
|
||||
import {
|
||||
Tooltip,
|
||||
TooltipContent,
|
||||
@@ -55,12 +56,15 @@ function normalizeRounds(
|
||||
export function ComposerUsagePopover({
|
||||
context,
|
||||
rounds,
|
||||
showLabel = false,
|
||||
bottomSheet = false,
|
||||
}: {
|
||||
context: ComposerContextUsage | null;
|
||||
rounds: readonly ComposerRoundUsage[];
|
||||
showLabel?: boolean;
|
||||
bottomSheet?: boolean;
|
||||
}) {
|
||||
const { t, i18n } = useTranslation();
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const normalizedRounds = useMemo(() => normalizeRounds(rounds), [rounds]);
|
||||
const hasContext = !!context
|
||||
&& Number.isFinite(context.contextTokens)
|
||||
@@ -110,109 +114,104 @@ export function ComposerUsagePopover({
|
||||
minute: "2-digit",
|
||||
});
|
||||
|
||||
return (
|
||||
<Popover>
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>
|
||||
<PopoverTrigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="composer-context-usage"
|
||||
aria-label={triggerLabel}
|
||||
className={cn(
|
||||
"touch-target inline-flex size-5 shrink-0 items-center justify-center rounded-full",
|
||||
"text-muted-foreground/75 transition-colors hover:text-foreground/85",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
)}
|
||||
>
|
||||
{contextPercentage === null ? (
|
||||
<svg viewBox="0 0 16 16" aria-hidden="true" className="size-[15px]">
|
||||
<path
|
||||
d="M3 12V9m5 3V5m5 7V2"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
viewBox="0 0 16 16"
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-[15px] shrink-0 -rotate-90",
|
||||
status === "critical" && "text-destructive",
|
||||
status === "caution" && "text-amber-600 dark:text-amber-400",
|
||||
status === "normal" && "text-muted-foreground/75",
|
||||
)}
|
||||
>
|
||||
<circle
|
||||
cx="8"
|
||||
cy="8"
|
||||
r="6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
className="opacity-20"
|
||||
/>
|
||||
<circle
|
||||
cx="8"
|
||||
cy="8"
|
||||
r="6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeDasharray={`${ringLength} ${ringCircumference}`}
|
||||
data-testid="composer-context-meter"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
</PopoverTrigger>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="top"
|
||||
align="center"
|
||||
sideOffset={8}
|
||||
className="w-fit max-w-[calc(100vw-2rem)] rounded-full border-border/70 px-2.5 py-1 text-xs font-medium shadow-[0_8px_24px_rgba(15,23,42,0.13)]"
|
||||
const Root = bottomSheet ? Sheet : Popover;
|
||||
const Trigger = bottomSheet ? SheetTrigger : PopoverTrigger;
|
||||
const trigger = (
|
||||
<Trigger asChild>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="composer-context-usage"
|
||||
aria-label={triggerLabel}
|
||||
className={cn(
|
||||
"touch-target inline-flex size-5 shrink-0 items-center justify-center rounded-full",
|
||||
"text-muted-foreground/75 transition-colors hover:text-foreground/85",
|
||||
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",
|
||||
showLabel && "w-auto gap-1.5 px-2 text-xs",
|
||||
)}
|
||||
>
|
||||
{contextPercentage === null ? (
|
||||
<svg viewBox="0 0 16 16" aria-hidden="true" className="size-[15px]">
|
||||
<path
|
||||
d="M3 12V9m5 3V5m5 7V2"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
viewBox="0 0 16 16"
|
||||
aria-hidden="true"
|
||||
className={cn(
|
||||
"size-[15px] shrink-0 -rotate-90",
|
||||
status === "critical" && "text-destructive",
|
||||
status === "caution" && "text-amber-600 dark:text-amber-400",
|
||||
status === "normal" && "text-muted-foreground/75",
|
||||
)}
|
||||
>
|
||||
<span className="whitespace-nowrap tabular-nums">{contextDescription}</span>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
<circle
|
||||
cx="8"
|
||||
cy="8"
|
||||
r="6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
className="opacity-20"
|
||||
/>
|
||||
<circle
|
||||
cx="8"
|
||||
cy="8"
|
||||
r="6"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeDasharray={`${ringLength} ${ringCircumference}`}
|
||||
data-testid="composer-context-meter"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
{showLabel ? <span aria-hidden>{contextDescription}</span> : null}
|
||||
</button>
|
||||
</Trigger>
|
||||
);
|
||||
|
||||
<PopoverContent
|
||||
ref={panelRef}
|
||||
side="top"
|
||||
align="end"
|
||||
sideOffset={10}
|
||||
onOpenAutoFocus={(event) => {
|
||||
event.preventDefault();
|
||||
panelRef.current?.focus();
|
||||
}}
|
||||
aria-label={t("thread.composer.context.panelTitle", {
|
||||
defaultValue: "Context usage",
|
||||
})}
|
||||
className="w-[min(22rem,calc(100vw-1.5rem))] p-0"
|
||||
>
|
||||
return (
|
||||
<Root>
|
||||
<TooltipProvider>
|
||||
{bottomSheet ? trigger : (
|
||||
<Tooltip>
|
||||
<TooltipTrigger asChild>{trigger}</TooltipTrigger>
|
||||
<TooltipContent
|
||||
side="top"
|
||||
align="center"
|
||||
sideOffset={8}
|
||||
className="w-fit max-w-[calc(100vw-2rem)] rounded-full border-border/70 px-2.5 py-1 text-xs font-medium shadow-[0_8px_24px_rgba(15,23,42,0.13)]"
|
||||
>
|
||||
<span className="whitespace-nowrap tabular-nums">{contextDescription}</span>
|
||||
</TooltipContent>
|
||||
</Tooltip>
|
||||
)}
|
||||
|
||||
<UsagePanel bottomSheet={bottomSheet}>
|
||||
<div className="px-4 pb-4 pt-3.5">
|
||||
{contextPercentage !== null ? (
|
||||
<>
|
||||
<div className="flex items-baseline justify-between gap-3">
|
||||
<div className="flex min-w-0 items-baseline gap-2">
|
||||
<span className="shrink-0 text-[12px] font-medium text-foreground">
|
||||
<span className={cn("shrink-0 font-medium text-foreground", bottomSheet ? "text-sm" : "text-[12px]")}>
|
||||
{t("thread.composer.context.contextTitle", {
|
||||
defaultValue: "Context",
|
||||
})}
|
||||
</span>
|
||||
<span className="truncate text-[11px] tabular-nums text-muted-foreground">
|
||||
<span className={cn("truncate tabular-nums text-muted-foreground", bottomSheet ? "text-xs" : "text-[11px]")}>
|
||||
{formatCompactTokenCount(context!.contextTokens)} / {formatCompactTokenCount(
|
||||
context!.contextWindowTokens!,
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<span className="shrink-0 text-[11px] tabular-nums text-muted-foreground">
|
||||
<span className={cn("shrink-0 tabular-nums text-muted-foreground", bottomSheet ? "text-xs" : "text-[11px]")}>
|
||||
{contextPercentage}%
|
||||
</span>
|
||||
</div>
|
||||
@@ -243,12 +242,12 @@ export function ComposerUsagePopover({
|
||||
"flex items-baseline justify-between gap-3",
|
||||
contextPercentage === null ? "mt-0" : "mt-5",
|
||||
)}>
|
||||
<span className="text-[12px] font-medium text-foreground">
|
||||
<span className={cn("font-medium text-foreground", bottomSheet ? "text-sm" : "text-[12px]")}>
|
||||
{t("thread.composer.context.recentRounds", {
|
||||
defaultValue: "Recent rounds",
|
||||
})}
|
||||
</span>
|
||||
<span className="text-[11px] text-muted-foreground">
|
||||
<span className={cn("text-muted-foreground", bottomSheet ? "text-xs" : "text-[11px]")}>
|
||||
{t("thread.composer.context.inputTrend", {
|
||||
defaultValue: "Input tokens",
|
||||
})}
|
||||
@@ -403,8 +402,56 @@ export function ComposerUsagePopover({
|
||||
) : null}
|
||||
|
||||
</div>
|
||||
</PopoverContent>
|
||||
</UsagePanel>
|
||||
</TooltipProvider>
|
||||
</Popover>
|
||||
</Root>
|
||||
);
|
||||
}
|
||||
|
||||
function UsagePanel({ bottomSheet, children }: { bottomSheet: boolean; children: ReactNode }) {
|
||||
const { t } = useTranslation();
|
||||
const panelRef = useRef<HTMLDivElement>(null);
|
||||
const title = t("thread.composer.context.panelTitle", { defaultValue: "Context usage" });
|
||||
const focusPanel = (event: Event) => {
|
||||
event.preventDefault();
|
||||
panelRef.current?.focus({ preventScroll: true });
|
||||
};
|
||||
|
||||
if (bottomSheet) {
|
||||
return (
|
||||
<SheetContent
|
||||
ref={panelRef}
|
||||
side="bottom"
|
||||
aria-describedby={undefined}
|
||||
onOpenAutoFocus={focusPanel}
|
||||
className={cn(
|
||||
"mx-auto max-h-[60dvh] w-full max-w-md gap-0 rounded-t-3xl border-t border-border/60 p-0 shadow-xl outline-none",
|
||||
"data-[state=open]:duration-300 data-[state=open]:ease-out data-[state=closed]:duration-200 data-[state=closed]:ease-in",
|
||||
)}
|
||||
closeButtonClassName="right-3 top-5 flex size-11 items-center justify-center rounded-full"
|
||||
>
|
||||
<div aria-hidden="true" className="mx-auto mt-2.5 h-1 w-8 shrink-0 rounded-full bg-foreground/15" />
|
||||
<div className="shrink-0 px-5 pb-2 pt-5 pr-16">
|
||||
<SheetTitle className="text-base font-medium">{title}</SheetTitle>
|
||||
</div>
|
||||
<div className="min-h-0 overflow-y-auto overscroll-contain px-1 pb-[max(0.75rem,env(safe-area-inset-bottom))]">
|
||||
{children}
|
||||
</div>
|
||||
</SheetContent>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<PopoverContent
|
||||
ref={panelRef}
|
||||
side="top"
|
||||
align="end"
|
||||
sideOffset={10}
|
||||
onOpenAutoFocus={focusPanel}
|
||||
aria-label={title}
|
||||
className="w-[min(22rem,calc(100vw-1.5rem))] p-0"
|
||||
>
|
||||
{children}
|
||||
</PopoverContent>
|
||||
);
|
||||
}
|
||||
@@ -483,7 +483,7 @@ function PresetOption({
|
||||
className={cn(
|
||||
floatingItemClassName,
|
||||
floatingItemFocusClassName,
|
||||
"flex min-h-9 w-full cursor-pointer gap-2.5 px-2.5 py-1.5 text-left hover:bg-muted/55",
|
||||
"flex min-h-9 w-full cursor-pointer gap-2.5 px-2.5 py-1.5 text-left hover:bg-muted/55 max-sm:min-h-11",
|
||||
selected && "bg-muted/55 text-foreground",
|
||||
)}
|
||||
>
|
||||
@@ -493,8 +493,8 @@ function PresetOption({
|
||||
provider={preset.provider}
|
||||
isHero={false}
|
||||
/>
|
||||
<span className="flex min-w-0 flex-1 items-baseline gap-1.5 overflow-hidden whitespace-nowrap">
|
||||
<span className="shrink-0 text-[13px] font-medium text-foreground">{preset.name}</span>
|
||||
<span className="flex min-w-0 flex-1 items-baseline gap-1.5 overflow-hidden whitespace-nowrap max-sm:flex-col max-sm:items-start max-sm:gap-0.5 max-sm:whitespace-normal">
|
||||
<span className="shrink-0 text-[13px] font-medium text-foreground max-sm:max-w-full max-sm:break-words">{preset.name}</span>
|
||||
{detail && detail !== preset.name ? (
|
||||
<span className="truncate text-[12px] text-muted-foreground">{detail}</span>
|
||||
) : null}
|
||||
|
||||
@@ -963,6 +963,32 @@ export function ThreadComposer({
|
||||
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
||||
const mentionOverlayRef = useRef<HTMLDivElement>(null);
|
||||
const formRef = useRef<HTMLFormElement>(null);
|
||||
const [compactControls, setCompactControls] = useState(false);
|
||||
|
||||
useLayoutEffect(() => {
|
||||
const form = formRef.current;
|
||||
if (!form) return;
|
||||
let previousWidth = 0;
|
||||
const update = () => {
|
||||
const width = form.getBoundingClientRect().width;
|
||||
if (width <= 0 || width === previousWidth) return;
|
||||
previousWidth = width;
|
||||
setCompactControls(width <= 512);
|
||||
const input = textareaRef.current;
|
||||
if (input) {
|
||||
input.style.height = "auto";
|
||||
input.style.height = `${Math.min(input.scrollHeight, 260)}px`;
|
||||
}
|
||||
};
|
||||
update();
|
||||
const observer = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(update);
|
||||
observer?.observe(form);
|
||||
window.addEventListener("resize", update);
|
||||
return () => {
|
||||
observer?.disconnect();
|
||||
window.removeEventListener("resize", update);
|
||||
};
|
||||
}, []);
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const chipRefs = useRef(new Map<string, HTMLButtonElement>());
|
||||
const queuedPromptCounterRef = useRef(0);
|
||||
@@ -1524,7 +1550,7 @@ export function ThreadComposer({
|
||||
el.style.height = "auto";
|
||||
el.style.height = `${Math.min(el.scrollHeight, 260)}px`;
|
||||
if (mentionOverlayRef.current) mentionOverlayRef.current.scrollTop = el.scrollTop;
|
||||
}, [mentionInput.isComposing, mentionInput.value]);
|
||||
}, [compactControls, mentionInput.isComposing, mentionInput.value]);
|
||||
|
||||
// Runs before paint so switching sessions never flashes stale draft text.
|
||||
useLayoutEffect(() => {
|
||||
@@ -2201,12 +2227,12 @@ export function ThreadComposer({
|
||||
: t("thread.composer.voice.hint");
|
||||
const showStopButton = isStreaming && !!onStop;
|
||||
const relaxedHeroInput = isHero && images.length === 0 && !isStreaming;
|
||||
const compactIdle = compactWhenIdle && !isHero && !composerFocused
|
||||
const compactIdle = compactWhenIdle && !compactControls && !isHero && !composerFocused
|
||||
&& value.length === 0 && images.length === 0 && !inlineError
|
||||
&& !normalizedQuotedContext && !queuedPrompts.length && !goalState?.active
|
||||
&& !isDragging && !sessionDragPreview && !voiceRecorder.isRecording && !showProjectPicker;
|
||||
useLayoutEffect(() => {
|
||||
if (!compactWhenIdle) return;
|
||||
if (!compactWhenIdle || compactControls) return;
|
||||
const form = formRef.current;
|
||||
const primary = form?.querySelector<HTMLElement>(".thread-composer-footer-primary");
|
||||
const actions = form?.querySelector<HTMLElement>(".thread-composer-footer-actions");
|
||||
@@ -2225,20 +2251,53 @@ export function ThreadComposer({
|
||||
controls.forEach((control) => observer?.observe(control));
|
||||
observer?.observe(actions);
|
||||
return () => observer?.disconnect();
|
||||
}, [compactWhenIdle, modelLabel, voiceRecorder.isRecording, workspaceScope]);
|
||||
}, [compactControls, compactWhenIdle, modelLabel, voiceRecorder.isRecording, workspaceScope]);
|
||||
const accessControl = workspaceScope && !workspaceControlsHidden ? (
|
||||
<WorkspaceAccessMenu
|
||||
scope={workspaceScope}
|
||||
disabled={interactionDisabled || workspaceScopeDisabled}
|
||||
canUseFullAccess={workspaceControls?.can_use_full_access !== false}
|
||||
isHero={isHero}
|
||||
onChange={onWorkspaceScopeChange}
|
||||
/>
|
||||
) : null;
|
||||
const modelControl = modelLabel && !voiceRecorder.isRecording ? (
|
||||
<ModelPresetBadge
|
||||
label={modelLabel}
|
||||
modelDetail={modelDetail}
|
||||
modelPreset={modelPreset}
|
||||
modelPresets={modelPresets}
|
||||
onPresetChange={onModelPresetChange}
|
||||
onManageModels={onManageModels}
|
||||
onRequestComposerFocus={() => textareaRef.current?.focus()}
|
||||
provider={modelProvider}
|
||||
providerLabel={modelProviderLabel}
|
||||
needsSetup={modelNeedsSetup}
|
||||
attentionRequest={modelSetupAttentionRequest}
|
||||
fallbackModelName={fallbackModelName}
|
||||
isHero={isHero && !compactControls}
|
||||
onClick={modelNeedsSetup ? onModelBadgeClick : undefined}
|
||||
/>
|
||||
) : null;
|
||||
const usageControl = !voiceRecorder.isRecording ? (
|
||||
<ComposerUsagePopover context={contextUsage} rounds={recentRoundUsage} showLabel={compactControls} bottomSheet={compactControls} />
|
||||
) : null;
|
||||
const inputTextClasses = cn(
|
||||
"w-full resize-none bg-transparent",
|
||||
isHero
|
||||
? cn(
|
||||
"min-h-[78px] px-4 text-[16px] leading-6 sm:px-5",
|
||||
relaxedHeroInput ? "pb-2 pt-[27px]" : "pb-1.5 pt-4",
|
||||
)
|
||||
: "min-h-[50px] px-3.5 pb-1.5 pt-3 text-[16px] leading-5 sm:px-4",
|
||||
compactControls
|
||||
? "min-h-[52px] px-4 pb-2 pt-3 text-[16px] leading-6"
|
||||
: isHero
|
||||
? cn(
|
||||
"min-h-[78px] px-4 text-[16px] leading-6 sm:px-5",
|
||||
relaxedHeroInput ? "pb-2 pt-[27px]" : "pb-1.5 pt-4",
|
||||
)
|
||||
: "min-h-[50px] px-3.5 pb-1.5 pt-3 text-[16px] leading-5 sm:px-4",
|
||||
);
|
||||
|
||||
return (
|
||||
<form
|
||||
ref={formRef}
|
||||
data-compact-controls={compactControls ? "true" : undefined}
|
||||
onFocusCapture={() => {
|
||||
if (!compactWhenIdle) return;
|
||||
// Portaled model controls belong to this composer too: keep its layout
|
||||
@@ -2488,7 +2547,7 @@ export function ThreadComposer({
|
||||
aria-label={t("thread.composer.attachImage")}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className={cn(
|
||||
"thread-composer-action touch-target rounded-full text-muted-foreground hover:text-foreground",
|
||||
"thread-composer-action thread-composer-round-action touch-target rounded-full text-muted-foreground hover:text-foreground",
|
||||
isHero
|
||||
? "h-8 w-8 border border-border/55 bg-card shadow-[0_2px_8px_rgba(15,23,42,0.05)] hover:bg-card"
|
||||
: "h-9 w-9 border border-border/55 bg-card shadow-[0_2px_8px_rgba(15,23,42,0.05)] hover:bg-card",
|
||||
@@ -2504,15 +2563,7 @@ export function ThreadComposer({
|
||||
isHero={isHero}
|
||||
levels={voiceRecorder.levels}
|
||||
/>
|
||||
) : workspaceScope && !workspaceControlsHidden ? (
|
||||
<WorkspaceAccessMenu
|
||||
scope={workspaceScope}
|
||||
disabled={interactionDisabled || workspaceScopeDisabled}
|
||||
canUseFullAccess={workspaceControls?.can_use_full_access !== false}
|
||||
isHero={isHero}
|
||||
onChange={onWorkspaceScopeChange}
|
||||
/>
|
||||
) : null}
|
||||
) : compactControls ? modelControl : accessControl}
|
||||
</div>
|
||||
<div
|
||||
className={cn(
|
||||
@@ -2520,30 +2571,8 @@ export function ThreadComposer({
|
||||
isHero ? "gap-1.5" : "gap-2",
|
||||
)}
|
||||
>
|
||||
{modelLabel && !voiceRecorder.isRecording ? (
|
||||
<ModelPresetBadge
|
||||
label={modelLabel}
|
||||
modelDetail={modelDetail}
|
||||
modelPreset={modelPreset}
|
||||
modelPresets={modelPresets}
|
||||
onPresetChange={onModelPresetChange}
|
||||
onManageModels={onManageModels}
|
||||
onRequestComposerFocus={() => textareaRef.current?.focus()}
|
||||
provider={modelProvider}
|
||||
providerLabel={modelProviderLabel}
|
||||
needsSetup={modelNeedsSetup}
|
||||
attentionRequest={modelSetupAttentionRequest}
|
||||
fallbackModelName={fallbackModelName}
|
||||
isHero={isHero}
|
||||
onClick={modelNeedsSetup ? onModelBadgeClick : undefined}
|
||||
/>
|
||||
) : null}
|
||||
{!voiceRecorder.isRecording ? (
|
||||
<ComposerUsagePopover
|
||||
context={contextUsage}
|
||||
rounds={recentRoundUsage}
|
||||
/>
|
||||
) : null}
|
||||
{!compactControls ? modelControl : null}
|
||||
{!compactControls ? usageControl : null}
|
||||
{showVoiceButton ? (
|
||||
<TooltipProvider>
|
||||
<Tooltip>
|
||||
@@ -2604,7 +2633,7 @@ export function ThreadComposer({
|
||||
}
|
||||
onClick={showStopButton ? handleStop : modelNeedsSetup ? onModelBadgeClick : undefined}
|
||||
className={cn(
|
||||
"thread-composer-action touch-target rounded-full transition-transform",
|
||||
"thread-composer-action thread-composer-round-action touch-target rounded-full transition-transform",
|
||||
showStopButton
|
||||
? "border border-border/70 bg-card text-foreground/85 shadow-[0_3px_10px_rgba(15,23,42,0.08)] hover:bg-muted/65 hover:text-foreground disabled:text-muted-foreground/50"
|
||||
: isHero
|
||||
@@ -2648,6 +2677,12 @@ export function ThreadComposer({
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
{compactControls ? (
|
||||
<div className="thread-composer-meta mx-auto flex w-full max-w-[58rem] items-center justify-between gap-2 px-2">
|
||||
{accessControl}
|
||||
<div className="ml-auto">{usageControl}</div>
|
||||
</div>
|
||||
) : null}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ function AccessMenuItem({
|
||||
disabled={disabled}
|
||||
onSelect={onSelect}
|
||||
className={cn(
|
||||
"flex h-10 items-center gap-3 px-3 text-[13.5px] font-semibold",
|
||||
"flex h-10 items-center gap-3 px-3 text-[13.5px] font-semibold max-sm:min-h-11",
|
||||
warning && "text-orange-600 focus:text-orange-600 dark:text-orange-300 dark:focus:text-orange-300",
|
||||
)}
|
||||
>
|
||||
|
||||
@@ -7,6 +7,7 @@ import { useTranslation } from "react-i18next";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
const Sheet = DialogPrimitive.Root;
|
||||
const SheetTrigger = DialogPrimitive.Trigger;
|
||||
const SheetPortal = DialogPrimitive.Portal;
|
||||
|
||||
const SheetOverlay = React.forwardRef<
|
||||
@@ -19,6 +20,7 @@ const SheetOverlay = React.forwardRef<
|
||||
"fixed inset-0 z-50 bg-black/40",
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out",
|
||||
"data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",
|
||||
"motion-reduce:data-[state=open]:animate-none motion-reduce:data-[state=closed]:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
@@ -85,7 +87,8 @@ const SheetContent = React.forwardRef<
|
||||
className={cn(
|
||||
sheetVariants({ side }),
|
||||
"data-[state=open]:animate-in data-[state=closed]:animate-out",
|
||||
"duration-300",
|
||||
"duration-300 motion-reduce:transition-none",
|
||||
"motion-reduce:data-[state=open]:animate-none motion-reduce:data-[state=closed]:animate-none",
|
||||
className,
|
||||
)}
|
||||
{...props}
|
||||
@@ -134,4 +137,4 @@ const SheetDescription = React.forwardRef<
|
||||
));
|
||||
SheetDescription.displayName = DialogPrimitive.Description.displayName;
|
||||
|
||||
export { Sheet, SheetContent, SheetDescription, SheetTitle };
|
||||
export { Sheet, SheetTrigger, SheetContent, SheetDescription, SheetTitle };
|
||||
+58
-75
@@ -758,9 +758,8 @@
|
||||
}
|
||||
|
||||
/*
|
||||
* Composer controls compress against their actual container, not the viewport.
|
||||
* Permission state has priority over the model label; both retain their full
|
||||
* accessible names and tooltip text when their visible labels are shortened.
|
||||
* Composer controls adapt to their actual container, not just the viewport.
|
||||
* Narrow layouts move access and usage into a separate metadata row.
|
||||
*/
|
||||
.thread-composer-surface {
|
||||
container-name: thread-composer;
|
||||
@@ -919,84 +918,68 @@
|
||||
}
|
||||
}
|
||||
|
||||
@container thread-composer (max-width: 21rem) {
|
||||
.thread-composer-footer {
|
||||
column-gap: 0.25rem;
|
||||
padding-inline: 0.5rem;
|
||||
}
|
||||
|
||||
.thread-composer-footer-primary,
|
||||
.thread-composer-footer-actions {
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
.thread-composer-access {
|
||||
max-width: 6.5rem;
|
||||
padding-inline: 0.5rem;
|
||||
font-size: 0.71875rem;
|
||||
}
|
||||
|
||||
.thread-composer-access-icon {
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.thread-composer-access-chevron {
|
||||
margin-left: 0.25rem;
|
||||
}
|
||||
|
||||
.thread-composer-access-label-full {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.thread-composer-access-label-short {
|
||||
display: inline;
|
||||
}
|
||||
/* Narrow composers separate message actions from permissions and usage instead
|
||||
* of shrinking touch targets or hiding the active model and access state. */
|
||||
[data-compact-controls] .thread-composer-footer {
|
||||
column-gap: 0.25rem;
|
||||
padding: 0 0.5rem 0.5rem;
|
||||
}
|
||||
|
||||
@container thread-composer (max-width: 19rem) {
|
||||
.thread-composer-model-badge {
|
||||
width: 2rem;
|
||||
flex: none;
|
||||
}
|
||||
|
||||
.thread-composer-model-badge .composer-model-pill {
|
||||
width: 100%;
|
||||
justify-content: center;
|
||||
gap: 0;
|
||||
padding-inline: 0;
|
||||
}
|
||||
|
||||
.thread-composer-model-label {
|
||||
display: none;
|
||||
}
|
||||
[data-compact-controls] .thread-composer-footer-primary,
|
||||
[data-compact-controls] .thread-composer-footer-actions {
|
||||
gap: 0.25rem;
|
||||
}
|
||||
|
||||
@container thread-composer (max-width: 16rem) {
|
||||
.thread-composer-access {
|
||||
width: 2rem;
|
||||
flex: none;
|
||||
justify-content: center;
|
||||
padding-inline: 0;
|
||||
}
|
||||
|
||||
.thread-composer-access-icon {
|
||||
margin-right: 0;
|
||||
}
|
||||
|
||||
.thread-composer-access-label-short,
|
||||
.thread-composer-access-chevron {
|
||||
display: none;
|
||||
}
|
||||
[data-compact-controls] .thread-composer-footer-actions {
|
||||
flex: none;
|
||||
max-width: none;
|
||||
}
|
||||
|
||||
@container thread-composer (max-width: 15rem) {
|
||||
.thread-composer-action.touch-target,
|
||||
.thread-composer-access.touch-target {
|
||||
width: 2rem;
|
||||
min-width: 2rem;
|
||||
height: 2rem;
|
||||
min-height: 2rem;
|
||||
}
|
||||
[data-compact-controls] .thread-composer-action.touch-target {
|
||||
flex: none;
|
||||
width: 2.75rem;
|
||||
height: 2.75rem;
|
||||
min-width: 2.75rem;
|
||||
min-height: 2.75rem;
|
||||
}
|
||||
|
||||
[data-compact-controls] .thread-composer-model-badge {
|
||||
max-width: 100%;
|
||||
min-height: 2.75rem;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
/* Keep a 44px hit area around the quieter 36px attachment/send circles.
|
||||
* The transparent pseudo-element belongs to the button, including its disabled
|
||||
* state; margins reserve its space so adjacent controls never overlap it. */
|
||||
[data-compact-controls] .thread-composer-round-action.touch-target {
|
||||
position: relative;
|
||||
width: 2.25rem;
|
||||
height: 2.25rem;
|
||||
min-width: 2.25rem;
|
||||
min-height: 2.25rem;
|
||||
margin: 0.25rem;
|
||||
}
|
||||
|
||||
[data-compact-controls] .thread-composer-round-action::before {
|
||||
content: "";
|
||||
position: absolute;
|
||||
inset: -0.3125rem;
|
||||
border-radius: inherit;
|
||||
}
|
||||
|
||||
[data-compact-controls] .composer-model-pill {
|
||||
height: 2.25rem;
|
||||
}
|
||||
|
||||
.thread-composer-meta .touch-target {
|
||||
min-height: 2.75rem;
|
||||
min-width: 2.75rem;
|
||||
}
|
||||
|
||||
.thread-composer-meta .thread-composer-access {
|
||||
max-width: 100%;
|
||||
padding-inline: 0.5rem;
|
||||
}
|
||||
@media (forced-colors: active) {
|
||||
[data-workbench-move-handle]:focus-visible {
|
||||
|
||||
@@ -1141,6 +1141,114 @@ describe("ThreadComposer", () => {
|
||||
expect(screen.getByDisplayValue("voice text")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each(["thread", "hero"] as const)("separates narrow %s actions from access and usage without losing the draft", async (variant) => {
|
||||
let width = 390;
|
||||
vi.spyOn(HTMLFormElement.prototype, "getBoundingClientRect").mockImplementation(
|
||||
() => rect({ width, height: 160 }),
|
||||
);
|
||||
const onSend = vi.fn();
|
||||
const onWorkspaceScopeChange = vi.fn();
|
||||
const { container } = render(
|
||||
<ThreadComposer
|
||||
variant={variant}
|
||||
compactWhenIdle
|
||||
onSend={onSend}
|
||||
modelLabel="codex"
|
||||
workspaceScope={{ project_path: "/tmp/project", project_name: "project", access_mode: "full", restrict_to_workspace: false }}
|
||||
onWorkspaceScopeChange={onWorkspaceScopeChange}
|
||||
contextUsage={{ contextTokens: 500, contextWindowTokens: 1000 }}
|
||||
/>,
|
||||
);
|
||||
const form = container.querySelector("form")!;
|
||||
const input = screen.getByRole("textbox");
|
||||
const access = screen.getByRole("button", { name: "Workspace access mode: Full Access" });
|
||||
const meta = container.querySelector(".thread-composer-meta")!;
|
||||
expect(form).toHaveAttribute("data-compact-controls", "true");
|
||||
expect(container.querySelector(".thread-composer-surface")).not.toHaveAttribute("data-compact");
|
||||
expect(meta).toContainElement(access);
|
||||
expect(meta).toContainElement(screen.getByTestId("composer-context-usage"));
|
||||
expect(within(meta as HTMLElement).getByText("Context 50%")).toBeVisible();
|
||||
expect(container.querySelector(".thread-composer-footer-primary")).toContainElement(screen.getByLabelText("codex"));
|
||||
fireEvent.change(input, { target: { value: "keep this draft" } });
|
||||
|
||||
// A narrow desktop panel uses the same layout; resizing must not replace the textarea.
|
||||
width = 800;
|
||||
fireEvent(window, new Event("resize"));
|
||||
expect(form).not.toHaveAttribute("data-compact-controls");
|
||||
expect(container.querySelector(".thread-composer-meta")).not.toBeInTheDocument();
|
||||
expect(screen.getByRole("textbox")).toBe(input);
|
||||
expect(input).toHaveValue("keep this draft");
|
||||
expect(container.querySelector(".thread-composer-footer-actions")).toContainElement(screen.getByLabelText("codex"));
|
||||
expect(screen.getAllByRole("button", { name: "Workspace access mode: Full Access" })).toHaveLength(1);
|
||||
|
||||
width = 320;
|
||||
fireEvent(window, new Event("resize"));
|
||||
expect(form).toHaveAttribute("data-compact-controls", "true");
|
||||
expect(input).toHaveValue("keep this draft");
|
||||
fireEvent.click(screen.getByRole("button", { name: "Send message" }));
|
||||
await waitFor(() => expect(onSend).toHaveBeenCalledWith("keep this draft", undefined, undefined));
|
||||
expect(onWorkspaceScopeChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each(["close button", "Escape"])("opens narrow context usage as a bottom sheet and restores interaction after %s", async (dismissal) => {
|
||||
vi.spyOn(HTMLFormElement.prototype, "getBoundingClientRect").mockReturnValue(
|
||||
rect({ width: 390, height: 160 }),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
const onSend = vi.fn();
|
||||
render(
|
||||
<ThreadComposer
|
||||
onSend={onSend}
|
||||
contextUsage={{ contextTokens: 10000, contextWindowTokens: 200000 }}
|
||||
recentRoundUsage={[{
|
||||
id: "turn-1",
|
||||
timestamp: Date.UTC(2026, 8, 13, 7, 20),
|
||||
inputTokens: 10000,
|
||||
outputTokens: 280,
|
||||
cachedTokens: 8000,
|
||||
}]}
|
||||
/>,
|
||||
);
|
||||
const trigger = screen.getByTestId("composer-context-usage");
|
||||
await user.click(trigger);
|
||||
const sheet = screen.getByRole("dialog", { name: "Context usage" });
|
||||
expect(sheet).toHaveClass("bottom-0", "max-h-[60dvh]");
|
||||
expect(sheet).toHaveFocus();
|
||||
expect(within(sheet).getByRole("heading", { name: "Context usage" })).toBeVisible();
|
||||
expect(within(sheet).getByText("10K / 200K")).toBeVisible();
|
||||
expect(within(sheet).getByTestId("round-usage-bar")).toBeVisible();
|
||||
expect(sheet).toContainElement(within(sheet).getByRole("group", { name: "Input tokens" }));
|
||||
expect(document.body).toHaveStyle({ pointerEvents: "none" });
|
||||
|
||||
if (dismissal === "Escape") await user.keyboard("{Escape}");
|
||||
else await user.click(within(sheet).getByRole("button", { name: "Close" }));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(document.body).not.toHaveStyle({ pointerEvents: "none" });
|
||||
expect(trigger).toHaveFocus();
|
||||
await user.type(screen.getByRole("textbox"), "still works");
|
||||
await user.click(screen.getByRole("button", { name: "Send message" }));
|
||||
expect(onSend).toHaveBeenCalledWith("still works", undefined, undefined);
|
||||
});
|
||||
|
||||
it("releases the mobile sheet when resizing to desktop and keeps the desktop popover", async () => {
|
||||
let width = 390;
|
||||
vi.spyOn(HTMLFormElement.prototype, "getBoundingClientRect").mockImplementation(
|
||||
() => rect({ width, height: 160 }),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
render(<ThreadComposer onSend={vi.fn()} contextUsage={{ contextTokens: 500, contextWindowTokens: 1000 }} />);
|
||||
await user.click(screen.getByTestId("composer-context-usage"));
|
||||
expect(screen.getByRole("dialog")).toHaveClass("bottom-0");
|
||||
|
||||
width = 800;
|
||||
fireEvent(window, new Event("resize"));
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
expect(document.body).not.toHaveStyle({ pointerEvents: "none" });
|
||||
await user.click(screen.getByTestId("composer-context-usage"));
|
||||
expect(screen.getByRole("dialog", { name: "Context usage" })).not.toHaveClass("bottom-0");
|
||||
expect(screen.getByRole("progressbar", { name: "Context 50%" })).toBeVisible();
|
||||
});
|
||||
|
||||
it("renders and changes workspace access mode", async () => {
|
||||
const onWorkspaceScopeChange = vi.fn();
|
||||
render(
|
||||
|
||||
Reference in new issue
Block a user