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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: Use custom logic for showing style source label for property names. (#2810)
Jaya Krishna Namburuedf39d8c4052
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.tsxindex 7abe3b353a..d1b0493c42 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@@ -121,15 +121,17 @@ const FlexChildSectionSizing = (props: RenderCategoryProps) => {const onReset = () => {setSizing.deleteProperty("flexGrow");setSizing.deleteProperty("flexShrink");+ setSizing.deleteProperty("flexBasis");setSizing.publish();};+return (<Grid css={{ gridTemplateColumns: "4fr auto" }}><PropertyNamestyle={currentStyle}- properties={["flexGrow", "flexShrink"]}+ properties={["flexGrow", "flexShrink", "flexBasis"]}label="Sizing"- description="Specifies the ability of a flex item to grow or shrink"+ description="Specifies the ability of a flex item to grow, shrink, or set its initial size within a flex container."onReset={onReset}/><ToggleGroupControldiff --git a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx b/apps/builder/app/builder/features/style-panel/shared/property-name.tsxindex 78523811d4..0cb8b792e3 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@@ -33,6 +33,7 @@ import {type StyleInfo,getStyleSource,type StyleValueInfo,+ getPriorityStyleSource,} from "./style-info";import { humanizeString } from "~/shared/string-utils";import { getInstanceLabel } from "~/shared/instance-utils";@@ -371,9 +372,18 @@ const PropertyNameInternal = ({onReset,disabled,}: PropertyNameInternalProps) => {- // When we have multiple properties, they must be originating from the same source, so we can just use one.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])+ );+return (<Flex align="center"><PropertyTooltip@@ -390,7 +400,9 @@ const PropertyNameInternal = ({color={onReset === undefined? "default"- : getStyleSource(style[property])+ : styleSourcesList.length === 0+ ? "default"+ : getPriorityStyleSource(styleSourcesList)}truncatedisabled={disabled}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.tsindex b4dce8321b..168b5ad783 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@@ -28,6 +28,7 @@ import {getInheritedInfo,getNextSourceInfo,getPreviousSourceInfo,+ getPriorityStyleSource,getStyleSource,useStyleInfo,} from "./style-info";@@ -947,4 +948,19 @@ describe("active states", () => {value: "green",});});++ test("get the style source from ['local', 'default', 'preset']", () => {+ const result = getPriorityStyleSource(["local", "default", "preset"]);+ expect(result).toBe("local");+ });++ test("get the style source from ['local', 'overwritten', 'preset']", () => {+ const result = getPriorityStyleSource(["local", "overwritten", "preset"]);+ expect(result).toBe("overwritten");+ });++ test("get the style source from ['default', 'default', 'preset']", () => {+ const result = getPriorityStyleSource(["default", "default", "preset"]);+ expect(result).toBe("preset");+ });});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.tsindex aca5b846c3..1750f997ab 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@@ -842,3 +842,23 @@ export const useStyleInfoByInstanceId = (lastStyleSource);};++export const getPriorityStyleSource = (+ styleSources: StyleSource[]+): StyleSource => {+ const customOrder: StyleSource[] = [+ "overwritten",+ "local",+ "remote",+ "preset",+ "default",+ ];++ for (const style of customOrder) {+ if (styleSources.includes(style)) {+ return style;+ }+ }++ return "default";+};