From 4091a0261397020d928a844bc25fc15b164460b7 Mon Sep 17 00:00:00 2001 From: Kit Langton Date: Wed, 21 Oct 2026 14:15:27 -0700 Subject: [PATCH] feat(app): fade sidebar contents and carry the toggle icon across (#57905) --- .../app/e2e/regression/panel-edges.spec.ts | 2 +- packages/app/e2e/regression/tabs.spec.ts | 5 +- .../session/header/session-header-actions.tsx | 25 +++++- packages/app/src/session/screen.tsx | 24 +++++- packages/app/src/shell/panel-motion.ts | 7 +- packages/app/src/shell/shell.tsx | 10 ++- packages/app/src/shell/sidebar-toggle.tsx | 81 ++++++++++++++----- 7 files changed, 122 insertions(+), 32 deletions(-) diff --git a/packages/app/e2e/regression/panel-edges.spec.ts b/packages/app/e2e/regression/panel-edges.spec.ts index 8c100a0d742..92d8263dda1 100644 --- a/packages/app/e2e/regression/panel-edges.spec.ts +++ b/packages/app/e2e/regression/panel-edges.spec.ts @@ -50,7 +50,7 @@ test("the content beside a panel follows the panel's edge on every frame of a to const sidebar = page .locator( - '[data-slot="vertical-tabs-sidebar"] button[aria-controls="vertical-tabs-sidebar"], main button[aria-controls="vertical-tabs-sidebar"]', + '[data-slot="vertical-tabs-sidebar"] button[aria-controls="vertical-tabs-sidebar"], [data-slot="collapsed-sidebar-toggle"] button[aria-controls="vertical-tabs-sidebar"]', ) .locator("visible=true") .first() diff --git a/packages/app/e2e/regression/tabs.spec.ts b/packages/app/e2e/regression/tabs.spec.ts index 1801ca9fbc6..b07486d4f75 100644 --- a/packages/app/e2e/regression/tabs.spec.ts +++ b/packages/app/e2e/regression/tabs.spec.ts @@ -491,7 +491,10 @@ for (const [screen, href] of [ const sidebar = page.locator('[data-slot="vertical-tabs-sidebar"]') await expect(sidebar).toHaveAttribute("data-state", "closed") - await page.locator("main").getByRole("button", { name: "Toggle sidebar", exact: true }).click() + await page + .locator('[data-slot="collapsed-sidebar-toggle"]') + .getByRole("button", { name: "Toggle sidebar", exact: true }) + .click() await expect(sidebar).toHaveAttribute("data-state", "open") await expect(sidebar.getByRole("button", { name: "Toggle sidebar", exact: true })).toHaveAttribute( "aria-expanded", diff --git a/packages/app/src/session/header/session-header-actions.tsx b/packages/app/src/session/header/session-header-actions.tsx index 9c4325cc2db..5305229d770 100644 --- a/packages/app/src/session/header/session-header-actions.tsx +++ b/packages/app/src/session/header/session-header-actions.tsx @@ -7,7 +7,10 @@ import { useCommand } from "@/shell/commands/command" import { useLanguage } from "@/runtime/i18n/language" import { useSessionLayout } from "@/session/session-layout" -export function SessionReviewToggle(props: { onToggle: () => void }) { +/** The review toggle's pane fill, scaled from the panel's edge to `open` of its width. */ +export const reviewGlyphFill = (open: number) => `matrix(${open} 0 0 1 ${2.917 * (1 - open)} 0)` + +export function SessionReviewToggle(props: { onToggle: () => void; glyph?: (fill: SVGPathElement) => void }) { const command = useCommand() const language = useLanguage() const { view } = useSessionLayout() @@ -20,6 +23,7 @@ export function SessionReviewToggle(props: { onToggle: () => void }) { reviewVisible: true, reviewOpened: view().side.opened(), onReviewToggle: props.onToggle, + reviewGlyph: props.glyph, }} /> ) @@ -31,6 +35,8 @@ export type SessionHeaderActionsState = { reviewVisible: boolean reviewOpened: boolean onReviewToggle: () => void + /** Draws the glyph's pane fill from a ref the caller scales as the panel moves; otherwise it follows the state. */ + reviewGlyph?: (fill: SVGPathElement) => void } export function SessionHeaderActions(props: { state: SessionHeaderActionsState }) { @@ -59,7 +65,22 @@ export function SessionHeaderActions(props: { state: SessionHeaderActionsState } aria-label={props.state.reviewLabel} aria-expanded={props.state.reviewOpened} aria-controls="review-panel" - icon={} + icon={ + props.state.reviewGlyph ? ( + + ) : ( + + ) + } /> diff --git a/packages/app/src/session/screen.tsx b/packages/app/src/session/screen.tsx index 470b6ae14cc..3c81502fd1b 100644 --- a/packages/app/src/session/screen.tsx +++ b/packages/app/src/session/screen.tsx @@ -45,7 +45,7 @@ import { SessionIdentityHeader, SessionLocation } from "./session-identity-heade import { SessionHeaderDrag, windowDragEnabled } from "./header/drag-area" import { usePlatform } from "@/runtime/platform/platform" import { useServer } from "@/runtime/server/current" -import { SessionReviewToggle } from "./header/session-header-actions" +import { reviewGlyphFill, SessionReviewToggle } from "./header/session-header-actions" import { createTimelineCache } from "./timeline/cache" import { createPanelMotion, replayPanelToggle } from "@/shell/panel-motion" @@ -155,11 +155,22 @@ function SessionScreenContent(props: { // Once opened, the side region stays mounted and is skipped by content-visibility when a close settles, so neither // direction mounts its contents mid-flight, and a reopen reuses their style and layout. + let sideContent: HTMLDivElement | undefined + let sideGlyph: SVGPathElement | undefined + let sideClosed = 0 + // The toggle's pane fills from the panel's edge as far as the panel is open. + const paintSideGlyph = () => sideGlyph?.setAttribute("transform", reviewGlyphFill(1 - sideClosed)) const sideMotion = createPanelMotion({ open: sideVisible, identity: session.layout.tabKey, // The chat's real width moves the side panel's edge, whose contents keep their open width pinned to it. paint: (closed) => { + sideClosed = closed + paintSideGlyph() + + // Dims the contents as they leave and fades them in as they arrive. + if (sideContent) sideContent.style.opacity = closed === 0 ? "" : `${1 - closed}` + if (!chat) return const open = chatOpenWidth() @@ -424,7 +435,13 @@ function SessionScreenContent(props: { onPointerDown={hideTimelineScrollbar} onClick={hideTimelineScrollbar} > - + { + sideGlyph = fill + paintSideGlyph() + }} + />
diff --git a/packages/app/src/shell/panel-motion.ts b/packages/app/src/shell/panel-motion.ts index ff26ce949e5..da3df6cd66d 100644 --- a/packages/app/src/shell/panel-motion.ts +++ b/packages/app/src/shell/panel-motion.ts @@ -46,6 +46,8 @@ export function createPanelMotion(input: { /** A change shows the new state without motion, e.g. switching to another session's layout. */ identity?: Accessor onClosed?: () => void + /** Reads layout in the frame loop's read phase, before each frame of a flight paints. */ + measure?: () => void }) { const [present, setPresent] = createSignal(input.open()) // Percent closed, so the spring's rest threshold stays well under a pixel. @@ -118,7 +120,7 @@ export function createPanelMotion(input: { motion.set(target) fly(true) // Writes only; anything reading layout this frame does so in the loop's read phase, before this runs. - stop ??= frameLoop.add((dt) => { + const step = (dt: number) => { motion.step(dt) paint() @@ -127,7 +129,8 @@ export function createPanelMotion(input: { settle() return false - }) + } + stop ??= input.measure ? frameLoop.addMeasured(input.measure, step) : frameLoop.add(step) }, ), ) diff --git a/packages/app/src/shell/shell.tsx b/packages/app/src/shell/shell.tsx index 871cb01ebbf..5628933fe8b 100644 --- a/packages/app/src/shell/shell.tsx +++ b/packages/app/src/shell/shell.tsx @@ -13,7 +13,7 @@ import { ExtensionServerCover } from "@/runtime/extension/server-shell" import { ExtensionSlot } from "@/runtime/extension/render" import { useCommand } from "@/shell/commands/command" import { useLanguage } from "@/runtime/i18n/language" -import { CollapsedSidebarToggle, paintCollapsedSlots } from "@/shell/sidebar-toggle" +import { CollapsedSidebarToggle, measureSidebarToggles, paintCollapsedSlots } from "@/shell/sidebar-toggle" import { createPanelMotion, guardClosingFocus, replayPanelToggle } from "@/shell/panel-motion" import { windowDragEnabled } from "@/session/header/drag-area" @@ -46,8 +46,12 @@ export default function Layout(props: ParentProps) { const aside = state.tabsAside if (aside) aside.style.width = `${state.tabsWidth * (1 - closed)}px` + + // Dims the contents, background included, as they leave and fade them in as they arrive. + if (state.tabsMount) state.tabsMount.style.opacity = closed === 0 ? "" : `${1 - closed}` paintCollapsedSlots(closed) }, + measure: () => measureSidebarToggles(state.tabsWidth), }) replayPanelToggle({ id: "sidebar", label: "Toggle the left sidebar", toggle: toggleSidebar }) @@ -124,7 +128,7 @@ export default function Layout(props: ParentProps) { >
setState("tabsMount", element)} - class="absolute inset-y-0 end-0 contain-strict flex min-h-0 flex-col bg-v2-background-bg-deep pe-0.5 ps-2.5 pb-[var(--shell-bottom-inset,8px)] pt-[var(--shell-top-inset,8px)]" + class="absolute inset-y-0 end-0 contain-strict will-change-[opacity] flex min-h-0 flex-col bg-v2-background-bg-deep pe-0.5 ps-2.5 pb-[var(--shell-bottom-inset,8px)] pt-[var(--shell-top-inset,8px)]" style={{ width: `${state.tabsWidth}px`, "padding-bottom": "max(10px, var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)))", @@ -165,8 +169,8 @@ export default function Layout(props: ParentProps) { {props.children} - +
diff --git a/packages/app/src/shell/sidebar-toggle.tsx b/packages/app/src/shell/sidebar-toggle.tsx index 37d6fa15b9e..8a0bd50ccdd 100644 --- a/packages/app/src/shell/sidebar-toggle.tsx +++ b/packages/app/src/shell/sidebar-toggle.tsx @@ -33,9 +33,9 @@ const slotWidth = 32 const contentStart = 18 /** - * `handoff` makes this one of the two vertical-tabs toggles, each shown only on its side of the motion: "out" rides - * the sidebar's header and fades as it passes the collapsed slot, then the "in" toggle fades up. Each keeps its own - * icon, so neither flips mid-flight. + * `handoff` makes this one of the two vertical-tabs toggles that read as one icon: "out" sits in the sidebar's header + * and shows only while the sidebar rests open; "in" shows otherwise, travelling from the header's spot to the + * collapsed one on the sidebar's spring as its glyph turns from the open one to the closed one. */ export function SidebarToggle(props: { handoff?: "out" | "in" }) { const command = useCommand() @@ -43,7 +43,28 @@ export function SidebarToggle(props: { handoff?: "out" | "in" }) { const settings = useSettings() const keybind = () => command.keybindParts("sidebar.toggle") const side = props.handoff - const ref = side && collapsedRef((button, closed) => (button.style.opacity = `${handoff(side, closed)}`)) + let full: SVGSVGElement | undefined + let outline: SVGSVGElement | undefined + const ref = + side === "out" + ? collapsedRef((button, closed) => { + travel.header = button + button.style.opacity = closed === 0 ? "" : "0" + }) + : side === "in" + ? collapsedRef((button, closed) => { + travel.toggle = button + const moving = closed > 0 && closed < 1 + travel.dx = moving ? travel.x * (1 - closed) : 0 + travel.dy = moving ? travel.y * (1 - closed) : 0 + button.style.opacity = closed === 0 ? "0" : "" + button.style.transform = moving ? `translate3d(${travel.dx}px, ${travel.dy}px, 0)` : "" + + if (full) full.style.opacity = `${1 - closed}` + + if (outline) outline.style.opacity = `${closed}` + }) + : undefined return ( + side === "in" ? ( + + + + + ) : ( + + ) } /> @@ -105,7 +133,7 @@ function useCollapsedSlot() { const slotClass = "flex shrink-0 justify-end overflow-hidden" // How far closed the left sidebar is, from 0 to 1. The shell paints it on every frame of the sidebar's motion; the -// collapsed toggle and the space headers keep for it grow with it, so header contents travel with the sidebar's edge. +// space headers keep for the collapsed toggle grows with it, so header contents travel with the sidebar's edge. const collapsed = { closed: 0, slots: new Set<() => void>() } export function paintCollapsedSlots(closed: number) { @@ -113,6 +141,28 @@ export function paintCollapsedSlots(closed: number) { collapsed.slots.forEach((paint) => paint()) } +// The two vertical-tabs toggles, how far the header one rests from the collapsed one (x, y), and the offset the +// collapsed one is drawn at now (dx, dy). +const travel: { header?: HTMLElement; toggle?: HTMLElement; x: number; y: number; dx: number; dy: number } = { + x: 0, + y: 0, + dx: 0, + dy: 0, +} + +/** + * Measures, in the frame loop's read phase of the sidebar's motion, how far the header toggle rests from the collapsed + * one. The header toggle rides the sidebar's edge, `width × closed` from where it rests open. + */ +export function measureSidebarToggles(width: number) { + if (!travel.header?.isConnected || !travel.toggle?.isConnected) return + const header = travel.header.getBoundingClientRect() + const toggle = travel.toggle.getBoundingClientRect() + const direction = document.documentElement.dir === "rtl" ? -1 : 1 + travel.x = header.left + direction * width * collapsed.closed - (toggle.left - travel.dx) + travel.y = header.top - (toggle.top - travel.dy) +} + /** A ref whose element `paint` styles from how far closed the sidebar is, now and on every frame of its motion. */ function collapsedRef(paint: (element: HTMLElement, closed: number) => void) { let target: HTMLElement | undefined @@ -136,25 +186,16 @@ function slotRef(width: () => number) { return collapsedRef((slot, closed) => (slot.style.width = `${width() * closed}px`)) } -// The collapsed toggle rides the content's edge, so the two never meet: the sliding one fades out as it passes the -// collapsed slot, then the collapsed one fades up, and only one shows at a time. -function handoff(side: "out" | "in", closed: number) { - if (side === "out") return 1 - Math.min(1, Math.max(0, (closed - 0.55) / 0.2)) - - return Math.min(1, Math.max(0, (closed - 0.75) / 0.25)) -} - -// Floats over the top of every screen, centered on the session header's 48px row. Appears at the content's start edge -// when the sidebar closes. +// Floats over the top of every screen, centered on the session header's 48px row, where the content starts once the +// sidebar has closed. It sits outside the sidebar and the content, so neither clips it as it travels. export function CollapsedSidebarToggle() { const slot = useCollapsedSlot() - const ref = slotRef(slot.width) return (