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.

Drop section style (#703)

Bogdan Chadkin9fcaac94b336
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 02257074cc..6e26342627 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,7 @@ export const MenuControl = ({
currentStyle,
setProperty,
}: ControlProps) => {
- const { label } = styleConfigByName[property];
+ const { label, items: defaultItems } = styleConfigByName[property];
const value = currentStyle[property];
const isFromCurrentBreakpoint = useIsFromCurrentBreakpoint(property);
@@ -32,7 +32,7 @@ export const MenuControl = ({
: 0
}deg)`,
};
- const items = passedItems
+ const items = (passedItems ?? defaultItems)
.map((item) => {
const ItemIcon = iconProps[item.name];
return {
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 49d89ff499..ff761f6653 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
@@ -1,5 +1,6 @@
import { toValue } from "@webstudio-is/css-engine";
import { Select } from "@webstudio-is/design-system";
+import { styleConfigByName } from "../../shared/configs";
import type { ControlProps } from "../../style-sections";
export const SelectControl = ({
@@ -8,6 +9,7 @@ export const SelectControl = ({
setProperty,
items,
}: ControlProps) => {
+ const { items: defaultItems } = styleConfigByName[property];
const value = currentStyle[property];
const setValue = setProperty(property);
@@ -17,7 +19,7 @@ export const SelectControl = ({
// show empty field instead of radix placeholder
// like css value input does
placeholder=""
- options={items.map(({ label }) => label)}
+ options={(items ?? defaultItems).map(({ label }) => label)}
value={toValue(value)}
onChange={setValue}
/>
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 4ecb3d2e14..bf00b3c6d1 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
@@ -16,7 +16,7 @@ export const TextControl = ({
deleteProperty,
icon,
}: ControlProps & { icon?: JSX.Element }) => {
- const { label } = styleConfigByName[property];
+ const { label, items: defaultItems } = styleConfigByName[property];
const value = currentStyle[property];
const setValue = setProperty(property);
@@ -33,7 +33,7 @@ export const TextControl = ({
property={property}
value={value}
intermediateValue={intermediateValue}
- keywords={items.map((item) => ({
+ keywords={(items ?? defaultItems).map((item) => ({
type: "keyword",
value: item.name,
}))}
diff --git a/apps/designer/app/designer/features/style-panel/sections/flex-child/flex-child.tsx b/apps/designer/app/designer/features/style-panel/sections/flex-child/flex-child.tsx
index 5c53347460..503bba9c4f 100644
--- a/apps/designer/app/designer/features/style-panel/sections/flex-child/flex-child.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/flex-child/flex-child.tsx
@@ -152,8 +152,9 @@ const FlexChildSectionSizing = (props: RenderCategoryProps) => {
};
const FlexChildSectionSizingPopover = ({
+ currentStyle,
+ setProperty,
deleteProperty,
- sectionStyle,
}: RenderCategoryProps) => {
return (
<FloatingPanel
@@ -172,7 +173,12 @@ const FlexChildSectionSizingPopover = ({
label="Basis"
onReset={() => deleteProperty("flexBasis")}
/>
- <TextControl {...sectionStyle.flexBasis} />
+ <TextControl
+ property="flexBasis"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
@@ -180,7 +186,12 @@ const FlexChildSectionSizingPopover = ({
label="Grow"
onReset={() => deleteProperty("flexGrow")}
/>
- <TextControl {...sectionStyle.flexGrow} />
+ <TextControl
+ property="flexGrow"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
@@ -188,7 +199,12 @@ const FlexChildSectionSizingPopover = ({
label="Shrink"
onReset={() => deleteProperty("flexShrink")}
/>
- <TextControl {...sectionStyle.flexShrink} />
+ <TextControl
+ property="flexShrink"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
</Grid>
}
@@ -252,7 +268,7 @@ const FlexChildSectionOrder = (props: RenderCategoryProps) => {
};
const FlexChildSectionOrderPopover = (props: RenderCategoryProps) => {
- const { deleteProperty, sectionStyle } = props;
+ const { currentStyle, setProperty, deleteProperty } = props;
return (
<FloatingPanel
title="Order"
@@ -264,7 +280,12 @@ const FlexChildSectionOrderPopover = (props: RenderCategoryProps) => {
label="Order"
onReset={() => deleteProperty("order")}
/>
- <TextControl {...sectionStyle.order} />
+ <TextControl
+ property="order"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
</Grid>
}
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 da522eaa3f..808b2e5ff7 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
@@ -11,33 +11,16 @@ import { styleConfigByName } from "../../shared/configs";
const LayoutSectionFlex = ({
currentStyle,
- sectionStyle,
createBatchUpdate,
}: {
- deleteProperty: RenderCategoryProps["deleteProperty"];
currentStyle: RenderCategoryProps["currentStyle"];
- sectionStyle: RenderCategoryProps["sectionStyle"];
+ deleteProperty: RenderCategoryProps["deleteProperty"];
createBatchUpdate: RenderCategoryProps["createBatchUpdate"];
}) => {
- const {
- flexDirection,
- flexWrap,
- alignItems,
- justifyContent,
- alignContent,
- columnGap,
- rowGap,
- } = sectionStyle;
const batchUpdate = createBatchUpdate();
- const hasMenuItems = [
- flexDirection,
- flexWrap,
- alignItems,
- justifyContent,
- alignContent,
- ].some((config) => config !== undefined);
+ const { setProperty, deleteProperty } = batchUpdate;
- const flexWrapValue = flexWrap.currentStyle.flexWrap;
+ const flexWrapValue = currentStyle.flexWrap;
// From design: Notice that the align-content icon button is not visible by default.
// This property only applies when flex-wrap is set to "wrap".
@@ -47,42 +30,64 @@ const LayoutSectionFlex = ({
return (
<Flex css={{ flexDirection: "column", gap: "$spacing$5" }}>
- {hasMenuItems && (
- <Grid
- css={{
- gap: "$spacing$5",
- gridTemplateColumns:
- "repeat(2, $spacing$13) repeat(3, $spacing$13)",
- gridTemplateRows: "repeat(2, $spacing$13)",
- gridTemplateAreas: `
+ <Grid
+ css={{
+ gap: "$spacing$5",
+ gridTemplateColumns: "repeat(2, $spacing$13) repeat(3, $spacing$13)",
+ gridTemplateRows: "repeat(2, $spacing$13)",
+ gridTemplateAreas: `
"grid grid flexDirection flexWrap ."
"grid grid alignItems justifyContent alignContent"
`,
- alignItems: "center",
- }}
- >
- <Box css={{ gridArea: "grid" }}>
- <FlexGrid currentStyle={currentStyle} batchUpdate={batchUpdate} />
- </Box>
- <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} />
+ alignItems: "center",
+ }}
+ >
+ <Box css={{ gridArea: "grid" }}>
+ <FlexGrid currentStyle={currentStyle} batchUpdate={batchUpdate} />
+ </Box>
+ <Box css={{ gridArea: "flexDirection" }}>
+ <MenuControl
+ property="flexDirection"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
+ </Box>
+ <Box css={{ gridArea: "flexWrap" }}>
+ <MenuControl
+ property="flexWrap"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
+ </Box>
+ <Box css={{ gridArea: "alignItems" }}>
+ <MenuControl
+ property="alignItems"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
+ </Box>
+ <Box css={{ gridArea: "justifyContent" }}>
+ <MenuControl
+ property="justifyContent"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
+ </Box>
+ {showAlignContent && (
+ <Box css={{ gridArea: "alignContent" }}>
+ <MenuControl
+ property="alignContent"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Box>
- {alignContent && showAlignContent && (
- <Box css={{ gridArea: "alignContent" }}>
- <MenuControl {...alignContent} />
- </Box>
- )}
- </Grid>
- )}
+ )}
+ </Grid>
<Grid
css={{
@@ -95,7 +100,13 @@ const LayoutSectionFlex = ({
}}
>
<Box css={{ gridArea: "columnGap" }}>
- <TextControl icon={<ColumnGapIcon />} {...columnGap} />
+ <TextControl
+ icon={<ColumnGapIcon />}
+ property="columnGap"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Box>
<Box css={{ gridArea: "lock", px: "$spacing$3" }}>
<Lock
@@ -105,7 +116,13 @@ const LayoutSectionFlex = ({
/>
</Box>
<Box css={{ gridArea: "rowGap" }}>
- <TextControl icon={<RowGapIcon />} {...rowGap} />
+ <TextControl
+ icon={<RowGapIcon />}
+ property="rowGap"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Box>
</Grid>
</Flex>
@@ -128,15 +145,14 @@ const compareDisplayValues = (a: { name: string }, b: { name: string }) => {
};
export const LayoutSection = ({
+ currentStyle,
+ setProperty,
deleteProperty,
createBatchUpdate,
- currentStyle,
- sectionStyle,
styleConfigsByCategory,
}: RenderCategoryProps) => {
const displayValue = toValue(currentStyle.display);
- const { display } = sectionStyle;
const { label, items } = styleConfigByName.display;
return (
@@ -149,9 +165,9 @@ export const LayoutSection = ({
/>
<SelectControl
property="display"
- currentStyle={display.currentStyle}
- setProperty={display.setProperty}
- deleteProperty={display.deleteProperty}
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
// show only important values first and hide others with scroll
items={items
.filter((item) => orderedDisplayValues.includes(item.name))
@@ -164,7 +180,6 @@ export const LayoutSection = ({
deleteProperty={deleteProperty}
createBatchUpdate={createBatchUpdate}
currentStyle={currentStyle}
- sectionStyle={sectionStyle}
/>
) : (
styleConfigsByCategory.map((entry) =>
diff --git a/apps/designer/app/designer/features/style-panel/sections/typography/typography.tsx b/apps/designer/app/designer/features/style-panel/sections/typography/typography.tsx
index ba295c7364..5811163f84 100644
--- a/apps/designer/app/designer/features/style-panel/sections/typography/typography.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/typography/typography.tsx
@@ -46,7 +46,7 @@ export const TypographySection = (props: RenderCategoryProps) => {
};
export const TypographySectionFont = (props: RenderCategoryProps) => {
- const { deleteProperty, sectionStyle } = props;
+ const { currentStyle, setProperty, deleteProperty } = props;
return (
<Grid
@@ -60,7 +60,12 @@ export const TypographySectionFont = (props: RenderCategoryProps) => {
property="fontFamily"
onReset={() => deleteProperty("fontFamily")}
/>
- <FontFamilyControl {...sectionStyle.fontFamily} />
+ <FontFamilyControl
+ property="fontFamily"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
<PropertyName
@@ -68,7 +73,12 @@ export const TypographySectionFont = (props: RenderCategoryProps) => {
property="fontWeight"
onReset={() => deleteProperty("fontWeight")}
/>
- <FontWeightControl {...sectionStyle.fontWeight} />
+ <FontWeightControl
+ property="fontWeight"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
<PropertyName
@@ -76,14 +86,19 @@ export const TypographySectionFont = (props: RenderCategoryProps) => {
property="color"
onReset={() => deleteProperty("color")}
/>
- <ColorControl {...sectionStyle.color} />
+ <ColorControl
+ property="color"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
</Grid>
);
};
export const TypographySectionSizing = (props: RenderCategoryProps) => {
- const { deleteProperty, sectionStyle } = props;
+ const { currentStyle, setProperty, deleteProperty } = props;
return (
<Grid
@@ -98,7 +113,12 @@ export const TypographySectionSizing = (props: RenderCategoryProps) => {
label="Size"
onReset={() => deleteProperty("fontSize")}
/>
- <TextControl {...sectionStyle.fontSize} />
+ <TextControl
+ property="fontSize"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
@@ -106,7 +126,12 @@ export const TypographySectionSizing = (props: RenderCategoryProps) => {
label="Height"
onReset={() => deleteProperty("lineHeight")}
/>
- <TextControl {...sectionStyle.lineHeight} />
+ <TextControl
+ property="lineHeight"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
@@ -114,7 +139,12 @@ export const TypographySectionSizing = (props: RenderCategoryProps) => {
label="Spacing"
onReset={() => deleteProperty("letterSpacing")}
/>
- <TextControl {...sectionStyle.letterSpacing} />
+ <TextControl
+ property="letterSpacing"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
</Grid>
);
@@ -249,7 +279,7 @@ export const TypographySectionAdvanced = (props: RenderCategoryProps) => {
export const TypographySectionAdvancedPopover = (
props: RenderCategoryProps
) => {
- const { deleteProperty, setProperty, currentStyle, sectionStyle } = props;
+ const { deleteProperty, setProperty, currentStyle } = props;
const setDirection = setProperty("direction");
const setTextOverflow = setProperty("textOverflow");
const setHyphens = setProperty("hyphens");
@@ -264,7 +294,12 @@ export const TypographySectionAdvancedPopover = (
label="White Space"
onReset={() => deleteProperty("whiteSpace")}
/>
- <SelectControl {...sectionStyle.whiteSpace} />
+ <SelectControl
+ property="whiteSpace"
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName
diff --git a/apps/designer/app/designer/features/style-panel/style-panel.tsx b/apps/designer/app/designer/features/style-panel/style-panel.tsx
index d97d8c9ad8..f62110db7c 100644
--- a/apps/designer/app/designer/features/style-panel/style-panel.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-panel.tsx
@@ -73,7 +73,6 @@ export const StylePanel = ({
>
<StyleSettings
search={search}
- selectedInstanceData={selectedInstanceData}
currentStyle={currentStyle}
setProperty={setProperty}
deleteProperty={deleteProperty}
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 5efe847f5d..e0a2200650 100644
--- a/apps/designer/app/designer/features/style-panel/style-sections.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-sections.tsx
@@ -26,7 +26,7 @@ import { PropertyName } from "./shared/property-name";
export type ControlProps = {
property: StyleProperty;
- items: Array<{ label: string; name: string }>;
+ items?: Array<{ label: string; name: string }>;
currentStyle: Style;
setProperty: SetProperty;
deleteProperty: DeleteProperty;
@@ -37,9 +37,6 @@ export type RenderCategoryProps = {
deleteProperty: DeleteProperty;
createBatchUpdate: CreateBatchUpdate;
currentStyle: Style;
- sectionStyle: {
- [Property in Required<keyof Style>]: RenderPropertyProps;
- };
category: Category;
styleConfigsByCategory: Array<RenderPropertyProps>;
moreStyleConfigsByCategory: Array<RenderPropertyProps>;
@@ -47,10 +44,9 @@ export type RenderCategoryProps = {
export type RenderPropertyProps = {
property: StyleProperty;
- items: Array<{ label: string; name: string }>;
+ currentStyle: Style;
setProperty: SetProperty;
deleteProperty: DeleteProperty;
- currentStyle: Style;
category: Category;
};
@@ -90,7 +86,6 @@ export const renderCategory = ({
deleteProperty,
createBatchUpdate,
currentStyle,
- sectionStyle,
category,
styleConfigsByCategory,
moreStyleConfigsByCategory,
@@ -102,7 +97,6 @@ export const renderCategory = ({
deleteProperty={deleteProperty}
createBatchUpdate={createBatchUpdate}
currentStyle={currentStyle}
- sectionStyle={sectionStyle}
category={category}
styleConfigsByCategory={styleConfigsByCategory}
moreStyleConfigsByCategory={moreStyleConfigsByCategory}
diff --git a/apps/designer/app/designer/features/style-panel/style-settings.tsx b/apps/designer/app/designer/features/style-panel/style-settings.tsx
index e89aaf550e..3dc9bd34f3 100644
--- a/apps/designer/app/designer/features/style-panel/style-settings.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-settings.tsx
@@ -1,6 +1,6 @@
import hyphenate from "hyphenate-style-name";
import { categories, type Category } from "@webstudio-is/react-sdk";
-import type { CssRule, Style, StyleProperty } from "@webstudio-is/css-data";
+import type { Style, StyleProperty } from "@webstudio-is/css-data";
import { toValue } from "@webstudio-is/css-engine";
import {
@@ -9,18 +9,13 @@ import {
styleConfigByName,
} from "./shared/configs";
import { CollapsibleSection } from "~/designer/shared/inspector";
-import {
- renderCategory,
- RenderCategoryProps,
- shouldRenderCategory,
-} from "./style-sections";
+import { renderCategory, shouldRenderCategory } from "./style-sections";
import { dependencies } from "./shared/dependencies";
import {
type SetProperty,
type CreateBatchUpdate,
} from "./shared/use-style-data";
-import { type SelectedInstanceData } from "@webstudio-is/project";
-import { type RenderPropertyProps } from "./style-sections";
+import type { RenderPropertyProps } from "./style-sections";
// Finds a property/value by using any available form: property, label, value
const filterProperties = (
@@ -89,11 +84,9 @@ const didRender = (category: Category, property: StyleProperty): boolean => {
export type StyleSettingsProps = {
currentStyle: Style;
- cssRule?: CssRule;
setProperty: SetProperty;
deleteProperty: (property: StyleProperty) => void;
createBatchUpdate: CreateBatchUpdate;
- selectedInstanceData: SelectedInstanceData;
search: string;
};
@@ -103,7 +96,6 @@ export const StyleSettings = ({
createBatchUpdate,
currentStyle,
search,
- ...rest
}: StyleSettingsProps) => {
const isSearchMode = search.length !== 0;
const all = [];
@@ -115,7 +107,6 @@ export const StyleSettings = ({
search
);
const { moreFrom } = categories[category];
- const sectionStyle = {} as RenderCategoryProps["sectionStyle"];
const styleConfigsByCategory: Array<RenderPropertyProps> = [];
const moreStyleConfigsByCategory: Array<RenderPropertyProps> = [];
@@ -128,17 +119,13 @@ export const StyleSettings = ({
: appliesTo(styleConfig, currentStyle);
const isRendered = didRender(category, property);
const element = {
- ...rest,
property,
- items: styleConfig.items,
setProperty,
deleteProperty,
currentStyle,
category,
};
- sectionStyle[property] = element;
-
// @todo remove isRendered once spacing section is converted to a section
if (isInCategory && isApplicable && isRendered === false) {
// We are making a separate array of properties which come after the "moreFrom"
@@ -159,13 +146,11 @@ export const StyleSettings = ({
continue;
}
const categoryProps = {
- ...rest,
setProperty,
deleteProperty,
createBatchUpdate,
currentStyle,
category,
- sectionStyle,
styleConfigsByCategory,
moreStyleConfigsByCategory,
};