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.

Show remote style source in UI (#713)

Bogdan Chadkin42c1ef8285b6
diff --git a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
index 3a5c42fb36..c37e5cf609 100644
--- a/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/menu/menu-control.tsx
@@ -41,13 +41,20 @@ export const MenuControl = ({
};
})
.filter((item) => item.icon);
+ let variant: "default" | "set" | "inherited" = "default";
+ if (styleSource === "local") {
+ variant = "set";
+ }
+ if (styleSource === "remote") {
+ variant = "inherited";
+ }
return (
<IconButtonWithMenu
+ variant={variant}
icon={items.find(({ name }) => name === currentValue)?.icon}
label={label}
items={items}
value={String(currentValue)}
- isActive={styleSource === "local"}
onChange={setValue}
onHover={(value) => setValue(value, { isEphemeral: true })}
/>
diff --git a/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsx b/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsx
index 55063744cd..f5d0cb131f 100644
--- a/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsx
+++ b/apps/designer/app/designer/features/style-panel/controls/toggle/toggle-control.tsx
@@ -20,10 +20,13 @@ export const ToggleGroupControl = ({
items = [],
onValueChange,
}: ToggleGroupControlProps) => {
- let state: undefined | "set" = undefined;
+ let state: undefined | "set" | "inherited" = undefined;
if (styleSource === "local") {
state = "set";
}
+ if (styleSource === "remote") {
+ state = "inherited";
+ }
return (
<ToggleGroup
type="single"
@@ -55,7 +58,7 @@ const ToggleGroupControlItem = styled(ToggleGroupItem, {
},
inherited: {
"&[data-state=on]": {
- color: "$colors$orange4",
+ color: "$colors$orange11",
backgroundColor: "$colors$orange4",
},
},
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
index 1060500c90..676cc35dd5 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout/layout.tsx
@@ -11,14 +11,16 @@ import { styleConfigByName } from "../../shared/configs";
const LayoutSectionFlex = ({
currentStyle,
+ setProperty,
+ deleteProperty,
createBatchUpdate,
}: {
currentStyle: RenderCategoryProps["currentStyle"];
+ setProperty: RenderCategoryProps["setProperty"];
deleteProperty: RenderCategoryProps["deleteProperty"];
createBatchUpdate: RenderCategoryProps["createBatchUpdate"];
}) => {
const batchUpdate = createBatchUpdate();
- const { setProperty, deleteProperty } = batchUpdate;
const flexWrapValue = currentStyle.flexWrap?.value;
@@ -178,9 +180,10 @@ export const LayoutSection = ({
{displayValue === "flex" || displayValue === "inline-flex" ? (
<LayoutSectionFlex
+ currentStyle={currentStyle}
+ setProperty={setProperty}
deleteProperty={deleteProperty}
createBatchUpdate={createBatchUpdate}
- currentStyle={currentStyle}
/>
) : (
styleConfigsByCategory.map((entry) =>
diff --git a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
index 47a62dc999..5ded466e5b 100644
--- a/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/layout/shared/flex-grid.tsx
@@ -33,6 +33,14 @@ export const FlexGrid = ({
const isFlexDirectionColumn =
flexDirection === "column" || flexDirection === "column-reverse";
+ let color = "$slate8";
+ if (styleSource === "local") {
+ color = "$blue9";
+ }
+ if (styleSource === "remote") {
+ color = "$orange9";
+ }
+
return (
<Grid
css={{
@@ -46,7 +54,7 @@ export const FlexGrid = ({
gap: "$spacing$1",
gridTemplateColumns: "repeat(3, 1fr)",
gridTemplateRows: "repeat(3, 1fr)",
- color: styleSource === "local" ? "$colors$blue9" : "$colors$slate8",
+ color,
}}
>
{Array.from(Array(gridSize * gridSize), (_, index) => {
diff --git a/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx b/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx
index 3a42921c92..ca7fb5c292 100644
--- a/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx
+++ b/apps/designer/app/designer/features/style-panel/sections/spacing/spacing.tsx
@@ -42,10 +42,13 @@ const Cell = ({
return null;
}
- let origin: "set" | "unset" = "unset";
+ let origin: "set" | "inherited" | "unset" = "unset";
if (styleSource === "local") {
origin = "set";
}
+ if (styleSource === "remote") {
+ origin = "inherited";
+ }
return (
<>
diff --git a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
index 6b94de3739..af9c68b84d 100644
--- a/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/css-value-input/css-value-input.tsx
@@ -418,6 +418,9 @@ export const CssValueInput = ({
if (styleSource === "local") {
state = "set" as const;
}
+ if (styleSource === "remote") {
+ state = "inherited" as const;
+ }
const prefix = icon && (
<CssValueInputIconButton
state={state}
diff --git a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
index eca12e07f2..b9b555348a 100644
--- a/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
+++ b/apps/designer/app/designer/features/style-panel/shared/property-name.tsx
@@ -43,15 +43,18 @@ export const PropertyName = ({
css={{
fontWeight: "inherit",
padding: "calc($spacing$3 / 2) $spacing$3",
- ...(styleSource === "local"
- ? {
- color: "$blue11",
- backgroundColor: "$colors$blue4",
- borderRadius: "$borderRadius$4",
- }
- : {
- color: "$hiContrast",
- }),
+ borderRadius: "$borderRadius$4",
+ ...(styleSource === "local" && {
+ color: "$blue11",
+ backgroundColor: "$blue4",
+ }),
+ ...(styleSource === "remote" && {
+ color: "$orange11",
+ backgroundColor: "$orange4",
+ }),
+ ...(styleSource === "preset" && {
+ color: "$hiContrast",
+ }),
}}
htmlFor={property.toString()}
>
diff --git a/apps/designer/app/designer/features/style-panel/shared/style-info.ts b/apps/designer/app/designer/features/style-panel/shared/style-info.ts
index 14f49280f1..790696beab 100644
--- a/apps/designer/app/designer/features/style-panel/shared/style-info.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/style-info.ts
@@ -44,16 +44,23 @@ export type StyleInfo = {
[property in StyleProperty]?: StyleValueInfo;
};
-export type StyleSource = "local" | "preset";
+export type StyleSource = "local" | "remote" | "preset";
export const getStyleSource = (
...styleValueInfos: (undefined | StyleValueInfo)[]
): StyleSource => {
+ // show source to use if at least one of control properties matches
+ // so user could see if something is set or something is inherited
for (const info of styleValueInfos) {
if (info?.local) {
return "local";
}
}
+ for (const info of styleValueInfos) {
+ if (info?.cascaded !== undefined || info?.inherited !== undefined) {
+ return "remote";
+ }
+ }
return "preset";
};
@@ -152,7 +159,7 @@ export const useStyleInfo = ({
localStyle,
browserStyle,
}: {
- localStyle: Style;
+ localStyle?: Style;
browserStyle?: Style;
}) => {
const [breakpoints] = useBreakpoints();
@@ -203,7 +210,7 @@ export const useStyleInfo = ({
const computed = browserStyle?.[property];
const inherited = inheritedInfo[property];
const cascaded = cascadedInfo[property];
- const local = localStyle[property];
+ const local = localStyle?.[property];
const value = local ?? cascaded?.value ?? inherited?.value ?? computed;
if (value) {
styleInfoData[property] = {
diff --git a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
index 171bec9241..d718063864 100644
--- a/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
+++ b/apps/designer/app/designer/features/style-panel/shared/use-style-data.ts
@@ -1,7 +1,7 @@
import { useState, useMemo, useEffect, useCallback } from "react";
import warnOnce from "warn-once";
import type { SelectedInstanceData, StyleUpdates } from "@webstudio-is/project";
-import type { Style, StyleProperty, StyleValue } from "@webstudio-is/css-data";
+import type { StyleProperty, StyleValue } from "@webstudio-is/css-data";
import { type Publish } from "~/shared/pubsub";
import { useSelectedBreakpoint } from "~/designer/shared/nano-states";
import { getCssRuleForBreakpoint } from "./get-css-rule-for-breakpoint";
@@ -55,9 +55,7 @@ export const useStyleData = ({
[selectedInstanceData?.cssRules, selectedBreakpoint]
);
- const [breakpointStyle, setBreakpointStyle] = useState(
- () => cssRule?.style as Style
- );
+ const [breakpointStyle, setBreakpointStyle] = useState(() => cssRule?.style);
const currentStyle = useStyleInfo({
localStyle: breakpointStyle,
diff --git a/packages/design-system/src/components/icon-button-with-menu.tsx b/packages/design-system/src/components/icon-button-with-menu.tsx
index ba2ff5a226..fc3d1c3430 100644
--- a/packages/design-system/src/components/icon-button-with-menu.tsx
+++ b/packages/design-system/src/components/icon-button-with-menu.tsx
@@ -2,7 +2,7 @@ import { CheckIcon, IconComponent } from "@webstudio-is/icons";
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu";
import { styled } from "../stitches.config";
import { Tooltip } from "./tooltip";
-import { DeprecatedIconButton } from "./__DEPRECATED__/icon-button";
+import { IconButton } from "./icon-button";
const StyledContent = styled(DropdownMenuPrimitive.Content, {
width: 192,
@@ -46,29 +46,6 @@ const itemIndicatorStyle = {
justifyContent: "center",
};
-const iconButtonStyle = {
- width: "$spacing$11",
- height: "$spacing$11",
- color: "$colors$gray12",
- backgroundColor: "$colors$loContrast",
- "&:focus-visible": {
- outline: "none",
- boxShadow: "inset 0 0 0 1px $colors$blue9, 0 0 0 1px $colors$blue9",
- },
-};
-
-const iconButtonActiveStyle = {
- color: "$colors$blue11",
- backgroundColor: "$colors$blue4",
- "&:hover,&:focus-visible": {
- backgroundColor: "$colors$blue4",
- },
- "&:focus-visible": {
- outline: "none",
- boxShadow: "inset 0 0 0 1px $colors$blue9, 0 0 0 1px $colors$blue9",
- },
-};
-
const arrowStyle = {
"& *": {
fill: "$colors$gray4",
@@ -86,14 +63,15 @@ const StyledItemIndicator = styled(
const StyledArrow = styled(DropdownMenuPrimitive.Arrow, arrowStyle);
export const IconButtonWithMenu = ({
+ variant,
icon: Icon,
label,
value,
items,
- isActive,
onChange,
onHover,
}: {
+ variant: "default" | "preset" | "set" | "inherited" | "active";
icon?: JSX.Element;
label?: string;
value: string;
@@ -102,7 +80,6 @@ export const IconButtonWithMenu = ({
name: string;
icon?: ReturnType<IconComponent>;
}>;
- isActive?: boolean;
onChange?: (value: string) => void;
onHover?: (value: string) => void;
}) => {
@@ -114,14 +91,7 @@ export const IconButtonWithMenu = ({
disableHoverableContent={true}
>
<DropdownMenuPrimitive.Trigger asChild>
- <DeprecatedIconButton
- css={{
- ...iconButtonStyle,
- ...(isActive && iconButtonActiveStyle),
- }}
- >
- {Icon}
- </DeprecatedIconButton>
+ <IconButton variant={variant}>{Icon}</IconButton>
</DropdownMenuPrimitive.Trigger>
</Tooltip>
<DropdownMenuPrimitive.Portal>