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.

refactor layout flex section

Sultan9d5d219806a1
diff --git a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
index 7c7c434539..005ab9f19a 100644
--- a/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/text/text-control.tsx
@@ -1,4 +1,4 @@
-import { FocusEvent, PointerEvent, useCallback } from "react";
+import { FocusEvent, KeyboardEvent, PointerEvent, useCallback } from "react";
import {
Box,
Text,
@@ -83,6 +83,41 @@ export const TextControl = ({
isEphemeral,
});
};
+ const handleKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {
+ handleKeyDownEnter(event, event.target);
+ if (isExpanded(event.target)) {
+ inputProps?.onKeyDown?.(event);
+ return false;
+ }
+ if (value.type !== "unit") return true;
+ if (!["ArrowUp", "ArrowDown"].includes(event.code)) return false;
+ event.preventDefault();
+ handleKeyDownArrowUpDown(event);
+ };
+ const handleKeyDownEnter = (event: KeyboardEvent<HTMLInputElement>) => {
+ if (event.code === "Enter" && String(value.value) !== event.target.value) {
+ setValue(event.target.value);
+ const number = parseFloat(event.target.value);
+ if (!isNaN(number)) event.target.value = String(number);
+ }
+ };
+ const handleKeyDownArrowUpDown = (event: KeyboardEvent<HTMLInputElement>) => {
+ let currentValue = parseFloat(event.target.value);
+ let currentDelta = 1;
+ if (event.shiftKey) currentDelta = 10;
+ if (event.altKey) currentDelta = 0.1;
+ if (event.code === "ArrowUp") currentValue = currentValue + currentDelta;
+ if (event.code === "ArrowDown") currentValue = currentValue - currentDelta;
+ const currentValueAsString =
+ currentValue % 1
+ ? currentValue.toPrecision(
+ Math.abs(currentValue).toString().indexOf(".") + 2
+ )
+ : String(currentValue);
+ event.target.value = currentValueAsString;
+ setValue(currentValueAsString, { isEphemeral: true });
+ };
+
return (
<Combobox
name={styleConfig.property}
@@ -107,37 +142,8 @@ export const TextControl = ({
if (event.target.value !== event.target.getAttribute("value"))
setValue(event.target.value);
}}
- onKeyDown={(event) => {
- const target = event.target as HTMLInputElement;
- if (
- event.code === "Enter" &&
- String(value.value) !== target.value
- ) {
- setValue(target.value);
- const number = parseFloat(target.value);
- if (!isNaN(number)) target.value = String(number);
- }
- if (isExpanded(target)) return inputProps?.onKeyDown?.(event);
- if (value.type !== "unit")
- return inputProps?.onKeyDown?.(event);
- if (!["ArrowUp", "ArrowDown"].includes(event.code)) return;
- event.preventDefault();
- let currentValue = parseFloat(target.value);
- let currentDelta = 1;
- if (event.shiftKey) currentDelta = 10;
- if (event.altKey) currentDelta = 0.1;
- if (event.code === "ArrowUp")
- currentValue = currentValue + currentDelta;
- if (event.code === "ArrowDown")
- currentValue = currentValue - currentDelta;
- const currentValueAsString =
- currentValue % 1
- ? currentValue.toPrecision(
- Math.abs(currentValue).toString().indexOf(".") + 2
- )
- : String(currentValue);
- target.value = currentValueAsString;
- setValue(currentValueAsString, { isEphemeral: true });
+ onKeyDown={(event: KeyboardEvent<HTMLInputElement>) => {
+ if (handleKeyDown(event)) inputProps?.onKeyDown?.(event);
}}
prefix={
<PropertyIcon
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.tsx
index d674cff66f..5f578fe4a0 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,4 +1,4 @@
-import { Box, Grid } from "@webstudio-is/design-system";
+import { Box, Flex, Grid } from "@webstudio-is/design-system";
import type { RenderCategoryProps } from "../../style-sections";
import { FlexGrid } from "./shared/flex-grid";
import { Lock } from "./shared/lock";
@@ -10,12 +10,6 @@ import { PropertyName } from "../../shared/property-name";
const layoutSectionStyle = {
alignItems: "center",
gap: "$space$styleSection",
- // "& > [data-type=iconbuttonwithmenu]": {
- // display: "flex",
- // justifyContent: "center",
- // alignItems: "center",
- // height: "100%",
- // },
};
const layoutSectionFlexStyle = {
@@ -32,41 +26,6 @@ const layoutSectionFlexStyle = {
`,
};
-// @todo shouldn't need this
-const layoutSectionChildStyle = { width: "fit-content" };
-
-const flexDirectionStyle = {
- gridArea: "flexDirection",
- ...layoutSectionChildStyle,
-};
-const flexWrapStyle = { gridArea: "flexWrap", ...layoutSectionChildStyle };
-const alignItemsStyle = { gridArea: "alignItems", ...layoutSectionChildStyle };
-const justifyContentStyle = {
- gridArea: "justifyContent",
- ...layoutSectionChildStyle,
-};
-const alignContentStyle = {
- gridArea: "alignContent",
- ...layoutSectionChildStyle,
-};
-const lockStyle = { gridArea: "lock" };
-const gridStyle = { gridArea: "grid" };
-const displayStyle = {
- gridArea: "display",
- gridTemplateColumns: "auto 1fr",
- gap: "$space$2",
- width: "fit-content",
- fontWeight: "500",
-};
-const columnGapStyle = {
- gridArea: "6 / 1 / -1 / 7",
- paddingRight: "10px",
-};
-const rowGapStyle = {
- gridArea: "6 / 7 / -1 / -1",
- paddingLeft: "10px",
-};
-
const LayoutSectionFlex = ({
currentStyle,
sectionStyle,
@@ -84,49 +43,78 @@ const LayoutSectionFlex = ({
} = sectionStyle;
const batchUpdate = createBatchUpdate();
return (
- <Grid css={layoutSectionFlexStyle}>
- <Box css={gridStyle}>
- {" "}
- <FlexGrid currentStyle={currentStyle} batchUpdate={batchUpdate} />
- </Box>
- <Grid css={displayStyle}>
+ <Flex css={{ flexDirection: "column", gap: "$2" }}>
+ <Grid
+ css={{
+ gridArea: "display",
+ gridTemplateColumns: "auto 1fr",
+ gap: "$space$2",
+ width: "fit-content",
+ fontWeight: "500",
+ }}
+ >
<PropertyName
property={display.styleConfig.property}
label={display.styleConfig.label}
/>
<SelectControl {...display} />
</Grid>
- <Box css={flexDirectionStyle}>
- <MenuControl {...flexDirection} />
- </Box>
- <Box css={flexWrapStyle}>
- <MenuControl {...flexWrap} />
- </Box>
- <Box css={alignItemsStyle}>
- <MenuControl {...alignItems} />
- </Box>
- <Box css={justifyContentStyle}>
- <MenuControl {...justifyContent} />
- </Box>
- {alignContent && (
- <Box css={alignContentStyle}>
- <MenuControl {...alignContent} />
+ <Grid
+ css={{
+ gap: "$2",
+ gridTemplateColumns: "repeat(2, $6) repeat(3, $6)",
+ gridTemplateRows: "repeat(2, $6)",
+ gridTemplateAreas: `
+ "grid grid flexDirection flexWrap ."
+ "grid grid alignItems justifyContent alignContent"
+ `,
+ }}
+ >
+ <Box css={{ gridArea: "grid" }}>
+ <FlexGrid currentStyle={currentStyle} batchUpdate={batchUpdate} />
</Box>
- )}
- <Box css={columnGapStyle}>
- <TextControl {...columnGap} />
- </Box>
- <Box css={rowGapStyle}>
- <TextControl {...rowGap} />
- </Box>
- <Box css={lockStyle}>
- <Lock
- pairedKeys={["columnGap", "rowGap"]}
- currentStyle={currentStyle}
- batchUpdate={batchUpdate}
- />
- </Box>
- </Grid>
+ <Box css={{ gridArea: "flexDirection" }}>
+ <MenuControl {...flexDirection} />
+ </Box>
+ <Box css={{ gridArea: "flexWrap" }}>
+ <MenuControl {...flexWrap} />
+ </Box>
+ <Box css={{ gridArea: "alignItems" }}>
+ <MenuControl {...alignItems} />
+ </Box>
+ <Box css={{ gridArea: "justifyContent" }}>
+ <MenuControl {...justifyContent} />
+ </Box>
+ {alignContent && (
+ <Box css={{ gridArea: "alignContent" }}>
+ <MenuControl {...alignContent} />
+ </Box>
+ )}
+ </Grid>
+ <Grid
+ css={{
+ gridTemplateColumns: "4fr 1fr 4fr",
+ gridTemplateRows: "auto",
+ gridTemplateAreas: `
+ "columnGap lock rowGap"
+ `,
+ }}
+ >
+ <Box css={{ gridArea: "columnGap" }}>
+ <TextControl {...columnGap} />
+ </Box>
+ <Box css={{ gridArea: "lock", px: "$1" }}>
+ <Lock
+ pairedKeys={["columnGap", "rowGap"]}
+ currentStyle={currentStyle}
+ batchUpdate={batchUpdate}
+ />
+ </Box>
+ <Box css={{ gridArea: "rowGap" }}>
+ <TextControl {...rowGap} />
+ </Box>
+ </Grid>
+ </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.tsx
index 2cc84b6230..f1754c79cc 100644
--- 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.tsx
@@ -43,14 +43,7 @@ export const Lock = ({
justifyContent: "center",
}}
>
- <IconButton
- css={{
- "&:focus": {
- outline: "none",
- },
- }}
- onClick={() => setIsPaired((value) => !value)}
- >
+ <IconButton onClick={() => setIsPaired((value) => !value)}>
{isPaired ? <LockCloseIcon /> : <LockOpenIcon />}
</IconButton>
</Flex>
diff --git a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
index ca0549a18b..d42bc8c4cf 100644
--- a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
@@ -65,28 +65,19 @@ export const PropertyIcon = forwardRef<
variant="ghost"
size="1"
css={{
- position: "relative",
marginLeft: "calc(-$space$1 + 1px)",
width: "calc(100% - 2px)",
height: "calc(100% - 2px)",
borderRadius: "$1",
border: "2px solid $colors$loContrast",
- "&:hover,&:active,&:focus": {
- bc: "$colors$slate4",
- outline: "none",
- },
...(isCurrentBreakpoint && {
bc: "$colors$blue4",
color: "$colors$blue11",
- outline: "none",
"&:hover,&:active,&:focus": {
bc: "$colors$blue4",
color: "$colors$blue11",
},
}),
- [`& ~ ${TextField}`]: {
- paddingLeft: "calc($sizes$5 + $sizes$1)",
- },
}}
>
<IconType />
diff --git a/packages/design-system/src/components/icon-button-with-menu.tsx b/packages/design-system/src/components/icon-button-with-menu.tsx
index 7f1bcc7345..21b9ff54e2 100644
--- a/packages/design-system/src/components/icon-button-with-menu.tsx
+++ b/packages/design-system/src/components/icon-button-with-menu.tsx
@@ -55,9 +55,6 @@ const iconButtonStyle = {
outline: "none",
boxShadow: "inset 0 0 0 1px $colors$blue9, 0 0 0 1px $colors$blue9",
},
- "&:hover,&:focus": {
- backgroundColor: "$colors$gray3",
- },
};
const iconButtonActiveStyle = {
diff --git a/packages/design-system/src/components/icon-button.tsx b/packages/design-system/src/components/icon-button.tsx
index 2fb04a9a71..a2286a99d4 100644
--- a/packages/design-system/src/components/icon-button.tsx
+++ b/packages/design-system/src/components/icon-button.tsx
@@ -23,11 +23,13 @@ export const IconButton = styled("button", {
"&::before, &::after": {
boxSizing: "border-box",
},
- "&:focus, &:hover, &:active": {
+ "&:hover, &:active": {
backgroundColor: "$slate5",
+ outline: "none",
},
"&:focus": {
- outlineColor: "$blue10",
+ backgroundColor: "$slate5",
+ outline: "none",
},
"&:disabled": {
pointerEvents: "none",
@@ -40,22 +42,22 @@ export const IconButton = styled("button", {
"1": {
borderRadius: 2,
height: "$5",
- width: "$5",
+ width: "min($5, 100%)",
},
"2": {
borderRadius: "$1",
height: "$6",
- width: "$6",
+ width: "min($6, 100%)",
},
"3": {
borderRadius: "$1",
height: "$7",
- width: "$7",
+ width: "min($7, 100%)",
},
"4": {
borderRadius: "$2",
height: "$8",
- width: "$8",
+ width: "min($8, 100%)",
},
},
state: {