diff --git a/changelog.d/280.md b/changelog.d/280.md new file mode 100644 index 000000000..bb08f514d --- /dev/null +++ b/changelog.d/280.md @@ -0,0 +1,5 @@ +--- +section: viewer +--- + +- **The renderer workbench shows the view as a card** (#280). In the fixtures workbench (`projections-renderer-workbench`), the Explorer sidebar and bottom panel were already rounded cards with an 8px gutter, while the view (the stage with its toolbar and the renderer) sat flush against them. Now the view is a card too, with the same radius, border and surface, spaced one gutter from its neighbours. Its toolbar sits flat inside, and the renderer frame and floating summary bar clip to its rounded corners. At the tablet or phone viewport width, the card narrows to that width, centred, with a dashed edge like the old frame. diff --git a/packages/host/inspector/browser/fixtures.spec.ts b/packages/host/inspector/browser/fixtures.spec.ts index 86e6fb568..ee133b964 100644 --- a/packages/host/inspector/browser/fixtures.spec.ts +++ b/packages/host/inspector/browser/fixtures.spec.ts @@ -1,4 +1,4 @@ -import {test as base, expect, type Page} from '@playwright/test' +import {test as base, expect, type Locator, type Page} from '@playwright/test' import {copyFile, mkdtemp, mkdir, readFile, rm, writeFile} from 'node:fs/promises' import {tmpdir} from 'node:os' import {join, resolve} from 'node:path' @@ -199,3 +199,82 @@ test('fixtures and renderer bundles reload live when their files change', async await sidebar(page) await expect(page.locator('[data-scenario="cases/platform"]')).toContainText('Unavailable', reload) }) + +test('the view is a card on the gutter, like the Explorer and the panel', async ({page, fixtures}, testInfo) => { + test.skip(testInfo.project.name !== 'chromium-desktop', 'One project covers the geometry') + const width = 1440 + await page.setViewportSize({width, height: 900}) + await page.goto(at(fixtures, 'cases/platform')) + await expect(page.locator('.ph[data-mode="comparison"][data-renderer-status="ready"]')).toBeVisible() + const gutter = await page + .locator('.pi-shell') + .evaluate(element => Number.parseFloat(getComputedStyle(element).getPropertyValue('--pi-gutter'))) + expect(gutter).toBeGreaterThan(0) + const box = async (locator: Locator) => { + const found = await locator.boundingBox() + if (!found) throw new Error('No box: the element is hidden') + return found + } + const look = (locator: Locator) => + locator.evaluate(element => { + const style = getComputedStyle(element) + return { + radius: style.borderTopLeftRadius, + border: `${style.borderTopWidth} ${style.borderTopStyle} ${style.borderTopColor}`, + surface: style.backgroundColor, + } + }) + const view = page.locator('.pi-view.pi-card') + const explorer = page.getByRole('complementary', {name: 'Explorer'}) + const panel = page.getByRole('region', {name: 'Panel'}) + const toggle = (name: RegExp) => page.locator('.pi-titlebar').getByRole('button', {name}) + if (!(await explorer.count())) await toggle(/^Show .* sidebar$/u).click() + if (!(await panel.count())) await toggle(/^Show panel$/u).click() + await expect(explorer).toBeVisible() + await expect(panel).toBeVisible() + // One radius, border and surface, and the view's own chrome flat inside; what it holds is clipped to its corners. + expect(await look(view)).toEqual(await look(explorer)) + expect(await look(view)).toEqual(await look(panel)) + await expect(view).toHaveCSS('overflow', 'hidden') + await expect(page.locator('.ph-toolbar').first()).toHaveCSS('border-top-left-radius', '0px') + // One gutter from the Explorer, the panel and the window's edge. + let card = await box(view) + const side = await box(explorer) + expect(Math.round(card.x - (side.x + side.width))).toBe(gutter) + expect(Math.round(card.y)).toBe(Math.round(side.y)) + expect(Math.round(width - (card.x + card.width))).toBe(gutter) + expect(Math.round((await box(panel)).y - (card.y + card.height))).toBe(gutter) + // The renderer's frame and the summary bar stay inside the card. + for (const inside of [view.locator('iframe').first(), view.locator('.ph-stage-foot').first()]) { + if (!(await inside.isVisible())) continue + const inner = await box(inside) + expect(inner.x).toBeGreaterThanOrEqual(card.x) + expect(inner.y).toBeGreaterThanOrEqual(card.y) + expect(inner.x + inner.width).toBeLessThanOrEqual(card.x + card.width + 0.5) + expect(inner.y + inner.height).toBeLessThanOrEqual(card.y + card.height + 0.5) + } + // A panel at its tallest leaves the view short: the view shrinks with its card, its foot (the summary bar) in view. + const handle = page.getByRole('separator', {name: 'Resize panel'}) + await handle.focus() + for (let step = 0; step < 10; step++) await handle.press('Shift+ArrowUp') + await expect.poll(async () => Math.round((await box(panel)).height)).toBe(640) + card = await box(view) + const ph = await box(view.locator('.ph').first()) + expect(ph.y + ph.height).toBeLessThanOrEqual(card.y + card.height + 0.5) + const foot = view.locator('.ph-stage-foot').first() + if (await foot.isVisible()) expect((await box(foot)).y + (await box(foot)).height).toBeLessThanOrEqual(card.y + card.height + 0.5) + // With the sidebar and panel closed, one gutter from the window's edge and the status bar. + await toggle(/^Hide .* sidebar$/u).click() + await toggle(/^Hide panel$/u).click() + await expect(explorer).toHaveCount(0) + await expect(panel).toHaveCount(0) + card = await box(view) + expect(Math.round(card.x)).toBe(gutter) + expect(Math.round((await box(page.locator('.pi-statusbar'))).y - (card.y + card.height))).toBe(gutter) + // At a device width the card is that wide (and its border), centred, with a dashed edge. + await page.getByRole('radiogroup', {name: 'Viewport'}).getByRole('radio', {name: 'Phone'}).click() + await expect(view).toHaveCSS('border-top-style', 'dashed') + card = await box(view) + expect(Math.round(card.width)).toBe(390 + 2) + expect(Math.abs(card.x + card.width / 2 - width / 2)).toBeLessThanOrEqual(1) +}) diff --git a/packages/host/inspector/src/fixtures/workbench/body.tsx b/packages/host/inspector/src/fixtures/workbench/body.tsx index 3ed1b32c6..0934ce242 100644 --- a/packages/host/inspector/src/fixtures/workbench/body.tsx +++ b/packages/host/inspector/src/fixtures/workbench/body.tsx @@ -81,11 +81,10 @@ export function WorkbenchBody({ )} {scenario && subject && ( + // The view is a card on the gutter like the Inspector's, its flat chrome inside; at a device width the card + // narrows to that width, centred, with a dashed edge.
diff --git a/packages/host/inspector/src/styles.css b/packages/host/inspector/src/styles.css index 716bf2737..2e45a3ee8 100644 --- a/packages/host/inspector/src/styles.css +++ b/packages/host/inspector/src/styles.css @@ -30,6 +30,16 @@ body { border-radius: calc(var(--pj-radius) - 2px); background-color: var(--pj-surface-canvas); } +/* The view fills its card and shrinks with it (a taller panel, a shorter window): the card clips, so a view kept at its + embedded minimum height would lose its foot, the summary bar included, with no way to scroll to it. */ +.pi-shell .pi-view.pi-card > .pj-root.ph[data-fill] { + min-height: 0; +} +/* The renderer workbench's view (only it is a `.pi-viewport`) at a tablet or phone width: the card is that wide, and + its dashed edge says so. */ +.pi-shell .pi-card.pi-viewport:not([data-viewport='desktop']) { + border-style: dashed; +} /* The title bar's three columns: each side wide enough for the wider side's content, so the centre is centred. */ .pi-shell .pi-titlebar-grid { grid-template-columns: minmax(var(--pi-side, 0px), 1fr) minmax(0, auto) minmax(var(--pi-side, 0px), 1fr);