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.

Reset properties with option-click (#1866)

Oleg Isonen603df8a22c1a
diff --git a/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx b/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx
index 487854454a..668b4007b4 100644
--- a/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx
+++ b/apps/builder/app/builder/features/style-panel/controls/toggle/toggle-control.tsx
@@ -11,6 +11,7 @@ export type ToggleGroupControlProps = {
value: string;
items: { child: JSX.Element; label: string; value: string }[];
onValueChange?: (value: string) => void;
+ onReset: () => void;
};
// @todo refactor this control to follow the standard interface we otherwise have for all controls
@@ -19,6 +20,7 @@ export const ToggleGroupControl = ({
value = "",
items = [],
onValueChange,
+ onReset,
}: ToggleGroupControlProps) => {
return (
<ToggleGroup
@@ -31,7 +33,14 @@ export const ToggleGroupControl = ({
{items.map(({ child, label, value }, index) => {
return (
<EnhancedTooltip key={index} content={label}>
- <ToggleGroupButton value={value}>
+ <ToggleGroupButton
+ value={value}
+ onClick={(event) => {
+ if (event.altKey) {
+ onReset?.();
+ }
+ }}
+ >
<Flex>{child}</Flex>
</ToggleGroupButton>
</EnhancedTooltip>
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
index 3fbec9ea4a..0497e779b8 100644
--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-content.tsx
@@ -271,6 +271,7 @@ export const BackgroundContent = (props: BackgroundContentProps) => {
value,
})
}
+ onReset={() => deleteProperty("backgroundRepeat")}
value={toValue(props.currentStyle.backgroundRepeat?.value)}
items={[
{
diff --git a/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx b/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
index 663e6624f2..1f6acd38ef 100644
--- a/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx
@@ -59,6 +59,7 @@ const FlexChildSectionAlign = (props: RenderCategoryProps) => {
/>
<ToggleGroupControl
onValueChange={(value) => setAlignSelf({ type: "keyword", value })}
+ onReset={() => deleteProperty("alignSelf")}
value={toValue(currentStyle.alignSelf?.value)}
items={[
{
@@ -100,7 +101,11 @@ const FlexChildSectionAlign = (props: RenderCategoryProps) => {
const FlexChildSectionSizing = (props: RenderCategoryProps) => {
const { createBatchUpdate, currentStyle } = props;
const setSizing = createBatchUpdate();
-
+ const onReset = () => {
+ setSizing.deleteProperty("flexGrow");
+ setSizing.deleteProperty("flexShrink");
+ setSizing.publish();
+ };
return (
<Grid css={{ gridTemplateColumns: "4fr auto" }}>
<PropertyName
@@ -108,13 +113,10 @@ const FlexChildSectionSizing = (props: RenderCategoryProps) => {
properties={["flexGrow", "flexShrink"]}
label="Sizing"
description="Specifies the ability of a flex item to grow or shrink"
- onReset={() => {
- setSizing.deleteProperty("flexGrow");
- setSizing.deleteProperty("flexShrink");
- setSizing.publish();
- }}
+ onReset={onReset}
/>
<ToggleGroupControl
+ onReset={onReset}
onValueChange={(value) => {
switch (value) {
case "none": {
@@ -273,6 +275,7 @@ const FlexChildSectionOrder = (props: RenderCategoryProps) => {
onReset={() => deleteProperty("order")}
/>
<ToggleGroupControl
+ onReset={() => deleteProperty("order")}
onValueChange={(value) => {
switch (value) {
case "0":
diff --git a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
index 5b69127858..bc9fce9470 100644
--- a/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/size/size.tsx
@@ -132,6 +132,7 @@ export const SizeSection = ({
onReset={() => deleteProperty("overflow")}
/>
<ToggleGroupControl
+ onReset={() => deleteProperty("overflow")}
items={[
{
child: <EyeconOpenIcon />,
diff --git a/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx b/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
index 27debfe137..d5e3781256 100644
--- a/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/typography/typography.tsx
@@ -184,7 +184,7 @@ export const TypographySectionSizing = (props: RenderCategoryProps) => {
};
export const TypographySectionAdvanced = (props: RenderCategoryProps) => {
- const { setProperty, currentStyle } = props;
+ const { setProperty, deleteProperty, currentStyle } = props;
const setTextAlign = setProperty("textAlign");
const setTextDecorationLine = setProperty("textDecorationLine");
const setTextTransform = setProperty("textTransform");
@@ -205,6 +205,7 @@ export const TypographySectionAdvanced = (props: RenderCategoryProps) => {
<ToggleGroupControl
styleSource={getStyleSource(currentStyle.textAlign)}
onValueChange={(value) => setTextAlign({ type: "keyword", value })}
+ onReset={() => deleteProperty("textAlign")}
value={String(getTextAlign(toValue(currentStyle.textAlign?.value)))}
items={[
{
@@ -234,6 +235,7 @@ export const TypographySectionAdvanced = (props: RenderCategoryProps) => {
onValueChange={(value) =>
setTextDecorationLine({ type: "keyword", value })
}
+ onReset={() => deleteProperty("textDecorationLine")}
value={toValue(currentStyle.textDecorationLine?.value)}
items={[
{
@@ -266,6 +268,7 @@ export const TypographySectionAdvanced = (props: RenderCategoryProps) => {
onValueChange={(value) =>
setTextTransform({ type: "keyword", value })
}
+ onReset={() => deleteProperty("textTransform")}
value={toValue(currentStyle.textTransform?.value)}
items={[
{
@@ -293,6 +296,7 @@ export const TypographySectionAdvanced = (props: RenderCategoryProps) => {
<ToggleGroupControl
styleSource={getStyleSource(currentStyle.fontStyle)}
onValueChange={(value) => setFontStyle({ type: "keyword", value })}
+ onReset={() => deleteProperty("fontStyle")}
value={toValue(currentStyle.fontStyle?.value)}
items={[
{
@@ -350,6 +354,7 @@ export const TypographySectionAdvancedPopover = (
onValueChange={(value) =>
setDirection({ type: "keyword", value })
}
+ onReset={() => deleteProperty("direction")}
value={toValue(currentStyle.direction?.value)}
items={[
{
@@ -374,6 +379,7 @@ export const TypographySectionAdvancedPopover = (
/>
<ToggleGroupControl
onValueChange={(value) => setHyphens({ type: "keyword", value })}
+ onReset={() => deleteProperty("hyphens")}
value={toValue(currentStyle.hyphens?.value)}
items={[
{
@@ -400,6 +406,7 @@ export const TypographySectionAdvancedPopover = (
onValueChange={(value) =>
setTextOverflow({ type: "keyword", value })
}
+ onReset={() => deleteProperty("textOverflow")}
value={toValue(currentStyle.textOverflow?.value)}
items={[
{
diff --git a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
index 00e455ad3b..39ebc3c50b 100644
--- a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
@@ -221,7 +221,7 @@ type PropertyNameInternalProps = {
label: string | ReactElement;
title?: string;
description?: React.ReactNode;
- onReset?: undefined | (() => void);
+ onReset?: () => void;
disabled?: boolean;
};
@@ -263,7 +263,11 @@ const PropertyNameInternal = ({
shrink
gap={1}
align="center"
- onClick={() => {
+ onClick={(event) => {
+ if (event.altKey) {
+ onReset?.();
+ return;
+ }
setIsOpen(true);
}}
>