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.

make default designer specific css for wrapper component static/reusable across all components

Oleg Isonen3f9815eadc13
diff --git a/apps/designer/app/canvas/features/wrapper-component/use-css.tsx b/apps/designer/app/canvas/features/wrapper-component/designer-css.tsx
similarity index 73%
rename from apps/designer/app/canvas/features/wrapper-component/use-css.tsx
rename to apps/designer/app/canvas/features/wrapper-component/designer-css.tsx
index 1a21980dce..9889079f1a 100644
--- a/apps/designer/app/canvas/features/wrapper-component/use-css.tsx
+++ b/apps/designer/app/canvas/features/wrapper-component/designer-css.tsx
@@ -1,10 +1,10 @@
-import { useMemo } from "react";
-import { css as createCss, type CSS } from "@webstudio-is/react-sdk";
+import { css as createCss, type CSS } from "@webstudio-is/design-system";
const voidElements =
"area, base, br, col, embed, hr, img, input, link, meta, source, track, wbr";
-const defaultStyle: CSS = {
+// Helper styles on for canvas in design mode
+const designerCss: CSS = {
"&": {
// When double clicking into an element to edit text, it should not select the word.
userSelect: "none",
@@ -27,6 +27,4 @@ const defaultStyle: CSS = {
},
};
-export const useCss = (css: CSS): string => {
- return useMemo(() => createCss({ ...css, ...defaultStyle })(), [css]);
-};
+export const designerClass = createCss(designerCss)();
diff --git a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
index 6cf687af22..5102358d15 100644
--- a/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
+++ b/apps/designer/app/canvas/features/wrapper-component/wrapper-component.tsx
@@ -1,16 +1,17 @@
-import { MouseEvent, FormEvent } from "react";
+import { MouseEvent, FormEvent, useMemo } from "react";
import { Suspense, lazy, useCallback } from "react";
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
import {
type Instance,
type CSS,
type OnChangeChildren,
+ css as createCss,
useUserProps,
renderWrapperComponentChildren,
components,
} from "@webstudio-is/react-sdk";
import { useTextEditingInstanceId } from "~/shared/nano-states";
-import { useCss } from "./use-css";
+import { designerClass } from "./designer-css";
import noop from "lodash.noop";
import { useSelectedElement } from "~/canvas/shared/nano-states";
@@ -52,7 +53,7 @@ export const WrapperComponentDev = ({
onChangeChildren = noop,
...rest
}: WrapperComponentDevProps) => {
- const className = useCss(css);
+ const className = useMemo(() => createCss(css)(), [css]);
const [editingInstanceId] = useTextEditingInstanceId();
const [, setSelectedElement] = useSelectedElement();
@@ -75,7 +76,7 @@ export const WrapperComponentDev = ({
...rest,
...readonlyProps,
// @todo merge className with props
- className,
+ className: `${className} ${designerClass} ${userProps.className || ""}`,
tabIndex: 0,
// @todo stop using id to free it up to the user
// we should replace id, data-component and data-id with "data-ws"=instance.id and grab the rest always over the id
diff --git a/apps/designer/app/canvas/shared/use-pointer-outline.ts b/apps/designer/app/canvas/shared/use-pointer-outline.ts
index 6b21db9b54..5845274fd5 100644
--- a/apps/designer/app/canvas/shared/use-pointer-outline.ts
+++ b/apps/designer/app/canvas/shared/use-pointer-outline.ts
@@ -1,5 +1,5 @@
import { useEffect, useRef } from "react";
-import { type Point } from "@webstudio-is/design-system";
+import type { Point } from "@webstudio-is/design-system";
// Draw a point where we think the pointer is to visualize if calculations are based on the right position
// Only needed for debugging.