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.

Fix link default and preset styles (#1591)

Bogdan Chadkin6fb341b1ce81
diff --git a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
index 081872af28..ed30fa6e3c 100644
--- a/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
+++ b/apps/builder/app/builder/features/style-panel/shared/property-name.tsx
@@ -110,7 +110,10 @@ const PropertyPopoverContent = ({
);
}
- if (styleValueInfo?.inherited) {
+ if (
+ styleValueInfo?.inherited &&
+ styleValueInfo.preset === undefined
+ ) {
const { value, instanceId } = styleValueInfo.inherited;
const instance = instances.get(instanceId);
return (
@@ -166,7 +169,7 @@ const PropertyPopoverContent = ({
);
}
- if (styleValueInfo?.inherited) {
+ if (styleValueInfo?.inherited && styleValueInfo.preset === undefined) {
const { instanceId } = styleValueInfo.inherited;
const instance = instances.get(instanceId);
return (
diff --git a/apps/builder/app/builder/features/style-panel/shared/style-info.ts b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
index 3d4d1e75f3..9e390fbdec 100644
--- a/apps/builder/app/builder/features/style-panel/shared/style-info.ts
+++ b/apps/builder/app/builder/features/style-panel/shared/style-info.ts
@@ -101,8 +101,7 @@ export const getStyleSource = (
if (
info?.previousSource !== undefined ||
info?.nextSource !== undefined ||
- info?.cascaded !== undefined ||
- info?.inherited !== undefined
+ info?.cascaded !== undefined
) {
return "remote";
}
@@ -112,6 +111,11 @@ export const getStyleSource = (
return "preset";
}
}
+ for (const info of styleValueInfos) {
+ if (info?.inherited !== undefined) {
+ return "remote";
+ }
+ }
return "default";
};
@@ -208,7 +212,11 @@ export const getInstanceComponent = (
return instance.component;
};
-export const getPresetStyleRule = (component: string, tagName: HtmlTags) => {
+export const getPresetStyleRule = (
+ component: string,
+ tagName: HtmlTags,
+ styleSourceSelector?: StyleSourceSelector
+) => {
const meta = getComponentMeta(component);
const presetStyles = meta?.presetStyle?.[tagName];
if (presetStyles === undefined) {
@@ -216,7 +224,7 @@ export const getPresetStyleRule = (component: string, tagName: HtmlTags) => {
}
const presetStyle: Style = {};
for (const styleDecl of presetStyles) {
- if (styleDecl.state === undefined) {
+ if (styleDecl.state === styleSourceSelector?.state) {
presetStyle[styleDecl.property] = styleDecl.value;
}
}
@@ -473,7 +481,10 @@ export const useStyleInfo = () => {
const presetStyle = useMemo(() => {
const selectedInstanceId = selectedInstanceSelector?.[0];
- if (selectedInstanceId === undefined) {
+ if (
+ selectedInstanceId === undefined ||
+ selectedOrLastStyleSourceSelector === undefined
+ ) {
return;
}
const tagName = selectedInstanceIntanceToTag?.get(selectedInstanceId);
@@ -481,8 +492,17 @@ export const useStyleInfo = () => {
if (tagName === undefined || component === undefined) {
return;
}
- return getPresetStyleRule(component, tagName);
- }, [instances, selectedInstanceSelector, selectedInstanceIntanceToTag]);
+ return getPresetStyleRule(
+ component,
+ tagName,
+ selectedOrLastStyleSourceSelector
+ );
+ }, [
+ instances,
+ selectedInstanceSelector,
+ selectedInstanceIntanceToTag,
+ selectedOrLastStyleSourceSelector,
+ ]);
const htmlStyle = useMemo(() => {
const instanceId = selectedInstanceSelector?.[0];
@@ -523,8 +543,8 @@ export const useStyleInfo = () => {
nextSource?.value ??
previousSource?.value ??
cascaded?.value ??
- inherited?.value ??
preset ??
+ inherited?.value ??
defaultValue;
if (value) {
if (property === "color") {
diff --git a/packages/css-data/src/html.ts b/packages/css-data/src/html.ts
index 801c43adb6..4a864e5b26 100644
--- a/packages/css-data/src/html.ts
+++ b/packages/css-data/src/html.ts
@@ -438,6 +438,17 @@ export const sup: Styles = [
},
];
+export const a: Styles = [
+ {
+ property: "textDecorationLine",
+ value: { type: "keyword", value: "underline" },
+ },
+ {
+ property: "cursor",
+ value: { type: "keyword", value: "pointer" },
+ },
+];
+
/* lists */
// nested lists have no top/bottom margins
diff --git a/packages/react-sdk/src/components/link.ws.tsx b/packages/react-sdk/src/components/link.ws.tsx
index 29182c1dd9..ed83ac3fd4 100644
--- a/packages/react-sdk/src/components/link.ws.tsx
+++ b/packages/react-sdk/src/components/link.ws.tsx
@@ -31,6 +31,10 @@ export const meta: WsComponentMeta = {
presetStyle,
states: [
...defaultStates,
+ {
+ selector: ":visited",
+ label: "Visited",
+ },
{
category: "component-states",
selector: "[aria-current=page]",
diff --git a/packages/react-sdk/src/css/normalize.ts b/packages/react-sdk/src/css/normalize.ts
index 46350da0e9..3caaeefb46 100644
--- a/packages/react-sdk/src/css/normalize.ts
+++ b/packages/react-sdk/src/css/normalize.ts
@@ -16,9 +16,11 @@
*/
// webstudio custom opinionated presets
-import { borders } from "./presets";
+import { borders, linkColors } from "./presets";
import type { EmbedTemplateStyleDecl } from "../embed-template";
+export type Styles = EmbedTemplateStyleDecl[];
+
/**
Use a better box model (opinionated).
*/
@@ -35,7 +37,7 @@ const boxSizing = {
* box-sizing: border-box;
}
*/
-const baseStyle = [boxSizing, ...borders] satisfies EmbedTemplateStyleDecl[];
+const baseStyle = [boxSizing, ...borders] satisfies Styles;
export const div = baseStyle;
export const address = baseStyle;
@@ -61,7 +63,7 @@ export const i = baseStyle;
export const img = baseStyle;
-export const a = baseStyle;
+export const a = [boxSizing, ...borders, ...linkColors];
export const li = baseStyle;
export const ul = baseStyle;
export const ol = baseStyle;
@@ -93,7 +95,7 @@ export const html = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/**
1. Remove the margin in all browsers.
@@ -127,7 +129,7 @@ export const body = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/**
1. Add the correct height in Firefox.
@@ -146,7 +148,7 @@ export const hr = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/**
Add the correct text decoration in Chrome, Edge, and Safari.
@@ -168,7 +170,7 @@ export const b = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
export const strong = b;
/**
@@ -191,7 +193,7 @@ export const code = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
export const kbd = code;
export const samp = code;
@@ -208,7 +210,7 @@ export const small = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/**
Prevent 'sub' and 'sup' elements from affecting the line height in all browsers.
@@ -233,7 +235,7 @@ const subSupBase = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
export const sub = [
...subSupBase,
@@ -241,7 +243,7 @@ export const sub = [
property: "bottom",
value: { type: "unit", value: -0.25, unit: "em" },
},
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
export const sup = [
...subSupBase,
@@ -249,7 +251,7 @@ export const sup = [
property: "top",
value: { type: "unit", value: -0.5, unit: "em" },
},
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/*
Tabular data
@@ -286,7 +288,7 @@ export const table = [
value: { type: "keyword", value: "inherit" },
},
boxSizing,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/*
Forms
@@ -331,7 +333,7 @@ const buttonBase = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
export const input = buttonBase;
export const optgroup = buttonBase;
@@ -346,7 +348,7 @@ export const button = [
property: "textTransform",
value: { type: "keyword", value: "none" },
},
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
export const select = button;
@@ -418,7 +420,7 @@ export const legend = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/**
Add the correct vertical alignment in Chrome and Firefox.
@@ -431,7 +433,7 @@ export const progress = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
/**
Correct the cursor style of increment and decrement buttons in Safari.
@@ -494,4 +496,4 @@ export const summary = [
},
boxSizing,
...borders,
-] satisfies EmbedTemplateStyleDecl[];
+] satisfies Styles;
diff --git a/packages/react-sdk/src/css/presets.ts b/packages/react-sdk/src/css/presets.ts
index 1943a6f95b..c43d8e64f9 100644
--- a/packages/react-sdk/src/css/presets.ts
+++ b/packages/react-sdk/src/css/presets.ts
@@ -1,6 +1,6 @@
-import type { EmbedTemplateStyleDecl } from "../embed-template";
+import type { Styles } from "./normalize";
-export const borders: EmbedTemplateStyleDecl[] = [
+export const borders: Styles = [
{
property: "borderTopWidth",
value: { type: "unit", value: 1, unit: "px" },
@@ -18,3 +18,21 @@ export const borders: EmbedTemplateStyleDecl[] = [
value: { type: "unit", value: 1, unit: "px" },
},
];
+
+export const linkColors: Styles = [
+ {
+ property: "color",
+ value: { type: "rgb", r: 0, g: 0, b: 238, alpha: 1 },
+ },
+ {
+ state: ":active",
+ property: "color",
+ // chrome and safari use rgb(255, 0, 0)
+ value: { type: "rgb", r: 238, g: 0, b: 0, alpha: 1 },
+ },
+ {
+ state: ":visited",
+ property: "color",
+ value: { type: "rgb", r: 85, g: 26, b: 139, alpha: 1 },
+ },
+];