mirror of
https://github.com/penpot/penpot.git
synced 2026-11-29 06:30:33 +00:00
♻️ Use the DS select for the constraints selects (#13308)
* ♻️ Use the DS select for the constraints selects The horizontal and vertical selects of the Constraints section (Design tab) move from the legacy select to the DS select*. Mixed values get their own "multiple" id, so the select shows "Mixed" as before and picking it changes nothing. The unused cuerdas require goes away. A zero-tolerance visual test captures the selects closed, on hover, open, with an option on hover, after changing the horizontal one, and mixed (closed and open) with two shapes selected. AI-assisted-by: claude-opus-5-5 * ♻️ Move the constraints select styles to the DS The column of the two selects takes the DS spacing token and its width px2rem(124); the padding: 0 did nothing on a plain div and goes away. refactor/ stays for the constraints widget (raw buttons) and the "Fix when scrolling" checkbox, which moves with the checkboxes group; a comment above the @use says so. AI-assisted-by: claude-opus-5-5
This commit is contained in:
parent
a767474773
commit
f29187aaec
@ -1584,6 +1584,81 @@ test.describe("Font variant select", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Constraints selects", () => {
|
||||
test("Shows the constraint selects closed, open, changed and mixed", async ({
|
||||
page,
|
||||
}) => {
|
||||
const shot = { maxDiffPixelRatio: 0, threshold: 0 };
|
||||
const workspace = new WorkspacePage(page);
|
||||
await workspace.setupEmptyFile();
|
||||
await workspace.mockRPC(
|
||||
/get\-file\?/,
|
||||
"design/get-file-multiple-constraints.json",
|
||||
);
|
||||
await workspace.mockRPC(
|
||||
"get-file-object-thumbnails?file-id=*",
|
||||
"design/get-file-object-thumbnails-multiple-constraints.json",
|
||||
);
|
||||
await workspace.mockRPC(
|
||||
"get-file-fragment?file-id=*",
|
||||
"design/get-file-fragment-multiple-constraints.json",
|
||||
);
|
||||
await workspace.mockRPC(
|
||||
"update-file?id=*",
|
||||
"workspace/update-file-empty.json",
|
||||
);
|
||||
await workspace.goToWorkspace({
|
||||
fileId: "03bff843-920f-81a1-8004-756365e1eb6a",
|
||||
pageId: "03bff843-920f-81a1-8004-756365e1eb6b",
|
||||
});
|
||||
await workspace.clickToggableLayer("Board");
|
||||
await workspace.clickLeafLayer("Ellipse");
|
||||
|
||||
const hSelect = page.getByTestId("constraint-h-select");
|
||||
const vSelect = page.getByTestId("constraint-v-select");
|
||||
await expect(hSelect).toBeVisible();
|
||||
const sidebarBox = await workspace.rightSidebar.boundingBox();
|
||||
const hBox = await hSelect.boundingBox();
|
||||
// The two selects, with room below them for an open list.
|
||||
const clip = {
|
||||
x: Math.floor(sidebarBox.x),
|
||||
y: Math.floor(hBox.y) - 8,
|
||||
width: Math.ceil(sidebarBox.width),
|
||||
height: 240,
|
||||
};
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(page).toHaveScreenshot({ clip, ...shot });
|
||||
|
||||
await hSelect.hover();
|
||||
await expect(page).toHaveScreenshot({ clip, ...shot });
|
||||
|
||||
await hSelect.click();
|
||||
const left = hSelect.getByText("Left", { exact: true });
|
||||
await expect(left).toBeVisible();
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(page).toHaveScreenshot({ clip, ...shot });
|
||||
|
||||
await left.hover();
|
||||
await expect(page).toHaveScreenshot({ clip, ...shot });
|
||||
|
||||
await left.click();
|
||||
await expect(hSelect).toContainText("Left");
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(page).toHaveScreenshot({ clip, ...shot });
|
||||
|
||||
// Two shapes with different constraints show "Mixed".
|
||||
await workspace.clickLeafLayer("Rectangle", { modifiers: ["Shift"] });
|
||||
await expect(vSelect).toContainText("Mixed");
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(page).toHaveScreenshot({ clip, ...shot });
|
||||
|
||||
await vSelect.click();
|
||||
await expect(vSelect.getByText("Top", { exact: true })).toBeVisible();
|
||||
await page.mouse.move(0, 0);
|
||||
await expect(page).toHaveScreenshot({ clip, ...shot });
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Shortcuts panel", () => {
|
||||
const shot = { maxDiffPixelRatio: 0, threshold: 0 };
|
||||
|
||||
|
||||
@ -14,12 +14,11 @@
|
||||
[app.main.data.workspace.shapes :as dwsh]
|
||||
[app.main.refs :as refs]
|
||||
[app.main.store :as st]
|
||||
[app.main.ui.components.select :refer [select]]
|
||||
[app.main.ui.components.title-bar :refer [title-bar*]]
|
||||
[app.main.ui.ds.controls.select :refer [select*]]
|
||||
[app.main.ui.icons :as deprecated-icon]
|
||||
[app.util.dom :as dom]
|
||||
[app.util.i18n :as i18n :refer [tr]]
|
||||
[cuerdas.core :as str]
|
||||
[rumext.v2 :as mf]))
|
||||
|
||||
(def constraint-attrs [:constraints-h
|
||||
@ -136,7 +135,7 @@
|
||||
(mf/use-fn
|
||||
(mf/deps ids)
|
||||
(fn [value]
|
||||
(when-not (str/empty? value)
|
||||
(when-not (= value "multiple")
|
||||
(st/emit! (dwsh/update-shapes
|
||||
ids
|
||||
#(assoc % :constraints-h (keyword value)))))))
|
||||
@ -145,7 +144,7 @@
|
||||
(mf/use-fn
|
||||
(mf/deps ids)
|
||||
(fn [value]
|
||||
(when-not (str/empty? value)
|
||||
(when-not (= value "multiple")
|
||||
(st/emit! (dwsh/update-shapes
|
||||
ids
|
||||
#(assoc % :constraints-v (keyword value)))))))
|
||||
@ -160,23 +159,23 @@
|
||||
(mf/with-memo [constraints-h]
|
||||
(d/concat-vec
|
||||
(when (= constraints-h :multiple)
|
||||
[{:value "" :label (tr "settings.multiple")}])
|
||||
[{:value "left" :label (tr "workspace.options.constraints.left")}
|
||||
{:value "right" :label (tr "workspace.options.constraints.right")}
|
||||
{:value "leftright" :label (tr "workspace.options.constraints.leftright")}
|
||||
{:value "center" :label (tr "workspace.options.constraints.center")}
|
||||
{:value "scale" :label (tr "workspace.options.constraints.scale")}]))
|
||||
[{:id "multiple" :label (tr "settings.multiple")}])
|
||||
[{:id "left" :label (tr "workspace.options.constraints.left")}
|
||||
{:id "right" :label (tr "workspace.options.constraints.right")}
|
||||
{:id "leftright" :label (tr "workspace.options.constraints.leftright")}
|
||||
{:id "center" :label (tr "workspace.options.constraints.center")}
|
||||
{:id "scale" :label (tr "workspace.options.constraints.scale")}]))
|
||||
|
||||
options-v
|
||||
(mf/with-memo [constraints-v]
|
||||
(d/concat-vec
|
||||
(when (= constraints-v :multiple)
|
||||
[{:value "" :label (tr "settings.multiple")}])
|
||||
[{:value "top" :label (tr "workspace.options.constraints.top")}
|
||||
{:value "bottom" :label (tr "workspace.options.constraints.bottom")}
|
||||
{:value "topbottom" :label (tr "workspace.options.constraints.topbottom")}
|
||||
{:value "center" :label (tr "workspace.options.constraints.center")}
|
||||
{:value "scale" :label (tr "workspace.options.constraints.scale")}]))]
|
||||
[{:id "multiple" :label (tr "settings.multiple")}])
|
||||
[{:id "top" :label (tr "workspace.options.constraints.top")}
|
||||
{:id "bottom" :label (tr "workspace.options.constraints.bottom")}
|
||||
{:id "topbottom" :label (tr "workspace.options.constraints.topbottom")}
|
||||
{:id "center" :label (tr "workspace.options.constraints.center")}
|
||||
{:id "scale" :label (tr "workspace.options.constraints.scale")}]))]
|
||||
|
||||
|
||||
;; CONSTRAINTS
|
||||
@ -234,15 +233,13 @@
|
||||
[:span {:class (stl/css :resalted-area)}]]]]
|
||||
[:div {:class (stl/css :constraints-selects)}
|
||||
[:div {:class (stl/css :horizontal-select) :data-testid "constraint-h-select"}
|
||||
[:& select
|
||||
{:default-value (if (not= constraints-h :multiple) (d/nilv (d/name constraints-h) "scale") "")
|
||||
:options options-h
|
||||
:on-change on-constraint-h-select-changed}]]
|
||||
[:> select* {:default-selected (if (= constraints-h :multiple) "multiple" (d/nilv (d/name constraints-h) "scale"))
|
||||
:options options-h
|
||||
:on-change on-constraint-h-select-changed}]]
|
||||
[:div {:class (stl/css :vertical-select) :data-testid "constraint-v-select"}
|
||||
[:& select
|
||||
{:default-value (if (not= constraints-v :multiple) (d/nilv (d/name constraints-v) "scale") "")
|
||||
:options options-v
|
||||
:on-change on-constraint-v-select-changed}]]
|
||||
[:> select* {:default-selected (if (= constraints-v :multiple) "multiple" (d/nilv (d/name constraints-v) "scale"))
|
||||
:options options-v
|
||||
:on-change on-constraint-v-select-changed}]]
|
||||
(when first-level?
|
||||
[:div {:class (stl/css :checkbox)}
|
||||
|
||||
|
||||
@ -4,6 +4,10 @@
|
||||
//
|
||||
// Copyright (c) KALEIDOS SUBSIDIARY SL
|
||||
|
||||
@use "ds/_utils.scss" as *;
|
||||
|
||||
// Only for the constraints widget (raw buttons) and the "Fix when
|
||||
// scrolling" checkbox, which moves to the DS with the checkboxes group.
|
||||
@use "refactor/common-refactor.scss" as deprecated;
|
||||
|
||||
.element-set {
|
||||
@ -131,13 +135,12 @@
|
||||
.constraints-selects {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
gap: var(--sp-xs);
|
||||
}
|
||||
|
||||
.horizontal-select,
|
||||
.vertical-select {
|
||||
width: deprecated.$s-124;
|
||||
padding: 0;
|
||||
inline-size: px2rem(124);
|
||||
}
|
||||
|
||||
.checkbox {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user