Skip to content

Commit c3c5b7f

Browse files
committed
fix(web): smooth responsive panel motion
1 parent 2e99c2d commit c3c5b7f

4 files changed

Lines changed: 131 additions & 8 deletions

File tree

‎apps/web/src/components/ChatView.tsx‎

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7110,11 +7110,22 @@ function ChatViewContent(props: ChatViewProps) {
71107110
)}
71117111
data-workspace-titlebar-controls
71127112
>
7113-
{inlineRightPanelPresent && !shouldUseRightPanelSheet ? (
7114-
<RightPanelMaximizeControl
7115-
maximized={rightPanelMaximized}
7116-
onToggle={toggleRightPanelMaximized}
7117-
/>
7113+
{!shouldUseRightPanelSheet ? (
7114+
<span
7115+
aria-hidden={!rightPanelOpen}
7116+
className={cn(
7117+
"flex shrink-0",
7118+
panelAnimationsActive &&
7119+
"motion-safe:transition-opacity motion-safe:[transition-duration:var(--panel-animation-duration)] motion-safe:ease-out",
7120+
rightPanelOpen ? "opacity-100" : "pointer-events-none opacity-0",
7121+
)}
7122+
inert={!rightPanelOpen}
7123+
>
7124+
<RightPanelMaximizeControl
7125+
maximized={rightPanelMaximized}
7126+
onToggle={toggleRightPanelMaximized}
7127+
/>
7128+
</span>
71187129
) : null}
71197130
{panelToggleControls}
71207131
</div>
@@ -7255,7 +7266,7 @@ function ChatViewContent(props: ChatViewProps) {
72557266

72567267
return (
72577268
<div className="relative flex min-h-0 min-w-0 flex-1 overflow-hidden bg-background">
7258-
{inlineRightPanelPresent && !shouldUseRightPanelSheet ? panelLayoutControls : null}
7269+
{!shouldUseRightPanelSheet ? panelLayoutControls : null}
72597270
<div
72607271
className={cn(
72617272
"flex min-h-0 min-w-0 flex-col overflow-x-hidden",
@@ -7270,7 +7281,7 @@ function ChatViewContent(props: ChatViewProps) {
72707281
reserveNativeControls={reserveTitleBarControlInset && !inlineRightPanelOwnsTitleBar}
72717282
className="relative bg-background"
72727283
>
7273-
{!rightPanelControlsInPanel ? panelLayoutControls : null}
7284+
{shouldUseRightPanelSheet && !rightPanelControlsInPanel ? panelLayoutControls : null}
72747285
<ChatHeader
72757286
{...(!supportsPullRequests || activeProjectRepository === null
72767287
? {}

‎apps/web/src/components/chat/ChatComposer.tsx‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,12 @@ import { ComposerPendingElementContexts } from "./ComposerPendingElementContexts
135135
import { ComposerPendingReviewComments } from "./ComposerPendingReviewComments";
136136
import { ComposerPreviewAnnotationCards } from "./ComposerPreviewAnnotationCards";
137137
import {
138+
COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX,
139+
COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX,
138140
shouldUseCompactComposerPrimaryActions,
139141
shouldUseCompactComposerFooter,
140142
} from "../composerFooterLayout";
143+
import { observeResponsiveBreakpointFade } from "../../panelAnimations";
141144
import { type ComposerPromptEditorHandle, ComposerPromptEditor } from "../ComposerPromptEditor";
142145
import { ProviderModelPicker } from "./ProviderModelPicker";
143146
import { type ComposerCommandItem, ComposerCommandMenu } from "./ComposerCommandMenu";
@@ -1236,6 +1239,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
12361239
const composerEditorRef = useRef<ComposerPromptEditorHandle>(null);
12371240
const attachmentInputRef = useRef<HTMLInputElement>(null);
12381241
const composerFormRef = useRef<HTMLFormElement>(null);
1242+
const composerFooterControlsRef = useRef<HTMLDivElement>(null);
12391243
const composerSurfaceRef = useRef<HTMLDivElement>(null);
12401244
const providerInputRejectedRef = useRef(false);
12411245
const composerSelectLockRef = useRef(false);
@@ -1773,6 +1777,16 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
17731777
setIsComposerPrimaryActionsCompact(initialCompactness.primaryActionsCompact);
17741778
setIsComposerFooterCompact(initialCompactness.footerCompact);
17751779
if (typeof ResizeObserver === "undefined") return;
1780+
const footerControls = composerFooterControlsRef.current;
1781+
const stopFooterControlsFade = footerControls
1782+
? observeResponsiveBreakpointFade({
1783+
target: footerControls,
1784+
container: composerForm,
1785+
breakpointPx: composerFooterHasWideActions
1786+
? COMPOSER_FOOTER_WIDE_ACTIONS_COMPACT_BREAKPOINT_PX
1787+
: COMPOSER_FOOTER_COMPACT_BREAKPOINT_PX,
1788+
})
1789+
: undefined;
17761790

17771791
const observer = new ResizeObserver(() => {
17781792
const nextCompactness = measureFooterCompactness();
@@ -1789,6 +1803,7 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
17891803
observer.observe(composerForm);
17901804
return () => {
17911805
observer.disconnect();
1806+
stopFooterControlsFade?.();
17921807
};
17931808
}, [activeThreadId, composerFooterActionLayoutKey, composerFooterHasWideActions]);
17941809

@@ -4167,7 +4182,11 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
41674182
showMobilePendingAnswerActions && "hidden sm:flex",
41684183
)}
41694184
>
4170-
<div className="-m-1 -ms-3.5 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto p-1 ps-3.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
4185+
<div
4186+
ref={composerFooterControlsRef}
4187+
data-chat-composer-footer-controls="true"
4188+
className="-m-1 -ms-3.5 flex min-w-0 flex-1 items-center gap-1 overflow-x-auto p-1 ps-3.5 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden"
4189+
>
41714190
{noProviderAvailable ? (
41724191
<Button
41734192
type="button"

‎apps/web/src/components/chat/ChatHeader.tsx‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { useT3ProjectFileScripts } from "~/hooks/useT3ProjectFileScripts";
3737
import { useThreadActionMenu } from "~/hooks/useThreadActionMenu";
3838
import { threadEnvironment } from "../../state/threads";
3939
import { useAtomCommand } from "../../state/use-atom-command";
40+
import { observeResponsiveBreakpointFade } from "../../panelAnimations";
4041
import { ProjectFavicon } from "../ProjectFavicon";
4142
import {
4243
WorkspaceBreadcrumb,
@@ -137,6 +138,18 @@ export const ChatHeader = memo(function ChatHeader({
137138
onUpdateProjectScript,
138139
onDeleteProjectScript,
139140
}: ChatHeaderProps) {
141+
const headerActionsRef = useRef<HTMLDivElement | null>(null);
142+
useEffect(() => {
143+
const actions = headerActionsRef.current;
144+
const container = actions?.parentElement;
145+
if (!actions || !container) return;
146+
const rootFontSize = Number.parseFloat(getComputedStyle(document.documentElement).fontSize);
147+
return observeResponsiveBreakpointFade({
148+
target: actions,
149+
container,
150+
breakpointPx: 48 * rootFontSize,
151+
});
152+
}, []);
140153
const primaryEnvironmentId = usePrimaryEnvironmentId();
141154
const fileScripts = useT3ProjectFileScripts(
142155
activeThreadEnvironmentId,
@@ -372,6 +385,7 @@ export const ChatHeader = memo(function ChatHeader({
372385
</WorkspaceBreadcrumbItem>
373386
</WorkspaceBreadcrumb>
374387
<div
388+
ref={headerActionsRef}
375389
data-chat-header-actions
376390
className={cn(
377391
"flex shrink-0 items-center justify-end gap-2 @3xl/header-actions:gap-3",

‎apps/web/src/panelAnimations.ts‎

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,85 @@ import { useClientSettings } from "./hooks/useSettings";
99

1010
export const PANEL_ANIMATION_DURATION_MS = DEFAULT_PANEL_ANIMATION_DURATION_MS;
1111

12+
export function observeResponsiveBreakpointFade(options: {
13+
target: HTMLElement;
14+
container: HTMLElement;
15+
breakpointPx: number;
16+
fadeDistancePx?: number;
17+
}): () => void {
18+
const { target, container, breakpointPx, fadeDistancePx = 160 } = options;
19+
if (typeof ResizeObserver === "undefined") return () => {};
20+
21+
let previousWidth = container.getBoundingClientRect().width;
22+
let previousSide = previousWidth >= breakpointPx;
23+
let crossedBreakpoint = false;
24+
let settleTimer: number | null = null;
25+
let restoreAnimation: Animation | null = null;
26+
27+
const restoreOpacity = () => {
28+
settleTimer = null;
29+
const currentOpacity = getComputedStyle(target).opacity;
30+
target.style.removeProperty("opacity");
31+
crossedBreakpoint = false;
32+
if (currentOpacity === "1") return;
33+
const panelDuration = Number.parseFloat(
34+
getComputedStyle(target).getPropertyValue("--panel-animation-duration"),
35+
);
36+
restoreAnimation = target.animate([{ opacity: currentOpacity }, { opacity: 1 }], {
37+
duration: Math.min(100, panelDuration / 4),
38+
easing: "ease-out",
39+
});
40+
};
41+
42+
const observer = new ResizeObserver(([entry]) => {
43+
if (!entry) return;
44+
const width = entry.contentRect.width;
45+
restoreAnimation?.cancel();
46+
restoreAnimation = null;
47+
if (settleTimer !== null) window.clearTimeout(settleTimer);
48+
settleTimer = null;
49+
const animationsEnabled =
50+
target.closest("[data-panel-animations]")?.getAttribute("data-panel-animations") === "true" &&
51+
!matchMedia("(prefers-reduced-motion: reduce)").matches;
52+
53+
if (!animationsEnabled) {
54+
target.style.removeProperty("opacity");
55+
previousWidth = width;
56+
previousSide = width >= breakpointPx;
57+
crossedBreakpoint = false;
58+
return;
59+
}
60+
61+
const side = width >= breakpointPx;
62+
const crossedOnThisFrame = side !== previousSide;
63+
const movingTowardBreakpoint =
64+
Math.abs(width - breakpointPx) < Math.abs(previousWidth - breakpointPx);
65+
if (crossedOnThisFrame) crossedBreakpoint = true;
66+
67+
if (crossedOnThisFrame) {
68+
target.style.opacity = "0";
69+
} else if (movingTowardBreakpoint || crossedBreakpoint) {
70+
target.style.opacity = Math.min(1, Math.abs(width - breakpointPx) / fadeDistancePx).toFixed(
71+
3,
72+
);
73+
} else {
74+
target.style.removeProperty("opacity");
75+
}
76+
77+
previousWidth = width;
78+
previousSide = side;
79+
settleTimer = window.setTimeout(restoreOpacity, 80);
80+
});
81+
82+
observer.observe(container);
83+
return () => {
84+
observer.disconnect();
85+
if (settleTimer !== null) window.clearTimeout(settleTimer);
86+
restoreAnimation?.cancel();
87+
target.style.removeProperty("opacity");
88+
};
89+
}
90+
1291
export function usePanelAnimationSettings(): {
1392
active: boolean;
1493
durationMs: PanelAnimationDurationMs;

0 commit comments

Comments
 (0)