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.

pass data instead of control elements themselves, let sections determine what properties to render as what controls

Sultan191ad8f041a1
diff --git a/apps/designer/app/designer/features/style-panel/controls/spacing/spacing-control.tsx b/apps/designer/app/designer/features/style-panel/controls/spacing/spacing-control.tsx
index e0834e1599..5a6eb62029 100644
--- a/apps/designer/app/designer/features/style-panel/controls/spacing/spacing-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/spacing/spacing-control.tsx
@@ -242,6 +242,7 @@ const SpacingWidget = ({ setProperty, values }: SpacingWidgetProps) => {
);
};
+// @todo convert to section, they way it does atm is a "hack"
export const SpacingControl = ({
currentStyle,
inheritedStyle,
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 a7528ec2a3..7b19684bf3 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
@@ -3,6 +3,7 @@ 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";
const layoutSectionStyle = {
alignItems: "center",
@@ -61,13 +62,15 @@ const layoutSectionFlexStyle = {
const LayoutSectionFlex = ({
currentStyle,
+ sectionStyle,
createBatchUpdate,
styleConfigsByCategory,
}: RenderCategoryProps) => {
+ console.log(sectionStyle);
const batchUpdate = createBatchUpdate();
return (
<Grid css={layoutSectionFlexStyle}>
- {styleConfigsByCategory}
+ {styleConfigsByCategory.map((entry) => renderProperty(entry))}
<Lock
name="lock"
pairedKeys={["columnGap", "rowGap"]}
@@ -90,6 +93,7 @@ export const LayoutSection = ({
setProperty,
createBatchUpdate,
currentStyle,
+ sectionStyle,
category,
styleConfigsByCategory,
moreStyleConfigsByCategory,
@@ -103,6 +107,7 @@ export const LayoutSection = ({
createBatchUpdate={createBatchUpdate}
currentStyle={currentStyle}
category={category}
+ sectionStyle={sectionStyle}
styleConfigsByCategory={styleConfigsByCategory}
moreStyleConfigsByCategory={moreStyleConfigsByCategory}
/>
@@ -111,8 +116,12 @@ export const LayoutSection = ({
return (
<>
- <ShowMore styleConfigs={moreStyleConfigsByCategory} />
- {styleConfigsByCategory}
+ <ShowMore
+ styleConfigs={moreStyleConfigsByCategory.map((entry) =>
+ renderProperty(entry)
+ )}
+ />
+ {styleConfigsByCategory.map((entry) => renderProperty(entry))}
</>
);
};
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 0be0f616fa..41718bdf90 100644
--- a/apps/designer/app/designer/features/style-panel/style-sections.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-sections.tsx
@@ -37,9 +37,10 @@ export type RenderCategoryProps = {
setProperty: SetProperty;
createBatchUpdate: CreateBatchUpdate;
currentStyle: Style;
+ sectionStyle: Style;
category: Category;
- styleConfigsByCategory: Array<JSX.Element | null>;
- moreStyleConfigsByCategory: Array<JSX.Element | null>;
+ styleConfigsByCategory: Array<RenderPropertyProps>;
+ moreStyleConfigsByCategory: Array<RenderPropertyProps>;
};
export type RenderPropertyProps = {
@@ -82,6 +83,7 @@ export const renderCategory = ({
setProperty,
createBatchUpdate,
currentStyle,
+ sectionStyle,
category,
styleConfigsByCategory,
moreStyleConfigsByCategory,
@@ -90,8 +92,12 @@ export const renderCategory = ({
if (!Category) {
return (
<>
- {styleConfigsByCategory}
- <ShowMore styleConfigs={moreStyleConfigsByCategory} />
+ {styleConfigsByCategory.map((entry) => renderProperty(entry))}
+ <ShowMore
+ styleConfigs={moreStyleConfigsByCategory.map((entry) =>
+ renderProperty(entry)
+ )}
+ />
</>
);
}
@@ -101,6 +107,7 @@ export const renderCategory = ({
setProperty={setProperty}
createBatchUpdate={createBatchUpdate}
currentStyle={currentStyle}
+ sectionStyle={sectionStyle}
category={category}
styleConfigsByCategory={styleConfigsByCategory}
moreStyleConfigsByCategory={moreStyleConfigsByCategory}
@@ -126,6 +133,7 @@ const sections: {
[key: string]: (props: RenderCategoryProps) => JSX.Element | null;
} = {
layout: LayoutSection,
+ // spacing: SpacingSection,
};
const controls: {
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 6b41e1b70b..bebac83466 100644
--- a/apps/designer/app/designer/features/style-panel/style-settings.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-settings.tsx
@@ -20,6 +20,7 @@ import {
type CreateBatchUpdate,
} from "./shared/use-style-data";
import { type SelectedInstanceData } from "~/shared/canvas-components";
+import { type RenderPropertyProps } from "./style-sections";
// Finds a property/value by using any available form: property, label, value
const filterProperties = (properties: Array<string>, search: string) => {
@@ -98,8 +99,9 @@ export const StyleSettings = ({
search
);
const { moreFrom } = categories[category];
- const styleConfigsByCategory: Array<JSX.Element | null> = [];
- const moreStyleConfigsByCategory: Array<JSX.Element | null> = [];
+ const sectionStyle: Style = {};
+ const styleConfigsByCategory: Array<RenderPropertyProps> = [];
+ const moreStyleConfigsByCategory: Array<RenderPropertyProps> = [];
for (const styleConfig of styleConfigs) {
const isInCategory = categoryProperties.includes(styleConfig.property);
@@ -109,14 +111,17 @@ export const StyleSettings = ({
: appliesTo(styleConfig, currentStyle);
const isRendered = didRender(category, styleConfig);
+ // @todo remove isRendered once spacing section is converted to a section
if (isInCategory && isApplicable && isRendered === false) {
- const element = renderProperty({
+ const element = {
...rest,
setProperty,
currentStyle,
styleConfig,
category,
- });
+ };
+
+ sectionStyle[styleConfig.property] = element;
// We are making a separate array of properties which come after the "moreFrom"
// so we can make them collapsable
@@ -139,6 +144,7 @@ export const StyleSettings = ({
createBatchUpdate,
currentStyle,
category,
+ sectionStyle,
styleConfigsByCategory,
moreStyleConfigsByCategory,
};