diff --git a/apps/web/src/components/preview/RightPanelResizeHandle.tsx b/apps/web/src/components/PanelResizeHandle.tsx similarity index 67% rename from apps/web/src/components/preview/RightPanelResizeHandle.tsx rename to apps/web/src/components/PanelResizeHandle.tsx index 5091c8b5915ad..875ab6f8a5b92 100644 --- a/apps/web/src/components/preview/RightPanelResizeHandle.tsx +++ b/apps/web/src/components/PanelResizeHandle.tsx @@ -3,24 +3,27 @@ import { cn } from "~/lib/utils"; interface Props { handlers: ResizableWidthHandlers; + /** The panel edge the handle sits on: "left" for right-anchored panels, "right" for left-anchored ones. */ + edge?: "left" | "right"; className?: string; } /** - * Hit target for resizing a right-anchored panel via its left edge. + * Hit target for resizing a side panel from one of its edges. * * - Sits on top of the panel's border with a 4px overlap on each side so the * user can grab a few pixels off the edge without aiming. * - Visual indicator is a 1px line that lights up on hover/active to mirror * VS Code / Cursor. */ -export function RightPanelResizeHandle({ handlers, className }: Props) { +export function PanelResizeHandle({ handlers, edge = "left", className }: Props) { return (
{ + it("uses the fixed cap before the row is measured and on wide rows", () => { + expect(getWorkspaceListPaneMaxWidth()).toBe(512); + expect(getWorkspaceListPaneMaxWidth(1_600)).toBe(512); + }); + + it("keeps the editor usable in a narrow window with the app sidebar open", () => { + // 800px window minus a 208px app sidebar leaves a 592px row. + expect(getWorkspaceListPaneMaxWidth(592)).toBe(232); + expect(getWorkspaceListPaneMaxWidth(592.7)).toBe(232); + }); + + it("never drops below the pane's minimum width", () => { + expect(getWorkspaceListPaneMaxWidth(400)).toBe(208); + }); +}); diff --git a/apps/web/src/components/WorkspaceListPane.tsx b/apps/web/src/components/WorkspaceListPane.tsx new file mode 100644 index 0000000000000..ef45dc55bdb4d --- /dev/null +++ b/apps/web/src/components/WorkspaceListPane.tsx @@ -0,0 +1,68 @@ +import { type CSSProperties, type ReactNode, useLayoutEffect, useRef, useState } from "react"; + +import { useResizableWidth } from "~/hooks/useResizableWidth"; +import { cn } from "~/lib/utils"; +import { PanelResizeHandle } from "./PanelResizeHandle"; + +const LIST_PANE_DEFAULT_WIDTH = 18 * 16; +const LIST_PANE_MIN_WIDTH = 13 * 16; +const LIST_PANE_MAX_WIDTH = 32 * 16; +/** Width kept free for the editor beside the pane so its controls never overflow. */ +const EDITOR_MIN_WIDTH = 360; + +export function getWorkspaceListPaneMaxWidth(rowWidth?: number): number { + const rowCap = rowWidth === undefined ? Infinity : Math.floor(rowWidth) - EDITOR_MIN_WIDTH; + // Never below the pane's minimum: when the row cannot fit both, the editor + // yields, and the width hook must not see max < min. + return Math.max(LIST_PANE_MIN_WIDTH, Math.min(LIST_PANE_MAX_WIDTH, rowCap)); +} + +/** + * The resizable list column on the left of a workspace page (Notes, + * Automations). Its width persists per page under `storageKey` and is clamped + * to the row it shares with the editor, so narrowing the window or opening the + * app sidebar never squeezes the editor below a usable width. + */ +export function WorkspaceListPane({ + storageKey, + className, + children, +}: { + readonly storageKey: string; + readonly className?: string; + readonly children: ReactNode; +}) { + const paneRef = useRef(null); + const [rowWidth, setRowWidth] = useState(undefined); + useLayoutEffect(() => { + const row = paneRef.current?.parentElement; + if (!row) return; + // Measure before first paint so a restored wide pane never flashes over the editor. + const measure = () => setRowWidth(row.clientWidth); + measure(); + if (typeof ResizeObserver === "undefined") return; + const observer = new ResizeObserver(measure); + observer.observe(row); + return () => observer.disconnect(); + }, []); + const { width, handlers } = useResizableWidth({ + storageKey, + defaultWidth: LIST_PANE_DEFAULT_WIDTH, + minWidth: LIST_PANE_MIN_WIDTH, + maxWidth: getWorkspaceListPaneMaxWidth(rowWidth), + edge: "right", + }); + return ( + + ); +} diff --git a/apps/web/src/components/automations/AutomationsPage.tsx b/apps/web/src/components/automations/AutomationsPage.tsx index f239b50f1bb94..80f9ca0c94b98 100644 --- a/apps/web/src/components/automations/AutomationsPage.tsx +++ b/apps/web/src/components/automations/AutomationsPage.tsx @@ -93,6 +93,7 @@ import { Toggle, ToggleGroup } from "../ui/toggle-group"; import { toastManager } from "../ui/toast"; import { WorkspaceBreadcrumb, WorkspaceBreadcrumbItem } from "../WorkspaceBreadcrumb"; import { WorkspacePageHeader } from "../WorkspacePageHeader"; +import { WorkspaceListPane } from "../WorkspaceListPane"; import { AutomationPromptField } from "./AutomationPromptField"; import { AUTOMATION_TEMPLATE_CATEGORIES, @@ -261,7 +262,7 @@ export function AutomationsPage({ return (
- +

@@ -272,8 +273,8 @@ export function AutomationsPage({
- +
{content}
diff --git a/apps/web/src/components/notes/NotesPage.tsx b/apps/web/src/components/notes/NotesPage.tsx index e74b9eac7173a..c3e8a6655fe49 100644 --- a/apps/web/src/components/notes/NotesPage.tsx +++ b/apps/web/src/components/notes/NotesPage.tsx @@ -37,6 +37,7 @@ import { Textarea } from "../ui/textarea"; import { toastManager } from "../ui/toast"; import { WorkspaceBreadcrumb, WorkspaceBreadcrumbItem } from "../WorkspaceBreadcrumb"; import { WorkspacePageHeader } from "../WorkspacePageHeader"; +import { WorkspaceListPane } from "../WorkspaceListPane"; interface Draft { title: string; @@ -251,7 +252,7 @@ export function NotesPage({ return (
- +

@@ -262,8 +263,8 @@ export function NotesPage({
-