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: background-position indicator in position grid for keywords (#3899)
Jaya Krishna Namburu025d9ad44c37
diff --git a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsxindex e61f914e81..8872a8da78 100644--- a/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx+++ b/apps/builder/app/builder/features/style-panel/sections/backgrounds/background-position.tsx@@ -1,9 +1,34 @@import { keywordValues } from "@webstudio-is/css-data";import { Flex, Grid, PositionGrid } from "@webstudio-is/design-system";-import { getStyleSource, type StyleInfo } from "../../shared/style-info";+import {+ getStyleSource,+ type StyleInfo,+ type StyleValueInfo,+} from "../../shared/style-info";import { CssValueInputContainer } from "../../shared/css-value-input";import { NonResetablePropertyName } from "../../shared/property-name";import type { DeleteProperty, SetProperty } from "../../shared/use-style-data";+import { useMemo } from "react";++const keyworkToValue: Record<string, number> = {+ left: 0,+ right: 100,+ center: 50,+ top: 0,+ bottom: 100,+};++const calculateBackgroundPosition = (info: StyleValueInfo | undefined) => {+ if (info?.value.type === "unit") {+ return info.value.value;+ }++ if (info?.value.type === "keyword") {+ return keyworkToValue[info.value.value];+ }++ return 0;+};export const BackgroundPosition = ({currentStyle,@@ -15,9 +40,9 @@ export const BackgroundPosition = ({deleteProperty: DeleteProperty;}) => {const xInfo = currentStyle.backgroundPositionX;- const x = xInfo?.value.type === "unit" ? xInfo.value.value : 0;const yInfo = currentStyle.backgroundPositionY;- const y = yInfo?.value.type === "unit" ? yInfo.value.value : 0;+ const x = useMemo(() => calculateBackgroundPosition(xInfo), [xInfo]);+ const y = useMemo(() => calculateBackgroundPosition(yInfo), [yInfo]);return (<Flex direction="column" gap="1">