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.

feat: Make local style visually more distinct (#2987)

Oleg Isonen27aa4ac70b11
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx
index 56d6d856f6..c71e4c0d71 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.stories.tsx
@@ -93,7 +93,7 @@ export const WithTruncatedItem: ComponentStory<
id: nanoid(),
label:
"Local Something Something Something Something Something Something Something Something Something Something Something",
- source: "local",
+ source: "token",
disabled: false,
states: [],
},
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
index 3791ae9e09..d75502bdd2 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source-input.tsx
@@ -31,8 +31,9 @@ import {
rawTheme,
theme,
styled,
+ Flex,
} from "@webstudio-is/design-system";
-import { CheckMarkIcon, DotIcon } from "@webstudio-is/icons";
+import { CheckMarkIcon, DotIcon, LocalStyleIcon } from "@webstudio-is/icons";
import {
forwardRef,
useState,
@@ -133,7 +134,6 @@ const TextFieldBase: ForwardRefRenderFunction<
items: value,
onSort,
});
-
return (
<TextFieldContainer
{...focusProps}
@@ -144,10 +144,29 @@ const TextFieldBase: ForwardRefRenderFunction<
}
onKeyDown={onKeyDown}
>
+ {/* We want input to be the first element in DOM so it receives the focus first */}
+ {editingItemId === undefined && (
+ <DeprecatedTextFieldInput
+ {...textFieldProps}
+ css={{
+ color: theme.colors.hiContrast,
+ fontVariantNumeric: "tabular-nums",
+ fontFamily: theme.fonts.sans,
+ fontSize: theme.deprecatedFontSize[3],
+ lineHeight: 1,
+ order: 1,
+ }}
+ value={label}
+ type={type}
+ onClick={onClick}
+ ref={mergeRefs(internalInputRef, inputRef ?? null)}
+ spellCheck={false}
+ aria-label="New Style Source Input"
+ />
+ )}
{value.map((item) => (
<StyleSource
key={item.id}
- label={item.label}
menuItems={renderStyleSourceMenuItems(item)}
id={item.id}
selected={item.id === selectedItemSelector?.styleSourceId}
@@ -174,28 +193,17 @@ const TextFieldBase: ForwardRefRenderFunction<
onEditItem?.();
onChangeItem?.({ ...item, label });
}}
- />
+ >
+ {item.source === "local" ? (
+ <Flex align="center" justify="center">
+ <LocalStyleIcon />
+ </Flex>
+ ) : (
+ item.label
+ )}
+ </StyleSource>
))}
{placementIndicator}
- {/* We want input to be the first element in DOM so it receives the focus first */}
- {editingItemId === undefined && (
- <DeprecatedTextFieldInput
- {...textFieldProps}
- css={{
- color: theme.colors.hiContrast,
- fontVariantNumeric: "tabular-nums",
- fontFamily: theme.fonts.sans,
- fontSize: theme.deprecatedFontSize[3],
- lineHeight: 1,
- }}
- value={label}
- type={type}
- onClick={onClick}
- ref={mergeRefs(internalInputRef, inputRef ?? null)}
- spellCheck={false}
- aria-label="New Style Source Input"
- />
- )}
</TextFieldContainer>
);
};
@@ -284,6 +292,7 @@ const renderMenuItems = (props: {
}) => {
return (
<>
+ <DropdownMenuLabel>{props.item.label}</DropdownMenuLabel>
{props.item.source !== "local" && (
<DropdownMenuItem onSelect={() => props.onEdit?.(props.item.id)}>
Edit Name
@@ -383,6 +392,18 @@ const renderMenuItems = (props: {
</Fragment>
);
})}
+
+ <DropdownMenuSeparator />
+ {props.item.source === "local" && (
+ <DropdownMenuItem hint>
+ Style instances without creating a token or override a token locally.
+ </DropdownMenuItem>
+ )}
+ {props.item.source !== "local" && (
+ <DropdownMenuItem hint>
+ Reuse styles across multiple instances by creating a token.
+ </DropdownMenuItem>
+ )}
</>
);
};
@@ -428,7 +449,20 @@ export const StyleSourceInput = (
},
});
- const inputProps = getInputProps();
+ const inputProps = getInputProps({
+ onKeyDown(event) {
+ if (
+ event.key === "Backspace" &&
+ label === "" &&
+ props.editingItemId === undefined
+ ) {
+ const item = value[value.length - 2];
+ if (item) {
+ props.onRemoveItem?.(item.id);
+ }
+ }
+ },
+ });
let hasNewTokenItem = false;
let hasGlobalTokenItem = false;
diff --git a/apps/builder/app/builder/features/style-panel/style-source/style-source.tsx b/apps/builder/app/builder/features/style-panel/style-source/style-source.tsx
index 3e0583da37..3d7351ee30 100644
--- a/apps/builder/app/builder/features/style-panel/style-source/style-source.tsx
+++ b/apps/builder/app/builder/features/style-panel/style-source/style-source.tsx
@@ -98,6 +98,7 @@ const Menu = (props: MenuProps) => {
<DropdownMenuPortal>
<DropdownMenuContent
onCloseAutoFocus={(event) => event.preventDefault()}
+ css={{ maxWidth: theme.spacing[24] }}
>
{props.children}
</DropdownMenuContent>
@@ -110,7 +111,6 @@ export type ItemSource = "token" | "componentToken" | "tag" | "local";
type EditableTextProps = {
label: string;
- isEditable: boolean;
isEditing: boolean;
onChangeEditing: (isEditing: boolean) => void;
onChangeValue: (value: string) => void;
@@ -118,13 +118,12 @@ type EditableTextProps = {
const EditableText = ({
label,
- isEditable,
isEditing,
onChangeEditing,
onChangeValue,
}: EditableTextProps) => {
const { ref, handlers } = useContentEditable({
- isEditable,
+ isEditable: true,
isEditing,
onChangeEditing,
onChangeValue,
@@ -160,6 +159,7 @@ const StyleSourceContainer = styled(Box, {
variants: {
source: {
local: {
+ order: 1,
backgroundColor: theme.colors.backgroundStyleSourceLocal,
[menuTriggerGradientVar]:
theme.colors.backgroundStyleSourceGradientLocal,
@@ -242,7 +242,7 @@ const StyleSourceState = styled(Text, {
type StyleSourceProps = {
id: string;
- label: string;
+ children: ReactNode;
menuItems: ReactNode;
selected: boolean;
state: undefined | string;
@@ -258,7 +258,6 @@ type StyleSourceProps = {
export const StyleSource = ({
id,
- label,
menuItems,
selected,
state,
@@ -267,6 +266,7 @@ export const StyleSource = ({
isEditing,
isDragging,
source,
+ children,
onChangeValue,
onChangeEditing,
onSelect,
@@ -287,14 +287,18 @@ export const StyleSource = ({
disabled={disabled || isEditing}
isEditing={isEditing}
onClick={onSelect}
+ tabIndex={-1}
>
- <EditableText
- isEditable={source !== "local"}
- isEditing={isEditing}
- onChangeEditing={onChangeEditing}
- onChangeValue={onChangeValue}
- label={label}
- />
+ {typeof children === "string" ? (
+ <EditableText
+ isEditing={isEditing}
+ onChangeEditing={onChangeEditing}
+ onChangeValue={onChangeValue}
+ label={children}
+ />
+ ) : (
+ children
+ )}
</StyleSourceButton>
</Flex>
{stateLabel !== undefined && (
diff --git a/packages/design-system/src/components/menu.stories.tsx b/packages/design-system/src/components/menu.stories.tsx
index 0f7bc12f4e..65c0c789b0 100644
--- a/packages/design-system/src/components/menu.stories.tsx
+++ b/packages/design-system/src/components/menu.stories.tsx
@@ -131,7 +131,8 @@ const DropdownDemo = ({ withIndicator }: { withIndicator: boolean }) => {
</DropdownMenuRadioGroup>
</>
)}
-
+ <DropdownMenuSeparator />
+ <DropdownMenuItem hint>Hint</DropdownMenuItem>
<DropdownMenuArrow />
</DropdownMenuContent>
</DropdownMenu>
diff --git a/packages/design-system/src/components/menu.tsx b/packages/design-system/src/components/menu.tsx
index 497b7d9a08..fd28d6b4e9 100644
--- a/packages/design-system/src/components/menu.tsx
+++ b/packages/design-system/src/components/menu.tsx
@@ -74,6 +74,24 @@ export const menuItemCss = css(textVariants.labelsTitleCase, {
color: theme.colors.foregroundDestructive,
},
},
+ hint: {
+ true: {
+ ...textVariants.labelsSentenceCase,
+ px: theme.spacing[5],
+ background: theme.colors.backgroundMenuHint,
+ borderRadius: theme.borderRadius[2],
+ overflow: "hidden",
+ "&::before": {
+ position: "absolute",
+ top: 0,
+ left: 0,
+ content: '""',
+ width: 2,
+ height: "100%",
+ background: theme.colors.backgroundGradientVertical,
+ },
+ },
+ },
},
});
diff --git a/packages/icons/icons/local-style.svg b/packages/icons/icons/local-style.svg
new file mode 100644
index 0000000000..58004a5371
--- /dev/null
+++ b/packages/icons/icons/local-style.svg
@@ -0,0 +1,22 @@
+<svg
+ width="16"
+ height="16"
+ viewBox="0 0 16 16"
+ fill="none"
+ xmlns="http://www.w3.org/2000/svg"
+>
+ <path
+ fill-rule="evenodd"
+ clip-rule="evenodd"
+ d="M8 7.23009C7.57479 7.23009 7.23009 7.57479 7.23009 8C7.23009 8.42521 7.57479 8.76991 8 8.76991C8.42521 8.76991 8.76991 8.42521 8.76991 8C8.76991 7.57479 8.42521 7.23009 8 7.23009ZM7 8C7 7.44772 7.44772 7 8 7C8.55228 7 9 7.44772 9 8C9 8.55228 8.55228 9 8 9C7.44772 9 7 8.55228 7 8Z"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ />
+ <path
+ fill-rule="evenodd"
+ clip-rule="evenodd"
+ d="M7.99998 3.65C5.59754 3.65 3.64998 5.59756 3.64998 8C3.64998 10.4024 5.59754 12.35 7.99998 12.35C10.4024 12.35 12.35 10.4024 12.35 8C12.35 5.59756 10.4024 3.65 7.99998 3.65ZM2.34998 8C2.34998 4.87959 4.87957 2.35 7.99998 2.35C11.1204 2.35 13.65 4.87959 13.65 8C13.65 11.1204 11.1204 13.65 7.99998 13.65C4.87957 13.65 2.34998 11.1204 2.34998 8Z"
+ />
+</svg>
diff --git a/packages/icons/src/__generated__/index.ts b/packages/icons/src/__generated__/index.ts
index 38fa7021e5..2669daaf65 100644
--- a/packages/icons/src/__generated__/index.ts
+++ b/packages/icons/src/__generated__/index.ts
@@ -123,6 +123,7 @@ export * from "./list-item";
export * from "./list-view";
export * from "./list";
export * from "./loading-dots";
+export * from "./local-style";
export * from "./maximize";
export * from "./menu-ellipses";
export * from "./mic-off";
diff --git a/packages/icons/src/__generated__/local-style.tsx b/packages/icons/src/__generated__/local-style.tsx
new file mode 100644
index 0000000000..a1d43b4ae3
--- /dev/null
+++ b/packages/icons/src/__generated__/local-style.tsx
@@ -0,0 +1,15 @@
+// Generated from icons/local-style.svg
+
+import { forwardRef } from "react";
+import type { IconProps } from "../types";
+
+// prettier-ignore
+export const LocalStyleIcon = forwardRef<SVGSVGElement, IconProps>(
+ ({ color = "currentColor", size = 16, ...props }, forwardedRef) => {
+ return (
+ <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width={size} height={size} fill={color} {...props} ref={forwardedRef}><path stroke="currentColor" strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M8 7.23a.77.77 0 1 0 0 1.54.77.77 0 0 0 0-1.54ZM7 8a1 1 0 1 1 2 0 1 1 0 0 1-2 0Z" clipRule="evenodd" /><path d="M8 3.65a4.35 4.35 0 1 0 0 8.7 4.35 4.35 0 0 0 0-8.7ZM2.35 8a5.65 5.65 0 1 1 11.3 0 5.65 5.65 0 0 1-11.3 0Z" clipRule="evenodd" /></svg>
+ );
+ }
+);
+
+LocalStyleIcon.displayName = "LocalStyleIcon";
diff --git a/packages/icons/src/__generated__/svg/index.ts b/packages/icons/src/__generated__/svg/index.ts
index ec2974edf3..edba7ea19b 100644
--- a/packages/icons/src/__generated__/svg/index.ts
+++ b/packages/icons/src/__generated__/svg/index.ts
@@ -123,6 +123,7 @@ export { ListItemIcon } from "./list-item";
export { ListViewIcon } from "./list-view";
export { ListIcon } from "./list";
export { LoadingDotsIcon } from "./loading-dots";
+export { LocalStyleIcon } from "./local-style";
export { MaximizeIcon } from "./maximize";
export { MenuEllipsesIcon } from "./menu-ellipses";
export { MicOffIcon } from "./mic-off";
diff --git a/packages/icons/src/__generated__/svg/local-style.ts b/packages/icons/src/__generated__/svg/local-style.ts
new file mode 100644
index 0000000000..c03d8cf1c8
--- /dev/null
+++ b/packages/icons/src/__generated__/svg/local-style.ts
@@ -0,0 +1 @@
+export const LocalStyleIcon = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 16 16" width="100%" height="100%" style="display: block;"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 7.23a.77.77 0 1 0 0 1.54.77.77 0 0 0 0-1.54ZM7 8a1 1 0 1 1 2 0 1 1 0 0 1-2 0Z" clip-rule="evenodd"/><path d="M8 3.65a4.35 4.35 0 1 0 0 8.7 4.35 4.35 0 0 0 0-8.7ZM2.35 8a5.65 5.65 0 1 1 11.3 0 5.65 5.65 0 0 1-11.3 0Z" clip-rule="evenodd"/></svg>`;