fixing the input ui at certain endpoints causing the button to overflow. (#1574)
This commit is contained in:
1 parent
19eb9e7227
commit
0bc94bc24e
6 files changed
+831
-173
No files matched your search
@@ -11,6 +11,7 @@ import {
|
||||
type ProjectId,
|
||||
type ServerConfig,
|
||||
type ThreadId,
|
||||
type TurnId,
|
||||
type WsWelcomePayload,
|
||||
WS_CHANNELS,
|
||||
WS_METHODS,
|
||||
@@ -79,6 +80,20 @@ const DEFAULT_VIEWPORT: ViewportSpec = {
|
||||
textTolerancePx: 44,
|
||||
attachmentTolerancePx: 56,
|
||||
};
|
||||
const WIDE_FOOTER_VIEWPORT: ViewportSpec = {
|
||||
name: "wide-footer",
|
||||
width: 1_400,
|
||||
height: 1_100,
|
||||
textTolerancePx: 44,
|
||||
attachmentTolerancePx: 56,
|
||||
};
|
||||
const COMPACT_FOOTER_VIEWPORT: ViewportSpec = {
|
||||
name: "compact-footer",
|
||||
width: 430,
|
||||
height: 932,
|
||||
textTolerancePx: 56,
|
||||
attachmentTolerancePx: 56,
|
||||
};
|
||||
const TEXT_VIEWPORT_MATRIX = [
|
||||
DEFAULT_VIEWPORT,
|
||||
{ name: "tablet", width: 720, height: 1_024, textTolerancePx: 44, attachmentTolerancePx: 56 },
|
||||
@@ -102,6 +117,7 @@ interface MountedChatView {
|
||||
cleanup: () => Promise<void>;
|
||||
measureUserRow: (targetMessageId: MessageId) => Promise<UserRowMeasurement>;
|
||||
setViewport: (viewport: ViewportSpec) => Promise<void>;
|
||||
setContainerSize: (viewport: Pick<ViewportSpec, "width" | "height">) => Promise<void>;
|
||||
router: ReturnType<typeof getRouter>;
|
||||
}
|
||||
|
||||
@@ -513,6 +529,114 @@ function createSnapshotWithLongProposedPlan(): OrchestrationReadModel {
|
||||
};
|
||||
}
|
||||
|
||||
function createSnapshotWithPendingUserInput(): OrchestrationReadModel {
|
||||
const snapshot = createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-pending-input-target" as MessageId,
|
||||
targetText: "question thread",
|
||||
});
|
||||
|
||||
return {
|
||||
...snapshot,
|
||||
threads: snapshot.threads.map((thread) =>
|
||||
thread.id === THREAD_ID
|
||||
? Object.assign({}, thread, {
|
||||
interactionMode: "plan",
|
||||
activities: [
|
||||
{
|
||||
id: EventId.makeUnsafe("activity-user-input-requested"),
|
||||
tone: "info",
|
||||
kind: "user-input.requested",
|
||||
summary: "User input requested",
|
||||
payload: {
|
||||
requestId: "req-browser-user-input",
|
||||
questions: [
|
||||
{
|
||||
id: "scope",
|
||||
header: "Scope",
|
||||
question: "What should this change cover?",
|
||||
options: [
|
||||
{
|
||||
label: "Tight",
|
||||
description: "Touch only the footer layout logic.",
|
||||
},
|
||||
{
|
||||
label: "Broad",
|
||||
description: "Also adjust the related composer controls.",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
id: "risk",
|
||||
header: "Risk",
|
||||
question: "How aggressive should the imaginary plan be?",
|
||||
options: [
|
||||
{
|
||||
label: "Conservative",
|
||||
description: "Favor reliability and low-risk changes.",
|
||||
},
|
||||
{
|
||||
label: "Balanced",
|
||||
description: "Mix quick wins with one structural improvement.",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
turnId: null,
|
||||
sequence: 1,
|
||||
createdAt: isoAt(1_000),
|
||||
},
|
||||
],
|
||||
updatedAt: isoAt(1_000),
|
||||
})
|
||||
: thread,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function createSnapshotWithPlanFollowUpPrompt(): OrchestrationReadModel {
|
||||
const snapshot = createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-plan-follow-up-target" as MessageId,
|
||||
targetText: "plan follow-up thread",
|
||||
});
|
||||
|
||||
return {
|
||||
...snapshot,
|
||||
threads: snapshot.threads.map((thread) =>
|
||||
thread.id === THREAD_ID
|
||||
? Object.assign({}, thread, {
|
||||
interactionMode: "plan",
|
||||
latestTurn: {
|
||||
turnId: "turn-plan-follow-up" as TurnId,
|
||||
state: "completed",
|
||||
requestedAt: isoAt(1_000),
|
||||
startedAt: isoAt(1_001),
|
||||
completedAt: isoAt(1_010),
|
||||
assistantMessageId: null,
|
||||
},
|
||||
proposedPlans: [
|
||||
{
|
||||
id: "plan-follow-up-browser-test",
|
||||
turnId: "turn-plan-follow-up" as TurnId,
|
||||
planMarkdown: "# Follow-up plan\n\n- Keep the composer footer stable on resize.",
|
||||
implementedAt: null,
|
||||
implementationThreadId: null,
|
||||
createdAt: isoAt(1_002),
|
||||
updatedAt: isoAt(1_003),
|
||||
},
|
||||
],
|
||||
session: {
|
||||
...thread.session,
|
||||
status: "ready",
|
||||
updatedAt: isoAt(1_010),
|
||||
},
|
||||
updatedAt: isoAt(1_010),
|
||||
})
|
||||
: thread,
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
function resolveWsRpc(body: WsRequestEnvelope["body"]): unknown {
|
||||
const customResult = customWsRpcResolver?.(body);
|
||||
if (customResult !== undefined) {
|
||||
@@ -694,6 +818,13 @@ async function waitForComposerEditor(): Promise<HTMLElement> {
|
||||
);
|
||||
}
|
||||
|
||||
async function waitForComposerMenuItem(itemId: string): Promise<HTMLElement> {
|
||||
return waitForElement(
|
||||
() => document.querySelector<HTMLElement>(`[data-composer-item-id="${itemId}"]`),
|
||||
`Unable to find composer menu item "${itemId}".`,
|
||||
);
|
||||
}
|
||||
|
||||
async function waitForSendButton(): Promise<HTMLButtonElement> {
|
||||
return waitForElement(
|
||||
() => document.querySelector<HTMLButtonElement>('button[aria-label="Send message"]'),
|
||||
@@ -701,6 +832,62 @@ async function waitForSendButton(): Promise<HTMLButtonElement> {
|
||||
);
|
||||
}
|
||||
|
||||
function findComposerProviderModelPicker(): HTMLButtonElement | null {
|
||||
return document.querySelector<HTMLButtonElement>('[data-chat-provider-model-picker="true"]');
|
||||
}
|
||||
|
||||
function findButtonByText(text: string): HTMLButtonElement | null {
|
||||
return (Array.from(document.querySelectorAll("button")).find(
|
||||
(button) => button.textContent?.trim() === text,
|
||||
) ?? null) as HTMLButtonElement | null;
|
||||
}
|
||||
|
||||
async function waitForButtonByText(text: string): Promise<HTMLButtonElement> {
|
||||
return waitForElement(() => findButtonByText(text), `Unable to find "${text}" button.`);
|
||||
}
|
||||
|
||||
function findButtonContainingText(text: string): HTMLButtonElement | null {
|
||||
return (Array.from(document.querySelectorAll("button")).find((button) =>
|
||||
button.textContent?.includes(text),
|
||||
) ?? null) as HTMLButtonElement | null;
|
||||
}
|
||||
|
||||
async function waitForButtonContainingText(text: string): Promise<HTMLButtonElement> {
|
||||
return waitForElement(
|
||||
() => findButtonContainingText(text),
|
||||
`Unable to find button containing "${text}".`,
|
||||
);
|
||||
}
|
||||
|
||||
async function expectComposerActionsContained(): Promise<void> {
|
||||
const footer = await waitForElement(
|
||||
() => document.querySelector<HTMLElement>('[data-chat-composer-footer="true"]'),
|
||||
"Unable to find composer footer.",
|
||||
);
|
||||
const actions = await waitForElement(
|
||||
() => document.querySelector<HTMLElement>('[data-chat-composer-actions="right"]'),
|
||||
"Unable to find composer actions container.",
|
||||
);
|
||||
|
||||
await vi.waitFor(
|
||||
() => {
|
||||
const footerRect = footer.getBoundingClientRect();
|
||||
const actionButtons = Array.from(actions.querySelectorAll<HTMLButtonElement>("button"));
|
||||
expect(actionButtons.length).toBeGreaterThanOrEqual(1);
|
||||
|
||||
const buttonRects = actionButtons.map((button) => button.getBoundingClientRect());
|
||||
const firstTop = buttonRects[0]?.top ?? 0;
|
||||
|
||||
for (const rect of buttonRects) {
|
||||
expect(rect.right).toBeLessThanOrEqual(footerRect.right + 0.5);
|
||||
expect(rect.bottom).toBeLessThanOrEqual(footerRect.bottom + 0.5);
|
||||
expect(Math.abs(rect.top - firstTop)).toBeLessThanOrEqual(1.5);
|
||||
}
|
||||
},
|
||||
{ timeout: 8_000, interval: 16 },
|
||||
);
|
||||
}
|
||||
|
||||
async function waitForInteractionModeButton(
|
||||
expectedLabel: "Chat" | "Plan",
|
||||
): Promise<HTMLButtonElement> {
|
||||
@@ -864,7 +1051,8 @@ async function mountChatView(options: {
|
||||
|
||||
const host = document.createElement("div");
|
||||
host.style.position = "fixed";
|
||||
host.style.inset = "0";
|
||||
host.style.top = "0";
|
||||
host.style.left = "0";
|
||||
host.style.width = "100vw";
|
||||
host.style.height = "100vh";
|
||||
host.style.display = "grid";
|
||||
@@ -897,6 +1085,11 @@ async function mountChatView(options: {
|
||||
await setViewport(viewport);
|
||||
await waitForProductionStyles();
|
||||
},
|
||||
setContainerSize: async (viewport) => {
|
||||
host.style.width = `${viewport.width}px`;
|
||||
host.style.height = `${viewport.height}px`;
|
||||
await waitForLayout();
|
||||
},
|
||||
router,
|
||||
};
|
||||
}
|
||||
@@ -2341,4 +2534,125 @@ describe("ChatView timeline estimator parity (full app)", () => {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps pending-question footer actions inside the composer after a real resize", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: WIDE_FOOTER_VIEWPORT,
|
||||
snapshot: createSnapshotWithPendingUserInput(),
|
||||
});
|
||||
|
||||
try {
|
||||
const firstOption = await waitForButtonContainingText("Tight");
|
||||
firstOption.click();
|
||||
|
||||
await waitForButtonByText("Previous");
|
||||
await waitForButtonByText("Submit answers");
|
||||
|
||||
await mounted.setContainerSize(COMPACT_FOOTER_VIEWPORT);
|
||||
await expectComposerActionsContained();
|
||||
} finally {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps plan follow-up footer actions fused and aligned after a real resize", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: WIDE_FOOTER_VIEWPORT,
|
||||
snapshot: createSnapshotWithPlanFollowUpPrompt(),
|
||||
});
|
||||
|
||||
try {
|
||||
const footer = await waitForElement(
|
||||
() => document.querySelector<HTMLElement>('[data-chat-composer-footer="true"]'),
|
||||
"Unable to find composer footer.",
|
||||
);
|
||||
const initialModelPicker = await waitForElement(
|
||||
findComposerProviderModelPicker,
|
||||
"Unable to find provider model picker.",
|
||||
);
|
||||
const initialModelPickerOffset =
|
||||
initialModelPicker.getBoundingClientRect().left - footer.getBoundingClientRect().left;
|
||||
|
||||
await waitForButtonByText("Implement");
|
||||
await waitForElement(
|
||||
() =>
|
||||
document.querySelector<HTMLButtonElement>('button[aria-label="Implementation actions"]'),
|
||||
"Unable to find implementation actions trigger.",
|
||||
);
|
||||
|
||||
await mounted.setContainerSize({
|
||||
width: 440,
|
||||
height: WIDE_FOOTER_VIEWPORT.height,
|
||||
});
|
||||
await expectComposerActionsContained();
|
||||
|
||||
const implementButton = await waitForButtonByText("Implement");
|
||||
const implementActionsButton = await waitForElement(
|
||||
() =>
|
||||
document.querySelector<HTMLButtonElement>('button[aria-label="Implementation actions"]'),
|
||||
"Unable to find implementation actions trigger.",
|
||||
);
|
||||
|
||||
await vi.waitFor(
|
||||
() => {
|
||||
const implementRect = implementButton.getBoundingClientRect();
|
||||
const implementActionsRect = implementActionsButton.getBoundingClientRect();
|
||||
const compactModelPicker = findComposerProviderModelPicker();
|
||||
expect(compactModelPicker).toBeTruthy();
|
||||
|
||||
const compactModelPickerOffset =
|
||||
compactModelPicker!.getBoundingClientRect().left - footer.getBoundingClientRect().left;
|
||||
|
||||
expect(Math.abs(implementRect.right - implementActionsRect.left)).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(implementRect.top - implementActionsRect.top)).toBeLessThanOrEqual(1);
|
||||
expect(Math.abs(compactModelPickerOffset - initialModelPickerOffset)).toBeLessThanOrEqual(
|
||||
1,
|
||||
);
|
||||
},
|
||||
{ timeout: 8_000, interval: 16 },
|
||||
);
|
||||
} finally {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
|
||||
it("keeps the slash-command menu visible above the composer", async () => {
|
||||
const mounted = await mountChatView({
|
||||
viewport: DEFAULT_VIEWPORT,
|
||||
snapshot: createSnapshotForTargetUser({
|
||||
targetMessageId: "msg-user-command-menu-target" as MessageId,
|
||||
targetText: "command menu thread",
|
||||
}),
|
||||
});
|
||||
|
||||
try {
|
||||
await waitForComposerEditor();
|
||||
await page.getByTestId("composer-editor").fill("/");
|
||||
|
||||
const menuItem = await waitForComposerMenuItem("slash:model");
|
||||
const composerForm = await waitForElement(
|
||||
() => document.querySelector<HTMLElement>('[data-chat-composer-form="true"]'),
|
||||
"Unable to find composer form.",
|
||||
);
|
||||
|
||||
await vi.waitFor(
|
||||
() => {
|
||||
const menuRect = menuItem.getBoundingClientRect();
|
||||
const composerRect = composerForm.getBoundingClientRect();
|
||||
const hitTarget = document.elementFromPoint(
|
||||
menuRect.left + menuRect.width / 2,
|
||||
menuRect.top + menuRect.height / 2,
|
||||
);
|
||||
|
||||
expect(menuRect.width).toBeGreaterThan(0);
|
||||
expect(menuRect.height).toBeGreaterThan(0);
|
||||
expect(menuRect.bottom).toBeLessThanOrEqual(composerRect.bottom);
|
||||
expect(hitTarget instanceof Element && menuItem.contains(hitTarget)).toBe(true);
|
||||
},
|
||||
{ timeout: 8_000, interval: 16 },
|
||||
);
|
||||
} finally {
|
||||
await mounted.cleanup();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -106,7 +106,6 @@ import {
|
||||
} from "lucide-react";
|
||||
import { Button } from "./ui/button";
|
||||
import { Separator } from "./ui/separator";
|
||||
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "./ui/menu";
|
||||
import { cn, randomUUID } from "~/lib/utils";
|
||||
import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip";
|
||||
import { toastManager } from "./ui/toast";
|
||||
@@ -148,7 +147,12 @@ import {
|
||||
type TerminalContextSelection,
|
||||
} from "../lib/terminalContext";
|
||||
import { deriveLatestContextWindowSnapshot } from "../lib/contextWindow";
|
||||
import { shouldUseCompactComposerFooter } from "./composerFooterLayout";
|
||||
import {
|
||||
resolveComposerFooterContentWidth,
|
||||
shouldForceCompactComposerFooterForFit,
|
||||
shouldUseCompactComposerPrimaryActions,
|
||||
shouldUseCompactComposerFooter,
|
||||
} from "./composerFooterLayout";
|
||||
import { selectThreadTerminalState, useTerminalStateStore } from "../terminalStateStore";
|
||||
import { ComposerPromptEditor, type ComposerPromptEditorHandle } from "./ComposerPromptEditor";
|
||||
import { PullRequestThreadDialog } from "./PullRequestThreadDialog";
|
||||
@@ -160,6 +164,7 @@ import { AVAILABLE_PROVIDER_OPTIONS, ProviderModelPicker } from "./chat/Provider
|
||||
import { ComposerCommandItem, ComposerCommandMenu } from "./chat/ComposerCommandMenu";
|
||||
import { ComposerPendingApprovalActions } from "./chat/ComposerPendingApprovalActions";
|
||||
import { CompactComposerControlsMenu } from "./chat/CompactComposerControlsMenu";
|
||||
import { ComposerPrimaryActions } from "./chat/ComposerPrimaryActions";
|
||||
import { ComposerPendingApprovalPanel } from "./chat/ComposerPendingApprovalPanel";
|
||||
import { ComposerPendingUserInputPanel } from "./chat/ComposerPendingUserInputPanel";
|
||||
import { ComposerPlanFollowUpBanner } from "./chat/ComposerPlanFollowUpBanner";
|
||||
@@ -499,6 +504,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const [expandedWorkGroups, setExpandedWorkGroups] = useState<Record<string, boolean>>({});
|
||||
const [planSidebarOpen, setPlanSidebarOpen] = useState(false);
|
||||
const [isComposerFooterCompact, setIsComposerFooterCompact] = useState(false);
|
||||
const [isComposerPrimaryActionsCompact, setIsComposerPrimaryActionsCompact] = useState(false);
|
||||
// Tracks whether the user explicitly dismissed the sidebar for the active turn.
|
||||
const planSidebarDismissedForTurnRef = useRef<string | null>(null);
|
||||
// When set, the thread-change reset effect will open the sidebar instead of closing it.
|
||||
@@ -541,6 +547,9 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const composerEditorRef = useRef<ComposerPromptEditorHandle>(null);
|
||||
const composerFormRef = useRef<HTMLFormElement>(null);
|
||||
const composerFormHeightRef = useRef(0);
|
||||
const composerFooterRef = useRef<HTMLDivElement>(null);
|
||||
const composerFooterLeadingRef = useRef<HTMLDivElement>(null);
|
||||
const composerFooterActionsRef = useRef<HTMLDivElement>(null);
|
||||
const composerImagesRef = useRef<ComposerImageAttachment[]>([]);
|
||||
const composerSelectLockRef = useRef(false);
|
||||
const composerMenuOpenRef = useRef(false);
|
||||
@@ -930,6 +939,28 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
pendingUserInputs.length > 0 ||
|
||||
(showPlanFollowUpPrompt && activeProposedPlan !== null);
|
||||
const composerFooterHasWideActions = showPlanFollowUpPrompt || activePendingProgress !== null;
|
||||
const composerFooterActionLayoutKey = useMemo(() => {
|
||||
if (activePendingProgress) {
|
||||
return `pending:${activePendingProgress.questionIndex}:${activePendingProgress.isLastQuestion}:${activePendingIsResponding}`;
|
||||
}
|
||||
if (phase === "running") {
|
||||
return "running";
|
||||
}
|
||||
if (showPlanFollowUpPrompt) {
|
||||
return prompt.trim().length > 0 ? "plan:refine" : "plan:implement";
|
||||
}
|
||||
return `idle:${composerSendState.hasSendableContent}:${isSendBusy}:${isConnecting}:${isPreparingWorktree}`;
|
||||
}, [
|
||||
activePendingIsResponding,
|
||||
activePendingProgress,
|
||||
composerSendState.hasSendableContent,
|
||||
isConnecting,
|
||||
isPreparingWorktree,
|
||||
isSendBusy,
|
||||
phase,
|
||||
prompt,
|
||||
showPlanFollowUpPrompt,
|
||||
]);
|
||||
const lastSyncedPendingInputRef = useRef<{
|
||||
requestId: string | null;
|
||||
questionId: string | null;
|
||||
@@ -2038,23 +2069,56 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
const composerForm = composerFormRef.current;
|
||||
if (!composerForm) return;
|
||||
const measureComposerFormWidth = () => composerForm.clientWidth;
|
||||
const measureFooterCompactness = () => {
|
||||
const composerFormWidth = measureComposerFormWidth();
|
||||
const heuristicFooterCompact = shouldUseCompactComposerFooter(composerFormWidth, {
|
||||
hasWideActions: composerFooterHasWideActions,
|
||||
});
|
||||
const footer = composerFooterRef.current;
|
||||
const footerStyle = footer ? window.getComputedStyle(footer) : null;
|
||||
const footerContentWidth = resolveComposerFooterContentWidth({
|
||||
footerWidth: footer?.clientWidth ?? null,
|
||||
paddingLeft: footerStyle ? Number.parseFloat(footerStyle.paddingLeft) : null,
|
||||
paddingRight: footerStyle ? Number.parseFloat(footerStyle.paddingRight) : null,
|
||||
});
|
||||
const fitInput = {
|
||||
footerContentWidth,
|
||||
leadingContentWidth: composerFooterLeadingRef.current?.scrollWidth ?? null,
|
||||
actionsWidth: composerFooterActionsRef.current?.scrollWidth ?? null,
|
||||
};
|
||||
const nextFooterCompact =
|
||||
heuristicFooterCompact || shouldForceCompactComposerFooterForFit(fitInput);
|
||||
const nextPrimaryActionsCompact =
|
||||
nextFooterCompact &&
|
||||
shouldUseCompactComposerPrimaryActions(composerFormWidth, {
|
||||
hasWideActions: composerFooterHasWideActions,
|
||||
});
|
||||
|
||||
return {
|
||||
primaryActionsCompact: nextPrimaryActionsCompact,
|
||||
footerCompact: nextFooterCompact,
|
||||
};
|
||||
};
|
||||
|
||||
composerFormHeightRef.current = composerForm.getBoundingClientRect().height;
|
||||
setIsComposerFooterCompact(
|
||||
shouldUseCompactComposerFooter(measureComposerFormWidth(), {
|
||||
hasWideActions: composerFooterHasWideActions,
|
||||
}),
|
||||
);
|
||||
const initialCompactness = measureFooterCompactness();
|
||||
setIsComposerPrimaryActionsCompact(initialCompactness.primaryActionsCompact);
|
||||
setIsComposerFooterCompact(initialCompactness.footerCompact);
|
||||
if (typeof ResizeObserver === "undefined") return;
|
||||
|
||||
const observer = new ResizeObserver((entries) => {
|
||||
const [entry] = entries;
|
||||
if (!entry) return;
|
||||
|
||||
const nextCompact = shouldUseCompactComposerFooter(measureComposerFormWidth(), {
|
||||
hasWideActions: composerFooterHasWideActions,
|
||||
});
|
||||
setIsComposerFooterCompact((previous) => (previous === nextCompact ? previous : nextCompact));
|
||||
const nextCompactness = measureFooterCompactness();
|
||||
setIsComposerPrimaryActionsCompact((previous) =>
|
||||
previous === nextCompactness.primaryActionsCompact
|
||||
? previous
|
||||
: nextCompactness.primaryActionsCompact,
|
||||
);
|
||||
setIsComposerFooterCompact((previous) =>
|
||||
previous === nextCompactness.footerCompact ? previous : nextCompactness.footerCompact,
|
||||
);
|
||||
|
||||
const nextHeight = entry.contentRect.height;
|
||||
const previousHeight = composerFormHeightRef.current;
|
||||
@@ -2069,7 +2133,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
};
|
||||
}, [activeThread?.id, composerFooterHasWideActions, scheduleStickToBottom]);
|
||||
}, [
|
||||
activeThread?.id,
|
||||
composerFooterActionLayoutKey,
|
||||
composerFooterHasWideActions,
|
||||
scheduleStickToBottom,
|
||||
]);
|
||||
useEffect(() => {
|
||||
if (!shouldAutoScrollRef.current) return;
|
||||
scheduleStickToBottom();
|
||||
@@ -3788,7 +3857,7 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
<form
|
||||
ref={composerFormRef}
|
||||
onSubmit={onSend}
|
||||
className="mx-auto w-full min-w-0 max-w-3xl"
|
||||
className="mx-auto w-full min-w-0 max-w-[52rem]"
|
||||
data-chat-composer-form="true"
|
||||
>
|
||||
<div
|
||||
@@ -3971,19 +4040,20 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
</div>
|
||||
) : (
|
||||
<div
|
||||
ref={composerFooterRef}
|
||||
data-chat-composer-footer="true"
|
||||
data-chat-composer-footer-compact={isComposerFooterCompact ? "true" : "false"}
|
||||
className={cn(
|
||||
"flex items-center justify-between px-2.5 pb-2.5 sm:px-3 sm:pb-3",
|
||||
isComposerFooterCompact
|
||||
? "gap-1.5"
|
||||
: "flex-wrap gap-2 sm:flex-nowrap sm:gap-0",
|
||||
"flex min-w-0 flex-nowrap items-center justify-between gap-2 overflow-hidden px-2.5 pb-2.5 sm:px-3 sm:pb-3",
|
||||
isComposerFooterCompact ? "gap-1.5" : "gap-2 sm:gap-0",
|
||||
)}
|
||||
>
|
||||
<div
|
||||
ref={composerFooterLeadingRef}
|
||||
className={cn(
|
||||
"flex min-w-0 flex-1 items-center",
|
||||
isComposerFooterCompact
|
||||
? "gap-1 overflow-hidden"
|
||||
? "gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
|
||||
: "gap-1 overflow-x-auto [scrollbar-width:none] [&::-webkit-scrollbar]:hidden sm:min-w-max sm:overflow-visible",
|
||||
)}
|
||||
>
|
||||
@@ -4113,8 +4183,12 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
|
||||
{/* Right side: send / stop button */}
|
||||
<div
|
||||
ref={composerFooterActionsRef}
|
||||
data-chat-composer-actions="right"
|
||||
className="flex shrink-0 items-center gap-2"
|
||||
data-chat-composer-primary-actions-compact={
|
||||
isComposerPrimaryActionsCompact ? "true" : "false"
|
||||
}
|
||||
className="flex shrink-0 flex-nowrap items-center justify-end gap-2"
|
||||
>
|
||||
{activeContextWindow ? (
|
||||
<ContextWindowMeter usage={activeContextWindow} />
|
||||
@@ -4124,156 +4198,32 @@ export default function ChatView({ threadId }: ChatViewProps) {
|
||||
Preparing worktree...
|
||||
</span>
|
||||
) : null}
|
||||
{activePendingProgress ? (
|
||||
<div className="flex items-center gap-2">
|
||||
{activePendingProgress.questionIndex > 0 ? (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="rounded-full"
|
||||
onClick={onPreviousActivePendingUserInputQuestion}
|
||||
disabled={activePendingIsResponding}
|
||||
>
|
||||
Previous
|
||||
</Button>
|
||||
) : null}
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
className="rounded-full px-4"
|
||||
disabled={
|
||||
activePendingIsResponding ||
|
||||
(activePendingProgress.isLastQuestion
|
||||
? !activePendingResolvedAnswers
|
||||
: !activePendingProgress.canAdvance)
|
||||
}
|
||||
>
|
||||
{activePendingIsResponding
|
||||
? "Submitting..."
|
||||
: activePendingProgress.isLastQuestion
|
||||
? "Submit answers"
|
||||
: "Next question"}
|
||||
</Button>
|
||||
</div>
|
||||
) : phase === "running" ? (
|
||||
<button
|
||||
type="button"
|
||||
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 hover:scale-105 sm:h-8 sm:w-8"
|
||||
onClick={() => void onInterrupt()}
|
||||
aria-label="Stop generation"
|
||||
>
|
||||
<svg
|
||||
width="12"
|
||||
height="12"
|
||||
viewBox="0 0 12 12"
|
||||
fill="currentColor"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<rect x="2" y="2" width="8" height="8" rx="1.5" />
|
||||
</svg>
|
||||
</button>
|
||||
) : pendingUserInputs.length === 0 ? (
|
||||
showPlanFollowUpPrompt ? (
|
||||
prompt.trim().length > 0 ? (
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
className="h-9 rounded-full px-4 sm:h-8"
|
||||
disabled={isSendBusy || isConnecting}
|
||||
>
|
||||
{isConnecting || isSendBusy ? "Sending..." : "Refine"}
|
||||
</Button>
|
||||
) : (
|
||||
<div className="flex items-center">
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
className="h-9 rounded-l-full rounded-r-none px-4 sm:h-8"
|
||||
disabled={isSendBusy || isConnecting}
|
||||
>
|
||||
{isConnecting || isSendBusy ? "Sending..." : "Implement"}
|
||||
</Button>
|
||||
<Menu>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="default"
|
||||
className="h-9 rounded-l-none rounded-r-full border-l-white/12 px-2 sm:h-8"
|
||||
aria-label="Implementation actions"
|
||||
disabled={isSendBusy || isConnecting}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ChevronDownIcon className="size-3.5" />
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end" side="top">
|
||||
<MenuItem
|
||||
disabled={isSendBusy || isConnecting}
|
||||
onClick={() => void onImplementPlanInNewThread()}
|
||||
>
|
||||
Implement in a new thread
|
||||
</MenuItem>
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
<button
|
||||
type="submit"
|
||||
className="flex h-9 w-9 enabled:cursor-pointer items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary hover:scale-105 disabled:pointer-events-none disabled:opacity-30 disabled:hover:scale-100 sm:h-8 sm:w-8"
|
||||
disabled={
|
||||
isSendBusy || isConnecting || !composerSendState.hasSendableContent
|
||||
}
|
||||
aria-label={
|
||||
isConnecting
|
||||
? "Connecting"
|
||||
: isPreparingWorktree
|
||||
? "Preparing worktree"
|
||||
: isSendBusy
|
||||
? "Sending"
|
||||
: "Send message"
|
||||
}
|
||||
>
|
||||
{isConnecting || isSendBusy ? (
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
fill="none"
|
||||
className="animate-spin"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle
|
||||
cx="7"
|
||||
cy="7"
|
||||
r="5.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeDasharray="20 12"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
fill="none"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<path
|
||||
d="M7 11.5V2.5M7 2.5L3 6.5M7 2.5L11 6.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
)
|
||||
) : null}
|
||||
<ComposerPrimaryActions
|
||||
compact={isComposerPrimaryActionsCompact}
|
||||
pendingAction={
|
||||
activePendingProgress
|
||||
? {
|
||||
questionIndex: activePendingProgress.questionIndex,
|
||||
isLastQuestion: activePendingProgress.isLastQuestion,
|
||||
canAdvance: activePendingProgress.canAdvance,
|
||||
isResponding: activePendingIsResponding,
|
||||
isComplete: Boolean(activePendingResolvedAnswers),
|
||||
}
|
||||
: null
|
||||
}
|
||||
isRunning={phase === "running"}
|
||||
showPlanFollowUpPrompt={
|
||||
pendingUserInputs.length === 0 && showPlanFollowUpPrompt
|
||||
}
|
||||
promptHasText={prompt.trim().length > 0}
|
||||
isSendBusy={isSendBusy}
|
||||
isConnecting={isConnecting}
|
||||
isPreparingWorktree={isPreparingWorktree}
|
||||
hasSendableContent={composerSendState.hasSendableContent}
|
||||
onPreviousPendingQuestion={onPreviousActivePendingUserInputQuestion}
|
||||
onInterrupt={() => void onInterrupt()}
|
||||
onImplementPlanInNewThread={() => void onImplementPlanInNewThread()}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
@@ -0,0 +1,217 @@
|
||||
import { memo } from "react";
|
||||
import { ChevronDownIcon, ChevronLeftIcon } from "lucide-react";
|
||||
import { cn } from "~/lib/utils";
|
||||
import { Button } from "../ui/button";
|
||||
import { Menu, MenuItem, MenuPopup, MenuTrigger } from "../ui/menu";
|
||||
|
||||
interface PendingActionState {
|
||||
questionIndex: number;
|
||||
isLastQuestion: boolean;
|
||||
canAdvance: boolean;
|
||||
isResponding: boolean;
|
||||
isComplete: boolean;
|
||||
}
|
||||
|
||||
interface ComposerPrimaryActionsProps {
|
||||
compact: boolean;
|
||||
pendingAction: PendingActionState | null;
|
||||
isRunning: boolean;
|
||||
showPlanFollowUpPrompt: boolean;
|
||||
promptHasText: boolean;
|
||||
isSendBusy: boolean;
|
||||
isConnecting: boolean;
|
||||
isPreparingWorktree: boolean;
|
||||
hasSendableContent: boolean;
|
||||
onPreviousPendingQuestion: () => void;
|
||||
onInterrupt: () => void;
|
||||
onImplementPlanInNewThread: () => void;
|
||||
}
|
||||
|
||||
const formatPendingPrimaryActionLabel = (input: {
|
||||
compact: boolean;
|
||||
isLastQuestion: boolean;
|
||||
isResponding: boolean;
|
||||
}) => {
|
||||
if (input.isResponding) {
|
||||
return "Submitting...";
|
||||
}
|
||||
if (input.compact) {
|
||||
return input.isLastQuestion ? "Submit" : "Next";
|
||||
}
|
||||
return input.isLastQuestion ? "Submit answers" : "Next question";
|
||||
};
|
||||
|
||||
export const ComposerPrimaryActions = memo(function ComposerPrimaryActions({
|
||||
compact,
|
||||
pendingAction,
|
||||
isRunning,
|
||||
showPlanFollowUpPrompt,
|
||||
promptHasText,
|
||||
isSendBusy,
|
||||
isConnecting,
|
||||
isPreparingWorktree,
|
||||
hasSendableContent,
|
||||
onPreviousPendingQuestion,
|
||||
onInterrupt,
|
||||
onImplementPlanInNewThread,
|
||||
}: ComposerPrimaryActionsProps) {
|
||||
if (pendingAction) {
|
||||
return (
|
||||
<div className={cn("flex items-center justify-end", compact ? "gap-1.5" : "gap-2")}>
|
||||
{pendingAction.questionIndex > 0 ? (
|
||||
compact ? (
|
||||
<Button
|
||||
size="icon-sm"
|
||||
variant="outline"
|
||||
className="rounded-full"
|
||||
onClick={onPreviousPendingQuestion}
|
||||
disabled={pendingAction.isResponding}
|
||||
aria-label="Previous question"
|
||||
>
|
||||
<ChevronLeftIcon className="size-3.5" />
|
||||
</Button>
|
||||
) : (
|
||||
<Button
|
||||
size="sm"
|
||||
variant="outline"
|
||||
className="rounded-full"
|
||||
onClick={onPreviousPendingQuestion}
|
||||
disabled={pendingAction.isResponding}
|
||||
>
|
||||
Previous
|
||||
</Button>
|
||||
)
|
||||
) : null}
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
className={cn("rounded-full", compact ? "px-3" : "px-4")}
|
||||
disabled={
|
||||
pendingAction.isResponding ||
|
||||
(pendingAction.isLastQuestion ? !pendingAction.isComplete : !pendingAction.canAdvance)
|
||||
}
|
||||
>
|
||||
{formatPendingPrimaryActionLabel({
|
||||
compact,
|
||||
isLastQuestion: pendingAction.isLastQuestion,
|
||||
isResponding: pendingAction.isResponding,
|
||||
})}
|
||||
</Button>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (isRunning) {
|
||||
return (
|
||||
<button
|
||||
type="button"
|
||||
className="flex size-8 cursor-pointer items-center justify-center rounded-full bg-rose-500/90 text-white transition-all duration-150 hover:bg-rose-500 hover:scale-105 sm:h-8 sm:w-8"
|
||||
onClick={onInterrupt}
|
||||
aria-label="Stop generation"
|
||||
>
|
||||
<svg width="12" height="12" viewBox="0 0 12 12" fill="currentColor" aria-hidden="true">
|
||||
<rect x="2" y="2" width="8" height="8" rx="1.5" />
|
||||
</svg>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
if (showPlanFollowUpPrompt) {
|
||||
if (promptHasText) {
|
||||
return (
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
className={cn("rounded-full", compact ? "h-9 px-3 sm:h-8" : "h-9 px-4 sm:h-8")}
|
||||
disabled={isSendBusy || isConnecting}
|
||||
>
|
||||
{isConnecting || isSendBusy ? "Sending..." : "Refine"}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<div data-chat-composer-implement-actions="true" className="flex items-center justify-end">
|
||||
<Button
|
||||
type="submit"
|
||||
size="sm"
|
||||
className={cn("h-9 rounded-l-full rounded-r-none sm:h-8", compact ? "px-3" : "px-4")}
|
||||
disabled={isSendBusy || isConnecting}
|
||||
>
|
||||
{isConnecting || isSendBusy ? "Sending..." : "Implement"}
|
||||
</Button>
|
||||
<Menu>
|
||||
<MenuTrigger
|
||||
render={
|
||||
<Button
|
||||
size="sm"
|
||||
variant="default"
|
||||
className="h-9 rounded-l-none rounded-r-full border-l-white/12 px-2 sm:h-8"
|
||||
aria-label="Implementation actions"
|
||||
disabled={isSendBusy || isConnecting}
|
||||
/>
|
||||
}
|
||||
>
|
||||
<ChevronDownIcon className="size-3.5" />
|
||||
</MenuTrigger>
|
||||
<MenuPopup align="end" side="top">
|
||||
<MenuItem
|
||||
disabled={isSendBusy || isConnecting}
|
||||
onClick={() => void onImplementPlanInNewThread()}
|
||||
>
|
||||
Implement in a new thread
|
||||
</MenuItem>
|
||||
</MenuPopup>
|
||||
</Menu>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<button
|
||||
type="submit"
|
||||
className="flex h-9 w-9 enabled:cursor-pointer items-center justify-center rounded-full bg-primary/90 text-primary-foreground transition-all duration-150 hover:bg-primary hover:scale-105 disabled:pointer-events-none disabled:opacity-30 disabled:hover:scale-100 sm:h-8 sm:w-8"
|
||||
disabled={isSendBusy || isConnecting || !hasSendableContent}
|
||||
aria-label={
|
||||
isConnecting
|
||||
? "Connecting"
|
||||
: isPreparingWorktree
|
||||
? "Preparing worktree"
|
||||
: isSendBusy
|
||||
? "Sending"
|
||||
: "Send message"
|
||||
}
|
||||
>
|
||||
{isConnecting || isSendBusy ? (
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
fill="none"
|
||||
className="animate-spin"
|
||||
aria-hidden="true"
|
||||
>
|
||||
<circle
|
||||
cx="7"
|
||||
cy="7"
|
||||
r="5.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeDasharray="20 12"
|
||||
/>
|
||||
</svg>
|
||||
) : (
|
||||
<svg width="14" height="14" viewBox="0 0 14 14" fill="none" aria-hidden="true">
|
||||
<path
|
||||
d="M7 11.5V2.5M7 2.5L3 6.5M7 2.5L11 6.5"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.8"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
/>
|
||||
</svg>
|
||||
)}
|
||||
</button>
|
||||
);
|
||||
});
|
||||
@@ -98,6 +98,7 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
<Button
|
||||
size="sm"
|
||||
variant={props.triggerVariant ?? "ghost"}
|
||||
data-chat-provider-model-picker="true"
|
||||
className={cn(
|
||||
"min-w-0 justify-start overflow-hidden whitespace-nowrap px-2 text-muted-foreground/70 hover:text-foreground/80 [&_svg]:mx-0",
|
||||
props.compact ? "max-w-42 shrink-0" : "max-w-48 shrink sm:max-w-56 sm:px-3",
|
||||
@@ -109,8 +110,8 @@ export const ProviderModelPicker = memo(function ProviderModelPicker(props: {
|
||||
>
|
||||
<span
|
||||
className={cn(
|
||||
"flex min-w-0 w-full items-center gap-2 overflow-hidden",
|
||||
props.compact ? "max-w-36" : undefined,
|
||||
"flex min-w-0 w-full box-border items-center gap-2 overflow-hidden",
|
||||
props.compact ? "max-w-36 sm:pl-1" : undefined,
|
||||
)}
|
||||
>
|
||||
<ProviderIcon
|
||||
|
||||
@@ -3,6 +3,11 @@ import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX,
|
||||
COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX,
|
||||
COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX,
|
||||
measureComposerFooterOverflowPx,
|
||||
resolveComposerFooterContentWidth,
|
||||
shouldForceCompactComposerFooterForFit,
|
||||
shouldUseCompactComposerPrimaryActions,
|
||||
shouldUseCompactComposerFooter,
|
||||
} from "./composerFooterLayout";
|
||||
|
||||
@@ -33,3 +38,117 @@ describe("shouldUseCompactComposerFooter", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldUseCompactComposerPrimaryActions", () => {
|
||||
it("matches the wide footer breakpoint", () => {
|
||||
expect(COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX).toBe(
|
||||
COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX,
|
||||
);
|
||||
expect(
|
||||
shouldUseCompactComposerPrimaryActions(COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX - 1, {
|
||||
hasWideActions: true,
|
||||
}),
|
||||
).toBe(true);
|
||||
expect(
|
||||
shouldUseCompactComposerPrimaryActions(COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX, {
|
||||
hasWideActions: true,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("measureComposerFooterOverflowPx", () => {
|
||||
it("returns the overflow amount when content exceeds the footer width", () => {
|
||||
expect(
|
||||
measureComposerFooterOverflowPx({
|
||||
footerContentWidth: 500,
|
||||
leadingContentWidth: 340,
|
||||
actionsWidth: 180,
|
||||
}),
|
||||
).toBe(28);
|
||||
});
|
||||
|
||||
it("returns zero when content fits", () => {
|
||||
expect(
|
||||
measureComposerFooterOverflowPx({
|
||||
footerContentWidth: 500,
|
||||
leadingContentWidth: 320,
|
||||
actionsWidth: 160,
|
||||
}),
|
||||
).toBe(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shouldForceCompactComposerFooterForFit", () => {
|
||||
it("stays expanded when content widths fit within the footer", () => {
|
||||
expect(
|
||||
shouldForceCompactComposerFooterForFit({
|
||||
footerContentWidth: 500,
|
||||
leadingContentWidth: 320,
|
||||
actionsWidth: 160,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("stays expanded when minor overflow can be recovered by compacting primary actions", () => {
|
||||
expect(
|
||||
shouldForceCompactComposerFooterForFit({
|
||||
footerContentWidth: 500,
|
||||
leadingContentWidth: 340,
|
||||
actionsWidth: 180,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
|
||||
it("forces footer compact mode when action compaction would not recover enough space", () => {
|
||||
expect(
|
||||
shouldForceCompactComposerFooterForFit({
|
||||
footerContentWidth: 500,
|
||||
leadingContentWidth: 420,
|
||||
actionsWidth: 220,
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it("ignores incomplete measurements", () => {
|
||||
expect(
|
||||
shouldForceCompactComposerFooterForFit({
|
||||
footerContentWidth: null,
|
||||
leadingContentWidth: 340,
|
||||
actionsWidth: 180,
|
||||
}),
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("resolveComposerFooterContentWidth", () => {
|
||||
it("subtracts horizontal padding from the measured footer width", () => {
|
||||
expect(
|
||||
resolveComposerFooterContentWidth({
|
||||
footerWidth: 500,
|
||||
paddingLeft: 10,
|
||||
paddingRight: 10,
|
||||
}),
|
||||
).toBe(480);
|
||||
});
|
||||
|
||||
it("clamps negative widths to zero", () => {
|
||||
expect(
|
||||
resolveComposerFooterContentWidth({
|
||||
footerWidth: 10,
|
||||
paddingLeft: 8,
|
||||
paddingRight: 8,
|
||||
}),
|
||||
).toBe(0);
|
||||
});
|
||||
|
||||
it("returns null when measurements are incomplete", () => {
|
||||
expect(
|
||||
resolveComposerFooterContentWidth({
|
||||
footerWidth: null,
|
||||
paddingLeft: 8,
|
||||
paddingRight: 8,
|
||||
}),
|
||||
).toBeNull();
|
||||
});
|
||||
});
|
||||
@@ -1,5 +1,9 @@
|
||||
export const COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX = 620;
|
||||
export const COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX = 720;
|
||||
export const COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX = 780;
|
||||
export const COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX =
|
||||
COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX;
|
||||
const COMPOSER_FOOTER_CONTENT_GAP_PX = 8;
|
||||
const COMPOSER_PRIMARY_ACTIONS_COMPACT_RECOVERY_PX = 120;
|
||||
|
||||
export function shouldUseCompactComposerFooter(
|
||||
width: number | null,
|
||||
@@ -10,3 +14,56 @@ export function shouldUseCompactComposerFooter(
|
||||
: COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX;
|
||||
return width !== null && width < breakpoint;
|
||||
}
|
||||
|
||||
export function shouldUseCompactComposerPrimaryActions(
|
||||
width: number | null,
|
||||
options?: { hasWideActions?: boolean },
|
||||
): boolean {
|
||||
if (!options?.hasWideActions) {
|
||||
return false;
|
||||
}
|
||||
return width !== null && width < COMPOSER_PRIMARY_ACTIONS_COMPACT_BREAKPOINT_PX;
|
||||
}
|
||||
|
||||
export function measureComposerFooterOverflowPx(input: {
|
||||
footerContentWidth: number | null;
|
||||
leadingContentWidth: number | null;
|
||||
actionsWidth: number | null;
|
||||
}): number | null {
|
||||
const footerContentWidth = input.footerContentWidth;
|
||||
const leadingContentWidth = input.leadingContentWidth;
|
||||
const actionsWidth = input.actionsWidth;
|
||||
if (footerContentWidth === null || leadingContentWidth === null || actionsWidth === null) {
|
||||
return null;
|
||||
}
|
||||
return Math.max(
|
||||
0,
|
||||
leadingContentWidth + actionsWidth + COMPOSER_FOOTER_CONTENT_GAP_PX - footerContentWidth,
|
||||
);
|
||||
}
|
||||
|
||||
export function shouldForceCompactComposerFooterForFit(input: {
|
||||
footerContentWidth: number | null;
|
||||
leadingContentWidth: number | null;
|
||||
actionsWidth: number | null;
|
||||
}): boolean {
|
||||
const overflowPx = measureComposerFooterOverflowPx(input);
|
||||
if (overflowPx === null) {
|
||||
return false;
|
||||
}
|
||||
return overflowPx > COMPOSER_PRIMARY_ACTIONS_COMPACT_RECOVERY_PX;
|
||||
}
|
||||
|
||||
export function resolveComposerFooterContentWidth(input: {
|
||||
footerWidth: number | null;
|
||||
paddingLeft: number | null;
|
||||
paddingRight: number | null;
|
||||
}): number | null {
|
||||
const footerWidth = input.footerWidth;
|
||||
const paddingLeft = input.paddingLeft;
|
||||
const paddingRight = input.paddingRight;
|
||||
if (footerWidth === null || paddingLeft === null || paddingRight === null) {
|
||||
return null;
|
||||
}
|
||||
return Math.max(0, footerWidth - paddingLeft - paddingRight);
|
||||
}
|
||||
Reference in new issue
Block a user