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.

move property-name rendering out of controls themselves

Sultanffd4557a3837
diff --git a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx
index d81672f355..0dae39cd15 100644
--- a/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/color/color-control.tsx
@@ -12,7 +12,6 @@ import {
Tooltip,
css,
} from "@webstudio-is/design-system";
-import { PropertyName } from "../../shared/property-name";
import { getFinalValue } from "../../shared/get-final-value";
import type { ControlProps } from "../../style-sections";
import { StyleConfig } from "../../shared/configs";
@@ -139,19 +138,16 @@ export const ColorControl = ({
const setValue = setProperty(styleConfig.property);
return (
- <Grid columns={2} align="center" gapX="1">
- <PropertyName property={styleConfig.property} label={styleConfig.label} />
- <Flex align="center" css={{ gridColumn: "2/4" }} gap="1">
- <ColorPicker
- id={styleConfig.property}
- value={String(value.value)}
- styleConfig={styleConfig}
- onChange={(value) => {
- setValue(value, { isEphemeral: true });
- }}
- onChangeComplete={setValue}
- />
- </Flex>
- </Grid>
+ <Flex align="center" css={{ gridColumn: "2/4" }} gap="1">
+ <ColorPicker
+ id={styleConfig.property}
+ value={String(value.value)}
+ styleConfig={styleConfig}
+ onChange={(value) => {
+ setValue(value, { isEphemeral: true });
+ }}
+ onChangeComplete={setValue}
+ />
+ </Flex>
);
};
diff --git a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
index a3aa40952c..6dd5114aa0 100644
--- a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
@@ -10,7 +10,6 @@ export const MenuControl = ({
inheritedStyle,
setProperty,
styleConfig,
- category,
}: ControlProps) => {
const value = getFinalValue({
currentStyle,
@@ -26,19 +25,6 @@ export const MenuControl = ({
const setValue = setProperty(styleConfig.property);
const currentValue = value.value as string;
- // @todo stop-gap measure until work on grid section is done
- if (String(currentStyle.display?.value).includes("flex") !== true) {
- return (
- <TextControl
- currentStyle={currentStyle}
- inheritedStyle={inheritedStyle}
- setProperty={setProperty}
- styleConfig={styleConfig}
- category={category}
- />
- );
- }
-
const iconProps = iconConfigs[styleConfig.property];
const iconStyle =
styleConfig.property === "flexDirection"
diff --git a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
index 73fa8bc783..71d632cde7 100644
--- a/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/select/select-control.tsx
@@ -21,23 +21,20 @@ export const SelectControl = ({
const setValue = setProperty(styleConfig.property);
return (
- <Grid css={{ gridTemplateColumns: "$columns$1" }}>
- <PropertyName property={styleConfig.property} label={styleConfig.label} />
- <Select
- options={styleConfig.items.map(({ label }) => label)}
- value={String(value.value)}
- onChange={setValue}
- ghost
- css={{
- gap: "calc($sizes$1 / 2)",
- paddingLeft: "calc($sizes$4 / 2)",
- height: "calc($sizes$5 + $sizes$1)",
- boxShadow: "inset 0 0 0 1px $colors$slate7",
- textTransform: "capitalize",
- fontWeight: "inherit",
- "&:hover": { background: "none" },
- }}
- />
- </Grid>
+ <Select
+ options={styleConfig.items.map(({ label }) => label)}
+ value={String(value.value)}
+ onChange={setValue}
+ ghost
+ css={{
+ gap: "calc($sizes$1 / 2)",
+ paddingLeft: "calc($sizes$4 / 2)",
+ height: "calc($sizes$5 + $sizes$1)",
+ boxShadow: "inset 0 0 0 1px $colors$slate7",
+ textTransform: "capitalize",
+ fontWeight: "inherit",
+ "&:hover": { background: "none" },
+ }}
+ />
);
};
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 7ddc8ecb45..9462e77da4 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
@@ -86,116 +86,113 @@ export const TextControl = ({
};
return (
- <Grid css={{ gridTemplateColumns: "$columns$1" }}>
- <PropertyName property={styleConfig.property} label={styleConfig.label} />
- <Combobox
- name={styleConfig.property}
- items={items.map((item) => item.label)}
- value={String(value.value)}
- selected={String(value.type === "unit" ? value.unit : value.value)}
- onItemSelect={(item) => {
- handleChange(value.type, item, false);
- }}
- onItemHighlight={(item) => {
- handleChange(value.type, item, true);
- }}
- renderTextField={({ inputProps, toggleProps }) => {
- return (
- <Box css={{ position: "relative" }}>
- <PropertyIcon
- property={styleConfig.property}
- label={styleConfig.label}
- {...(value.type === "unit" && {
- onPointerUp: (event: PointerEvent<HTMLInputElement>) => {
- setValue(String(getInputNode(event.target).value));
- },
- ref: numericScrubRefCallback,
- })}
- />
- <TextField
- {...inputProps}
- css={{
- cursor: "default",
- height: "calc($sizes$5 + $sizes$1)",
- fontWeight: "500",
- paddingLeft: "calc($sizes$4 / 2)",
- }}
- onFocus={(event: FocusEvent<HTMLInputElement>) => {
- event.target.select();
- }}
- onBlur={(event) => {
- 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 });
- }}
- />
- <IconButton
- {...toggleProps}
- css={{
- visibility: items.length ? "visible" : "hidden",
- position: "absolute",
- right: "1px",
- top: "1px",
- width: "auto",
- height: "calc(100% - 2px)",
- px: "calc($1 / 2)",
- borderRadius: "$1",
- border: "2px solid $colors$loContrast",
- "&:focus": {
- outline: "none",
- },
- }}
- >
- {value.type === "unit" ? (
- <Text
- css={{
- cursor: "default",
- minWidth: "calc($sizes$3 - $nudge$1)",
- textAlign: "center",
- fontSize: "calc($fontSizes$1 - $nudge$1)",
- }}
- >
- {value.unit === "number" ? "—" : value.unit}
- </Text>
- ) : (
- <ChevronDownIcon />
- )}
- </IconButton>
- </Box>
- );
- }}
- />
- </Grid>
+ <Combobox
+ name={styleConfig.property}
+ items={items.map((item) => item.label)}
+ value={String(value.value)}
+ selected={String(value.type === "unit" ? value.unit : value.value)}
+ onItemSelect={(item) => {
+ handleChange(value.type, item, false);
+ }}
+ onItemHighlight={(item) => {
+ handleChange(value.type, item, true);
+ }}
+ renderTextField={({ inputProps, toggleProps }) => {
+ return (
+ <Box css={{ position: "relative" }}>
+ <PropertyIcon
+ property={styleConfig.property}
+ label={styleConfig.label}
+ {...(value.type === "unit" && {
+ onPointerUp: (event: PointerEvent<HTMLInputElement>) => {
+ setValue(String(getInputNode(event.target).value));
+ },
+ ref: numericScrubRefCallback,
+ })}
+ />
+ <TextField
+ {...inputProps}
+ css={{
+ cursor: "default",
+ height: "calc($sizes$5 + $sizes$1)",
+ fontWeight: "500",
+ paddingLeft: "calc($sizes$4 / 2)",
+ }}
+ onFocus={(event: FocusEvent<HTMLInputElement>) => {
+ event.target.select();
+ }}
+ onBlur={(event) => {
+ 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 });
+ }}
+ />
+ <IconButton
+ {...toggleProps}
+ css={{
+ visibility: items.length ? "visible" : "hidden",
+ position: "absolute",
+ right: "1px",
+ top: "1px",
+ width: "auto",
+ height: "calc(100% - 2px)",
+ px: "calc($1 / 2)",
+ borderRadius: "$1",
+ border: "2px solid $colors$loContrast",
+ "&:focus": {
+ outline: "none",
+ },
+ }}
+ >
+ {value.type === "unit" ? (
+ <Text
+ css={{
+ cursor: "default",
+ minWidth: "calc($sizes$3 - $nudge$1)",
+ textAlign: "center",
+ fontSize: "calc($fontSizes$1 - $nudge$1)",
+ }}
+ >
+ {value.unit === "number" ? "—" : value.unit}
+ </Text>
+ ) : (
+ <ChevronDownIcon />
+ )}
+ </IconButton>
+ </Box>
+ );
+ }}
+ />
);
};
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 7b19684bf3..3186d706bd 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,29 +1,21 @@
-import { Grid } from "@webstudio-is/design-system";
+import { Box, Grid } from "@webstudio-is/design-system";
import type { RenderCategoryProps } from "../../style-sections";
import { FlexGrid } from "./shared/flex-grid";
import { Lock } from "./shared/lock";
import { ShowMore } from "../../shared/show-more";
import { renderProperty } from "../../style-sections";
+import { MenuControl, SelectControl, TextControl } from "../../controls";
+import { PropertyName } from "../../shared/property-name";
const layoutSectionStyle = {
alignItems: "center",
gap: "$space$styleSection",
- "& > [data-type=iconbuttonwithmenu]": {
- display: "flex",
- justifyContent: "center",
- alignItems: "center",
- height: "100%",
- },
- "& [data-property=display]": {
- "& > :first-child": {
- gridTemplateColumns: "auto 1fr",
- gap: "$space$2",
- fontWeight: "500",
- "& > :last-child": {
- width: "fit-content",
- },
- },
- },
+ // "& > [data-type=iconbuttonwithmenu]": {
+ // display: "flex",
+ // justifyContent: "center",
+ // alignItems: "center",
+ // height: "100%",
+ // },
};
const layoutSectionFlexStyle = {
@@ -38,53 +30,102 @@ const layoutSectionFlexStyle = {
"grid grid grid grid grid . . . . . . ."
"columnGap columnGap columnGap columnGap columnGap lock lock rowGap rowGap rowGap rowGap rowGap"
`,
- "& [data-control=text]": {
- "& > :first-child": {
- gridTemplateColumns: "repeat(1, 1fr)",
- "& > :first-child": {
- display: "none",
- },
- },
- },
- // @todo justifyItems icons are using justifycontent icons atm
- "& [data-property=justifyItems]": {
- display: "none",
- },
- "& [data-property=columnGap]": {
- gridArea: "6 / 1 / -1 / 7",
- paddingRight: "10px",
- },
- "& [data-property=rowGap]": {
- gridArea: "6 / 7 / -1 / -1",
- paddingLeft: "10px",
- },
+};
+
+// @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", ...layoutSectionChildStyle };
+const gridStyle = { gridArea: "grid", ...layoutSectionChildStyle };
+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,
createBatchUpdate,
- styleConfigsByCategory,
}: RenderCategoryProps) => {
- console.log(sectionStyle);
+ const {
+ display,
+ flexDirection,
+ flexWrap,
+ alignItems,
+ justifyContent,
+ alignContent,
+ columnGap,
+ rowGap,
+ } = sectionStyle;
const batchUpdate = createBatchUpdate();
return (
<Grid css={layoutSectionFlexStyle}>
- {styleConfigsByCategory.map((entry) => renderProperty(entry))}
- <Lock
- name="lock"
- pairedKeys={["columnGap", "rowGap"]}
- currentStyle={{
- columnGap: currentStyle.columnGap,
- rowGap: currentStyle.rowGap,
- }}
- batchUpdate={batchUpdate}
- />
- <FlexGrid
- name="grid"
- currentStyle={currentStyle}
- batchUpdate={batchUpdate}
- />
+ <Box css={gridStyle}>
+ {" "}
+ <FlexGrid currentStyle={currentStyle} batchUpdate={batchUpdate} />
+ </Box>
+ <Grid css={displayStyle}>
+ <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} />
+ </Box>
+ )}
+ <Box css={columnGapStyle}>
+ <TextControl {...columnGap} hideLabel={true} />
+ </Box>
+ <Box css={rowGapStyle}>
+ <TextControl {...rowGap} hideLabel={true} />
+ </Box>
+ <Box css={lockStyle}>
+ <Lock
+ pairedKeys={["columnGap", "rowGap"]}
+ currentStyle={currentStyle}
+ batchUpdate={batchUpdate}
+ />
+ </Box>
</Grid>
);
};
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
index 723868f769..a6787f758a 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
@@ -5,11 +5,9 @@ import type { Style } from "@webstudio-is/react-sdk";
import type { CreateBatchUpdate } from "../../../shared/use-style-data";
export const FlexGrid = ({
- name,
currentStyle,
batchUpdate,
}: {
- name: string;
currentStyle: Style;
batchUpdate: ReturnType<CreateBatchUpdate>;
}) => {
@@ -56,7 +54,6 @@ export const FlexGrid = ({
const setJustifyContent = batchUpdate.setProperty("justifyContent");
return (
<Grid
- data-property={name}
css={{
width: "100%",
aspectRatio: "1 / 1",
@@ -66,7 +63,6 @@ export const FlexGrid = ({
border: "2px solid currentColor",
alignItems: "center",
gap: "1px",
- gridArea: name,
gridTemplateColumns: "repeat(3, 1fr)",
gridTemplateRows: "repeat(3, 1fr)",
gridTemplateAreas: `
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 c114965deb..2cc84b6230 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
@@ -5,12 +5,10 @@ import type { Style } from "@webstudio-is/react-sdk";
import type { CreateBatchUpdate } from "../../../shared/use-style-data";
export const Lock = ({
- name,
pairedKeys,
currentStyle,
batchUpdate,
}: {
- name: string;
pairedKeys: Array<keyof Style>;
currentStyle: Style;
batchUpdate: ReturnType<CreateBatchUpdate>;
@@ -40,11 +38,9 @@ export const Lock = ({
disableHoverableContent={true}
>
<Flex
- data-property={name}
css={{
width: "100%",
justifyContent: "center",
- gridArea: name,
}}
>
<IconButton
diff --git a/apps/designer/app/designer/features/style-panel/shared/configs.ts b/apps/designer/app/designer/features/style-panel/shared/configs.ts
index cbdf44a614..0739dd6e71 100644
--- a/apps/designer/app/designer/features/style-panel/shared/configs.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/configs.ts
@@ -75,24 +75,27 @@ const getControl = (property: StyleProperty): Control => {
return "Spacing";
}
- switch (property) {
- case "display": {
- return "Select";
- }
- case "flexDirection":
- case "flexWrap":
- case "alignItems":
- case "justifyItems":
- case "justifyContent":
- case "alignContent": {
- return "Menu";
- }
- case "placeContent": {
- return "Empty";
- }
+ // @todo remove once all sections are done
+ switch (
+ property
+ // case "display": {
+ // return "Select";
+ // }
+ // case "flexDirection":
+ // case "flexWrap":
+ // case "alignItems":
+ // case "justifyItems":
+ // case "justifyContent":
+ // case "alignContent": {
+ // return "Menu";
+ // }
+ // case "placeContent": {
+ // return "Empty";
+ // }
//case "fontFamily": {
// return "FontFamily";
//}
+ ) {
}
return "Text";
diff --git a/apps/designer/app/designer/features/style-panel/style-sections.tsx b/apps/designer/app/designer/features/style-panel/style-sections.tsx
index 41718bdf90..355019e9ac 100644
--- a/apps/designer/app/designer/features/style-panel/style-sections.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-sections.tsx
@@ -1,4 +1,4 @@
-import { Box } from "@webstudio-is/design-system";
+import { Box, Grid } from "@webstudio-is/design-system";
import type { StyleConfig } from "./shared/configs";
import {
type Style,
@@ -18,6 +18,7 @@ import {
} from "./controls";
import { ShowMore } from "./shared/show-more";
import { LayoutSection } from "./sections";
+import { PropertyName } from "./shared/property-name";
export type PropertyProps = {
property: StyleProperty;
@@ -61,13 +62,10 @@ export const renderProperty = ({
const Control = controls[styleConfig.control];
const { property } = styleConfig;
if (!Control) return null;
+
return (
- <Box
- key={category + property}
- data-control={styleConfig.control.toLowerCase()}
- data-property={property}
- css={{ gridArea: property }}
- >
+ <Grid key={category + property} css={{ gridTemplateColumns: "40% 60%" }}>
+ <PropertyName property={styleConfig.property} label={styleConfig.label} />
<Control
currentStyle={currentStyle}
inheritedStyle={inheritedStyle}
@@ -75,7 +73,7 @@ export const renderProperty = ({
styleConfig={styleConfig}
category={category}
/>
- </Box>
+ </Grid>
);
};
diff --git a/packages/design-system/src/stitches.config.ts b/packages/design-system/src/stitches.config.ts
index 3ad781ad76..e159c2e7d7 100644
--- a/packages/design-system/src/stitches.config.ts
+++ b/packages/design-system/src/stitches.config.ts
@@ -271,9 +271,6 @@ export const {
4: "400",
max: "999",
},
- columns: {
- 1: "40% 60%",
- },
},
media: {
bp1: "(min-width: 520px)",