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.

Add proprety reset button in popover (#583)

Bogdan Chadkinaba5506e1360
diff --git a/apps/designer/app/canvas/shared/instance.ts b/apps/designer/app/canvas/shared/instance.ts
index f192f84637..197c9c2ca6 100644
--- a/apps/designer/app/canvas/shared/instance.ts
+++ b/apps/designer/app/canvas/shared/instance.ts
@@ -1,4 +1,4 @@
-import { useCallback, useEffect, useMemo, useState } from "react";
+import { useCallback, useEffect, useState } from "react";
import {
type Instance,
type UserProp,
@@ -192,10 +192,6 @@ export const usePublishSelectedInstanceData = (treeId: Tree["id"]) => {
const [instance] = useSelectedInstance();
const [selectedElement] = useSelectedElement();
const [allUserProps] = useAllUserProps();
- const browserStyle = useMemo(
- () => getBrowserStyle(selectedElement),
- [selectedElement]
- );
useEffect(() => {
// Unselects the instance by `undefined`
@@ -204,6 +200,7 @@ export const usePublishSelectedInstanceData = (treeId: Tree["id"]) => {
const props =
allUserProps[instance.id] ??
utils.props.createInstanceProps({ instanceId: instance.id, treeId });
+ const browserStyle = getBrowserStyle(selectedElement);
payload = {
id: instance.id,
component: instance.component,
@@ -216,7 +213,7 @@ export const usePublishSelectedInstanceData = (treeId: Tree["id"]) => {
type: "selectInstance",
payload,
});
- }, [instance, allUserProps, treeId, browserStyle]);
+ }, [instance, allUserProps, treeId, selectedElement]);
};
export const usePublishHoveredInstanceData = () => {
diff --git a/apps/designer/app/canvas/shared/styles.ts b/apps/designer/app/canvas/shared/styles.ts
index dfa0f3b919..b57bc29718 100644
--- a/apps/designer/app/canvas/shared/styles.ts
+++ b/apps/designer/app/canvas/shared/styles.ts
@@ -180,6 +180,12 @@ export const useCssRules = ({
for (property in dynamicStyle) {
rule.styleMap.set(property, dynamicStyle[property]);
}
+ // delete previously rendered properties when reset
+ for (const property of rule.styleMap.keys()) {
+ if (dynamicStyle[property] === undefined) {
+ rule.styleMap.delete(property);
+ }
+ }
}
cssEngine.render();
}, [id, cssRules]);
@@ -253,16 +259,18 @@ const usePreviewStyle = () => {
}
for (const update of updates) {
- // This is possible on newly created instances, properties are not yet defined in the style.
- if (rule.styleMap.has(update.property) === false) {
- const dynamicStyle = toVarStyleWithFallback(id, {
- [update.property]: update.value,
- });
+ if (update.operation === "set") {
+ // This is possible on newly created instances, properties are not yet defined in the style.
+ if (rule.styleMap.has(update.property) === false) {
+ const dynamicStyle = toVarStyleWithFallback(id, {
+ [update.property]: update.value,
+ });
- rule.styleMap.set(update.property, dynamicStyle[update.property]);
- }
+ rule.styleMap.set(update.property, dynamicStyle[update.property]);
+ }
- setCssVar(id, update.property, update.value);
+ setCssVar(id, update.property, update.value);
+ }
}
cssEngine.render();
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 a22b77acbb..9a783d3d59 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
@@ -30,14 +30,15 @@ export const FlexChildSection = (props: RenderCategoryProps) => {
};
const FlexChildSectionAlign = (props: RenderCategoryProps) => {
- const { setProperty, currentStyle, sectionStyle } = props;
+ const { setProperty, deleteProperty, currentStyle, sectionStyle } = props;
const setAlignSelf = setProperty("alignSelf");
return (
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName
- property={sectionStyle.alignSelf?.styleConfig.property}
+ property="alignSelf"
label="Align"
+ onReset={() => deleteProperty("alignSelf")}
/>
<ToggleGroupControl
property={sectionStyle.alignSelf?.styleConfig.property}
@@ -87,11 +88,13 @@ const FlexChildSectionSizing = (props: RenderCategoryProps) => {
return (
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName
- property={[
- sectionStyle.flexGrow?.styleConfig.property,
- sectionStyle.flexShrink?.styleConfig.property,
- ]}
+ property={["flexGrow", "flexShrink"]}
label="Sizing"
+ onReset={() => {
+ setSizing.deleteProperty("flexGrow");
+ setSizing.deleteProperty("flexShrink");
+ setSizing.publish();
+ }}
/>
<ToggleGroupControl
property={[
@@ -152,6 +155,7 @@ const FlexChildSectionSizing = (props: RenderCategoryProps) => {
};
const FlexChildSectionSizingPopover = ({
+ deleteProperty,
sectionStyle,
}: RenderCategoryProps) => {
return (
@@ -167,22 +171,25 @@ const FlexChildSectionSizingPopover = ({
>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
- property={sectionStyle.flexBasis?.styleConfig.property}
+ property="flexBasis"
label="Basis"
+ onReset={() => deleteProperty("flexBasis")}
/>
<TextControl {...sectionStyle.flexBasis} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
- property={sectionStyle.flexGrow?.styleConfig.property}
+ property="flexGrow"
label="Grow"
+ onReset={() => deleteProperty("flexGrow")}
/>
<TextControl {...sectionStyle.flexGrow} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
<PropertyName
- property={sectionStyle.flexShrink?.styleConfig.property}
+ property="flexShrink"
label="Shrink"
+ onReset={() => deleteProperty("flexShrink")}
/>
<TextControl {...sectionStyle.flexShrink} />
</Grid>
@@ -197,14 +204,15 @@ const FlexChildSectionSizingPopover = ({
};
const FlexChildSectionOrder = (props: RenderCategoryProps) => {
- const { setProperty, currentStyle, sectionStyle } = props;
+ const { deleteProperty, setProperty, currentStyle, sectionStyle } = props;
const setOrder = setProperty("order");
return (
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName
- property={sectionStyle.order?.styleConfig.property}
+ property="order"
label="Order"
+ onReset={() => deleteProperty("order")}
/>
<ToggleGroupControl
property={sectionStyle.order?.styleConfig.property}
@@ -247,7 +255,7 @@ const FlexChildSectionOrder = (props: RenderCategoryProps) => {
};
const FlexChildSectionOrderPopover = (props: RenderCategoryProps) => {
- const { sectionStyle } = props;
+ const { deleteProperty, sectionStyle } = props;
return (
<ValuePickerPopover
title="Order"
@@ -255,8 +263,9 @@ const FlexChildSectionOrderPopover = (props: RenderCategoryProps) => {
<Grid css={{ padding: "$spacing$9" }}>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
<PropertyName
- property={sectionStyle.order?.styleConfig.property}
+ property="order"
label="Order"
+ onReset={() => deleteProperty("order")}
/>
<TextControl {...sectionStyle.order} />
</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 17aba83303..d1c055bac7 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,6 +11,7 @@ import { ColumnGapIcon, RowGapIcon } from "@webstudio-is/icons";
import { getFinalValue } from "../../shared/get-final-value";
const LayoutSectionFlex = ({
+ deleteProperty,
currentStyle,
sectionStyle,
createBatchUpdate,
@@ -59,8 +60,9 @@ const LayoutSectionFlex = ({
}}
>
<PropertyName
- property={display.styleConfig.property}
+ property="display"
label={display.styleConfig.label}
+ onReset={() => deleteProperty("display")}
/>
<SelectControl {...display} />
</Grid>
@@ -146,6 +148,7 @@ const LayoutSectionFlex = ({
export const LayoutSection = ({
setProperty,
+ deleteProperty,
createBatchUpdate,
currentStyle,
sectionStyle,
@@ -160,6 +163,7 @@ export const LayoutSection = ({
return (
<ActiveLayout
setProperty={setProperty}
+ deleteProperty={deleteProperty}
createBatchUpdate={createBatchUpdate}
currentStyle={currentStyle}
sectionStyle={sectionStyle}
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 67c941d281..4e07d430db 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 { sectionStyle } = props;
+ const { deleteProperty, sectionStyle } = props;
return (
<Grid
@@ -55,15 +55,27 @@ export const TypographySectionFont = (props: RenderCategoryProps) => {
}}
>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
- <PropertyName label="Font" property="fontFamily" />
+ <PropertyName
+ label="Font"
+ property="fontFamily"
+ onReset={() => deleteProperty("fontFamily")}
+ />
<FontFamilyControl {...sectionStyle.fontFamily} />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
- <PropertyName label="Weight" property="fontWeight" />
+ <PropertyName
+ label="Weight"
+ property="fontWeight"
+ onReset={() => deleteProperty("fontWeight")}
+ />
<FontWeightControl {...sectionStyle.fontWeight} />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
- <PropertyName label="Color" property="color" />
+ <PropertyName
+ label="Color"
+ property="color"
+ onReset={() => deleteProperty("color")}
+ />
<ColorControl {...sectionStyle.color} />
</Grid>
</Grid>
@@ -71,7 +83,7 @@ export const TypographySectionFont = (props: RenderCategoryProps) => {
};
export const TypographySectionSizing = (props: RenderCategoryProps) => {
- const { sectionStyle } = props;
+ const { deleteProperty, sectionStyle } = props;
return (
<Grid
@@ -81,15 +93,27 @@ export const TypographySectionSizing = (props: RenderCategoryProps) => {
}}
>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
- <PropertyName property="fontSize" label="Size" />
+ <PropertyName
+ property="fontSize"
+ label="Size"
+ onReset={() => deleteProperty("fontSize")}
+ />
<TextControl {...sectionStyle.fontSize} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
- <PropertyName property="lineHeight" label="Height" />
+ <PropertyName
+ property="lineHeight"
+ label="Height"
+ onReset={() => deleteProperty("lineHeight")}
+ />
<TextControl {...sectionStyle.lineHeight} />
</Grid>
<Grid css={{ gridTemplateColumns: "auto", gap: "$spacing$3" }}>
- <PropertyName property="letterSpacing" label="Spacing" />
+ <PropertyName
+ property="letterSpacing"
+ label="Spacing"
+ onReset={() => deleteProperty("letterSpacing")}
+ />
<TextControl {...sectionStyle.letterSpacing} />
</Grid>
</Grid>
@@ -225,7 +249,7 @@ export const TypographySectionAdvanced = (props: RenderCategoryProps) => {
export const TypographySectionAdvancedPopover = (
props: RenderCategoryProps
) => {
- const { setProperty, currentStyle, sectionStyle } = props;
+ const { deleteProperty, setProperty, currentStyle, sectionStyle } = props;
const setDirection = setProperty("direction");
const setTextOverflow = setProperty("textOverflow");
const setHyphens = setProperty("hyphens");
@@ -235,11 +259,19 @@ export const TypographySectionAdvancedPopover = (
content={
<Grid css={{ padding: "$spacing$9", gap: "$spacing$9" }}>
<Grid css={{ gridTemplateColumns: "4fr 6fr" }}>
- <PropertyName property="whiteSpace" label="White Space" />
+ <PropertyName
+ property="whiteSpace"
+ label="White Space"
+ onReset={() => deleteProperty("whiteSpace")}
+ />
<SelectControl {...sectionStyle.whiteSpace} />
</Grid>
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
- <PropertyName property="direction" label="Direction" />
+ <PropertyName
+ property="direction"
+ label="Direction"
+ onReset={() => deleteProperty("direction")}
+ />
<ToggleGroupControl
property="direction"
onValueChange={(value) => setDirection(value)}
@@ -259,7 +291,11 @@ export const TypographySectionAdvancedPopover = (
/>
</Grid>
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
- <PropertyName property="hyphens" label="Hyphens" />
+ <PropertyName
+ property="hyphens"
+ label="Hyphens"
+ onReset={() => deleteProperty("hyphens")}
+ />
<ToggleGroupControl
property="hyphens"
onValueChange={(value) => setHyphens(value)}
@@ -279,7 +315,11 @@ export const TypographySectionAdvancedPopover = (
/>
</Grid>
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
- <PropertyName property="textOverflow" label="Text Overflow" />
+ <PropertyName
+ property="textOverflow"
+ label="Text Overflow"
+ onReset={() => deleteProperty("textOverflow")}
+ />
<ToggleGroupControl
property="textOverflow"
onValueChange={(value) => setTextOverflow(value)}
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 260911c56a..ee440c8817 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
@@ -1,39 +1,91 @@
-import { Flex, Label, Tooltip } from "@webstudio-is/design-system";
+import { useState } from "react";
+import type { StyleProperty } from "@webstudio-is/css-data";
+import {
+ Button,
+ Flex,
+ Box,
+ Text,
+ Label,
+ Tooltip,
+ Popover,
+ PopoverContent,
+ PopoverPortal,
+ PopoverTrigger,
+ Separator,
+} from "@webstudio-is/design-system";
+import { UndoIcon } from "@webstudio-is/icons";
import { useIsFromCurrentBreakpoint } from "./use-is-from-current-breakpoint";
-import { propertyNameColorForSelectedBreakpoint } from "./constants";
-import type { PropertyProps } from "../style-sections";
+import { isFeatureEnabled } from "~/shared/feature-flags";
-export const PropertyName = ({ property, label, css }: PropertyProps) => {
+type PropertyProps = {
+ property: StyleProperty | StyleProperty[];
+ label: string;
+ onReset: () => void;
+};
+
+export const PropertyName = ({ property, label, onReset }: PropertyProps) => {
const isCurrentBreakpoint = useIsFromCurrentBreakpoint(property);
+ const [isOpen, setIsOpen] = useState(false);
+ const isPopoverEnabled =
+ isFeatureEnabled("propertyReset") && isCurrentBreakpoint;
+
+ const labelElement = (
+ <Label
+ css={{
+ fontWeight: "inherit",
+ padding: "calc($spacing$3 / 2) $spacing$3",
+ ...(isCurrentBreakpoint
+ ? {
+ color: "$blue11",
+ backgroundColor: "$colors$blue4",
+ borderRadius: "$borderRadius$4",
+ }
+ : {
+ color: "$hiContrast",
+ }),
+ }}
+ htmlFor={property.toString()}
+ >
+ {label}
+ </Label>
+ );
+
+ if (isPopoverEnabled) {
+ return (
+ <Flex align="center">
+ <Popover modal open={isOpen} onOpenChange={setIsOpen}>
+ <PopoverTrigger asChild aria-label="Show proprety description">
+ {labelElement}
+ </PopoverTrigger>
+ <PopoverPortal>
+ <PopoverContent align="start" onClick={() => setIsOpen(false)}>
+ <Flex align="start" css={{ px: "$spacing$4", py: "$spacing$3" }}>
+ <Button onClick={onReset}>
+ <UndoIcon /> &nbsp; Reset
+ </Button>
+ </Flex>
+ <Separator />
+ <Box css={{ px: "$spacing$4", py: "$spacing$3" }}>
+ <Text color="hint">
+ Resetting will revert to initial or inherited value
+ </Text>
+ </Box>
+ </PopoverContent>
+ </PopoverPortal>
+ </Popover>
+ </Flex>
+ );
+ }
+
return (
- <Tooltip content={label} delayDuration={600} disableHoverableContent={true}>
- <Flex
- css={{
- ...css,
- alignItems: "center",
- }}
+ <Flex align="center">
+ <Tooltip
+ content={label}
+ delayDuration={600}
+ disableHoverableContent={true}
>
- <Label
- css={{
- gridColumn: "1",
- fontWeight: "inherit",
- ...(isCurrentBreakpoint
- ? {
- color: propertyNameColorForSelectedBreakpoint,
- backgroundColor: "$colors$blue4",
- padding: "calc($spacing$3 / 2) $spacing$3",
- borderRadius: "$borderRadius$4",
- }
- : {
- color: "$hiContrast",
- }),
- }}
- htmlFor={String(property)}
- >
- {label}
- </Label>
- </Flex>
- </Tooltip>
+ {labelElement}
+ </Tooltip>
+ </Flex>
);
};
-PropertyName.displayName = "PropertyName";
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.ts
index 3ea42e34fa..5964b6e6dc 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
@@ -31,6 +31,7 @@ export type SetProperty = (
export type CreateBatchUpdate = () => {
setProperty: SetProperty;
+ deleteProperty: (property: StyleProperty) => void;
publish: () => void;
};
@@ -122,7 +123,9 @@ export const useStyleData = ({
: inputOrStyle;
if (nextValue.type !== "invalid") {
- const updates = [{ property, value: nextValue }];
+ const updates = [
+ { operation: "set" as const, property, value: nextValue },
+ ];
const type = options.isEphemeral ? "preview" : "update";
publishUpdates(type, updates);
@@ -134,6 +137,18 @@ export const useStyleData = ({
};
};
+ const deleteProperty = (property: StyleProperty) => {
+ if (currentStyle === undefined) {
+ return;
+ }
+
+ const updates = [{ operation: "delete" as const, property }];
+ publishUpdates("update", updates);
+ const nextStyle = { ...currentStyle };
+ delete nextStyle[property];
+ setCurrentStyle(nextStyle);
+ };
+
const createBatchUpdate = () => {
let updates: StyleUpdates["updates"] = [];
@@ -157,20 +172,32 @@ export const useStyleData = ({
return;
}
- updates.push({ property, value });
+ updates.push({ operation: "set", property, value });
};
return setValue;
};
+ const deleteProperty = (property: StyleProperty) => {
+ if (currentStyle === undefined) {
+ return;
+ }
+
+ updates.push({ operation: "delete", property });
+ };
+
const publish = () => {
if (!updates.length) {
return;
}
publishUpdates("update", updates);
const nextStyle = updates.reduce(
- (currentStyle, { property, value }) => {
- // @todo
- currentStyle[property] = value;
+ (currentStyle, update) => {
+ if (update.operation === "delete") {
+ delete currentStyle[update.property];
+ }
+ if (update.operation === "set") {
+ currentStyle[update.property] = update.value;
+ }
return currentStyle;
},
{ ...currentStyle }
@@ -181,9 +208,16 @@ export const useStyleData = ({
return {
setProperty,
+ deleteProperty,
publish,
};
};
- return { currentStyle, inheritedStyle, setProperty, createBatchUpdate };
+ return {
+ currentStyle,
+ inheritedStyle,
+ setProperty,
+ deleteProperty,
+ createBatchUpdate,
+ };
};
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 98ea93d7e4..7a73c6c38f 100644
--- a/apps/designer/app/designer/features/style-panel/style-panel.tsx
+++ b/apps/designer/app/designer/features/style-panel/style-panel.tsx
@@ -19,11 +19,16 @@ export const StylePanel = ({
selectedInstanceData,
publish,
}: StylePanelProps) => {
- const { currentStyle, inheritedStyle, setProperty, createBatchUpdate } =
- useStyleData({
- selectedInstanceData,
- publish,
- });
+ const {
+ currentStyle,
+ inheritedStyle,
+ setProperty,
+ deleteProperty,
+ createBatchUpdate,
+ } = useStyleData({
+ selectedInstanceData,
+ publish,
+ });
const [breakpoint] = useSelectedBreakpoint();
const [canvasWidth] = useCanvasWidth();
const [search, setSearch] = useState("");
@@ -77,6 +82,7 @@ export const StylePanel = ({
currentStyle={currentStyle}
inheritedStyle={inheritedStyle}
setProperty={setProperty}
+ deleteProperty={deleteProperty}
createBatchUpdate={createBatchUpdate}
/>
</Box>
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 d97d770f76..fb2dd7fd28 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 { Grid, type CSS } from "@webstudio-is/design-system";
+import { Grid } from "@webstudio-is/design-system";
import { toValue } from "@webstudio-is/css-engine";
import type { StyleConfig } from "./shared/configs";
import type { Category } from "@webstudio-is/react-sdk";
@@ -21,12 +21,6 @@ import {
} from "./sections";
import { PropertyName } from "./shared/property-name";
-export type PropertyProps = {
- property: StyleProperty | StyleProperty[];
- label: string;
- css?: CSS;
-};
-
export type ControlProps = {
setProperty: SetProperty;
currentStyle: Style;
@@ -37,6 +31,7 @@ export type ControlProps = {
export type RenderCategoryProps = {
setProperty: SetProperty;
+ deleteProperty: (property: StyleProperty) => void;
createBatchUpdate: CreateBatchUpdate;
currentStyle: Style;
sectionStyle: {
@@ -50,6 +45,7 @@ export type RenderCategoryProps = {
export type RenderPropertyProps = {
setProperty: SetProperty;
+ deleteProperty: (property: StyleProperty) => void;
currentStyle: Style;
inheritedStyle: InheritedStyle;
styleConfig: StyleConfig;
@@ -60,6 +56,7 @@ export const renderProperty = ({
currentStyle,
inheritedStyle,
setProperty,
+ deleteProperty,
styleConfig,
category,
}: RenderPropertyProps) => {
@@ -71,7 +68,11 @@ export const renderProperty = ({
return (
<Grid key={category + property} css={{ gridTemplateColumns: "4fr 6fr" }}>
- <PropertyName property={styleConfig.property} label={styleConfig.label} />
+ <PropertyName
+ property={styleConfig.property}
+ label={styleConfig.label}
+ onReset={() => deleteProperty(styleConfig.property)}
+ />
<Control
currentStyle={currentStyle}
inheritedStyle={inheritedStyle}
@@ -85,6 +86,7 @@ export const renderProperty = ({
export const renderCategory = ({
setProperty,
+ deleteProperty,
createBatchUpdate,
currentStyle,
sectionStyle,
@@ -97,6 +99,7 @@ export const renderCategory = ({
return (
<Section
setProperty={setProperty}
+ deleteProperty={deleteProperty}
createBatchUpdate={createBatchUpdate}
currentStyle={currentStyle}
sectionStyle={sectionStyle}
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 50a7976f6b..fa7b8cabb8 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 } from "@webstudio-is/css-data";
+import type { CssRule, Style, StyleProperty } from "@webstudio-is/css-data";
import { toValue } from "@webstudio-is/css-engine";
import { type StyleConfig, styleConfigs } from "./shared/configs";
@@ -90,6 +90,7 @@ export type StyleSettingsProps = {
inheritedStyle: InheritedStyle;
cssRule?: CssRule;
setProperty: SetProperty;
+ deleteProperty: (property: StyleProperty) => void;
createBatchUpdate: CreateBatchUpdate;
selectedInstanceData: SelectedInstanceData;
search: string;
@@ -97,6 +98,7 @@ export type StyleSettingsProps = {
export const StyleSettings = ({
setProperty,
+ deleteProperty,
createBatchUpdate,
currentStyle,
search,
@@ -126,6 +128,7 @@ export const StyleSettings = ({
const element = {
...rest,
setProperty,
+ deleteProperty,
currentStyle,
styleConfig,
category,
@@ -156,6 +159,7 @@ export const StyleSettings = ({
const categoryProps = {
...rest,
setProperty,
+ deleteProperty,
createBatchUpdate,
currentStyle,
category,
diff --git a/apps/designer/app/shared/feature-flags/flags.ts b/apps/designer/app/shared/feature-flags/flags.ts
index c9639f6b34..2f3c578e62 100644
--- a/apps/designer/app/shared/feature-flags/flags.ts
+++ b/apps/designer/app/shared/feature-flags/flags.ts
@@ -1,3 +1,4 @@
export const designTokens = false;
export const example = false;
export const dark = false;
+export const propertyReset = false;
diff --git a/packages/css-engine/src/core/css-engine.test.ts b/packages/css-engine/src/core/css-engine.test.ts
index ac38fbb164..127e6b33a8 100644
--- a/packages/css-engine/src/core/css-engine.test.ts
+++ b/packages/css-engine/src/core/css-engine.test.ts
@@ -11,6 +11,11 @@ const style1 = {
display: { type: "keyword", value: "flex" },
} as const;
+const style2 = {
+ display: { type: "keyword", value: "block" },
+ color: { type: "keyword", value: "black" },
+} as const;
+
const mediaRuleOptions1 = { minWidth: 300 } as const;
const mediaId1 = "1";
@@ -278,4 +283,30 @@ describe("CssEngine", () => {
engine.clear();
expect(engine.cssText).toMatchInlineSnapshot(`""`);
});
+
+ test("get all rule style keys", () => {
+ const rule = engine.addStyleRule(".c", {
+ style: style2,
+ breakpoint: "0",
+ });
+ expect(Array.from(rule.styleMap.keys())).toMatchInlineSnapshot(`
+ [
+ "display",
+ "color",
+ ]
+ `);
+ });
+
+ test("delete style from rule", () => {
+ const rule = engine.addStyleRule(".c", {
+ style: style2,
+ breakpoint: "0",
+ });
+ rule.styleMap.delete("display");
+ expect(engine.cssText).toMatchInlineSnapshot(`
+ "@media all {
+ .c { color: black }
+ }"
+ `);
+ });
});
diff --git a/packages/css-engine/src/core/rules.ts b/packages/css-engine/src/core/rules.ts
index b237c455db..06a0cb2835 100644
--- a/packages/css-engine/src/core/rules.ts
+++ b/packages/css-engine/src/core/rules.ts
@@ -15,6 +15,14 @@ class StylePropertyMap {
has(property: StyleProperty) {
return this.#styleMap.has(property);
}
+ keys() {
+ return this.#styleMap.keys();
+ }
+ delete(property: StyleProperty) {
+ this.#styleMap.delete(property);
+ this.#isDirty = true;
+ this.onChange?.();
+ }
clear() {
this.#styleMap.clear();
this.#isDirty = true;
diff --git a/packages/project/src/shared/canvas-components/instance-data.ts b/packages/project/src/shared/canvas-components/instance-data.ts
index 20ce1a74b8..32dd75c60f 100644
--- a/packages/project/src/shared/canvas-components/instance-data.ts
+++ b/packages/project/src/shared/canvas-components/instance-data.ts
@@ -20,10 +20,16 @@ export type HoveredInstanceData = {
component: Instance["component"];
};
-type StyleUpdate = {
- property: StyleProperty;
- value: StyleValue;
-};
+type StyleUpdate =
+ | {
+ operation: "delete";
+ property: StyleProperty;
+ }
+ | {
+ operation: "set";
+ property: StyleProperty;
+ value: StyleValue;
+ };
export type StyleUpdates = {
id: Instance["id"];
diff --git a/packages/project/src/shared/tree-utils/set-instance-style.ts b/packages/project/src/shared/tree-utils/set-instance-style.ts
index 2580fd4c85..4a270e6072 100644
--- a/packages/project/src/shared/tree-utils/set-instance-style.ts
+++ b/packages/project/src/shared/tree-utils/set-instance-style.ts
@@ -22,7 +22,12 @@ export const setInstanceStyleMutable = (
}
for (const update of updates) {
- cssRule.style[update.property] = update.value;
+ if (update.operation === "delete") {
+ delete cssRule.style[update.property];
+ }
+ if (update.operation === "set") {
+ cssRule.style[update.property] = update.value;
+ }
}
return true;
};