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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
Fix linked flex gap and replace icons (#737)
Bogdan Chadkinf076352b29d0
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsxindex 676cc35dd5..cd88de654b 100644--- a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx+++ b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx@@ -1,13 +1,239 @@-import { Box, Flex, Grid } from "@webstudio-is/design-system";+import { useState } from "react";+import {+ Box,+ DeprecatedIconButton,+ EnhancedTooltip,+ Flex,+ Grid,+ Tooltip,+} from "@webstudio-is/design-system";+import type { StyleProperty, StyleValue } from "@webstudio-is/css-data";import { toValue } from "@webstudio-is/css-engine";+import {+ ColumnGapIcon,+ RowGapIcon,+ LinkedIcon,+ UnlinkedIcon,+} from "@webstudio-is/icons";import type { RenderCategoryProps } from "../../style-sections";import { FlexGrid } from "./shared/flex-grid";-import { Lock } from "./shared/lock";import { renderProperty } from "../../style-sections";-import { MenuControl, SelectControl, TextControl } from "../../controls";+import { MenuControl, SelectControl } from "../../controls";import { PropertyName } from "../../shared/property-name";-import { ColumnGapIcon, RowGapIcon } from "@webstudio-is/icons";import { styleConfigByName } from "../../shared/configs";+import type { CreateBatchUpdate } from "../../shared/use-style-data";+import { getStyleSource, type StyleInfo } from "../../shared/style-info";+import {+ type IntermediateStyleValue,+ CssValueInput,+} from "../../shared/css-value-input";++const GapLinked = ({+ isLinked,+ onChange,+}: {+ isLinked: boolean;+ onChange: (isLinked: boolean) => void;+}) => {+ return (+ <Tooltip+ content={isLinked ? "Unlink gap values" : "Link gap values"}+ delayDuration={400}+ disableHoverableContent={true}+ >+ <Flex+ css={{+ width: "100%",+ justifyContent: "center",+ }}+ >+ <DeprecatedIconButton onClick={() => onChange(isLinked === false)}>+ {isLinked ? <LinkedIcon /> : <UnlinkedIcon />}+ </DeprecatedIconButton>+ </Flex>+ </Tooltip>+ );+};++const GapInput = ({+ icon,+ style,+ property,+ intermediateValue,+ onIntermediateChange,+ onPreviewChange,+ onChange,+}: {+ icon: JSX.Element;+ style: StyleInfo;+ property: StyleProperty;+ intermediateValue?: StyleValue | IntermediateStyleValue;+ onIntermediateChange: (value?: StyleValue | IntermediateStyleValue) => void;+ onPreviewChange: (value?: StyleValue) => void;+ onChange: (value: StyleValue) => void;+}) => {+ const { label, items } = styleConfigByName[property];+ return (+ <EnhancedTooltip content={label}>+ <Box>+ <CssValueInput+ styleSource={getStyleSource(style[property])}+ icon={icon}+ property="columnGap"+ value={style[property]?.value}+ intermediateValue={intermediateValue}+ keywords={items.map((item) => ({+ type: "keyword",+ value: item.name,+ }))}+ onChange={(styleValue) => {+ onIntermediateChange(styleValue);+ if (styleValue === undefined) {+ onPreviewChange();+ return;+ }+ if (styleValue.type !== "intermediate") {+ onPreviewChange(styleValue);+ }+ }}+ onHighlight={(styleValue) => {+ if (styleValue !== undefined) {+ onPreviewChange(styleValue);+ } else {+ onPreviewChange();+ }+ }}+ onChangeComplete={({ value }) => {+ onChange(value);+ onIntermediateChange(undefined);+ }}+ onAbort={() => {+ onPreviewChange();+ }}+ />+ </Box>+ </EnhancedTooltip>+ );+};++const FlexGap = ({+ style,+ createBatchUpdate,+}: {+ style: StyleInfo;+ createBatchUpdate: CreateBatchUpdate;+}) => {+ const batchUpdate = createBatchUpdate();++ const [isLinked, setIsLinked] = useState(() => {+ return toValue(style.columnGap?.value) === toValue(style.rowGap?.value);+ });++ const [intermediateColumnGap, setIntermediateColumnGap] = useState<+ StyleValue | IntermediateStyleValue+ >();+ const [intermediateRowGap, setIntermediateRowGap] = useState<+ StyleValue | IntermediateStyleValue+ >();++ return (+ <Grid+ css={{+ gridTemplateColumns: "4fr 1fr 4fr",+ gridTemplateRows: "auto",+ gridTemplateAreas: `+ "columnGap linked rowGap"+ `,+ alignItems: "center",+ }}+ >+ <Box css={{ gridArea: "columnGap" }}>+ <GapInput+ icon={<ColumnGapIcon />}+ style={style}+ property="columnGap"+ intermediateValue={intermediateColumnGap}+ onIntermediateChange={(value) => {+ setIntermediateColumnGap(value);+ if (isLinked) {+ setIntermediateRowGap(value);+ }+ }}+ onPreviewChange={(value) => {+ if (value === undefined) {+ batchUpdate.deleteProperty("columnGap");+ if (isLinked) {+ batchUpdate.deleteProperty("rowGap");+ }+ } else {+ batchUpdate.setProperty("columnGap")(value);+ if (isLinked) {+ batchUpdate.setProperty("rowGap")(value);+ }+ }+ batchUpdate.publish({ isEphemeral: true });+ }}+ onChange={(value) => {+ batchUpdate.setProperty("columnGap")(value);+ if (isLinked) {+ batchUpdate.setProperty("rowGap")(value);+ }+ batchUpdate.publish();+ }}+ />+ </Box>++ <Box css={{ gridArea: "linked", px: "$spacing$3" }}>+ <GapLinked+ isLinked={isLinked}+ onChange={(isLinked) => {+ setIsLinked(isLinked);+ if (isLinked && style.columnGap?.value) {+ batchUpdate.setProperty("rowGap")(style.columnGap.value);+ batchUpdate.publish();+ }+ }}+ />+ </Box>++ <Box css={{ gridArea: "rowGap" }}>+ <GapInput+ icon={<RowGapIcon />}+ style={style}+ property="rowGap"+ intermediateValue={intermediateRowGap}+ onIntermediateChange={(value) => {+ setIntermediateRowGap(value);+ if (isLinked) {+ setIntermediateColumnGap(value);+ }+ }}+ onPreviewChange={(value) => {+ if (value === undefined) {+ batchUpdate.deleteProperty("rowGap");+ if (isLinked) {+ batchUpdate.deleteProperty("columnGap");+ }+ } else {+ batchUpdate.setProperty("rowGap")(value);+ if (isLinked) {+ batchUpdate.setProperty("columnGap")(value);+ }+ }+ batchUpdate.publish({ isEphemeral: true });+ }}+ onChange={(value) => {+ batchUpdate.setProperty("rowGap")(value);+ if (isLinked) {+ batchUpdate.setProperty("columnGap")(value);+ }+ batchUpdate.publish();+ }}+ />+ </Box>+ </Grid>+ );+};const LayoutSectionFlex = ({currentStyle,@@ -91,42 +317,7 @@ const LayoutSectionFlex = ({)}</Grid>- <Grid- css={{- gridTemplateColumns: "4fr 1fr 4fr",- gridTemplateRows: "auto",- gridTemplateAreas: `- "columnGap lock rowGap"- `,- alignItems: "center",- }}- >- <Box css={{ gridArea: "columnGap" }}>- <TextControl- icon={<ColumnGapIcon />}- property="columnGap"- currentStyle={currentStyle}- setProperty={setProperty}- deleteProperty={deleteProperty}- />- </Box>- <Box css={{ gridArea: "lock", px: "$spacing$3" }}>- <Lock- pairedKeys={["columnGap", "rowGap"]}- currentStyle={currentStyle}- batchUpdate={batchUpdate}- />- </Box>- <Box css={{ gridArea: "rowGap" }}>- <TextControl- icon={<RowGapIcon />}- property="rowGap"- currentStyle={currentStyle}- setProperty={setProperty}- deleteProperty={deleteProperty}- />- </Box>- </Grid>+ <FlexGap style={currentStyle} createBatchUpdate={createBatchUpdate} /></Flex>);};diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsxdeleted file mode 100644index 468196bed4..0000000000--- a/apps/designer/app/designer/features/style-panel/sections/layout/shared/lock.tsx+++ /dev/null@@ -1,62 +0,0 @@-import { useState, useEffect } from "react";-import {- Flex,- DeprecatedIconButton,- Tooltip,-} from "@webstudio-is/design-system";-import { toValue } from "@webstudio-is/css-engine";-import { LockOpenIcon, LockCloseIcon } from "@webstudio-is/icons";-import type { Style } from "@webstudio-is/css-data";-import type { CreateBatchUpdate } from "../../../shared/use-style-data";-import type { StyleInfo } from "../../../shared/style-info";--export const Lock = ({- pairedKeys,- currentStyle,- batchUpdate,-}: {- pairedKeys: Array<keyof Style>;- currentStyle: StyleInfo;- batchUpdate: ReturnType<CreateBatchUpdate>;-}) => {- const aKey = pairedKeys[0];- const bKey = pairedKeys[1];- const a = currentStyle[aKey]?.value;- const b = currentStyle[bKey]?.value;- const aVal =- toValue(a) + (a?.type === "unit" && a.unit !== "number" ? a.unit : "");- const bVal =- toValue(b) + (b?.type === "unit" && b.unit !== "number" ? b.unit : "");- const [isPaired, setIsPaired] = useState(aVal === bVal);-- useEffect(() => {- if (isPaired === false) {- return;- }- if (aVal === bVal) {- return;- }- batchUpdate.setProperty(aKey)(aVal);- batchUpdate.setProperty(bKey)(aVal);- batchUpdate.publish();- }, [aKey, bKey, aVal, bVal, isPaired, batchUpdate]);-- return (- <Tooltip- content={isPaired ? "Unlock" : "Lock"}- delayDuration={400}- disableHoverableContent={true}- >- <Flex- css={{- width: "100%",- justifyContent: "center",- }}- >- <DeprecatedIconButton onClick={() => setIsPaired((value) => !value)}>- {isPaired ? <LockCloseIcon /> : <LockOpenIcon />}- </DeprecatedIconButton>- </Flex>- </Tooltip>- );-};diff --git a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts b/apps/designer/app/designer/features/style-panel/shared/use-style-data.tsindex 710cbadaaf..c397a6dd63 100644--- a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts+++ b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts@@ -195,10 +195,10 @@ export const useStyleData = ({},{ ...prevStyle });- updates = [];return nextStyle;});}+ updates = [];};return {diff --git a/packages/icons/icons/linked.svg b/packages/icons/icons/linked.svgnew file mode 100644index 0000000000..5befb0b539--- /dev/null+++ b/packages/icons/icons/linked.svg@@ -0,0 +1,3 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M11.2233 6.08011L10.0814 6.08011C9.69485 6.08011 9.38145 5.76671 9.38145 5.38011C9.38145 4.99352 9.69485 4.68011 10.0814 4.68011L11.2233 4.68011C13.1747 4.68012 14.9233 6.0805 14.9233 8.00012C14.9233 9.91975 13.1747 11.3201 11.2233 11.3201L10.0814 11.3201C9.69485 11.3201 9.38145 11.0067 9.38145 10.6201C9.38145 10.2335 9.69485 9.92012 10.0814 9.92012L11.2233 9.92012C12.5856 9.92012 13.5233 8.97447 13.5233 8.00012C13.5233 7.02577 12.5856 6.08011 11.2233 6.08011ZM4.77565 6.08035C3.41335 6.08035 2.47565 7.026 2.47565 8.00035C2.47565 8.97471 3.41335 9.92036 4.77565 9.92036L5.91753 9.92036C6.30413 9.92036 6.61753 10.2338 6.61753 10.6204C6.61753 11.007 6.30413 11.3204 5.91753 11.3204L4.77565 11.3204C2.82425 11.3204 1.07565 9.91998 1.07565 8.00035C1.07565 6.08073 2.82425 4.68035 4.77565 4.68035L5.91753 4.68035C6.30413 4.68035 6.61753 4.99375 6.61753 5.38035C6.61753 5.76695 6.30413 6.08035 5.91753 6.08035H4.77565ZM5.23276 8.00024C5.23276 7.61364 5.54616 7.30024 5.93276 7.30024H10.0663C10.4529 7.30024 10.7663 7.61364 10.7663 8.00024C10.7663 8.38684 10.4529 8.70024 10.0663 8.70024H5.93276C5.54616 8.70024 5.23276 8.38684 5.23276 8.00024Z" fill="#11181C"/>+</svg>diff --git a/packages/icons/icons/unlinked.svg b/packages/icons/icons/unlinked.svgnew file mode 100644index 0000000000..e838b6e067--- /dev/null+++ b/packages/icons/icons/unlinked.svg@@ -0,0 +1,3 @@+<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M11.2233 6.08011L10.0814 6.08011C9.69485 6.08011 9.38145 5.76671 9.38145 5.38011C9.38145 4.99352 9.69485 4.68011 10.0814 4.68011L11.2233 4.68011C13.1747 4.68012 14.9233 6.0805 14.9233 8.00012C14.9233 9.91975 13.1747 11.3201 11.2233 11.3201L10.0814 11.3201C9.69485 11.3201 9.38145 11.0067 9.38145 10.6201C9.38145 10.2335 9.69485 9.92012 10.0814 9.92012L11.2233 9.92012C12.5856 9.92012 13.5233 8.97447 13.5233 8.00012C13.5233 7.02577 12.5856 6.08011 11.2233 6.08011ZM4.77565 6.08035C3.41335 6.08035 2.47565 7.026 2.47565 8.00035C2.47565 8.97471 3.41335 9.92036 4.77565 9.92036L5.91753 9.92036C6.30413 9.92036 6.61753 10.2338 6.61753 10.6204C6.61753 11.007 6.30413 11.3204 5.91753 11.3204L4.77565 11.3204C2.82425 11.3204 1.07565 9.91998 1.07565 8.00035C1.07565 6.08073 2.82425 4.68035 4.77565 4.68035L5.91753 4.68035C6.30413 4.68035 6.61753 4.99375 6.61753 5.38035C6.61753 5.76695 6.30413 6.08035 5.91753 6.08035H4.77565Z" fill="#11181C"/>+</svg>diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.tsindex b9cfbad7cc..ae260102ee 100644--- a/packages/icons/src/__generated__/index.ts+++ b/packages/icons/src/__generated__/index.ts@@ -1,2 +1,4 @@+export * from "./linked";export * from "./subscript";export * from "./superscript";+export * from "./unlinked";diff --git a/packages/icons/src/__generated__/linked.tsx b/packages/icons/src/__generated__/linked.tsxnew file mode 100644index 0000000000..4a6e26f192--- /dev/null+++ b/packages/icons/src/__generated__/linked.tsx@@ -0,0 +1,15 @@+// Generated from icons/linked.svg++import { forwardRef } from "react";+import { IconProps } from "../types";++// prettier-ignore+export const LinkedIcon = forwardRef<SVGSVGElement, IconProps>(+ ({ color = "currentColor", ...props }, forwardedRef) => {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill={color} {...props} ref={forwardedRef}><path fill="#11181C" fillRule="evenodd" d="M11.223 6.08h-1.142a.7.7 0 0 1 0-1.4h1.142c1.952 0 3.7 1.4 3.7 3.32s-1.748 3.32-3.7 3.32h-1.142a.7.7 0 0 1 0-1.4h1.142c1.363 0 2.3-.946 2.3-1.92s-.937-1.92-2.3-1.92Zm-6.447 0c-1.363 0-2.3.946-2.3 1.92 0 .975.937 1.92 2.3 1.92h1.142a.7.7 0 0 1 0 1.4H4.776c-1.952 0-3.7-1.4-3.7-3.32s1.748-3.32 3.7-3.32h1.142a.7.7 0 1 1 0 1.4H4.776ZM5.233 8a.7.7 0 0 1 .7-.7h4.133a.7.7 0 1 1 0 1.4H5.933a.7.7 0 0 1-.7-.7Z" clipRule="evenodd" /></svg>+ );+ }+);++LinkedIcon.displayName = "LinkedIcon";diff --git a/packages/icons/src/__generated__/unlinked.tsx b/packages/icons/src/__generated__/unlinked.tsxnew file mode 100644index 0000000000..116c72079b--- /dev/null+++ b/packages/icons/src/__generated__/unlinked.tsx@@ -0,0 +1,15 @@+// Generated from icons/unlinked.svg++import { forwardRef } from "react";+import { IconProps } from "../types";++// prettier-ignore+export const UnlinkedIcon = forwardRef<SVGSVGElement, IconProps>(+ ({ color = "currentColor", ...props }, forwardedRef) => {+ return (+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16" fill={color} {...props} ref={forwardedRef}><path fill="#11181C" fillRule="evenodd" d="M11.223 6.08h-1.142a.7.7 0 0 1 0-1.4h1.142c1.952 0 3.7 1.4 3.7 3.32s-1.748 3.32-3.7 3.32h-1.142a.7.7 0 0 1 0-1.4h1.142c1.363 0 2.3-.946 2.3-1.92s-.937-1.92-2.3-1.92Zm-6.447 0c-1.363 0-2.3.946-2.3 1.92 0 .975.937 1.92 2.3 1.92h1.142a.7.7 0 0 1 0 1.4H4.776c-1.952 0-3.7-1.4-3.7-3.32s1.748-3.32 3.7-3.32h1.142a.7.7 0 1 1 0 1.4H4.776Z" clipRule="evenodd" /></svg>+ );+ }+);++UnlinkedIcon.displayName = "UnlinkedIcon";diff --git a/packages/icons/src/index.ts b/packages/icons/src/index.tsindex 7e491bd74d..0e7b4c64f8 100644--- a/packages/icons/src/index.ts+++ b/packages/icons/src/index.ts@@ -41,8 +41,6 @@ export * from "./justify-items-space-between";export * from "./justify-items-start";export * from "./gap-row";export * from "./gap-column";-export * from "./lock-open";-export * from "./lock-close";export * from "./aspect-ratio";export * from "./cloud";export * from "./trash";diff --git a/packages/icons/src/lock-close.tsx b/packages/icons/src/lock-close.tsxdeleted file mode 100644index ebcf1fb836..0000000000--- a/packages/icons/src/lock-close.tsx+++ /dev/null@@ -1,39 +0,0 @@-import * as React from "react";-import { IconProps } from "./types";--export const LockCloseIcon = React.forwardRef<SVGSVGElement, IconProps>(- ({ color = "currentColor", ...props }, forwardedRef) => {- return (- <svg- width="8"- height="10"- viewBox="0 0 8 10"- fill="none"- xmlns="http://www.w3.org/2000/svg"- {...props}- ref={forwardedRef}- >- <g clipPath="url(#clip0_561_9202)">- <rect width="8" height="9" transform="translate(0 0.5)" fill="none" />- <path- fillRule="evenodd"- clipRule="evenodd"- d="M1.14286 4.4375V3.3125C1.14286 2.56658 1.44388 1.85121 1.97969 1.32376C2.51551 0.796316 3.24224 0.5 4 0.5C4.75776 0.5 5.48449 0.796316 6.02031 1.32376C6.55612 1.85121 6.85714 2.56658 6.85714 3.3125V4.4375C7.16025 4.4375 7.45094 4.55603 7.66527 4.767C7.87959 4.97798 8 5.26413 8 5.5625V8.375C8 8.67337 7.87959 8.95952 7.66527 9.1705C7.45094 9.38147 7.16025 9.5 6.85714 9.5H1.14286C0.839753 9.5 0.549062 9.38147 0.334735 9.1705C0.120408 8.95952 0 8.67337 0 8.375V5.5625C0 5.26413 0.120408 4.97798 0.334735 4.767C0.549062 4.55603 0.839753 4.4375 1.14286 4.4375ZM5.71429 3.3125V4.4375H2.28571V3.3125C2.28571 2.86495 2.46633 2.43572 2.78782 2.11926C3.10931 1.80279 3.54534 1.625 4 1.625C4.45466 1.625 4.89069 1.80279 5.21218 2.11926C5.53367 2.43572 5.71429 2.86495 5.71429 3.3125Z"- fill={color}- />- </g>- <defs>- <clipPath id="clip0_561_9202">- <rect- width="8"- height="9"- fill="none"- transform="translate(0 0.5)"- />- </clipPath>- </defs>- </svg>- );- }-);-LockCloseIcon.displayName = "LockCloseIcon";diff --git a/packages/icons/src/lock-open.tsx b/packages/icons/src/lock-open.tsxdeleted file mode 100644index c248c1e941..0000000000--- a/packages/icons/src/lock-open.tsx+++ /dev/null@@ -1,37 +0,0 @@-import * as React from "react";-import { IconProps } from "./types";--export const LockOpenIcon = React.forwardRef<SVGSVGElement, IconProps>(- ({ color = "currentColor", ...props }, forwardedRef) => {- return (- <svg- width="8"- height="10"- viewBox="0 0 8 10"- fill="none"- xmlns="http://www.w3.org/2000/svg"- {...props}- ref={forwardedRef}- >- <g clipPath="url(#clip0_561_9202)">- <rect width="8" height="9" transform="translate(0 0.5)" fill="none" />- <path- d="M4 0.5C3.24224 0.5 2.51551 0.80102 1.97969 1.33684C1.44388 1.87266 1.14286 2.59938 1.14286 3.35714V4.5C0.839753 4.5 0.549062 4.62041 0.334735 4.83474C0.120408 5.04906 0 5.33975 0 5.64286V8.5C0 8.8031 0.120408 9.09379 0.334735 9.30812C0.549062 9.52245 0.839753 9.64286 1.14286 9.64286H6.85714C7.16025 9.64286 7.45094 9.52245 7.66527 9.30812C7.87959 9.09379 8 8.8031 8 8.5V5.64286C8 5.33975 7.87959 5.04906 7.66527 4.83474C7.45094 4.62041 7.16025 4.5 6.85714 4.5H2.28571V3.35714C2.28557 2.9398 2.43768 2.53673 2.71352 2.22353C2.98936 1.91034 3.36998 1.70852 3.784 1.65594C4.19802 1.60335 4.61701 1.70361 4.96239 1.9379C5.30776 2.1722 5.5558 2.52444 5.66 2.92857C5.69789 3.07535 5.79253 3.20107 5.92311 3.27806C5.98777 3.31619 6.0593 3.3412 6.13362 3.35168C6.20795 3.36216 6.28361 3.3579 6.35629 3.33914C6.42896 3.32038 6.49723 3.28749 6.5572 3.24235C6.61717 3.1972 6.66765 3.14069 6.70578 3.07603C6.7439 3.01138 6.76892 2.93984 6.7794 2.86552C6.78988 2.7912 6.78562 2.71553 6.76686 2.64286C6.60831 2.02958 6.25053 1.48634 5.74972 1.09848C5.24891 0.710614 4.63344 0.500099 4 0.5V0.5Z"- fill={color}- />- </g>- <defs>- <clipPath id="clip0_561_9202">- <rect- width="8"- height="9"- fill="none"- transform="translate(0 0.5)"- />- </clipPath>- </defs>- </svg>- );- }-);-LockOpenIcon.displayName = "LockOpenIcon";