Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 5 commits into from
Jul 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 31 additions & 22 deletions packages/react-sdk/src/css/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[];
Expand All @@ -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;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might not need margins, but only vertical margins, need to check browser defaults there

export const footer = baseStyle;
export const header = baseStyle;
export const main = baseStyle;
Expand All @@ -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;

Expand All @@ -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
Expand All @@ -94,7 +102,7 @@ export const html = [
value: { type: "unit", value: 4, unit: "number" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

/**
Expand Down Expand Up @@ -136,7 +144,7 @@ export const body = [
value: { type: "unit", unit: "number", value: 1.2 },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

/**
Expand All @@ -155,7 +163,8 @@ export const hr = [
value: { type: "keyword", value: "inherit" },
},
boxSizing,
...borders,
...presets.borders,
...presets.margins,
] satisfies Styles;

/**
Expand All @@ -177,7 +186,7 @@ export const b = [
value: { type: "keyword", value: "700" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;
export const strong = b;

Expand All @@ -200,7 +209,7 @@ export const code = [
value: { type: "unit", value: 1, unit: "em" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

export const kbd = code;
Expand All @@ -217,7 +226,7 @@ export const small = [
value: { type: "unit", value: 80, unit: "%" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

/**
Expand All @@ -242,7 +251,7 @@ const subSupBase = [
value: { type: "keyword", value: "baseline" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

export const sub = [
Expand Down Expand Up @@ -277,7 +286,7 @@ export const table = [
property: "textIndent",
value: { type: "unit", value: 0, unit: "number" },
},
...borders,
...presets.borders,
/* 2 */
{
property: "borderTopColor",
Expand Down Expand Up @@ -340,7 +349,7 @@ const buttonBase = [
value: { type: "unit", value: 0, unit: "number" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

export const input = buttonBase;
Expand Down Expand Up @@ -427,7 +436,7 @@ export const legend = [
value: { type: "unit", value: 0, unit: "number" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

/**
Expand All @@ -440,7 +449,7 @@ export const progress = [
value: { type: "keyword", value: "baseline" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;

/**
Expand Down Expand Up @@ -503,5 +512,5 @@ export const summary = [
value: { type: "keyword", value: "list-item" },
},
boxSizing,
...borders,
...presets.borders,
] satisfies Styles;
110 changes: 110 additions & 0 deletions packages/react-sdk/src/css/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
50 changes: 2 additions & 48 deletions packages/sdk-components-react/src/blockquote.ws.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down