Skip to content

Commit 728dd72

Browse files
committed
fix(web): keep sidebar branding and build pills from clipping
1 parent 384de08 commit 728dd72

3 files changed

Lines changed: 94 additions & 39 deletions

File tree

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { useAtomValue } from "@effect/atom-react";
22
import * as Schema from "effect/Schema";
33
import {
44
useEffect,
5+
useCallback,
56
useState,
67
useSyncExternalStore,
78
type CSSProperties,
@@ -23,7 +24,7 @@ import {
2324
import LegacyThreadSidebar from "./LegacySidebar";
2425
import ThreadSidebar from "./Sidebar";
2526
import { SettingsSidebarNav } from "./settings/SettingsSidebarNav";
26-
import { SidebarChromeHeader } from "./sidebar/SidebarChrome";
27+
import { SidebarChromeHeader, SidebarChromeIntrinsicWidthProbe } from "./sidebar/SidebarChrome";
2728
import {
2829
resolveSidebarStageFocusRingOffsetClass,
2930
useSidebarStageBackdropVariant,
@@ -154,18 +155,26 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
154155
const isOnSettings = pathname === "/settings" || pathname.startsWith("/settings/");
155156
const isMacosDesktop = isElectron && isMacPlatform(navigator.platform);
156157
const [sidebarWidth, setSidebarWidth] = useState(readInitialThreadSidebarWidth);
158+
const [sidebarMinimumWidth, setSidebarMinimumWidth] = useState(THREAD_SIDEBAR_MIN_WIDTH);
159+
const updateSidebarMinimumWidth = useCallback((intrinsicWidth: number) => {
160+
setSidebarMinimumWidth(Math.max(THREAD_SIDEBAR_MIN_WIDTH, Math.ceil(intrinsicWidth)));
161+
}, []);
157162
// Subscribed rather than read once: the clamp must track live window size,
158163
// and a clamped drag ends with an unchanged width, which skips the re-render
159164
// that would otherwise refresh a render-time snapshot.
160165
const viewportWidth = useSyncExternalStore(subscribeToViewportWidth, readViewportWidth);
161-
const sidebarMaximumWidth = resolveThreadSidebarMaximumWidth(viewportWidth);
166+
const sidebarMaximumWidth = resolveThreadSidebarMaximumWidth(viewportWidth, sidebarMinimumWidth);
167+
const renderedSidebarWidth = Math.min(
168+
sidebarMaximumWidth,
169+
Math.max(sidebarMinimumWidth, sidebarWidth),
170+
);
162171
const resetSidebarWidth = () => {
163172
try {
164173
removeLocalStorageItem(THREAD_SIDEBAR_WIDTH_STORAGE_KEY);
165174
} catch (error) {
166175
console.error("Could not clear persisted thread sidebar width.", error);
167176
}
168-
setSidebarWidth(resolveInitialThreadSidebarWidth(null, viewportWidth));
177+
setSidebarWidth(resolveInitialThreadSidebarWidth(null, viewportWidth, sidebarMinimumWidth));
169178
};
170179
const [isWindowFullscreen, setIsWindowFullscreen] = useState(() => {
171180
const getWindowFullscreenState = window.desktopBridge?.getWindowFullscreenState;
@@ -174,7 +183,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
174183
: false;
175184
});
176185
const sidebarProviderStyle = {
177-
"--sidebar-width": `${sidebarWidth}px`,
186+
"--sidebar-width": `${renderedSidebarWidth}px`,
178187
"--panel-animation-duration": `${panelAnimationDurationMs}ms`,
179188
...(isMacosDesktop && !isWindowFullscreen
180189
? { "--workspace-controls-left": MACOS_TRAFFIC_LIGHTS_LEFT_INSET }
@@ -221,11 +230,14 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
221230
return (
222231
<PanelAnimationSuppressionProvider value={panelAnimationsSuppressed}>
223232
<SidebarProvider
224-
className="h-dvh! min-h-0!"
233+
className="relative h-dvh! min-h-0!"
225234
data-panel-animations={routePanelAnimationsActive ? "true" : "false"}
226235
defaultOpen
227236
style={sidebarProviderStyle}
228237
>
238+
{isMacosDesktop ? (
239+
<SidebarChromeIntrinsicWidthProbe onWidthChange={updateSidebarMinimumWidth} />
240+
) : null}
229241
<ProjectProjectionRetention />
230242
<Sidebar
231243
side="left"
@@ -234,7 +246,7 @@ export function AppSidebarLayout({ children }: { children: ReactNode }) {
234246
className="border-r border-sidebar-border bg-sidebar text-sidebar-foreground"
235247
resizable={{
236248
maxWidth: sidebarMaximumWidth,
237-
minWidth: THREAD_SIDEBAR_MIN_WIDTH,
249+
minWidth: sidebarMinimumWidth,
238250
shouldAcceptWidth: ({ currentWidth, nextWidth, wrapper }) =>
239251
nextWidth <= currentWidth ||
240252
wrapper.clientWidth - nextWidth >= THREAD_MAIN_CONTENT_MIN_WIDTH,

‎apps/web/src/components/sidebar/SidebarChrome.tsx‎

Lines changed: 68 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ArrowLeftIcon, ChartNoAxesColumnIcon, SettingsIcon } from "lucide-react";
22
import type { ReactNode } from "react";
3-
import { memo, useCallback } from "react";
3+
import { memo, useCallback, useLayoutEffect, useRef } from "react";
44
import { Link, useCanGoBack, useLocation, useNavigate } from "@tanstack/react-router";
55

66
import { useEnvironmentIdentificationMode } from "../../hooks/useSettings";
@@ -62,41 +62,86 @@ export const SidebarChromeHeader = memo(function SidebarChromeHeader({
6262
backdropVariant && resolveSidebarStageFocusRingOffsetClass(backdropVariant),
6363
)}
6464
/>
65-
<SidebarBrand onBackdrop={backdropVariant !== null} />
66-
{pillLabel ? (
67-
<Badge
68-
className="relative z-10 ml-1 hidden rounded-full px-1.5 text-muted-foreground @[15rem]/sidebar-header:inline-flex"
69-
data-environment-identification="pill"
70-
size="sm"
71-
variant="secondary"
72-
>
73-
{pillLabel}
74-
</Badge>
75-
) : null}
65+
{/* Keep one visible row: the pill wraps out before the brand hides Code. */}
66+
<div className="flex h-7 min-w-0 flex-1 flex-wrap content-start items-center gap-x-2 gap-y-0 overflow-hidden">
67+
<SidebarBrand onBackdrop={backdropVariant !== null} />
68+
{pillLabel ? (
69+
<div className="ml-1 hidden h-7 shrink-0 items-center @[15rem]/sidebar-header:flex md:flex">
70+
<Badge
71+
className="relative z-10 rounded-full px-1.5 text-muted-foreground"
72+
data-environment-identification="pill"
73+
size="sm"
74+
variant="secondary"
75+
>
76+
{pillLabel}
77+
</Badge>
78+
</div>
79+
) : null}
80+
</div>
7681
</SidebarHeader>
7782
);
7883
});
7984

85+
export function SidebarChromeIntrinsicWidthProbe({
86+
onWidthChange,
87+
}: {
88+
onWidthChange: (width: number) => void;
89+
}) {
90+
const probeRef = useRef<HTMLDivElement | null>(null);
91+
92+
useLayoutEffect(() => {
93+
const probe = probeRef.current;
94+
if (!probe) return;
95+
96+
const update = (entry?: ResizeObserverEntry) => {
97+
const width = entry?.borderBoxSize[0]?.inlineSize ?? probe.offsetWidth;
98+
if (Number.isFinite(width)) onWidthChange(width);
99+
};
100+
update();
101+
if (typeof ResizeObserver === "undefined") return;
102+
const observer = new ResizeObserver(([entry]) => update(entry));
103+
observer.observe(probe, { box: "border-box" });
104+
return () => observer.disconnect();
105+
}, [onWidthChange]);
106+
107+
return (
108+
<div
109+
aria-hidden="true"
110+
className="pointer-events-none invisible absolute top-0 left-0 -z-10 box-content flex h-7 w-max items-center border-r border-transparent pr-3 pl-[var(--workspace-titlebar-content-left)] text-sm font-medium tracking-tight"
111+
data-sidebar-header-width-probe=""
112+
ref={probeRef}
113+
>
114+
<span className="inline-flex h-7 shrink-0 items-center">
115+
<T3Wordmark aria-hidden className="h-[1cap] w-auto shrink-0" />
116+
</span>
117+
</div>
118+
);
119+
}
120+
80121
function SidebarBrand({ onBackdrop }: { onBackdrop: boolean }) {
81122
return (
82123
<Link
83124
aria-label="Go to threads"
84125
className={cn(
85-
"relative z-10 ml-[var(--workspace-titlebar-content-left)] hidden h-7 w-fit min-w-0 shrink-0 items-center overflow-hidden rounded-md outline-hidden ring-ring focus-visible:ring-2 md:flex",
126+
"relative z-10 ml-[var(--workspace-titlebar-content-left)] hidden h-7 w-fit min-w-0 shrink items-center overflow-hidden rounded-md outline-hidden ring-ring focus-visible:ring-2 focus-visible:ring-inset md:flex [flex-basis:max-content]",
86127
onBackdrop ? "text-white" : "text-foreground",
87128
)}
88129
to="/"
89130
>
90-
{/* Center the visible capitals, without the font's ascender/descender space. */}
91-
<span className="inline-flex min-w-0 items-baseline gap-1 text-sm font-medium tracking-tight">
92-
<T3Wordmark aria-label="T3" className="h-[1cap] w-auto shrink-0" />
93-
<span
94-
className={cn(
95-
"truncate [text-box:trim-both_cap_alphabetic]",
96-
onBackdrop ? "text-white/70" : "text-muted-foreground",
97-
)}
98-
>
99-
Code
131+
<span className="flex h-7 min-w-0 flex-wrap content-start gap-1 overflow-hidden text-sm font-medium tracking-tight">
132+
<span className="inline-flex h-7 shrink-0 items-center">
133+
<T3Wordmark aria-label="T3" className="h-[1cap] w-auto shrink-0" />
134+
</span>
135+
{/* Center the visible capitals, without the font's ascender/descender space. */}
136+
<span className="inline-flex h-7 shrink-0 items-center">
137+
<span
138+
className={cn(
139+
"whitespace-nowrap [text-box:trim-both_cap_alphabetic]",
140+
onBackdrop ? "text-white/70" : "text-muted-foreground",
141+
)}
142+
>
143+
Code
144+
</span>
100145
</span>
101146
</span>
102147
</Link>

‎apps/web/src/components/threadSidebarWidth.ts‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,18 @@ const THREAD_SIDEBAR_DEFAULT_WIDTH = 16 * 16;
33
export const THREAD_SIDEBAR_MIN_WIDTH = 13 * 16;
44
export const THREAD_MAIN_CONTENT_MIN_WIDTH = 40 * 16;
55

6-
export function resolveThreadSidebarMaximumWidth(viewportWidth: number): number {
7-
return Math.max(
8-
THREAD_SIDEBAR_MIN_WIDTH,
9-
Math.floor(viewportWidth) - THREAD_MAIN_CONTENT_MIN_WIDTH,
10-
);
6+
export function resolveThreadSidebarMaximumWidth(
7+
viewportWidth: number,
8+
minimumWidth = THREAD_SIDEBAR_MIN_WIDTH,
9+
): number {
10+
return Math.max(minimumWidth, Math.floor(viewportWidth) - THREAD_MAIN_CONTENT_MIN_WIDTH);
1111
}
1212

1313
export function resolveInitialThreadSidebarWidth(
1414
storedWidth: number | null,
1515
viewportWidth: number,
16+
minimumWidth = THREAD_SIDEBAR_MIN_WIDTH,
1617
): number {
17-
const preferredWidth =
18-
storedWidth === null
19-
? THREAD_SIDEBAR_DEFAULT_WIDTH
20-
: Math.max(THREAD_SIDEBAR_MIN_WIDTH, storedWidth);
21-
return Math.min(preferredWidth, resolveThreadSidebarMaximumWidth(viewportWidth));
18+
const preferredWidth = Math.max(minimumWidth, storedWidth ?? THREAD_SIDEBAR_DEFAULT_WIDTH);
19+
return Math.min(preferredWidth, resolveThreadSidebarMaximumWidth(viewportWidth, minimumWidth));
2220
}

0 commit comments

Comments
 (0)