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.
TypeScript accessibilityalternativecloudflarecloudflare-workersdesignfreefrontendopen-sourceradix-uireactremixweb-developmentwebflowwebsite-builderwebsite-developmentwebsiteswebstudio
fix: Normalize border style (#2867)
Oleg Isonen4f868c5a5f3d
diff --git a/fixtures/webstudio-remix-vercel/app/__generated__/index.css b/fixtures/webstudio-remix-vercel/app/__generated__/index.cssindex a4dccbc511..c92260cc4b 100644--- a/fixtures/webstudio-remix-vercel/app/__generated__/index.css+++ b/fixtures/webstudio-remix-vercel/app/__generated__/index.css@@ -232,13 +232,13 @@ html {border-right-width: 0px;border-bottom-width: 0px;border-left-width: 0px;- text-transform: none;- background-color: transparent;- background-image: none;border-top-style: solid;border-right-style: solid;border-bottom-style: solid;border-left-style: solid;+ text-transform: none;+ background-color: transparent;+ background-image: none;border-top-color: rgba(226, 232, 240, 1);border-right-color: rgba(226, 232, 240, 1);border-bottom-color: rgba(226, 232, 240, 1);@@ -289,6 +289,10 @@ html {border-right-width: 1px;border-bottom-width: 1px;border-left-width: 1px;+ border-top-style: solid;+ border-right-style: solid;+ border-bottom-style: solid;+ border-left-style: solid;display: block;}button:where([data-ws-component="Button"]) {@@ -304,6 +308,10 @@ html {border-right-width: 1px;border-bottom-width: 1px;border-left-width: 1px;+ border-top-style: solid;+ border-right-style: solid;+ border-bottom-style: solid;+ border-left-style: solid;text-transform: none;}}diff --git a/packages/react-sdk/src/css/normalize-type-check.ts b/packages/react-sdk/src/css/normalize-type-check.tsindex bf1c549c13..14e099fd35 100644--- a/packages/react-sdk/src/css/normalize-type-check.ts+++ b/packages/react-sdk/src/css/normalize-type-check.ts@@ -7,7 +7,11 @@ import type { Style } from "@webstudio-is/css-engine";const normalizeWithKeyof = { ...normalize };type ExportedTags = keyof typeof normalizeWithKeyof;+// Custom tags are needed because we need to be able to address+// elements like input `type="checkbox"` and HTML has historically terrible naming.+type CustomTags = "checkbox" | "radio";+type ExpectedTags = HtmlTags | CustomTags;-type ValidTags = ExportedTags extends HtmlTags ? ExportedTags : false;+type ValidTags = ExportedTags extends ExpectedTags ? ExportedTags : false;normalizeWithKeyof satisfies Record<ValidTags, Style>;diff --git a/packages/react-sdk/src/css/normalize.ts b/packages/react-sdk/src/css/normalize.tsindex 221c802885..78f24d1cc9 100644--- a/packages/react-sdk/src/css/normalize.ts+++ b/packages/react-sdk/src/css/normalize.ts@@ -16,28 +16,28 @@*/// webstudio custom opinionated presets-import { borders, outline } from "./presets";+import { borderStyle, borderWidth, outline } from "./presets";import type { EmbedTemplateStyleDecl } from "../embed-template";export type Styles = EmbedTemplateStyleDecl[];/**-Use a better box model (opinionated).-*/+ * Use a better box model (opinionated).+ */const boxSizing = {property: "boxSizing",value: { type: "keyword", value: "border-box" },} satisfies EmbedTemplateStyleDecl;/**- * We dont support rules like this now, implement boxSizing for each used element- * *,+ * We dont support rules like this now, implement boxSizing for each used element+ * *,* ::before,* ::after {* box-sizing: border-box;- }-*/-const baseStyle = [boxSizing, ...borders, ...outline] satisfies Styles;+ * }+ */+const baseStyle = [boxSizing, ...borderWidth, ...outline] satisfies Styles;export const div = baseStyle;export const address = baseStyle;@@ -73,10 +73,10 @@ export const span = baseStyle;// @todo for now not applied to html, as we don't have html element/**-1. Correct the line height in all browsers.-2. Prevent adjustments of font size after orientation changes in iOS.-3. Use a more readable tab size (opinionated).-*/+ * 1. Correct the line height in all browsers.+ * 2. Prevent adjustments of font size after orientation changes in iOS.+ * 3. Use a more readable tab size (opinionated).+ */export const html = [/* 1 */{@@ -94,13 +94,13 @@ export const html = [value: { type: "unit", value: 4, unit: "number" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;/**-1. Remove the margin in all browsers.-2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)-*/+ * 1. Remove the margin in all browsers.+ * 2. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)+ */export const body = [/* 1 */{@@ -136,13 +136,13 @@ export const body = [value: { type: "unit", unit: "number", value: 1.2 },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;/**-1. Add the correct height in Firefox.-2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)-*/+ * 1. Add the correct height in Firefox.+ * 2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655)+ */export const hr = [/* 1 */{@@ -155,7 +155,7 @@ export const hr = [value: { type: "keyword", value: "inherit" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;/**@@ -169,22 +169,23 @@ abbr[title] {*//**-Add the correct font weight in Edge and Safari.-*/+ * Add the correct font weight in Edge and Safari.+ */export const b = [{property: "fontWeight",value: { type: "keyword", value: "700" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;+export const strong = b;/**-1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)-2. Correct the odd 'em' font sizing in all browsers.-*/+ * 1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3)+ * 2. Correct the odd 'em' font sizing in all browsers.+ */export const code = [/* 1 */{@@ -200,7 +201,7 @@ export const code = [value: { type: "unit", value: 1, unit: "em" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;export const kbd = code;@@ -208,22 +209,20 @@ export const samp = code;export const pre = code;/**-Add the correct font size in all browsers.-*/-+ * Add the correct font size in all browsers.+ */export const small = [{property: "fontSize",value: { type: "unit", value: 80, unit: "%" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;/**-Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.-*/-+ * Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.+ */const subSupBase = [{property: "fontSize",@@ -242,7 +241,7 @@ const subSupBase = [value: { type: "keyword", value: "baseline" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;export const sub = [@@ -267,17 +266,16 @@ Tabular data*//**-1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)-2. Correct table border color inheritance in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)-*/-+ * 1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297)+ * 2. Correct table border color inheritance in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016)+ */export const table = [/* 1 */{property: "textIndent",value: { type: "unit", value: 0, unit: "number" },},- ...borders,+ ...borderWidth,/* 2 */{property: "borderTopColor",@@ -304,10 +302,9 @@ Forms*//**-1. Change the font styles in all browsers.-2. Remove the margin in Firefox and Safari.-*/-+ * 1. Change the font styles in all browsers.+ * 2. Remove the margin in Firefox and Safari.+ */const buttonBase = [/* 1 */{@@ -340,18 +337,25 @@ const buttonBase = [value: { type: "unit", value: 0, unit: "number" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;-export const input = buttonBase;+// Input and Textarea uses border style inset by default, wich we don't support in style panel.+export const input = [...buttonBase, ...borderStyle("solid")];+export const textarea = input;export const optgroup = buttonBase;-export const textarea = buttonBase;++// Radio and checkbox have by default border style "none", we are setting it here to reflect in the style panel.+export const radio = [...buttonBase, ...borderStyle("none")];+export const checkbox = [...buttonBase, ...borderStyle("none")];/**-Remove the inheritance of text transform in Edge and Firefox.-*/+ * Remove the inheritance of text transform in Edge and Firefox.+ */export const button = [...buttonBase,+ // Button uses border style outset by default, wich we don't support in style panel.+ ...borderStyle("solid"),{property: "textTransform",value: { type: "keyword", value: "none" },@@ -406,9 +410,8 @@ See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d4*//**-Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.-*/-+ * Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers.+ */export const legend = [{property: "paddingTop",@@ -427,20 +430,19 @@ export const legend = [value: { type: "unit", value: 0, unit: "number" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;/**-Add the correct vertical alignment in Chrome and Firefox.-*/-+ * Add the correct vertical alignment in Chrome and Firefox.+ */export const progress = [{property: "verticalAlign",value: { type: "keyword", value: "baseline" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;/**@@ -493,15 +495,14 @@ Interactive===========*/-/*-Add the correct display in Chrome and Safari.-*/-+/**+ * Add the correct display in Chrome and Safari.+ */export const summary = [{property: "display",value: { type: "keyword", value: "list-item" },},boxSizing,- ...borders,+ ...borderWidth,] satisfies Styles;diff --git a/packages/react-sdk/src/css/presets.ts b/packages/react-sdk/src/css/presets.tsindex fc2c86f822..278c762371 100644--- a/packages/react-sdk/src/css/presets.ts+++ b/packages/react-sdk/src/css/presets.ts@@ -1,6 +1,6 @@import type { Styles } from "./normalize";-export const borders: Styles = [+export const borderWidth: Styles = [{property: "borderTopWidth",value: { type: "unit", value: 1, unit: "px" },@@ -25,3 +25,22 @@ export const outline: Styles = [value: { type: "unit", value: 1, unit: "px" },},];++export const borderStyle = (value: string): Styles => [+ {+ property: "borderTopStyle",+ value: { type: "keyword", value },+ },+ {+ property: "borderRightStyle",+ value: { type: "keyword", value },+ },+ {+ property: "borderBottomStyle",+ value: { type: "keyword", value },+ },+ {+ property: "borderLeftStyle",+ value: { type: "keyword", value },+ },+];diff --git a/packages/sdk-components-react/src/checkbox.ws.ts b/packages/sdk-components-react/src/checkbox.ws.tsindex 40d7bb8c3a..b3d6dfaf0a 100644--- a/packages/sdk-components-react/src/checkbox.ws.ts+++ b/packages/sdk-components-react/src/checkbox.ws.ts@@ -5,13 +5,13 @@ import {type PresetStyle,defaultStates,} from "@webstudio-is/react-sdk";-import { input } from "@webstudio-is/react-sdk/css-normalize";+import { checkbox } from "@webstudio-is/react-sdk/css-normalize";import type { defaultTag } from "./checkbox";import { props } from "./__generated__/checkbox.props";const presetStyle = {input: [- ...input,+ ...checkbox,{property: "marginRight",value: { type: "unit", unit: "em", value: 0.5 },diff --git a/packages/sdk-components-react/src/radio-button.ws.ts b/packages/sdk-components-react/src/radio-button.ws.tsindex 2ae2cec42e..35e361f0e0 100644--- a/packages/sdk-components-react/src/radio-button.ws.ts+++ b/packages/sdk-components-react/src/radio-button.ws.ts@@ -6,12 +6,12 @@ import {defaultStates,} from "@webstudio-is/react-sdk";import type { defaultTag } from "./radio-button";-import { input } from "@webstudio-is/react-sdk/css-normalize";+import { radio } from "@webstudio-is/react-sdk/css-normalize";import { props } from "./__generated__/radio-button.props";const presetStyle = {input: [- ...input,+ ...radio,{property: "marginRight",value: { type: "unit", unit: "em", value: 0.5 },