Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

get lock utility working

Sultane98ab8f2f48a
diff --git a/apps/designer/app/designer/features/style-panel/controls/combobox-control.tsx b/apps/designer/app/designer/features/style-panel/controls/combobox-control.tsx
index 28f9e6470b..bf72d836cc 100644
--- a/apps/designer/app/designer/features/style-panel/controls/combobox-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/combobox-control.tsx
@@ -1,4 +1,4 @@
-import { KeyboardEvent } from "react";
+import { ChangeEvent } from "react";
import type { StyleValue } from "@webstudio-is/react-sdk";
import {
Flex,
@@ -98,15 +98,9 @@ export const ComboboxControl = ({
</Tooltip>
<TextField
type="number"
- // @todo as above fit into that as a better abstraction
- // was returning value with unit i.e 0px instead of 0, so we first stringify to satisfy the typechecker
- // then parseFloat for the value
- defaultValue={parseFloat(String(value.value)) || 0}
- // @todo looses input state and focus
- // onChange={(event: ChangeEvent<HTMLInputElement>) => setValue(event.target.value + "px")
- onKeyDown={(event: KeyboardEvent<HTMLInputElement>) =>
- event.key === "Enter" &&
- setValue(event.currentTarget.value + "px")
+ value={value.value}
+ onChange={(event: ChangeEvent<HTMLInputElement>) =>
+ setValue(event.target.value + "px")
}
css={{
fontWeight: "500",
diff --git a/apps/designer/app/designer/features/style-panel/controls/lock-utility.tsx b/apps/designer/app/designer/features/style-panel/controls/lock-utility.tsx
index 23eafa6a80..9ee6a822bb 100644
--- a/apps/designer/app/designer/features/style-panel/controls/lock-utility.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/lock-utility.tsx
@@ -1,18 +1,41 @@
+import { useState, useEffect } from "react";
import { IconButton } from "@webstudio-is/design-system";
-import { LockOpenIcon } from "@webstudio-is/icons";
+import { LockOpenIcon, LockCloseIcon } from "@webstudio-is/icons";
import type { Style } from "@webstudio-is/react-sdk";
import type { CreateBatchUpdate } from "../shared/use-style-data";
export const LockUtility = ({
name,
+ pairedKeys,
+ currentStyle,
+ batchUpdate,
}: {
name: string;
+ pairedKeys: Array<keyof Style>;
currentStyle: Style;
batchUpdate: ReturnType<CreateBatchUpdate>;
}) => {
+ const aKey = pairedKeys[0];
+ const bKey = pairedKeys[1];
+ const aVal = currentStyle[aKey]?.value;
+ const bVal = currentStyle[bKey]?.value;
+ const [isPaired, setIsPaired] = useState(aVal === bVal);
+
+ useEffect(() => {
+ if (!isPaired) return;
+ if (aVal === bVal) return;
+ batchUpdate.setProperty(aKey)(String(aVal));
+ batchUpdate.setProperty(bKey)(String(aVal));
+ batchUpdate.publish();
+ }, [batchUpdate, isPaired, aKey, bKey, aVal, bVal]);
+
return (
- <IconButton data-property={name} css={{ width: "100%", gridArea: name }}>
- <LockOpenIcon />
+ <IconButton
+ data-property={name}
+ css={{ width: "100%", gridArea: name }}
+ onClick={() => setIsPaired((value) => !value)}
+ >
+ {isPaired ? <LockCloseIcon /> : <LockOpenIcon />}
</IconButton>
);
};
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout.tsx b/apps/designer/app/designer/features/style-panel/sections/layout.tsx
index 1cc582e296..3c5005b078 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout.tsx
@@ -42,6 +42,7 @@ const LayoutSectionFlex = ({
{styleConfigsByCategory}
<LockUtility
name="lock"
+ pairedKeys={["columnGap", "rowGap"]}
currentStyle={{
columnGap: currentStyle.columnGap,
rowGap: currentStyle.rowGap,