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.

experimental: add backface-visibility property for transforms (#3802)

Jaya Krishna Namburu62c9f9bbcee9
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-backface-visibility.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-backface-visibility.tsx
new file mode 100644
index 0000000000..8b4ecdbc66
--- /dev/null
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-backface-visibility.tsx
@@ -0,0 +1,40 @@
+import { type StyleProperty } from "@webstudio-is/css-engine";
+import { Grid, theme } from "@webstudio-is/design-system";
+import { TextControl } from "../../controls";
+import { PropertyName } from "../../shared/property-name";
+import { styleConfigByName } from "../../shared/configs";
+import type { SectionProps } from "../shared/section";
+
+const property: StyleProperty = "backfaceVisibility";
+
+export const BackfaceVisibility = (props: SectionProps) => {
+ const { currentStyle, setProperty, deleteProperty } = props;
+ const value = currentStyle[property]?.local;
+ const { label } = styleConfigByName(property);
+
+ if (value?.type !== "keyword") {
+ return;
+ }
+
+ return (
+ <Grid
+ css={{
+ px: theme.spacing[9],
+ gridTemplateColumns: `2fr 1fr`,
+ }}
+ >
+ <PropertyName
+ label={label}
+ properties={[property]}
+ style={currentStyle}
+ onReset={() => deleteProperty(property)}
+ />
+ <TextControl
+ property={property}
+ currentStyle={currentStyle}
+ setProperty={setProperty}
+ deleteProperty={deleteProperty}
+ />
+ </Grid>
+ );
+};
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-utils.ts b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-utils.ts
index e0495af6cf..9787af0fc2 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transform-utils.ts
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transform-utils.ts
@@ -8,7 +8,7 @@ import {
} from "@webstudio-is/css-engine";
import type { DeleteProperty, SetProperty } from "../../shared/use-style-data";
import type { StyleInfo } from "../../shared/style-info";
-import type { TransformPanel } from "./transforms";
+import type { TransformPanel, transformPanelDropdown } from "./transforms";
export type TransformPanelProps = {
currentStyle: StyleInfo;
@@ -81,7 +81,7 @@ export const getHumanizedTextFromTransformLayer = (
};
export const addDefaultsForTransormSection = (props: {
- panel: TransformPanel;
+ panel: (typeof transformPanelDropdown)[number];
currentStyle: StyleInfo;
setProperty: SetProperty;
}) => {
@@ -98,6 +98,13 @@ export const addDefaultsForTransormSection = (props: {
return setProperty("scale")(scale);
}
+ case "backfaceVisibility": {
+ return setProperty("backfaceVisibility")({
+ type: "keyword",
+ value: "visible",
+ });
+ }
+
case "skew":
case "rotate": {
const value = currentStyle["transform"]?.value;
@@ -127,7 +134,7 @@ export const addDefaultsForTransormSection = (props: {
export const isTransformPanelPropertyUsed = (params: {
currentStyle: StyleInfo;
- panel: TransformPanel;
+ panel: (typeof transformPanelDropdown)[number];
}): boolean => {
const { currentStyle, panel } = params;
switch (panel) {
@@ -135,6 +142,15 @@ export const isTransformPanelPropertyUsed = (params: {
case "translate":
return currentStyle[panel]?.value.type === "tuple";
+ /*
+ backface-visibility is a keyword property. And it's default value is visible.
+ It's not inherited. So, we need to check with the local value to enable/disable in the dropdown.
+ If we check with the computed value, it will always return true.
+ https://developer.mozilla.org/en-US/docs/Web/CSS/backface-visibility#formal_definition
+ */
+ case "backfaceVisibility":
+ return currentStyle["backfaceVisibility"]?.local?.type === "keyword";
+
case "rotate": {
const rotate = currentStyle["transform"]?.value;
return (
diff --git a/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx b/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx
index e900ac4023..0ab9ce4b59 100644
--- a/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx
+++ b/apps/builder/app/builder/features/style-panel/sections/transforms/transforms.tsx
@@ -38,6 +38,7 @@ import { TranslatePanelContent } from "./transform-translate";
import { ScalePanelContent } from "./transform-scale";
import { RotatePanelContent } from "./transform-rotate";
import { SkewPanelContent } from "./transform-skew";
+import { BackfaceVisibility } from "./transform-backface-visibility";
import { humanizeString } from "~/shared/string-utils";
import { getStyleSource } from "../../shared/style-info";
import { PropertyName } from "../../shared/property-name";
@@ -51,6 +52,11 @@ export const transformPanels = [
"skew",
] as const;
+export const transformPanelDropdown = [
+ ...transformPanels,
+ "backfaceVisibility",
+] as const;
+
export type TransformPanel = (typeof transformPanels)[number];
const label = "Transforms";
@@ -58,6 +64,7 @@ export const properties = [
"translate",
"scale",
"transform",
+ "backfaceVisibility",
] satisfies Array<StyleProperty>;
export const Section = (props: SectionProps) => {
@@ -71,6 +78,9 @@ export const Section = (props: SectionProps) => {
const translateStyleSource = getStyleSource(currentStyle["translate"]);
const scaleStyleSource = getStyleSource(currentStyle["scale"]);
const rotateAndSkewStyleSrouce = getStyleSource(currentStyle["transform"]);
+ const backfaceVisibilityStyleSource = getStyleSource(
+ currentStyle["backfaceVisibility"]
+ );
const isAnyTransformPropertyAdded = transformPanels.some((panel) =>
isTransformPanelPropertyUsed({
@@ -84,6 +94,7 @@ export const Section = (props: SectionProps) => {
batch.deleteProperty("translate");
batch.deleteProperty("scale");
batch.deleteProperty("transform");
+ batch.deleteProperty("backfaceVisibility");
batch.publish();
};
@@ -106,7 +117,7 @@ export const Section = (props: SectionProps) => {
collisionPadding={16}
css={{ width: theme.spacing[20] }}
>
- {transformPanels.map((panel) => {
+ {transformPanelDropdown.map((panel) => {
return (
<DropdownMenuItem
disabled={
@@ -143,7 +154,8 @@ export const Section = (props: SectionProps) => {
color={
translateStyleSource ||
scaleStyleSource ||
- rotateAndSkewStyleSrouce
+ rotateAndSkewStyleSrouce ||
+ backfaceVisibilityStyleSource
}
>
{label}
@@ -156,16 +168,20 @@ export const Section = (props: SectionProps) => {
>
{isAnyTransformPropertyAdded === true ? (
<CssValueListArrowFocus>
- {transformPanels.map((panel, index) => (
- <TransformSection
- {...props}
- key={panel}
- index={index}
- panel={panel}
- />
- ))}
+ <Flex direction="column">
+ {transformPanels.map((panel, index) => (
+ <TransformSection
+ {...props}
+ key={panel}
+ index={index}
+ panel={panel}
+ />
+ ))}
+ </Flex>
</CssValueListArrowFocus>
) : undefined}
+
+ <BackfaceVisibility {...props} />
</CollapsibleSectionRoot>
);
};
@@ -178,6 +194,7 @@ const TransformSection = (
const property =
panel === "rotate" || panel === "skew" ? "transform" : panel;
const value = currentStyle[property]?.value;
+
if (value === undefined || value.type !== "tuple") {
return;
}