feat(app): fade sidebar contents and carry the toggle icon across (#57905)

This commit is contained in:
Kit Langton
2026-10-21 14:15:27 -07:00
committed by GitHub
Unverified
parent 87e87d51f5
commit 4091a02613
7 changed files with 122 additions and 32 deletions
@@ -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()
+4 -1
View File
@@ -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",
@@ -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 name={props.state.reviewOpened ? "layout-right-full" : "layout-right"} />}
icon={
props.state.reviewGlyph ? (
<svg data-slot="icon-svg" width="16" height="16" viewBox="0 0 20 20" fill="none" aria-hidden="true">
<g transform="matrix(-1 0 0 1 20 0)">
<path ref={props.state.reviewGlyph} d="M2.917 2.916H7.917V17.083H2.917Z" fill="currentColor" />
<path
d="M2.917 2.916H17.084V17.083H2.917ZM7.917 2.916V17.083"
stroke="currentColor"
stroke-linecap="square"
/>
</g>
</svg>
) : (
<Icon name={props.state.reviewOpened ? "layout-right-full" : "layout-right"} />
)
}
/>
</Tooltip>
</Show>
+21 -3
View File
@@ -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}
>
<SessionReviewToggle onToggle={region.toggle} />
<SessionReviewToggle
onToggle={region.toggle}
glyph={(fill) => {
sideGlyph = fill
paintSideGlyph()
}}
/>
</div>
</Show>
<div
@@ -474,8 +491,9 @@ function SessionScreenContent(props: {
}}
>
<div
ref={sideContent}
data-slot="session-side-panel-content"
class="absolute inset-y-0 start-0 size-full [contain:layout_style]"
class="absolute inset-y-0 start-0 size-full [contain:layout_style] will-change-[opacity]"
style={{ "--session-side-content-width": screen.side.contentWidth() }}
>
<div data-slot="session-side-region" class="absolute inset-0 min-h-0 overflow-visible">
+5 -2
View File
@@ -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<unknown>
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)
},
),
)
+7 -3
View File
@@ -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) {
>
<div
ref={(element) => 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) {
<ExtensionServerCover>
<Suspense>{props.children}</Suspense>
</ExtensionServerCover>
<CollapsedSidebarToggle />
</main>
<CollapsedSidebarToggle />
</div>
<ExtensionSlot at="window.bottom" input={{}} />
<ToastRegion />
+61 -20
View File
@@ -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 (
<Tooltip
@@ -70,9 +91,16 @@ export function SidebarToggle(props: { handoff?: "out" | "in" }) {
aria-expanded={settings.appearance.sidebarOpen()}
aria-controls="vertical-tabs-sidebar"
icon={
<Icon
name={side === "out" || (!side && settings.appearance.sidebarOpen()) ? "layout-left-full" : "layout-left"}
/>
side === "in" ? (
<span class="relative flex">
<Icon ref={full} name="layout-left-full" />
<Icon ref={outline} name="layout-left" class="absolute inset-0" />
</span>
) : (
<Icon
name={side === "out" || (!side && settings.appearance.sidebarOpen()) ? "layout-left-full" : "layout-left"}
/>
)
}
/>
</Tooltip>
@@ -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 (
<Show when={slot.visible()}>
<div
ref={ref}
data-slot="collapsed-sidebar-toggle"
style={{ width: `${slot.width()}px` }}
class={`absolute top-[calc(var(--shell-top-inset,8px)+10px)] start-[calc(var(--shell-inline-inset,8px)+10px)] z-40 flex shrink-0 justify-end`}
inert={slot.open()}
>