diff --git a/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-1.png b/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-1.png new file mode 100644 index 000000000..1434eb785 Binary files /dev/null and b/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-1.png differ diff --git a/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-2.png b/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-2.png new file mode 100644 index 000000000..94246181a Binary files /dev/null and b/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-2.png differ diff --git a/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-3.png b/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-3.png new file mode 100644 index 000000000..6c9c48895 Binary files /dev/null and b/e2e-tests/__screenshots__/darwin/viewport-menu.spec.ts/can-set-and-reset-Viewport-3.png differ diff --git a/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-1.png b/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-1.png new file mode 100644 index 000000000..51b66d44e Binary files /dev/null and b/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-1.png differ diff --git a/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-2.png b/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-2.png new file mode 100644 index 000000000..ab0b6bcd9 Binary files /dev/null and b/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-2.png differ diff --git a/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-3.png b/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-3.png new file mode 100644 index 000000000..51b66d44e Binary files /dev/null and b/e2e-tests/__screenshots__/win32/viewport-menu.spec.ts/can-set-and-reset-Viewport-3.png differ diff --git a/e2e-tests/tests/infra/StudioPlaywrightPage.ts b/e2e-tests/tests/infra/StudioPlaywrightPage.ts index 5ae63714a..882cb91e1 100644 --- a/e2e-tests/tests/infra/StudioPlaywrightPage.ts +++ b/e2e-tests/tests/infra/StudioPlaywrightPage.ts @@ -263,6 +263,18 @@ export default class StudioPlaywrightPage { return path.join(this.tmpDir, "src/components", componentName + ".tsx"); } + async openViewportMenu() { + await this.page + .getByRole("button", { name: "See Available Viewports" }) + .click(); + } + + async setViewport(viewportName: string) { + await this.page + .getByRole("button", { name: `Select ${viewportName} Viewport` }) + .click(); + } + async takePageScreenshotAfterImgRender() { await this.waitForIFrameImagesToLoad(); await expect(this.page).toHaveScreenshot(); diff --git a/e2e-tests/tests/viewport-menu.spec.ts b/e2e-tests/tests/viewport-menu.spec.ts new file mode 100644 index 000000000..9f9d9421a --- /dev/null +++ b/e2e-tests/tests/viewport-menu.spec.ts @@ -0,0 +1,13 @@ +import { studioTest } from "./infra/studioTest.js"; + +studioTest("can set and reset Viewport", async ({ studioPage }) => { + await studioPage.switchPage("LocationPage"); + await studioPage.openViewportMenu(); + await studioPage.takePageScreenshotAfterImgRender(); + await studioPage.setViewport("Galaxy Z Flip5 Folded"); + await studioPage.openViewportMenu(); + await studioPage.takePageScreenshotAfterImgRender(); + await studioPage.setViewport("Reset Viewport"); + await studioPage.openViewportMenu(); + await studioPage.takePageScreenshotAfterImgRender(); +}); diff --git a/packages/studio-ui/src/components/Viewport/ViewportButton.tsx b/packages/studio-ui/src/components/Viewport/ViewportButton.tsx index 34186364e..1840a204c 100644 --- a/packages/studio-ui/src/components/Viewport/ViewportButton.tsx +++ b/packages/studio-ui/src/components/Viewport/ViewportButton.tsx @@ -14,7 +14,7 @@ export default function ViewportButton(): JSX.Element { return (
- {isOpen && } diff --git a/packages/studio-ui/src/components/Viewport/ViewportMenu.tsx b/packages/studio-ui/src/components/Viewport/ViewportMenu.tsx index 4d084d2d5..4e1f716e2 100644 --- a/packages/studio-ui/src/components/Viewport/ViewportMenu.tsx +++ b/packages/studio-ui/src/components/Viewport/ViewportMenu.tsx @@ -1,6 +1,7 @@ import { useCallback } from "react"; import { VIEWPORTS, Viewport } from "./defaults"; import useStudioStore from "../../store/useStudioStore"; +import classNames from "classnames"; export interface ViewportMenuProps { closeMenu: () => void; @@ -9,8 +10,9 @@ export interface ViewportMenuProps { export default function ViewportMenu({ closeMenu, }: ViewportMenuProps): JSX.Element { - const [setViewport] = useStudioStore((store) => [ + const [setViewport, currentViewport] = useStudioStore((store) => [ store.pagePreview.setViewport, + store.pagePreview.viewport, ]); const handleSelect = useCallback( @@ -23,9 +25,17 @@ export default function ViewportMenu({ return (
- {Object.values(VIEWPORTS).map((val) => { + {Object.values(VIEWPORTS).map((viewport) => { return ( -
@@ -33,19 +43,27 @@ export default function ViewportMenu({ } interface OptionProps { viewport: Viewport; + isCurrentlySelected: boolean; handleSelect: (viewport) => void; } -function Option({ viewport, handleSelect }: OptionProps) { +function Option({ viewport, isCurrentlySelected, handleSelect }: OptionProps) { const onClick = useCallback( () => handleSelect(viewport), [handleSelect, viewport] ); const { name, styles } = viewport; + const className = classNames( + "flex items-center gap-x-2 px-6 py-2 cursor-pointer w-full text-left", + { + "bg-gray-300": isCurrentlySelected, + "hover:bg-gray-100": !isCurrentlySelected, + } + ); return (