diff --git a/frontend/playwright/ui/visual-specs/workspace.spec.js b/frontend/playwright/ui/visual-specs/workspace.spec.js index 7aef87e747..5c5e41c42e 100644 --- a/frontend/playwright/ui/visual-specs/workspace.spec.js +++ b/frontend/playwright/ui/visual-specs/workspace.spec.js @@ -368,6 +368,50 @@ test.describe("Design tab", () => { }); }); +test.describe("Measures controls", () => { + test("Shows the clip content, show in view mode and ratio lock toggles", async ({ + page, + }) => { + const workspace = new WorkspacePage(page); + await workspace.setupEmptyFile(); + await workspace.mockRPC(/get\-file\?/, "workspace/get-file-9066.json"); + await workspace.goToWorkspace({ + fileId: "e179d9df-de35-80bf-8005-283bbd5516b0", + pageId: "e179d9df-de35-80bf-8005-283bbd5516b1", + }); + await workspace.clickLeafLayer("Board"); + + const sidebar = workspace.rightSidebar; + const toggles = sidebar.locator("[class*='menus_measures__clip-show']"); + // A label over a hidden checkbox before, a button after. + const clip = sidebar + .getByTitle("Clip content") + .or(sidebar.getByRole("button", { name: "Clip content" })); + const shot = { maxDiffPixelRatio: 0, threshold: 0 }; + + await expect(toggles).toBeVisible(); + await page.mouse.move(0, 0); + await expect(toggles).toHaveScreenshot("measures-toggles-rest.png", shot); + + await clip.hover(); + await expect(toggles).toHaveScreenshot("measures-toggles-hover.png", shot); + + // Both start on: one click turns clip content off. + await clip.click(); + await page.mouse.move(0, 0); + await expect(toggles).toHaveScreenshot("measures-toggles-off.png", shot); + + const lock = sidebar.getByRole("button", { name: /^(Lock|Unlock) ratio$/ }); + await expect(lock).toHaveScreenshot("measures-lock-off.png", shot); + await lock.click(); + await page.mouse.move(0, 0); + await expect( + sidebar.getByRole("button", { name: "Unlock ratio" }), + ).toBeVisible(); + await expect(lock).toHaveScreenshot("measures-lock-on.png", shot); + }); +}); + test.describe("Component options", () => { test("Shows the component pill of a copy", async ({ page }) => { const workspace = new WorkspacePage(page); diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs index 3f56fbbc23..aa412ef7e2 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.cljs @@ -28,7 +28,7 @@ [app.main.ui.components.radio-buttons :refer [radio-button radio-buttons]] [app.main.ui.components.search-bar :refer [search-bar*]] [app.main.ui.ds.buttons.icon-button :refer [icon-button*]] - [app.main.ui.ds.foundations.assets.icon :refer [icon*] :as i] + [app.main.ui.ds.foundations.assets.icon :as i] [app.main.ui.icons :as deprecated-icon] [app.main.ui.workspace.sidebar.options.menus.border-radius :refer [border-radius-menu*]] [app.main.ui.workspace.sidebar.options.menus.input-wrapper-tokens :refer [numeric-input-wrapper*]] @@ -322,11 +322,11 @@ proportion-lock (get values :proportion-lock) - clip-content-ref - (mf/use-ref nil) + clip-content? + (not (:show-content values)) - show-in-viewer-ref - (mf/use-ref nil) + show-in-viewer? + (not (:hide-in-viewer values)) ;; PRESETS preset-state* @@ -460,16 +460,16 @@ ;; CLIP CONTENT AND SHOW IN VIEWER on-change-clip-content (mf/use-fn - (mf/deps ids) - (fn [event] - (let [value (-> event dom/get-target dom/checked?)] + (mf/deps ids clip-content?) + (fn [] + (let [value (not clip-content?)] (st/emit! (dwsh/update-shapes ids (fn [shape] (assoc shape :show-content (not value)))))))) on-change-show-in-viewer (mf/use-fn - (mf/deps ids) - (fn [event] - (let [value (-> event dom/get-target dom/checked?) + (mf/deps ids show-in-viewer?) + (fn [] + (let [value (not show-in-viewer?) undo-id (js/Symbol)] (st/emit! (dwu/start-undo-transaction undo-id) (dwsh/update-shapes ids (fn [shape] (cls/change-show-in-viewer shape (not value))))) @@ -610,7 +610,7 @@ [:> icon-button* {:variant "ghost" :tooltip-placement "top-left" :icon (if proportion-lock "lock" "unlock") - :class (stl/css-case :selected (true? proportion-lock)) + :aria-pressed (true? proportion-lock) :disabled (= proportion-lock :multiple) :aria-label (if proportion-lock (tr "workspace.options.size.unlock") (tr "workspace.options.size.lock")) :on-click on-proportion-lock-change}]]) @@ -708,31 +708,14 @@ (when (or (options :clip-content) (options :show-in-viewer)) [:div {:class (stl/css :clip-show)} (when (options :clip-content) - [:div {:class (stl/css :clip-content)} - [:input {:type "checkbox" - :id "clip-content" - :ref clip-content-ref - :class (stl/css :clip-content-input) - :checked (not (:show-content values)) - :on-change on-change-clip-content}] - - [:label {:for "clip-content" - :title (tr "workspace.options.clip-content") - :class (stl/css-case :clip-content-label true - :selected (not (:show-content values)))} - - [:> icon* {:icon-id i/clip-content}]]]) + [:> icon-button* {:variant "ghost" + :aria-label (tr "workspace.options.clip-content") + :aria-pressed (boolean clip-content?) + :on-click on-change-clip-content + :icon i/clip-content}]) (when (options :show-in-viewer) - [:div {:class (stl/css :show-in-viewer)} - [:input {:type "checkbox" - :id "show-in-viewer" - :ref show-in-viewer-ref - :class (stl/css :clip-content-input) - :checked (not (:hide-in-viewer values)) - :on-change on-change-show-in-viewer}] - - [:label {:for "show-in-viewer" - :title (tr "workspace.options.show-in-viewer") - :class (stl/css-case :clip-content-label true - :selected (not (:hide-in-viewer values)))} - [:> icon* {:icon-id i/play}]]])])])) + [:> icon-button* {:variant "ghost" + :aria-label (tr "workspace.options.show-in-viewer") + :aria-pressed (boolean show-in-viewer?) + :on-click on-change-show-in-viewer + :icon i/play}])])])) diff --git a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.scss b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.scss index 8fa48d1bb0..3d2ea6481a 100644 --- a/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.scss +++ b/frontend/src/app/main/ui/workspace/sidebar/options/menus/measures.scss @@ -4,6 +4,9 @@ // // Copyright (c) KALEIDOS SUBSIDIARY SL +// Only for the presets dropdown (%asset-element, %dropdown-*) and the +// inputs (%input-element, %disabled-input): they move to the DS with the +// selects and inputs groups. @use "refactor/common-refactor.scss" as deprecated; @use "../../../sidebar/common/sidebar.scss" as sidebar; @use "ds/_utils.scss" as *; @@ -182,55 +185,9 @@ grid-column: 2/-1; } -.lock-size-btn { - @extend %button-tertiary; - - border-radius: deprecated.$br-8; - height: deprecated.$s-32; - width: deprecated.$s-28; - - &.selected { - @extend %button-icon-selected; - } -} - -.lock-ratio-icon { - @extend %button-icon; - - stroke: var(--icon-foreground); -} - .clip-show { display: flex; align-items: flex-start; justify-content: flex-start; - gap: deprecated.$s-4; -} - -.clip-content, -.show-in-viewer { - .clip-content-input { - display: none; - } -} - -.clip-content-label { - @extend %button-tertiary; - - height: var(--sp-xxxl); - width: var(--sp-xxxl); - border-radius: deprecated.$br-8; -} - -.selected { - @extend %button-icon-selected; -} - -.checkbox-button { - @extend %button-icon; -} - -// TODO: Add a proper variable to this sizing -.numeric-input-measures { - --dropdown-width: var(--seven-columns-width); + gap: var(--sp-xs); }