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.

feat: Add tooltip when transforms are unavailable (#5778)

Oleg Isonen5ed75888776b
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 376948213c..ff28495121 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
@@ -1,7 +1,13 @@
import { forwardRef, type ElementRef, type ComponentProps } from "react";
-import type { CssProperty } from "@webstudio-is/css-engine";
-import { propertyDescriptions } from "@webstudio-is/css-data";
+import { computed } from "nanostores";
+import { useStore } from "@nanostores/react";
+import { toValue, type CssProperty } from "@webstudio-is/css-engine";
import {
+ isHtmlReplacedElementTag,
+ propertyDescriptions,
+} from "@webstudio-is/css-data";
+import {
+ Box,
CssValueListArrowFocus,
CssValueListItem,
DropdownMenu,
@@ -39,8 +45,13 @@ import {
PropertyLabel,
PropertySectionLabel,
} from "../../property-label";
-import { useComputedStyleDecl, useComputedStyles } from "../../shared/model";
+import {
+ $instanceTags,
+ useComputedStyleDecl,
+ useComputedStyles,
+} from "../../shared/model";
import { createBatchUpdate } from "../../shared/use-style-data";
+import { $selectedInstance } from "~/shared/nano-states";
import { TextControl } from "../../controls";
import {
addDefaultsForTransormSection,
@@ -59,6 +70,35 @@ import { TransformAndPerspectiveOrigin } from "./transform-and-perspective-origi
const label = "Transforms";
+const transformUnavailableTooltip =
+ "Transforms don't work on display: inline. Change display to inline-block or block.";
+
+const $selectedInstanceTag = computed(
+ [$selectedInstance, $instanceTags],
+ (selectedInstance, instanceTags) => {
+ if (selectedInstance === undefined) {
+ return;
+ }
+ return instanceTags.get(selectedInstance.id);
+ }
+);
+
+const isTransformUnavailable = ({
+ display,
+ tag,
+}: {
+ display: string;
+ tag: string | undefined;
+}) => {
+ if (display === "table-column" || display === "table-column-group") {
+ return true;
+ }
+ if (display === "inline") {
+ return tag === undefined || isHtmlReplacedElementTag(tag) === false;
+ }
+ return false;
+};
+
const advancedProperties = [
"transform-origin",
"backface-visibility",
@@ -75,8 +115,8 @@ export const properties = [
const TransformAdvancedButton = forwardRef<
ElementRef<"button">,
- ComponentProps<"button">
->((props, ref) => {
+ ComponentProps<"button"> & { unavailable?: boolean }
+>(({ unavailable, ...props }, ref) => {
const readonly = useReadonly();
const styles = useComputedStyles(advancedProperties);
const styleValueSourceColor = getPriorityStyleValueSource(styles);
@@ -86,7 +126,7 @@ const TransformAdvancedButton = forwardRef<
{...props}
ref={ref}
variant={styleValueSourceColor}
- disabled={readonly}
+ disabled={readonly || unavailable}
onClick={(event) => {
if (event.altKey) {
const batch = createBatchUpdate();
@@ -105,7 +145,11 @@ const TransformAdvancedButton = forwardRef<
);
});
-const TransformAdvancedPopover = () => {
+const TransformAdvancedPopover = ({
+ unavailable,
+}: {
+ unavailable?: boolean;
+}) => {
const readonly = useReadonly();
return (
<FloatingPanel
@@ -145,7 +189,7 @@ const TransformAdvancedPopover = () => {
</Grid>
}
>
- <TransformAdvancedButton />
+ <TransformAdvancedButton unavailable={unavailable || readonly} />
</FloatingPanel>
);
};
@@ -153,6 +197,13 @@ const TransformAdvancedPopover = () => {
export const Section = () => {
const [isOpen, setIsOpen] = useOpenState(label);
const readonly = useReadonly();
+ const tag = useStore($selectedInstanceTag);
+ const display = toValue(useComputedStyleDecl("display").computedValue);
+ // Transform applies to transformable elements. The spec excludes
+ // non-replaced inline boxes, table-column boxes, and table-column-group boxes.
+ // https://drafts.csswg.org/css-transforms-1/#transformable-element
+ const unavailable = isTransformUnavailable({ display, tag });
+ const controlsDisabled = unavailable || readonly;
const styles = useComputedStyles(properties);
const isAnyTransformPropertyAdded = transformPanels.some((panel) =>
@@ -167,47 +218,58 @@ export const Section = () => {
<CollapsibleSectionRoot
fullWidth
label={label}
- isOpen={isOpen}
+ isOpen={unavailable ? false : isOpen}
onOpenChange={setIsOpen}
trigger={
<SectionTitle
- inactive={dots.length === 0}
- collapsible={dots.length !== 0}
+ inactive={unavailable || dots.length === 0}
+ collapsible={unavailable ? false : dots.length !== 0}
dots={dots}
suffix={
<Flex gap="1" align="center">
- <TransformAdvancedPopover />
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <SectionTitleButton
- disabled={readonly}
- prefix={<PlusIcon />}
- ></SectionTitleButton>
- </DropdownMenuTrigger>
- <DropdownMenuContent
- collisionPadding={16}
- css={{ width: theme.spacing[24] }}
+ <TransformAdvancedPopover unavailable={unavailable} />
+ {unavailable ? (
+ <Tooltip
+ content={transformUnavailableTooltip}
+ variant="wrapped"
>
- {transformPanels.map((panel) => (
- <DropdownMenuItem
- disabled={isTransformPanelPropertyUsed({
- panel,
- styles,
- })}
- key={panel}
- onSelect={() => {
- addDefaultsForTransormSection({
+ <Box>
+ <SectionTitleButton disabled prefix={<PlusIcon />} />
+ </Box>
+ </Tooltip>
+ ) : (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <SectionTitleButton
+ disabled={controlsDisabled}
+ prefix={<PlusIcon />}
+ />
+ </DropdownMenuTrigger>
+ <DropdownMenuContent
+ collisionPadding={16}
+ css={{ width: theme.spacing[24] }}
+ >
+ {transformPanels.map((panel) => (
+ <DropdownMenuItem
+ disabled={isTransformPanelPropertyUsed({
panel,
styles,
- });
- setIsOpen(true);
- }}
- >
- {humanizeString(panel)}
- </DropdownMenuItem>
- ))}
- </DropdownMenuContent>
- </DropdownMenu>
+ })}
+ key={panel}
+ onSelect={() => {
+ addDefaultsForTransormSection({
+ panel,
+ styles,
+ });
+ setIsOpen(true);
+ }}
+ >
+ {humanizeString(panel)}
+ </DropdownMenuItem>
+ ))}
+ </DropdownMenuContent>
+ </DropdownMenu>
+ )}
</Flex>
}
>
diff --git a/apps/builder/app/builder/features/style-panel/style-panel.tsx b/apps/builder/app/builder/features/style-panel/style-panel.tsx
index ef4d8067ba..ceda8ddd2a 100644
--- a/apps/builder/app/builder/features/style-panel/style-panel.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-panel.tsx
@@ -39,11 +39,7 @@ import {
} from "~/builder/shared/client-settings";
import { sections } from "./sections";
import { StyleSourcesSection } from "./style-source-section";
-import {
- $instanceTags,
- useComputedStyleDecl,
- useParentComputedStyleDecl,
-} from "./shared/model";
+import { $instanceTags, useParentComputedStyleDecl } from "./shared/model";
const $selectedInstanceTag = computed(
[$selectedInstance, $instanceTags],
@@ -129,7 +125,6 @@ export const StylePanel = () => {
const selectedInstanceRenderState = useStore($selectedInstanceRenderState);
const readonly = isStyleSourceLocked(useStore($selectedStyleSource));
const tag = useStore($selectedInstanceTag);
- const display = toValue(useComputedStyleDecl("display").computedValue);
const parentDisplay = toValue(
useParentComputedStyleDecl("display").computedValue
);
@@ -171,16 +166,6 @@ export const StylePanel = () => {
) {
continue;
}
- // non-replaced inline boxes cannot be transformed
- // https://drafts.csswg.org/css-transforms-1/#css-values
- if (
- category === "transforms" &&
- (display === "inline" ||
- display === "table-column" ||
- display === "table-column-group")
- ) {
- continue;
- }
all.push(<Section key={category} />);
}
diff --git a/packages/css-data/src/html-elements.ts b/packages/css-data/src/html-elements.ts
new file mode 100644
index 0000000000..e3a58be6c0
--- /dev/null
+++ b/packages/css-data/src/html-elements.ts
@@ -0,0 +1,29 @@
+/**
+ * HTML elements whose rendering is replaced by external content or a
+ * browser-provided widget.
+ *
+ * This is useful for CSS rules that distinguish regular inline boxes from
+ * replaced inline boxes.
+ */
+export const htmlReplacedElementTags = [
+ "audio",
+ "canvas",
+ "embed",
+ "iframe",
+ "img",
+ "input",
+ "object",
+ "select",
+ "textarea",
+ "video",
+] as const;
+
+const htmlReplacedElementTagSet = new Set(htmlReplacedElementTags);
+
+export const isHtmlReplacedElementTag = (
+ tag: string
+): tag is (typeof htmlReplacedElementTags)[number] => {
+ return htmlReplacedElementTagSet.has(
+ tag as (typeof htmlReplacedElementTags)[number]
+ );
+};
diff --git a/packages/css-data/src/index.ts b/packages/css-data/src/index.ts
index 566d74f38b..148845a891 100644
--- a/packages/css-data/src/index.ts
+++ b/packages/css-data/src/index.ts
@@ -1,4 +1,5 @@
export { html } from "./__generated__/html";
+export * from "./html-elements";
export * from "./__generated__/keyword-values";
export * from "./__generated__/units";
export {