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.

Override browser default tag based styles that use EM units (#1888)

Oleg Isonen8f53eadf5bf7
diff --git a/packages/react-sdk/src/css/normalize.ts b/packages/react-sdk/src/css/normalize.ts
index 46603b1b7d..31f715965d 100644
--- a/packages/react-sdk/src/css/normalize.ts
+++ b/packages/react-sdk/src/css/normalize.ts
@@ -16,7 +16,7 @@
*/
// webstudio custom opinionated presets
-import { borders, outline } from "./presets";
+import * as presets from "./presets";
import type { EmbedTemplateStyleDecl } from "../embed-template";
export type Styles = EmbedTemplateStyleDecl[];
@@ -37,13 +37,21 @@ const boxSizing = {
* box-sizing: border-box;
}
*/
-const baseStyle = [boxSizing, ...borders, ...outline] satisfies Styles;
+const baseStyle = [
+ boxSizing,
+ ...presets.borders,
+ ...presets.outline,
+] satisfies Styles;
export const div = baseStyle;
export const address = baseStyle;
export const article = baseStyle;
export const aside = baseStyle;
-export const figure = baseStyle;
+export const blockquote = [
+ ...baseStyle,
+ ...presets.blockquote,
+] satisfies Styles;
+export const figure = [...baseStyle, ...presets.margins] satisfies Styles;
export const footer = baseStyle;
export const header = baseStyle;
export const main = baseStyle;
@@ -52,12 +60,12 @@ export const section = baseStyle;
export const form = baseStyle;
export const label = baseStyle;
-export const h1 = baseStyle;
-export const h2 = baseStyle;
-export const h3 = baseStyle;
-export const h4 = baseStyle;
-export const h5 = baseStyle;
-export const h6 = baseStyle;
+export const h1 = [...baseStyle, ...presets.h1] satisfies Styles;
+export const h2 = [...baseStyle, ...presets.h2] satisfies Styles;
+export const h3 = [...baseStyle, ...presets.h3] satisfies Styles;
+export const h4 = [...baseStyle, ...presets.h4] satisfies Styles;
+export const h5 = [...baseStyle, ...presets.h5] satisfies Styles;
+export const h6 = [...baseStyle, ...presets.h6] satisfies Styles;
export const i = baseStyle;
@@ -68,7 +76,7 @@ export const li = baseStyle;
export const ul = baseStyle;
export const ol = baseStyle;
-export const p = baseStyle;
+export const p = [...baseStyle, ...presets.verticalMargins];
export const span = baseStyle;
// @todo for now not applied to html, as we don't have html element
@@ -94,7 +102,7 @@ export const html = [
value: { type: "unit", value: 4, unit: "number" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
/**
@@ -136,7 +144,7 @@ export const body = [
value: { type: "unit", unit: "number", value: 1.2 },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
/**
@@ -155,7 +163,8 @@ export const hr = [
value: { type: "keyword", value: "inherit" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
+ ...presets.margins,
] satisfies Styles;
/**
@@ -177,7 +186,7 @@ export const b = [
value: { type: "keyword", value: "700" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
export const strong = b;
@@ -200,7 +209,7 @@ export const code = [
value: { type: "unit", value: 1, unit: "em" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
export const kbd = code;
@@ -217,7 +226,7 @@ export const small = [
value: { type: "unit", value: 80, unit: "%" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
/**
@@ -242,7 +251,7 @@ const subSupBase = [
value: { type: "keyword", value: "baseline" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
export const sub = [
@@ -277,7 +286,7 @@ export const table = [
property: "textIndent",
value: { type: "unit", value: 0, unit: "number" },
},
- ...borders,
+ ...presets.borders,
/* 2 */
{
property: "borderTopColor",
@@ -340,7 +349,7 @@ const buttonBase = [
value: { type: "unit", value: 0, unit: "number" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
export const input = buttonBase;
@@ -427,7 +436,7 @@ export const legend = [
value: { type: "unit", value: 0, unit: "number" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
/**
@@ -440,7 +449,7 @@ export const progress = [
value: { type: "keyword", value: "baseline" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
/**
@@ -503,5 +512,5 @@ export const summary = [
value: { type: "keyword", value: "list-item" },
},
boxSizing,
- ...borders,
+ ...presets.borders,
] satisfies Styles;
diff --git a/packages/react-sdk/src/css/presets.ts b/packages/react-sdk/src/css/presets.ts
index fc2c86f822..38a62addcf 100644
--- a/packages/react-sdk/src/css/presets.ts
+++ b/packages/react-sdk/src/css/presets.ts
@@ -25,3 +25,113 @@ export const outline: Styles = [
value: { type: "unit", value: 1, unit: "px" },
},
];
+
+export const margins = [
+ {
+ property: "marginTop",
+ value: { type: "unit", value: 0, unit: "px" },
+ },
+ {
+ property: "marginRight",
+ value: { type: "unit", value: 0, unit: "px" },
+ },
+ {
+ property: "marginBottom",
+ value: { type: "unit", value: 0, unit: "px" },
+ },
+ {
+ property: "marginLeft",
+ value: { type: "unit", value: 0, unit: "px" },
+ },
+] satisfies Styles;
+
+export const verticalMargins = [
+ {
+ property: "marginTop",
+ value: { type: "unit", value: 0, unit: "px" },
+ },
+ {
+ property: "marginBottom",
+ value: { type: "unit", value: 0, unit: "px" },
+ },
+] satisfies Styles;
+
+export const blockquote = [
+ ...margins,
+ {
+ property: "paddingTop",
+ value: { type: "unit", value: 10, unit: "px" },
+ },
+ {
+ property: "paddingBottom",
+ value: { type: "unit", value: 10, unit: "px" },
+ },
+ {
+ property: "paddingLeft",
+ value: { type: "unit", value: 20, unit: "px" },
+ },
+ {
+ property: "paddingRight",
+ value: { type: "unit", value: 20, unit: "px" },
+ },
+ {
+ property: "borderLeftWidth",
+ value: { type: "unit", value: 5, unit: "px" },
+ },
+ {
+ property: "borderLeftStyle",
+ value: { type: "keyword", value: "solid" },
+ },
+ {
+ property: "borderLeftColor",
+ value: { type: "rgb", r: 226, g: 226, b: 226, alpha: 1 },
+ },
+] satisfies Styles;
+
+export const h1 = [
+ ...verticalMargins,
+ {
+ property: "fontSize",
+ value: { type: "unit", value: 38, unit: "px" },
+ },
+] satisfies Styles;
+
+export const h2 = [
+ ...verticalMargins,
+ {
+ property: "fontSize",
+ value: { type: "unit", value: 32, unit: "px" },
+ },
+] satisfies Styles;
+
+export const h3 = [
+ ...verticalMargins,
+ {
+ property: "fontSize",
+ value: { type: "unit", value: 24, unit: "px" },
+ },
+] satisfies Styles;
+
+export const h4 = [
+ ...verticalMargins,
+ {
+ property: "fontSize",
+ value: { type: "unit", value: 18, unit: "px" },
+ },
+] satisfies Styles;
+
+export const h5 = [
+ ...verticalMargins,
+ {
+ property: "fontSize",
+ value: { type: "unit", value: 14, unit: "px" },
+ },
+] satisfies Styles;
+
+export const h6 = [
+ ...verticalMargins,
+ {
+ property: "fontSize",
+ value: { type: "unit", value: 12, unit: "px" },
+ },
+] satisfies Styles;
diff --git a/packages/sdk-components-react/src/blockquote.ws.tsx b/packages/sdk-components-react/src/blockquote.ws.tsx
index 23978967a2..a0002cd6ef 100644
--- a/packages/sdk-components-react/src/blockquote.ws.tsx
+++ b/packages/sdk-components-react/src/blockquote.ws.tsx
@@ -5,58 +5,12 @@ import {
type WsComponentMeta,
type WsComponentPropsMeta,
} from "@webstudio-is/react-sdk";
+import { blockquote } from "@webstudio-is/react-sdk/css-normalize";
import type { defaultTag } from "./blockquote";
import { props } from "./__generated__/blockquote.props";
const presetStyle = {
- blockquote: [
- {
- property: "marginTop",
- value: { type: "unit", value: 0, unit: "number" },
- },
- {
- property: "marginRight",
- value: { type: "unit", value: 0, unit: "number" },
- },
- {
- property: "marginBottom",
- value: { type: "unit", value: 10, unit: "px" },
- },
- {
- property: "marginLeft",
- value: { type: "unit", value: 0, unit: "number" },
- },
-
- {
- property: "paddingTop",
- value: { type: "unit", value: 10, unit: "px" },
- },
- {
- property: "paddingBottom",
- value: { type: "unit", value: 10, unit: "px" },
- },
- {
- property: "paddingLeft",
- value: { type: "unit", value: 20, unit: "px" },
- },
- {
- property: "paddingRight",
- value: { type: "unit", value: 20, unit: "px" },
- },
-
- {
- property: "borderLeftWidth",
- value: { type: "unit", value: 5, unit: "px" },
- },
- {
- property: "borderLeftStyle",
- value: { type: "keyword", value: "solid" },
- },
- {
- property: "borderLeftColor",
- value: { type: "rgb", r: 226, g: 226, b: 226, alpha: 1 },
- },
- ],
+ blockquote,
} satisfies PresetStyle<typeof defaultTag>;
export const meta: WsComponentMeta = {