diff --git a/.changeset/36227-sidebar-resize-float-card.md b/.changeset/36227-sidebar-resize-float-card.md new file mode 100644 index 00000000000..48498be4d6a --- /dev/null +++ b/.changeset/36227-sidebar-resize-float-card.md @@ -0,0 +1,13 @@ +--- +'@object-ui/app-shell': patch +'@object-ui/i18n': patch +--- + +feat(console): the left sidebar resizes by its right edge, the collapsed sidebar floats as a card, and a menu opened from the float no longer leaves it folded with the menu cut off + +Clause-②: yes (widening) — one new `@object-ui/i18n` key (`sidebar.resize`) in all 11 locales; no spec, schema, server or published export change +Metadata-protocol: none + +- **Resize** (`@object-ui/app-shell`): from 768 px up, the docked sidebar's right edge drags it between 200 and 350 px; a double-click comes back to 256; ← → move it 16 px, Home and End to either end. The width is kept in this browser (`console.sidebar.width`) and the menu floating over a collapsed sidebar takes it too. A phone's drawer keeps its own width. +- **The float is a card:** 8 px off the window's left, top and bottom edges, with rounded corners, a border and a shadow; the page under it is not dimmed or moved. Resting the pointer at the window's left edge still floats it and moving away still folds it. +- **A menu opened from the float keeps it out:** pressing the app name (or the account, or an entry's `…`) while the float was still sliding in under the pointer opened the menu and folded the float a moment later, leaving the menu cut off at the window's left edge. A press in the float now stops the fold's clock, and the fold does not happen while a menu or dialog is open, or while the pointer is on the float. diff --git a/ui/packages/app-shell/src/layout/SidebarWidthHandle.tsx b/ui/packages/app-shell/src/layout/SidebarWidthHandle.tsx new file mode 100644 index 00000000000..18df5cdcb16 --- /dev/null +++ b/ui/packages/app-shell/src/layout/SidebarWidthHandle.tsx @@ -0,0 +1,119 @@ +// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. + +/** + * SidebarWidthHandle — the docked console sidebar's right edge, which resizes + * it (objectstack#36227, as Attio): dragged with the pointer between + * {@link CONSOLE_SIDEBAR_MIN_WIDTH} and {@link CONSOLE_SIDEBAR_MAX_WIDTH}, or + * moved with ← → (Home / End to either end). A double-click comes back to + * {@link CONSOLE_EXPANDED_SIDEBAR_WIDTH}. `onPreview` follows a drag; + * `onCommit` keeps the width once it ends. The same shape as the record page's + * details-column handle (`RecordPageColumns` in `@object-ui/plugin-detail`). + */ + +import * as React from 'react'; +import { useObjectTranslation } from '@object-ui/i18n'; +import { + CONSOLE_EXPANDED_SIDEBAR_WIDTH, + CONSOLE_SIDEBAR_MAX_WIDTH, + CONSOLE_SIDEBAR_MIN_WIDTH, + clampConsoleSidebarWidth, +} from './consoleSidebarRail.js'; + +/** How far one arrow-key press moves the sidebar's edge, in CSS pixels. */ +export const SIDEBAR_WIDTH_KEY_STEP = 16; + +export interface SidebarWidthHandleProps { + /** The width the sidebar has now, a drag's included. */ + width: number; + /** A drag in progress: its width, or `null` once it ends. */ + onPreview: (width: number | null) => void; + /** Keep this width. */ + onCommit: (width: number) => void; +} + +export function SidebarWidthHandle({ width, onPreview, onCommit }: SidebarWidthHandleProps) { + const { t } = useObjectTranslation(); + const drag = React.useRef<{ x: number; width: number; last: number } | null>(null); + + const end = (commit: boolean) => { + const start = drag.current; + drag.current = null; + document.body.style.removeProperty('cursor'); + document.body.style.removeProperty('user-select'); + onPreview(null); + if (commit && start && start.last !== start.width) onCommit(start.last); + }; + + // The handle can go away mid-drag: ⌘/Ctrl+B folds the sidebar, or the window + // narrows past 768 px, while the edge is still held. The drag then ends as a + // cancel: the page is selectable again and the sidebar goes back to the + // width it had when the drag began, the way a pointer-cancel ends it. + const previewRef = React.useRef(onPreview); + React.useEffect(() => { + previewRef.current = onPreview; + }); + React.useEffect( + () => () => { + if (!drag.current) return; + drag.current = null; + document.body.style.removeProperty('cursor'); + document.body.style.removeProperty('user-select'); + previewRef.current(null); + }, + [], + ); + + return ( +
{ + if (event.button !== 0) return; + event.preventDefault(); + event.currentTarget.setPointerCapture?.(event.pointerId); + drag.current = { x: event.clientX, width, last: width }; + document.body.style.setProperty('cursor', 'col-resize'); + document.body.style.setProperty('user-select', 'none'); + }} + onPointerMove={(event) => { + const start = drag.current; + if (!start) return; + start.last = clampConsoleSidebarWidth(start.width + event.clientX - start.x); + onPreview(start.last); + }} + onPointerUp={(event) => { + event.currentTarget.releasePointerCapture?.(event.pointerId); + end(true); + }} + onPointerCancel={() => end(false)} + onDoubleClick={() => { + end(false); + onCommit(CONSOLE_EXPANDED_SIDEBAR_WIDTH); + }} + onKeyDown={(event) => { + const next = + event.key === 'ArrowLeft' ? width - SIDEBAR_WIDTH_KEY_STEP + : event.key === 'ArrowRight' ? width + SIDEBAR_WIDTH_KEY_STEP + : event.key === 'Home' ? CONSOLE_SIDEBAR_MIN_WIDTH + : event.key === 'End' ? CONSOLE_SIDEBAR_MAX_WIDTH + : null; + if (next === null) return; + event.preventDefault(); + const clamped = clampConsoleSidebarWidth(next); + if (clamped !== width) onCommit(clamped); + }} + > +
+ ); +} diff --git a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx index 560ffcfaa2b..6eb1d0c1f89 100644 --- a/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx +++ b/ui/packages/app-shell/src/layout/UnifiedSidebar.tsx @@ -85,7 +85,16 @@ import { InboxBell } from './InboxBell.js'; import { AccountMenu } from './AccountMenu.js'; import { useCommandPalette, useCommandPaletteProviderMounted } from '../context/CommandPaletteProvider.js'; import { confirmUnsavedLeave } from '../chrome/unsavedEdits.js'; -import { SIDEBAR_EDGE_ZONE, useConsoleSidebarRail, useConsoleSidebarRailPanel } from './consoleSidebarRail.js'; +import { + CONSOLE_EXPANDED_SIDEBAR_WIDTH, + CONSOLE_SIDEBAR_WIDTH_PREFERENCE, + SIDEBAR_EDGE_ZONE, + SIDEBAR_RESIZING_FRAME, + useConsoleSidebarRail, + useConsoleSidebarRailPanel, +} from './consoleSidebarRail.js'; +import { SidebarWidthHandle } from './SidebarWidthHandle.js'; +import { useWorkspacePreference } from '../utils/workspacePreference.js'; import { SidebarItemMenu, sidebarItemDesignPath, favoriteDesignPath } from './SidebarItemMenu.js'; import { SortableFavoriteRows, type FavoriteRowDragProps } from './SortableFavoriteRows.js'; import { favoriteAppSegment } from './listViewFavorites.js'; @@ -214,6 +223,16 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false const rail = useConsoleSidebarRail({ enabled: railOverlay }); const sidebarRef = React.useRef(null); const railPanel = useConsoleSidebarRailPanel(rail, sidebarRef); + // objectstack#36227 — from 768 px up the reader drags the docked sidebar's + // right edge to resize it; this browser keeps the width, and the menu + // floating over a collapsed sidebar takes it too. + const [keptWidth, setKeptWidth] = useWorkspacePreference( + CONSOLE_SIDEBAR_WIDTH_PREFERENCE, + 'user', + CONSOLE_EXPANDED_SIDEBAR_WIDTH, + ); + const [dragWidth, setDragWidth] = React.useState(null); + const sidebarWidth = dragWidth ?? keptWidth; // objectstack#36112 — from 768 px up the console draws no top bar: the // sidebar starts at the top of the window and carries the app menu, the // search and the bell in its head, and the account at its foot. @@ -743,7 +762,11 @@ export function UnifiedSidebar({ activeAppName, onAppChange, railOverlay = false ); return ( -
+
+ )} {/* objectstack#35062 — the window's left edge while the sidebar is hidden: resting the pointer on it, or a press, floats the menu. For diff --git a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx index 66905a3cc57..ff903027907 100644 --- a/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/UnifiedSidebar.hiddenCollapse-35062.test.tsx @@ -112,8 +112,15 @@ import { SidebarProvider, useSidebar } from '@object-ui/components'; import { UnifiedSidebar } from '../UnifiedSidebar'; import { useResponsiveSidebar } from '../../hooks/useResponsiveSidebar'; import { + CONSOLE_EXPANDED_SIDEBAR_WIDTH, + CONSOLE_SIDEBAR_MAX_WIDTH, + CONSOLE_SIDEBAR_MIN_WIDTH, CONSOLE_SIDEBAR_NARROW_OPEN_PREFERENCE, + CONSOLE_SIDEBAR_WIDTH_PREFERENCE, + RAIL_HIDDEN_PANEL, RAIL_OVERLAY_FRAME_NO_GAP, + RAIL_OVERLAY_PANEL, + SIDEBAR_RESIZING_FRAME, SIDEBAR_EDGE_ZONE, SIDEBAR_FLOAT_CLOSE_DELAY_MS, SIDEBAR_FLOAT_OPEN_DELAY_MS, @@ -749,3 +756,201 @@ describe('the float carries the app menu, and its 「Edit app」 enters the desi expect(screen.getByTestId('mode')).toHaveTextContent('on'); }); }); + +/** The width the frame hands the sidebar primitive (its `--sidebar-width`). */ +const frameWidth = () => frame().style.getPropertyValue('--sidebar-width'); +const resizeHandle = () => screen.queryByTestId('console-sidebar-resize'); +const keptWidth = () => readWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user'); + +describe('the docked sidebar’s right edge resizes it, and the float takes the width (objectstack#36227)', () => { + it('at 1440 px a drag on the edge resizes it between 200 and 350; the width is kept once the drag ends, and a reload keeps it', () => { + renderShell(1440); + expectDocked(); + expect(frameWidth()).toBe(`${CONSOLE_EXPANDED_SIDEBAR_WIDTH}px`); + const handle = resizeHandle()!; + expect(handle).toHaveAttribute('role', 'separator'); + expect(handle).toHaveAttribute('aria-valuenow', '256'); + expect(handle).toHaveAttribute('aria-valuemin', String(CONSOLE_SIDEBAR_MIN_WIDTH)); + expect(handle).toHaveAttribute('aria-valuemax', String(CONSOLE_SIDEBAR_MAX_WIDTH)); + + // Dragged far right: held at the widest, the primitive's transition off while it follows. + fireEvent.pointerDown(handle, { button: 0, clientX: 256, pointerId: 1 }); + fireEvent.pointerMove(handle, { clientX: 900, pointerId: 1 }); + expect(frameWidth()).toBe('350px'); + expect(tokens(frame())).toContain(SIDEBAR_RESIZING_FRAME); + expect(keptWidth(), 'nothing is kept mid-drag').toBeUndefined(); + // Dragged far left: held at the narrowest. + fireEvent.pointerMove(handle, { clientX: 0, pointerId: 1 }); + expect(frameWidth()).toBe('200px'); + fireEvent.pointerMove(handle, { clientX: 300, pointerId: 1 }); + fireEvent.pointerUp(handle, { clientX: 300, pointerId: 1 }); + expect(frameWidth()).toBe('300px'); + expect(tokens(frame())).toEqual(['contents']); + expect(keptWidth()).toBe(300); + + reload(1440); + expectDocked(); + expect(frameWidth()).toBe('300px'); + expect(resizeHandle()).toHaveAttribute('aria-valuenow', '300'); + }); + + it('a double-click on the edge comes back to 256; the arrow keys, Home and End move it too', () => { + writeWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user', 320); + renderShell(1440); + expect(frameWidth()).toBe('320px'); + fireEvent.doubleClick(resizeHandle()!); + expect(frameWidth()).toBe('256px'); + expect(keptWidth()).toBe(256); + + fireEvent.keyDown(resizeHandle()!, { key: 'End' }); + expect(frameWidth()).toBe('350px'); + fireEvent.keyDown(resizeHandle()!, { key: 'ArrowRight' }); + expect(frameWidth(), 'held at the widest').toBe('350px'); + fireEvent.keyDown(resizeHandle()!, { key: 'ArrowLeft' }); + expect(frameWidth()).toBe('334px'); + fireEvent.keyDown(resizeHandle()!, { key: 'Home' }); + expect(frameWidth()).toBe('200px'); + expect(keptWidth()).toBe(200); + }); + + it('a kept width out of the range reads as the nearest end', () => { + writeWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user', 9000); + renderShell(1440); + expect(frameWidth()).toBe('350px'); + }); + + it('collapsed, the edge is gone; the float takes the kept width, drawn as a card, and the hidden panel keeps the card parked past the edge', () => { + vi.useFakeTimers(); + writeWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user', 300); + renderShell(1024); + expectHidden(); + expect(resizeHandle()).toBeNull(); + expect(frameWidth()).toBe('300px'); + for (const token of RAIL_HIDDEN_PANEL.split(' ')) expect(tokens(panel())).toContain(token); + + hoverEdge(SIDEBAR_FLOAT_OPEN_DELAY_MS); + expectFloat(); + expect(resizeHandle(), 'the float is not resized').toBeNull(); + expect(frameWidth()).toBe('300px'); + for (const token of RAIL_OVERLAY_PANEL.split(' ')) expect(tokens(panel())).toContain(token); + // A card: off the window's edges, rounded, with a shadow. + expect(tokens(panel())).toEqual(expect.arrayContaining(['inset-y-2', 'left-2', 'rounded-lg', 'shadow-xl'])); + expect(tokens(panel())).not.toContain('inset-y-0'); + expect(tokens(panel())).not.toContain('left-0'); + }); + + it('the edge going away mid-drag ends the drag as a cancel: the page is selectable again and the width goes back (⌘B, then a narrow window)', () => { + const body = document.body.style; + writeWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user', 300); + renderShell(1440); + + // ⌘B folds the sidebar while the edge is held. + fireEvent.pointerDown(resizeHandle()!, { button: 0, clientX: 300, pointerId: 1 }); + fireEvent.pointerMove(resizeHandle()!, { clientX: 340, pointerId: 1 }); + expect(frameWidth()).toBe('340px'); + expect(body.getPropertyValue('user-select')).toBe('none'); + commandB(); + expectHidden(); + expect(resizeHandle()).toBeNull(); + expect(body.getPropertyValue('user-select'), 'the page is selectable again').toBe(''); + expect(body.getPropertyValue('cursor')).toBe(''); + expect(frameWidth(), 'back to the width it had').toBe('300px'); + expect(tokens(frame())).not.toContain(SIDEBAR_RESIZING_FRAME); + expect(keptWidth()).toBe(300); + + // The window narrows past 768 px while the edge is held. + commandB(); + expectDocked(); + fireEvent.pointerDown(resizeHandle()!, { button: 0, clientX: 300, pointerId: 2 }); + fireEvent.pointerMove(resizeHandle()!, { clientX: 220, pointerId: 2 }); + expect(body.getPropertyValue('user-select')).toBe('none'); + resizeTo(700); + expect(resizeHandle()).toBeNull(); + expect(body.getPropertyValue('user-select')).toBe(''); + expect(body.getPropertyValue('cursor')).toBe(''); + expect(keptWidth()).toBe(300); + resizeTo(1440); + expect(frameWidth(), 'nothing of the drag is left behind').toBe('300px'); + expect(tokens(frame())).not.toContain(SIDEBAR_RESIZING_FRAME); + }); + + it('on a phone the drawer keeps its own width and draws no edge', () => { + writeWorkspacePreference(CONSOLE_SIDEBAR_WIDTH_PREFERENCE, 'user', 300); + renderShell(700); + expect(resizeHandle()).toBeNull(); + expect(frameWidth()).toBe(''); + }); +}); + +describe('a menu opened from the float keeps it out (objectstack#36471)', () => { + /** The float a resting pointer opened on a wide window, the pointer then past it on the page. */ + function floatThenPointerAway() { + vi.useFakeTimers(); + writeWideWindowOpen(false); + reload(1440); + expectHidden(); + hoverEdge(SIDEBAR_FLOAT_OPEN_DELAY_MS); + expectFloat(); + // The float still sliding in: the pointer is past its edge a moment, which starts the fold's clock. + fireEvent.pointerMove(screen.getByText('The page'), { pointerType: 'mouse' }); + } + + it('the app name pressed before the fold’s moment is up: the menu opens, and the float stays while it is open', () => { + floatThenPointerAway(); + fireEvent.pointerDown(within(panel()).getByTestId('sidebar-app-menu-trigger'), { + button: 0, + ctrlKey: false, + pointerType: 'mouse', + }); + expect(screen.getByTestId('sidebar-app-menu')).toBeInTheDocument(); + act(() => { + vi.advanceTimersByTime(SIDEBAR_FLOAT_CLOSE_DELAY_MS * 3); + }); + expectFloat(); + expect(screen.getByTestId('sidebar-app-menu')).toBeInTheDocument(); + }); + + it('a menu opened from the float with no press in it (the keyboard) holds the float when the moment is up', () => { + floatThenPointerAway(); + fireEvent.keyDown(within(panel()).getByTestId('sidebar-app-menu-trigger'), { key: 'Enter' }); + expect(screen.getByTestId('sidebar-app-menu')).toBeInTheDocument(); + act(() => { + vi.advanceTimersByTime(SIDEBAR_FLOAT_CLOSE_DELAY_MS * 3); + }); + expectFloat(); + }); + + it('a press in the float stops the fold’s clock; a later move away starts it again', () => { + floatThenPointerAway(); + fireEvent.pointerDown(within(panel()).getByRole('link', { name: 'Contacts' }), { button: 0, pointerType: 'mouse' }); + act(() => { + vi.advanceTimersByTime(SIDEBAR_FLOAT_CLOSE_DELAY_MS * 3); + }); + expectFloat(); + fireEvent.pointerMove(screen.getByText('The page'), { pointerType: 'mouse' }); + act(() => { + vi.advanceTimersByTime(SIDEBAR_FLOAT_CLOSE_DELAY_MS); + }); + expectHidden(); + }); + + it('once the menu closes, moving away folds the float as before', () => { + floatThenPointerAway(); + fireEvent.pointerDown(within(panel()).getByTestId('sidebar-app-menu-trigger'), { + button: 0, + ctrlKey: false, + pointerType: 'mouse', + }); + act(() => { + vi.advanceTimersByTime(SIDEBAR_FLOAT_CLOSE_DELAY_MS * 3); + }); + expectFloat(); + fireEvent.keyDown(screen.getByTestId('sidebar-app-menu'), { key: 'Escape' }); + expect(screen.queryByTestId('sidebar-app-menu')).toBeNull(); + fireEvent.pointerMove(screen.getByText('The page'), { pointerType: 'mouse' }); + act(() => { + vi.advanceTimersByTime(SIDEBAR_FLOAT_CLOSE_DELAY_MS); + }); + expectHidden(); + }); +}); diff --git a/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx b/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx index ff38facf6d9..17dbe9baa10 100644 --- a/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx +++ b/ui/packages/app-shell/src/layout/__tests__/consoleSidebarRail.width-27593.test.tsx @@ -6,7 +6,7 @@ * record drawer, the list beside it and the expanded sidebar (1416 px); the * ruling on objectstack#36112 (7069868269) moved it to 1280 px and accepted * the cost. `CONSOLE_EXPANDED_SIDEBAR_WIDTH` restates the sidebar primitive's - * `--sidebar-width` (fixed at 256, objectstack#36112 F2) and + * default `--sidebar-width` (256; the reader may drag it, objectstack#36227) and * `RECORD_DRAWER_WIDTH` the side preview's default width (objectstack#36149), * so this reads both off their owners and holds them equal, and the cost the * code pays is the one stated beside the threshold. diff --git a/ui/packages/app-shell/src/layout/consoleSidebarRail.ts b/ui/packages/app-shell/src/layout/consoleSidebarRail.ts index 537b7e4a45d..702a6d88eea 100644 --- a/ui/packages/app-shell/src/layout/consoleSidebarRail.ts +++ b/ui/packages/app-shell/src/layout/consoleSidebarRail.ts @@ -54,13 +54,45 @@ import { } from '../utils/workspacePreference.js'; /** - * The expanded sidebar's width in CSS pixels: the sidebar primitive's + * The expanded sidebar's default width in CSS pixels: the sidebar primitive's * `--sidebar-width` (16rem) in `@object-ui/components`. * `consoleSidebarRail.width-27593.test.tsx` reads the primitive's value and - * holds this equal to it. The width is fixed (objectstack#36112 F2). + * holds this equal to it. From the phone breakpoint up the reader drags the + * docked sidebar's right edge between {@link CONSOLE_SIDEBAR_MIN_WIDTH} and + * {@link CONSOLE_SIDEBAR_MAX_WIDTH}, and a double-click on it comes back here + * (objectstack#36227). */ export const CONSOLE_EXPANDED_SIDEBAR_WIDTH = 256; +/** The narrowest the reader can drag the sidebar, in CSS pixels (objectstack#36227, as Attio). */ +export const CONSOLE_SIDEBAR_MIN_WIDTH = 200; + +/** The widest the reader can drag the sidebar, in CSS pixels (objectstack#36227, as Attio). */ +export const CONSOLE_SIDEBAR_MAX_WIDTH = 350; + +/** A width held to the sidebar's range, in whole pixels. */ +export function clampConsoleSidebarWidth(width: number): number { + return Math.round(Math.min(CONSOLE_SIDEBAR_MAX_WIDTH, Math.max(CONSOLE_SIDEBAR_MIN_WIDTH, width))); +} + +/** + * The width, in CSS px, the reader dragged the sidebar to (objectstack#36227): + * a reader preference, per browser, never metadata. Stored as + * `{"width":N,"v":1}`. With no choice: {@link CONSOLE_EXPANDED_SIDEBAR_WIDTH}. + * The docked sidebar and the menu floating over a collapsed one both take it. + */ +export const CONSOLE_SIDEBAR_WIDTH_PREFERENCE = defineWorkspacePreference({ + name: 'console.sidebar.width', + codec: versionedPreferenceCodec({ + version: 1, + toRecord: (width) => ({ width }), + fromRecord: (record) => + typeof record.width === 'number' && Number.isFinite(record.width) + ? clampConsoleSidebarWidth(record.width) + : undefined, + }), +}); + /** * The record drawer's width in CSS pixels: a list record opens in the side * preview at `RECORD_PREVIEW_DEFAULT_WIDTH` = `min(92vw, 460px)` @@ -315,8 +347,26 @@ export const SIDEBAR_EDGE_ZONE = 'fixed left-0 z-40 w-2'; */ export const RAIL_OVERLAY_FRAME_NO_GAP = '[&>[data-collapsible=offcanvas]>div:first-child]:w-0'; -/** The panel's classes while the menu floats: above the page, with a shadow. */ -export const RAIL_OVERLAY_PANEL = 'z-40 shadow-xl'; +/** + * The panel's classes while the menu floats: a card above the page, 8 px off + * the window's left, top and bottom edges, with rounded corners, a border and + * a shadow, and nothing dimmed under it (objectstack#36227, as Attio). + */ +export const RAIL_OVERLAY_PANEL = + 'z-40 inset-y-2 left-2 h-auto overflow-hidden rounded-lg border border-sidebar-border shadow-xl'; + +/** + * The panel's classes while the sidebar is hidden: the float's card, parked + * past the window's left edge by its own width and 2 rem more, so its shadow + * does not show at the edge. The card keeps its shape as it slides in and out. + */ +export const RAIL_HIDDEN_PANEL = `${RAIL_OVERLAY_PANEL} group-data-[state=collapsed]:group-data-[collapsible=offcanvas]:left-[calc(var(--sidebar-width)*-1-2rem)]`; + +/** + * The frame's class while the reader drags the sidebar's edge: the gap and the + * panel follow the pointer at once, without the primitive's width transition. + */ +export const SIDEBAR_RESIZING_FRAME = '[&>[data-collapsible]>div]:transition-none'; /** A layer drawn over the page that takes Esc for itself, or holds the pointer while it is open. */ const ESCAPE_LAYER = '[role="dialog"], [role="alertdialog"], [role="menu"], [role="listbox"]'; @@ -339,6 +389,21 @@ function escapeOnlyForHiddenTooltip(): boolean { return !layerShown(); } +/** + * Is this point on the float: on the sidebar's panel (the fixed box the float + * is drawn in, the last child of the primitive's `data-collapsible` root), or + * in the margin the card keeps from the window's edges (objectstack#36227), + * where the pointer that floated it rests? + */ +function pointerOnFloat(root: HTMLElement | null, point: { x: number; y: number } | null): boolean { + const panel = root?.lastElementChild; + if (!panel || !point) return false; + const box = panel.getBoundingClientRect(); + if (box.width === 0 || box.height === 0) return false; + const margin = Math.max(0, box.left); + return point.x < box.right && point.y >= box.top - margin && point.y < box.bottom + margin; +} + /** * The sidebar trigger focus can go to: the first one not inside an inert * region. The sidebar's own collapse button is inert while it is hidden, so @@ -369,6 +434,8 @@ export interface ConsoleSidebarRailPanel { collapsible: 'offcanvas' | 'icon'; /** The menu floats over the content. */ overlayOpen: boolean; + /** From the phone breakpoint up, the sidebar is open beside the content: its right edge resizes it. */ + docked: boolean; /** The class of the `display: contents` frame around the sidebar. */ frameClassName: string; /** Classes added to the sidebar panel. */ @@ -443,6 +510,8 @@ export function useConsoleSidebarRailPanel( // tell them from outside ones. const insidePress = useRef(null); const insideMove = useRef(null); + // Where the pointer last moved outside the float, for the fold's last look. + const awayAt = useRef<{ x: number; y: number } | null>(null); useLayoutEffect(() => { setOpenRef.current = setOpen; @@ -605,14 +674,20 @@ export function useConsoleSidebarRailPanel( // A float the pointer opened folds once the pointer has been away from it a moment. const onPointerMove = (event: globalThis.PointerEvent) => { if (openedBy.current !== 'hover' || event.pointerType === 'touch') return; - if (event === insideMove.current || layerShown()) { + if (event === insideMove.current || layerShown() || pointerOnFloat(sidebarRef.current, { x: event.clientX, y: event.clientY })) { clearTimeout(closeTimer.current); closeTimer.current = undefined; return; } + awayAt.current = { x: event.clientX, y: event.clientY }; if (closeTimer.current !== undefined) return; closeTimer.current = setTimeout(() => { closeTimer.current = undefined; + // Still away when the moment is up (objectstack#36471): not if a menu + // or dialog opened from the float since (a press on the app name + // while the float was still sliding in under the pointer), nor if the + // float slid in under a pointer that has not moved since. + if (layerShown() || pointerOnFloat(sidebarRef.current, awayAt.current)) return; close('away'); }, SIDEBAR_FLOAT_CLOSE_DELAY_MS); }; @@ -638,10 +713,13 @@ export function useConsoleSidebarRailPanel( clearTimeout(closeTimer.current); closeTimer.current = undefined; }; - }, [overlayOpen, close]); + }, [overlayOpen, close, sidebarRef]); const onPointerDown = useCallback((event: PointerEvent) => { insidePress.current = event.nativeEvent; + // A press in the float: the pointer is on it, not away (objectstack#36471). + clearTimeout(closeTimer.current); + closeTimer.current = undefined; }, []); const onPointerMove = useCallback((event: PointerEvent) => { @@ -678,8 +756,9 @@ export function useConsoleSidebarRailPanel( return { collapsible: enabled ? 'offcanvas' : 'icon', overlayOpen, + docked: desktop && open && !overlayOpen, frameClassName: cn('contents', overlayOpen && RAIL_OVERLAY_FRAME_NO_GAP), - panelClassName: overlayOpen ? RAIL_OVERLAY_PANEL : undefined, + panelClassName: overlayOpen ? RAIL_OVERLAY_PANEL : hidden ? RAIL_HIDDEN_PANEL : undefined, panelProps, edgeZoneProps: hidden ? { onPointerEnter: onEdgeEnter, onPointerLeave: onEdgeLeave, onClick: onEdgePress } : null, }; diff --git a/ui/packages/i18n/src/locales/ar.ts b/ui/packages/i18n/src/locales/ar.ts index 0679e2e1ccf..6b52a8397de 100644 --- a/ui/packages/i18n/src/locales/ar.ts +++ b/ui/packages/i18n/src/locales/ar.ts @@ -3891,6 +3891,7 @@ const ar = { allReports: "كل التقارير", collapse: 'طي الشريط الجانبي', expand: 'توسيع الشريط الجانبي', + resize: 'تغيير حجم الشريط الجانبي', }, designMode: { title: 'وضع التصميم', diff --git a/ui/packages/i18n/src/locales/de.ts b/ui/packages/i18n/src/locales/de.ts index 910717801c8..208341059b6 100644 --- a/ui/packages/i18n/src/locales/de.ts +++ b/ui/packages/i18n/src/locales/de.ts @@ -3568,6 +3568,7 @@ const de = { allReports: "Alle Berichte", collapse: 'Seitenleiste einklappen', expand: 'Seitenleiste ausklappen', + resize: 'Breite der Seitenleiste ändern', }, designMode: { title: 'Designmodus', diff --git a/ui/packages/i18n/src/locales/en.ts b/ui/packages/i18n/src/locales/en.ts index ccc2bfd0238..f33bd677187 100644 --- a/ui/packages/i18n/src/locales/en.ts +++ b/ui/packages/i18n/src/locales/en.ts @@ -4309,6 +4309,7 @@ const en = { allReports: 'All reports', collapse: 'Collapse sidebar', expand: 'Expand sidebar', + resize: 'Resize sidebar', }, designMode: { title: 'Design mode', diff --git a/ui/packages/i18n/src/locales/es.ts b/ui/packages/i18n/src/locales/es.ts index 6aee49a0be6..1b6fdeb80d4 100644 --- a/ui/packages/i18n/src/locales/es.ts +++ b/ui/packages/i18n/src/locales/es.ts @@ -3650,6 +3650,7 @@ const es = { allReports: "Todos los informes", collapse: 'Contraer la barra lateral', expand: 'Expandir la barra lateral', + resize: 'Cambiar el ancho de la barra lateral', }, designMode: { title: 'Modo de diseño', diff --git a/ui/packages/i18n/src/locales/fr.ts b/ui/packages/i18n/src/locales/fr.ts index 39b45f2e033..6323d87b770 100644 --- a/ui/packages/i18n/src/locales/fr.ts +++ b/ui/packages/i18n/src/locales/fr.ts @@ -3646,6 +3646,7 @@ const fr = { allReports: "Tous les rapports", collapse: 'Réduire la barre latérale', expand: 'Développer la barre latérale', + resize: 'Redimensionner la barre latérale', }, designMode: { title: 'Mode conception', diff --git a/ui/packages/i18n/src/locales/ja.ts b/ui/packages/i18n/src/locales/ja.ts index 3fe7cbbe72d..ba5516eeb92 100644 --- a/ui/packages/i18n/src/locales/ja.ts +++ b/ui/packages/i18n/src/locales/ja.ts @@ -3570,6 +3570,7 @@ const ja = { allReports: "すべてのレポート", collapse: 'サイドバーを折りたたむ', expand: 'サイドバーを展開', + resize: 'サイドバーの幅を調整', }, designMode: { title: 'デザインモード', diff --git a/ui/packages/i18n/src/locales/ko.ts b/ui/packages/i18n/src/locales/ko.ts index 18a7a4d3436..95546f38d68 100644 --- a/ui/packages/i18n/src/locales/ko.ts +++ b/ui/packages/i18n/src/locales/ko.ts @@ -3568,6 +3568,7 @@ const ko = { allReports: "모든 보고서", collapse: '사이드바 접기', expand: '사이드바 펼치기', + resize: '사이드바 너비 조정', }, designMode: { title: '디자인 모드', diff --git a/ui/packages/i18n/src/locales/pt-BR.ts b/ui/packages/i18n/src/locales/pt-BR.ts index 9ba1bffd5a6..4ee1b78b884 100644 --- a/ui/packages/i18n/src/locales/pt-BR.ts +++ b/ui/packages/i18n/src/locales/pt-BR.ts @@ -3645,6 +3645,7 @@ const pt = { allReports: "Todos os relatórios", collapse: 'Recolher a barra lateral', expand: 'Expandir a barra lateral', + resize: 'Redimensionar a barra lateral', }, designMode: { title: 'Modo de design', diff --git a/ui/packages/i18n/src/locales/ru.ts b/ui/packages/i18n/src/locales/ru.ts index ee2a1dd4590..2cb821bdeff 100644 --- a/ui/packages/i18n/src/locales/ru.ts +++ b/ui/packages/i18n/src/locales/ru.ts @@ -3737,6 +3737,7 @@ const ru = { allReports: "Все отчёты", collapse: 'Свернуть боковую панель', expand: 'Развернуть боковую панель', + resize: 'Изменить ширину боковой панели', }, designMode: { title: 'Режим дизайна', diff --git a/ui/packages/i18n/src/locales/zh-Hans.ts b/ui/packages/i18n/src/locales/zh-Hans.ts index 64aa3bb029b..476349f63ed 100644 --- a/ui/packages/i18n/src/locales/zh-Hans.ts +++ b/ui/packages/i18n/src/locales/zh-Hans.ts @@ -3705,6 +3705,7 @@ const zh = { allReports: '全部报表', collapse: '收起侧边栏', expand: '展开侧边栏', + resize: '调整侧边栏宽度', }, designMode: { title: '设计模式', diff --git a/ui/packages/i18n/src/locales/zh-Hant.ts b/ui/packages/i18n/src/locales/zh-Hant.ts index f3c31a110dc..4ee878e61a5 100644 --- a/ui/packages/i18n/src/locales/zh-Hant.ts +++ b/ui/packages/i18n/src/locales/zh-Hant.ts @@ -3705,6 +3705,7 @@ const zhHant = { allReports: '全部報表', collapse: '收起側邊欄', expand: '展開側邊欄', + resize: '調整側邊欄寬度', }, designMode: { title: '設計模式',