Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog.d/280.md
Original file line number Diff line number Diff line change
@@ -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.
81 changes: 80 additions & 1 deletion packages/host/inspector/browser/fixtures.spec.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)
Comment thread
agorischek marked this conversation as resolved.
Resolved
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)
})
7 changes: 3 additions & 4 deletions packages/host/inspector/src/fixtures/workbench/body.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,10 @@ export function WorkbenchBody({
<LoadingStatus className="ph-computing" label="Computing the comparison in this browser…" />
)}
{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.
<div
className={cn(
'pi-viewport pj:mx-auto pj:flex pj:min-h-0 pj:w-full pj:min-w-0 pj:flex-1 pj:flex-col',
width && 'pj:my-2 pj:overflow-hidden pj:rounded-lg pj:border pj:border-dashed',
)}
className="pi-view pi-viewport pi-card pj:mx-auto pj:my-[var(--pi-gutter)] pj:flex pj:min-h-0 pj:w-[calc(100%-2*var(--pi-gutter))] pj:min-w-0 pj:flex-1 pj:flex-col"
Comment thread
agorischek marked this conversation as resolved.
Resolved
data-viewport={viewport}
style={width ? {maxWidth: `${width + 2}px`} : undefined}
>
Expand Down
10 changes: 10 additions & 0 deletions packages/host/inspector/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading