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.

chore: Display styles label for advanced properties behind a menu on the icon button (#3250)

Oleg Isonen84395189bb3c
diff --git a/apps/builder/app/builder/features/style-panel/controls/index.ts b/apps/builder/app/builder/features/style-panel/controls/index.ts
index cf8b9d60d2..7489539d90 100644
--- a/apps/builder/app/builder/features/style-panel/controls/index.ts
+++ b/apps/builder/app/builder/features/style-panel/controls/index.ts
@@ -5,6 +5,5 @@ export * from "./menu/menu-control";
export * from "./font-family/font-family-control";
export * from "./font-weight/font-weight-control";
export * from "./image/image-control";
-export * from "./object-position/object-position-control";
export * from "./position/position-control";
export type { ControlProps } from "./types";
diff --git a/apps/builder/app/builder/features/style-panel/controls/object-position/object-position-control.tsx b/apps/builder/app/builder/features/style-panel/controls/object-position/object-position-control.tsx
deleted file mode 100644
index 541d017f9a..0000000000
--- a/apps/builder/app/builder/features/style-panel/controls/object-position/object-position-control.tsx
+++ /dev/null
@@ -1,36 +0,0 @@
-import { Flex, IconButton, theme } from "@webstudio-is/design-system";
-import type { ControlProps } from "../types";
-import { FloatingPanel } from "~/builder/shared/floating-panel";
-import { EllipsesIcon } from "@webstudio-is/icons";
-import { PositionControl } from "../position/position-control";
-
-export const ObjectPositionControl = ({
- property,
- currentStyle,
- setProperty,
- deleteProperty,
- isAdvanced,
-}: ControlProps) => {
- return (
- <Flex justify="end">
- <FloatingPanel
- title="Object Position"
- content={
- <Flex css={{ px: theme.spacing[9], py: theme.spacing[5] }}>
- <PositionControl
- property={property}
- currentStyle={currentStyle}
- setProperty={setProperty}
- deleteProperty={deleteProperty}
- isAdvanced={isAdvanced}
- />
- </Flex>
- }
- >
- <IconButton>
- <EllipsesIcon />
- </IconButton>
- </FloatingPanel>
- </Flex>
- );
-};
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 f9bd38e3e0..f206428cd6 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
@@ -16,7 +16,7 @@ import {
GrowIcon,
OrderFirstIcon,
OrderLastIcon,
- MenuEllipsesIcon,
+ EllipsesIcon,
} from "@webstudio-is/icons";
import { FloatingPanel } from "~/builder/shared/floating-panel";
import { CollapsibleSection } from "../../shared/collapsible-section";
@@ -297,7 +297,7 @@ const FlexChildSectionSizingPopover = ({
}
>
<Flex>
- <MenuEllipsesIcon />
+ <EllipsesIcon />
</Flex>
</FloatingPanel>
);
@@ -399,7 +399,7 @@ const FlexChildSectionOrderPopover = (props: SectionProps) => {
}
>
<Flex>
- <MenuEllipsesIcon />
+ <EllipsesIcon />
</Flex>
</FloatingPanel>
);
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 153edfc7bd..0b5b8e9780 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
@@ -1,12 +1,18 @@
import type { StyleProperty } from "@webstudio-is/css-engine";
-import { Grid, Separator, styled } from "@webstudio-is/design-system";
+import {
+ Flex,
+ Grid,
+ IconButton,
+ Separator,
+ styled,
+} from "@webstudio-is/design-system";
import { styleConfigByName } from "../../shared/configs";
import type { SectionProps } from "../shared/section";
import { PropertyName } from "../../shared/property-name";
import {
+ PositionControl,
SelectControl,
TextControl,
- ObjectPositionControl,
type ControlProps,
} from "../../controls";
import {
@@ -14,10 +20,13 @@ import {
EyeconClosedIcon,
ScrollIcon,
AutoScrollIcon,
+ EllipsesIcon,
} from "@webstudio-is/icons";
import { CollapsibleSection } from "../../shared/collapsible-section";
import { theme } from "@webstudio-is/design-system";
import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";
+import { getStyleSourceColor } from "../../shared/style-info";
+import { FloatingPanel } from "~/builder/shared/floating-panel";
const SizeProperty = ({
property,
@@ -44,6 +53,50 @@ const SizeProperty = ({
);
};
+const ObjectPosition = ({
+ property,
+ currentStyle,
+ setProperty,
+ deleteProperty,
+ isAdvanced,
+}: ControlProps) => {
+ const styleSourceColor = getStyleSourceColor({
+ properties: [property],
+ currentStyle,
+ });
+
+ return (
+ <Flex justify="end">
+ <FloatingPanel
+ title="Object Position"
+ content={
+ <Flex css={{ px: theme.spacing[9], py: theme.spacing[5] }}>
+ <PositionControl
+ property={property}
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ isAdvanced={isAdvanced}
+ />
+ </Flex>
+ }
+ >
+ <IconButton
+ variant={styleSourceColor}
+ onClick={(event) => {
+ if (event.altKey) {
+ event.preventDefault();
+ deleteProperty(property);
+ }
+ }}
+ >
+ <EllipsesIcon />
+ </IconButton>
+ </FloatingPanel>
+ </Flex>
+ );
+};
+
export const properties = [
"width",
"height",
@@ -192,7 +245,7 @@ export const Section = ({
style={currentStyle}
onReset={() => deleteProperty("objectPosition")}
/>
- <ObjectPositionControl
+ <ObjectPosition
property="objectPosition"
currentStyle={currentStyle}
setProperty={setProperty}
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 3a9926aec5..4df9061c65 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
@@ -4,7 +4,6 @@ import {
EnhancedTooltip,
theme,
IconButton,
- rawTheme,
} from "@webstudio-is/design-system";
import { toValue, type StyleProperty } from "@webstudio-is/css-engine";
import type { SectionProps } from "../shared/section";
@@ -36,8 +35,8 @@ import {
} from "@webstudio-is/icons";
import { ToggleGroupControl } from "../../controls/toggle-group/toggle-group-control";
import { FloatingPanel } from "~/builder/shared/floating-panel";
-import { type StyleInfo } from "../../shared/style-info";
-import { CollapsibleSection, getDots } from "../../shared/collapsible-section";
+import { getStyleSourceColor, type StyleInfo } from "../../shared/style-info";
+import { CollapsibleSection } from "../../shared/collapsible-section";
import { forwardRef, type ComponentProps } from "react";
export const properties = [
@@ -317,25 +316,31 @@ const AdvancedOptionsButton = forwardRef<
ComponentProps<typeof IconButton> & {
currentStyle: StyleInfo;
properties: StyleProperty[];
+ onReset: () => void;
/** https://www.radix-ui.com/docs/primitives/components/collapsible#trigger */
"data-state"?: "open" | "closed";
}
->(({ currentStyle, properties, ...rest }, ref) => {
- const dots = getDots(currentStyle, properties);
- const finalDots = rest["data-state"] === "open" ? [] : dots ?? [];
- const dotColors = {
- local: rawTheme.colors.foregroundLocalFlexUi,
- overwritten: rawTheme.colors.foregroundOverwrittenFlexUi,
- remote: rawTheme.colors.foregroundRemoteFlexUi,
- };
-
- const colors = finalDots.map((dot) => dotColors[dot]);
-
+>(({ currentStyle, properties, onReset, onClick, ...rest }, ref) => {
+ const styleSourceColor = getStyleSourceColor({
+ properties,
+ currentStyle,
+ });
return (
<Flex>
<EnhancedTooltip content="More typography options">
- <IconButton {...rest} ref={ref}>
- <EllipsesIcon colors={colors} />
+ <IconButton
+ {...rest}
+ onClick={(event) => {
+ if (event.altKey) {
+ onReset();
+ return;
+ }
+ onClick?.(event);
+ }}
+ variant={styleSourceColor}
+ ref={ref}
+ >
+ <EllipsesIcon />
</IconButton>
</EnhancedTooltip>
</Flex>
@@ -344,13 +349,14 @@ const AdvancedOptionsButton = forwardRef<
AdvancedOptionsButton.displayName = "AdvancedOptionsButton";
export const TypographySectionAdvancedPopover = (props: SectionProps) => {
- const { deleteProperty, setProperty, currentStyle } = props;
+ const { deleteProperty, setProperty, createBatchUpdate, currentStyle } =
+ props;
const properties = {
whiteSpace: "whiteSpace",
direction: "direction",
hyphens: "hyphens",
textOverflow: "textOverflow",
- } as const;
+ } as const; // in Record<StyleProperty, StyleProperty>//{ [key: StyleProperty]: StyleProperty } { [key in StyleProperty]: string };
return (
<FloatingPanel
@@ -473,6 +479,13 @@ export const TypographySectionAdvancedPopover = (props: SectionProps) => {
<AdvancedOptionsButton
currentStyle={currentStyle}
properties={Object.values(properties)}
+ onReset={() => {
+ const batch = createBatchUpdate();
+ Object.values(properties).forEach((property) => {
+ batch.deleteProperty(property);
+ });
+ batch.publish();
+ }}
/>
</FloatingPanel>
);
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 2e0fe1f75e..6b42e0b7cc 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
@@ -39,7 +39,7 @@ import {
type StyleInfo,
getStyleSource,
type StyleValueInfo,
- getPriorityStyleSource,
+ getStyleSourceColor,
} from "./style-info";
import { humanizeString } from "~/shared/string-utils";
import { getInstanceLabel } from "~/shared/instance-utils";
@@ -369,7 +369,7 @@ type PropertyNameProps = Pick<
"text" | "color"
> & {
style: StyleInfo;
- properties: StyleProperty[];
+ properties: Array<StyleProperty>;
label: string | ReactElement;
title?: string;
description?: ReactNode;
@@ -389,24 +389,12 @@ export const PropertyName = ({
disabled,
}: PropertyNameProps) => {
const property = properties[0];
-
- // When there are multiple properties. We need to make a consolidated choice.
- // As we can't show multiple badges in the property name.
- // Eg: flex-grow, flex-shrink, flex-basis
- // All three managed by single section. If flex-basis is set, but if we pick only flex-grow from the three.
- // The section does't show the badge. So, we need to pick the one which is being used.
-
- const styleSourcesList = properties.map((property) =>
- getStyleSource(style[property])
- );
-
- const styleSource =
- onReset === undefined
- ? "default"
- : styleSourcesList.length === 0
- ? "default"
- : getPriorityStyleSource(styleSourcesList);
-
+ const styleSourceColor = onReset
+ ? getStyleSourceColor({
+ properties,
+ currentStyle: style,
+ })
+ : "default";
return (
<Flex align="center">
<PropertyTooltip
@@ -420,7 +408,11 @@ export const PropertyName = ({
<Flex shrink gap={1} align="center">
{typeof label === "string" && property ? (
<Label
- color={color && styleSource === "default" ? color : styleSource}
+ color={
+ color && styleSourceColor === "default"
+ ? color
+ : styleSourceColor
+ }
truncate
disabled={disabled}
text={text}
diff --git a/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts b/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts
index c83a24321f..3701ff33c4 100644
--- a/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/style-info.test.ts
@@ -29,11 +29,13 @@ import {
getInheritedInfo,
getNextSourceInfo,
getPreviousSourceInfo,
- getPriorityStyleSource,
+ __testing__,
getStyleSource,
useStyleInfo,
} from "./style-info";
+const { getPriorityStyleSource } = __testing__;
+
const toMap = <T extends { id: string }>(list: T[]) =>
new Map(list.map((item) => [item.id, item]));
diff --git a/apps/builder/app/builder/features/style-panel/shared/style-info.ts b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
index 2467f9f90e..d422092169 100644
--- a/apps/builder/app/builder/features/style-panel/shared/style-info.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
@@ -862,9 +862,7 @@ export const useStyleInfoByInstanceId = (
);
};
-export const getPriorityStyleSource = (
- styleSources: StyleSource[]
-): StyleSource => {
+const getPriorityStyleSource = (styleSources: StyleSource[]): StyleSource => {
const customOrder: StyleSource[] = [
"overwritten",
"local",
@@ -882,6 +880,28 @@ export const getPriorityStyleSource = (
return "default";
};
+export const getStyleSourceColor = ({
+ properties,
+ currentStyle,
+}: {
+ properties: Array<StyleProperty>;
+ currentStyle: StyleInfo;
+}) => {
+ // When there are multiple properties. We need to make a consolidated choice.
+ // As we can't show multiple badges in the property name.
+ // Eg: flex-grow, flex-shrink, flex-basis
+ // All three managed by single section. If flex-basis is set, but if we pick only flex-grow from the three.
+ // The section does't show the badge. So, we need to pick the one which is being used.
+
+ const styleSourcesList = properties.map((property) =>
+ getStyleSource(currentStyle[property])
+ );
+
+ return styleSourcesList.length === 0
+ ? "default"
+ : getPriorityStyleSource(styleSourcesList);
+};
+
/**
* Has any value defined on that particular instance,
* excluding preset and inherited values.
@@ -900,3 +920,7 @@ export const hasInstanceValue = (
info?.previousSource?.value
);
};
+
+export const __testing__ = {
+ getPriorityStyleSource,
+};
diff --git a/packages/icons/icons/ellipses.svg b/packages/icons/icons/ellipses.svg
new file mode 100644
index 0000000000..c4199b2426
--- /dev/null
+++ b/packages/icons/icons/ellipses.svg
@@ -0,0 +1,17 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ d="M4 8C4 8.82843 3.32843 9.5 2.5 9.5C1.67157 9.5 1 8.82843 1 8C1 7.17157 1.67157 6.5 2.5 6.5C3.32843 6.5 4 7.17157 4 8Z"
+ />
+ <path
+ d="M9.5 8C9.5 8.82843 8.82843 9.5 8 9.5C7.17157 9.5 6.5 8.82843 6.5 8C6.5 7.17157 7.17157 6.5 8 6.5C8.82843 6.5 9.5 7.17157 9.5 8Z"
+ />
+ <path
+ d="M15 8C15 8.82843 14.3284 9.5 13.5 9.5C12.6716 9.5 12 8.82843 12 8C12 7.17157 12.6716 6.5 13.5 6.5C14.3284 6.5 15 7.17157 15 8Z"
+ />
+</svg>
diff --git a/packages/icons/icons/menu-ellipses.svg b/packages/icons/icons/menu-ellipses.svg
deleted file mode 100644
index 6f856b4db2..0000000000
--- a/packages/icons/icons/menu-ellipses.svg
+++ /dev/null
@@ -1,5 +0,0 @@
-<svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg">
-<path d="M4 8C4 8.82843 3.32843 9.5 2.5 9.5C1.67157 9.5 1 8.82843 1 8C1 7.17157 1.67157 6.5 2.5 6.5C3.32843 6.5 4 7.17157 4 8Z"/>
-<path d="M9.5 8C9.5 8.82843 8.82843 9.5 8 9.5C7.17157 9.5 6.5 8.82843 6.5 8C6.5 7.17157 7.17157 6.5 8 6.5C8.82843 6.5 9.5 7.17157 9.5 8Z"/>
-<path d="M15 8C15 8.82843 14.3284 9.5 13.5 9.5C12.6716 9.5 12 8.82843 12 8C12 7.17157 12.6716 6.5 13.5 6.5C14.3284 6.5 15 7.17157 15 8Z"/>
-</svg>
diff --git a/packages/icons/src/__generated__/menu-ellipses.tsx b/packages/icons/src/__generated__/ellipses.tsx
similarity index 74%
rename from packages/icons/src/__generated__/menu-ellipses.tsx
rename to packages/icons/src/__generated__/ellipses.tsx
index 51608f5a67..d71c1fa465 100644
--- a/packages/icons/src/__generated__/menu-ellipses.tsx
+++ b/packages/icons/src/__generated__/ellipses.tsx
@@ -1,10 +1,10 @@
-// Generated from icons/menu-ellipses.svg
+// Generated from icons/ellipses.svg
import { forwardRef } from "react";
import type { IconProps } from "../types";
// prettier-ignore
-export const MenuEllipsesIcon = forwardRef<SVGSVGElement, IconProps>(
+export const EllipsesIcon = forwardRef<SVGSVGElement, IconProps>(
({ color = "currentColor", size = 16, ...props }, forwardedRef) => {
return (
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path d="M4 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM9.5 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM15 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z" /></svg>
@@ -12,4 +12,4 @@ export const MenuEllipsesIcon = forwardRef<SVGSVGElement, IconProps>(
}
);
-MenuEllipsesIcon.displayName = "MenuEllipsesIcon";
+EllipsesIcon.displayName = "EllipsesIcon";
diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.ts
index 0eefd96eb8..21b8439949 100644
--- a/packages/icons/src/__generated__/index.ts
+++ b/packages/icons/src/__generated__/index.ts
@@ -85,6 +85,7 @@ export * from "./dot";
export * from "./dotted-border";
export * from "./drag-handle";
export * from "./dynamic-page";
+export * from "./ellipses";
export * from "./email";
export * from "./embed";
export * from "./extension";
@@ -126,7 +127,6 @@ export * from "./list";
export * from "./loading-dots";
export * from "./local-style";
export * from "./maximize";
-export * from "./menu-ellipses";
export * from "./mic-off";
export * from "./mic";
export * from "./minimize";
diff --git a/packages/icons/src/__generated__/svg/ellipses.ts b/packages/icons/src/__generated__/svg/ellipses.ts
new file mode 100644
index 0000000000..7bad156f45
--- /dev/null
+++ b/packages/icons/src/__generated__/svg/ellipses.ts
@@ -0,0 +1 @@
+export const EllipsesIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path d="M4 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM9.5 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM15 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z"/></svg>`;
diff --git a/packages/icons/src/__generated__/svg/index.ts b/packages/icons/src/__generated__/svg/index.ts
index 852b91fe77..8b25abf84b 100644
--- a/packages/icons/src/__generated__/svg/index.ts
+++ b/packages/icons/src/__generated__/svg/index.ts
@@ -85,6 +85,7 @@ export { DotIcon } from "./dot";
export { DottedBorderIcon } from "./dotted-border";
export { DragHandleIcon } from "./drag-handle";
export { DynamicPageIcon } from "./dynamic-page";
+export { EllipsesIcon } from "./ellipses";
export { EmailIcon } from "./email";
export { EmbedIcon } from "./embed";
export { ExtensionIcon } from "./extension";
@@ -126,7 +127,6 @@ export { ListIcon } from "./list";
export { LoadingDotsIcon } from "./loading-dots";
export { LocalStyleIcon } from "./local-style";
export { MaximizeIcon } from "./maximize";
-export { MenuEllipsesIcon } from "./menu-ellipses";
export { MicOffIcon } from "./mic-off";
export { MicIcon } from "./mic";
export { MinimizeIcon } from "./minimize";
diff --git a/packages/icons/src/__generated__/svg/menu-ellipses.ts b/packages/icons/src/__generated__/svg/menu-ellipses.ts
deleted file mode 100644
index 9941ab8ed4..0000000000
--- a/packages/icons/src/__generated__/svg/menu-ellipses.ts
+++ /dev/null
@@ -1 +0,0 @@
-export const MenuEllipsesIcon = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" fill="currentColor" width="100%" height="100%" style="display: block;"><path d="M4 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM9.5 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0ZM15 8a1.5 1.5 0 1 1-3 0 1.5 1.5 0 0 1 3 0Z"/></svg>`;
diff --git a/packages/icons/src/ellipses.tsx b/packages/icons/src/ellipses.tsx
deleted file mode 100644
index d69f9bdb2b..0000000000
--- a/packages/icons/src/ellipses.tsx
+++ /dev/null
@@ -1,27 +0,0 @@
-import * as React from "react";
-import type { IconProps } from "./types";
-
-type EllipsesIconProps = IconProps & {
- colors?: Array<string>;
-};
-
-export const EllipsesIcon = React.forwardRef<SVGSVGElement, EllipsesIconProps>(
- ({ color = "currentColor", colors = [], ...props }, forwardedRef) => {
- return (
- <svg
- xmlns="http://www.w3.org/2000/svg"
- fill="none"
- viewBox="0 0 16 16"
- width="16"
- height="16"
- {...props}
- ref={forwardedRef}
- >
- <circle cx="2.3" cy="8" r="1.8" fill={colors[0] ?? color} />
- <circle cx="8" cy="8" r="1.8" fill={colors[1] ?? color} />
- <circle cx="14" cy="8" r="1.8" fill={colors[2] ?? color} />
- </svg>
- );
- }
-);
-EllipsesIcon.displayName = "EllipsesIcon";
diff --git a/packages/icons/src/index.ts b/packages/icons/src/index.ts
index d8c160f522..2f300a66ef 100644
--- a/packages/icons/src/index.ts
+++ b/packages/icons/src/index.ts
@@ -22,7 +22,6 @@ export * from "./cross";
export * from "./magnifying-glass";
export * from "./cross-small";
export * from "./cross-large";
-export * from "./ellipses";
export * from "./text-align-center";
export * from "./text-align-justify";
export * from "./text-align-right";