Skip to content

Commit 9e392f4

Browse files
authored
feat: autocomplete remote css variables (#5119)
When user search to add css variable in advanced style section we show now added css variables as well. Can be handy to update value defined remotely. <img width="565" alt="Screenshot 2025-04-12 at 00 25 20" src="https://github.com/user-attachments/assets/fc69f417-6b04-4ca0-b876-2a1eab6d67a2" />
1 parent 8fbda55 commit 9e392f4

File tree

1 file changed

+17
-8
lines changed

1 file changed

+17
-8
lines changed

apps/builder/app/builder/shared/css-editor/add-style-input.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@ import {
2929
toValue,
3030
type CssProperty,
3131
} from "@webstudio-is/css-engine";
32+
import { composeEventHandlers } from "~/shared/event-utils";
3233
import {
3334
deleteProperty,
3435
setProperty,
35-
} from "../../features/style-panel/shared/use-style-data";
36-
import { composeEventHandlers } from "~/shared/event-utils";
36+
} from "~/builder/features/style-panel/shared/use-style-data";
37+
import { $availableVariables } from "~/builder/features/style-panel/shared/model";
3738
import { parseStyleInput } from "./parse-style-input";
3839

3940
type SearchItem = {
@@ -43,19 +44,27 @@ type SearchItem = {
4344
key: string;
4445
};
4546

46-
const autoCompleteItems: Array<SearchItem> = [];
47-
4847
const getNewPropertyDescription = (item: null | SearchItem) => {
49-
let description: string | undefined = `Create CSS variable.`;
50-
if (item && item.property in propertyDescriptions) {
48+
let description: string | undefined = "Add CSS property.";
49+
if (item?.property.startsWith("--")) {
50+
description = "Create CSS variable.";
51+
}
52+
if (item && propertyDescriptions[item.property]) {
5153
description = propertyDescriptions[item.property];
5254
}
5355
return <Box css={{ width: theme.spacing[28] }}>{description}</Box>;
5456
};
5557

5658
const getAutocompleteItems = () => {
57-
if (autoCompleteItems.length > 0) {
58-
return autoCompleteItems;
59+
const autoCompleteItems: SearchItem[] = [];
60+
for (const varValue of $availableVariables.get()) {
61+
const property = `--${varValue.value}`;
62+
autoCompleteItems.push({
63+
// consider additional properties to be custom properties
64+
key: property,
65+
property,
66+
label: property,
67+
});
5968
}
6069
for (const property in propertiesData) {
6170
autoCompleteItems.push({

0 commit comments

Comments
 (0)