Skip to content

Commit 0c25e50

Browse files
authored
feat: preview variable values in autocomplete (#4336)
Ref #3399 Here added 2 things to improve accessibility of variables for users 1. Added color and unit values preview in autocomplete list 2. Color inputs no longer autocomplete unit values and unit inputs no longer autocomplete color values. ![Screenshot 2024-10-24 at 00 40 15](https://github.com/user-attachments/assets/2406460c-ad68-4657-97ea-0abc4080ce2f) ![Screenshot 2024-10-24 at 00 35 49](https://github.com/user-attachments/assets/36c68bb7-9365-4914-bf3d-4324be7fae96)
1 parent c28faf2 commit 0c25e50

File tree

15 files changed

+171
-68
lines changed

15 files changed

+171
-68
lines changed

apps/builder/app/builder/features/style-panel/controls/color/color-control.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import type { StyleProperty } from "@webstudio-is/css-engine";
22
import { ColorPicker } from "../../shared/color-picker";
33
import { styleConfigByName } from "../../shared/configs";
4-
import { $availableVariables, useComputedStyleDecl } from "../../shared/model";
4+
import {
5+
$availableColorVariables,
6+
useComputedStyleDecl,
7+
} from "../../shared/model";
58
import { deleteProperty, setProperty } from "../../shared/use-style-data";
69

710
export const ColorControl = ({ property }: { property: StyleProperty }) => {
@@ -19,7 +22,7 @@ export const ColorControl = ({ property }: { property: StyleProperty }) => {
1922
type: "keyword" as const,
2023
value: item.name,
2124
})),
22-
...$availableVariables.get(),
25+
...$availableColorVariables.get(),
2326
]}
2427
onChange={(styleValue) => setValue(styleValue, { isEphemeral: true })}
2528
onChangeComplete={setValue}

apps/builder/app/builder/features/style-panel/controls/text/text-control.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@ import {
66
} from "../../shared/css-value-input";
77
import { styleConfigByName } from "../../shared/configs";
88
import { deleteProperty, setProperty } from "../../shared/use-style-data";
9-
import { $availableVariables, useComputedStyleDecl } from "../../shared/model";
9+
import {
10+
$availableUnitVariables,
11+
useComputedStyleDecl,
12+
} from "../../shared/model";
1013

1114
export const TextControl = ({ property }: { property: StyleProperty }) => {
1215
const computedStyleDecl = useComputedStyleDecl(property);
@@ -26,7 +29,7 @@ export const TextControl = ({ property }: { property: StyleProperty }) => {
2629
type: "keyword" as const,
2730
value: item.name,
2831
})),
29-
...$availableVariables.get(),
32+
...$availableUnitVariables.get(),
3033
]}
3134
onChange={(styleValue) => {
3235
setIntermediateValue(styleValue);

apps/builder/app/builder/features/style-panel/sections/borders/border-color.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ import { styleConfigByName } from "../../shared/configs";
44
import { rowCss } from "./utils";
55
import { PropertyLabel, PropertyValueTooltip } from "../../property-label";
66
import { ColorPicker } from "../../shared/color-picker";
7-
import { $availableVariables, useComputedStyles } from "../../shared/model";
7+
import {
8+
$availableColorVariables,
9+
useComputedStyles,
10+
} from "../../shared/model";
811
import { createBatchUpdate } from "../../shared/use-style-data";
912

1013
export const properties = [
@@ -58,7 +61,7 @@ export const BorderColor = () => {
5861
type: "keyword" as const,
5962
value: item.name,
6063
})),
61-
...$availableVariables.get(),
64+
...$availableColorVariables.get(),
6265
]}
6366
onChange={(styleValue) => {
6467
const batch = createBatchUpdate();

apps/builder/app/builder/features/style-panel/sections/borders/border-property.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
deleteProperty,
1616
setProperty,
1717
} from "../../shared/use-style-data";
18-
import { $availableVariables, useComputedStyles } from "../../shared/model";
18+
import { $availableUnitVariables, useComputedStyles } from "../../shared/model";
1919

2020
export const BorderProperty = ({
2121
individualModeIcon,
@@ -83,7 +83,7 @@ export const BorderProperty = ({
8383
type: "keyword" as const,
8484
value: item.name,
8585
})),
86-
...$availableVariables.get(),
86+
...$availableUnitVariables.get(),
8787
]}
8888
value={value}
8989
setValue={(newValue, options) => {

apps/builder/app/builder/features/style-panel/sections/layout/layout.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { PropertyInfo, PropertyLabel } from "../../property-label";
5454
import {
5555
useComputedStyles,
5656
useComputedStyleDecl,
57-
$availableVariables,
57+
$availableUnitVariables,
5858
} from "../../shared/model";
5959
import type { ComputedStyleDecl } from "~/shared/style-object-model";
6060

@@ -161,7 +161,7 @@ const GapInput = ({
161161
type: "keyword" as const,
162162
value: item.name,
163163
})),
164-
...$availableVariables.get(),
164+
...$availableUnitVariables.get(),
165165
]}
166166
onChange={(styleValue) => {
167167
onIntermediateChange(styleValue);

apps/builder/app/builder/features/style-panel/sections/shared/input-popover.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import { theme } from "@webstudio-is/design-system";
1717
import { getInsetModifiersGroup, getSpaceModifiersGroup } from "./scrub";
1818
import type { SpaceStyleProperty } from "../space/types";
1919
import type { InsetProperty } from "../position/inset-layout";
20-
import { $availableVariables } from "../../shared/model";
20+
import { $availableUnitVariables } from "../../shared/model";
2121

2222
const slideUpAndFade = keyframes({
2323
"0%": { opacity: 0, transform: "scale(0.8)" },
@@ -50,7 +50,7 @@ const Input = ({
5050
property={property}
5151
value={value}
5252
intermediateValue={intermediateValue}
53-
getOptions={() => $availableVariables.get()}
53+
getOptions={() => $availableUnitVariables.get()}
5454
onChange={(styleValue) => {
5555
setIntermediateValue(styleValue);
5656
if (styleValue === undefined) {

apps/builder/app/builder/features/style-panel/sections/transforms/transform-rotate.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import type { StyleValue } from "@webstudio-is/css-engine";
88
import { propertySyntaxes } from "@webstudio-is/css-data";
99
import { CssValueInputContainer } from "../../shared/css-value-input";
1010
import { PropertyInlineLabel } from "../../property-label";
11-
import { $availableVariables, useComputedStyleDecl } from "../../shared/model";
11+
import {
12+
$availableUnitVariables,
13+
useComputedStyleDecl,
14+
} from "../../shared/model";
1215
import { updateTransformFunction } from "./transform-utils";
1316

1417
export const RotatePanelContent = () => {
@@ -48,7 +51,7 @@ export const RotatePanelContent = () => {
4851
<CssValueInputContainer
4952
styleSource="local"
5053
property="rotate"
51-
getOptions={() => $availableVariables.get()}
54+
getOptions={() => $availableUnitVariables.get()}
5255
value={rotateX}
5356
setValue={(value, options) =>
5457
updateTransformFunction(styleDecl, "rotateX", value, options)
@@ -68,7 +71,7 @@ export const RotatePanelContent = () => {
6871
<CssValueInputContainer
6972
styleSource="local"
7073
property="rotate"
71-
getOptions={() => $availableVariables.get()}
74+
getOptions={() => $availableUnitVariables.get()}
7275
value={rotateY}
7376
setValue={(value, options) =>
7477
updateTransformFunction(styleDecl, "rotateY", value, options)
@@ -88,7 +91,7 @@ export const RotatePanelContent = () => {
8891
<CssValueInputContainer
8992
styleSource="local"
9093
property="rotate"
91-
getOptions={() => $availableVariables.get()}
94+
getOptions={() => $availableUnitVariables.get()}
9295
value={rotateZ}
9396
setValue={(value, options) =>
9497
updateTransformFunction(styleDecl, "rotateZ", value, options)

apps/builder/app/builder/features/style-panel/sections/transforms/transform-scale.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ import {
2525
} from "../../shared/use-style-data";
2626
import type { IntermediateStyleValue } from "../../shared/css-value-input/css-value-input";
2727
import { PropertyInlineLabel } from "../../property-label";
28-
import { $availableVariables, useComputedStyleDecl } from "../../shared/model";
28+
import {
29+
$availableUnitVariables,
30+
useComputedStyleDecl,
31+
} from "../../shared/model";
2932

3033
const property: StyleProperty = "scale";
3134

@@ -97,7 +100,7 @@ export const ScalePanelContent = () => {
97100
<CssValueInput
98101
styleSource="local"
99102
property={property}
100-
getOptions={() => $availableVariables.get()}
103+
getOptions={() => $availableUnitVariables.get()}
101104
value={scaleX}
102105
intermediateValue={intermediateScalingX}
103106
onChange={(value) => {
@@ -138,7 +141,7 @@ export const ScalePanelContent = () => {
138141
<CssValueInput
139142
styleSource="local"
140143
property={property}
141-
getOptions={() => $availableVariables.get()}
144+
getOptions={() => $availableUnitVariables.get()}
142145
value={scaleY}
143146
intermediateValue={intermediateScalingY}
144147
onChange={(value) => {
@@ -179,7 +182,7 @@ export const ScalePanelContent = () => {
179182
<CssValueInput
180183
styleSource="local"
181184
property={property}
182-
getOptions={() => $availableVariables.get()}
185+
getOptions={() => $availableUnitVariables.get()}
183186
value={scaleZ}
184187
intermediateValue={intermediateScalingZ}
185188
onChange={(value) => {

apps/builder/app/builder/features/style-panel/sections/transforms/transform-translate.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,10 @@ import {
88
type StyleUpdateOptions,
99
} from "../../shared/use-style-data";
1010
import { PropertyInlineLabel } from "../../property-label";
11-
import { $availableVariables, useComputedStyleDecl } from "../../shared/model";
11+
import {
12+
$availableUnitVariables,
13+
useComputedStyleDecl,
14+
} from "../../shared/model";
1215

1316
const property: StyleProperty = "translate";
1417

@@ -58,7 +61,7 @@ export const TranslatePanelContent = () => {
5861
<CssValueInputContainer
5962
styleSource="local"
6063
property={property}
61-
getOptions={() => $availableVariables.get()}
64+
getOptions={() => $availableUnitVariables.get()}
6265
value={translateX}
6366
setValue={(newValue, options) => setAxis(0, newValue, options)}
6467
deleteProperty={(property, options) =>
@@ -78,7 +81,7 @@ export const TranslatePanelContent = () => {
7881
<CssValueInputContainer
7982
styleSource="local"
8083
property={property}
81-
getOptions={() => $availableVariables.get()}
84+
getOptions={() => $availableUnitVariables.get()}
8285
value={translateY}
8386
setValue={(newValue, options) => setAxis(1, newValue, options)}
8487
deleteProperty={(property, options) =>
@@ -98,7 +101,7 @@ export const TranslatePanelContent = () => {
98101
<CssValueInputContainer
99102
styleSource="local"
100103
property={property}
101-
getOptions={() => $availableVariables.get()}
104+
getOptions={() => $availableUnitVariables.get()}
102105
value={translateZ}
103106
setValue={(newValue, options) => setAxis(2, newValue, options)}
104107
deleteProperty={(property, options) =>

apps/builder/app/builder/features/style-panel/sections/transitions/transition-content.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ import { CssValueInputContainer } from "../../shared/css-value-input";
2323
import { parseCssFragment } from "../../shared/css-fragment";
2424
import { PropertyInlineLabel } from "../../property-label";
2525
import { TransitionProperty } from "./transition-property";
26-
import { $availableVariables, useComputedStyles } from "../../shared/model";
26+
import {
27+
$availableVariables,
28+
$availableUnitVariables,
29+
useComputedStyles,
30+
} from "../../shared/model";
2731
import {
2832
editRepeatedStyleItem,
2933
setRepeatedStyleItem,
@@ -139,7 +143,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
139143
<CssValueInputContainer
140144
property="transitionDuration"
141145
styleSource="local"
142-
getOptions={() => $availableVariables.get()}
146+
getOptions={() => $availableUnitVariables.get()}
143147
value={duration ?? properties.transitionDuration.initial}
144148
deleteProperty={() => {}}
145149
setValue={(value, options) => {
@@ -164,7 +168,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
164168
<CssValueInputContainer
165169
property="transitionDelay"
166170
styleSource="local"
167-
getOptions={() => $availableVariables.get()}
171+
getOptions={() => $availableUnitVariables.get()}
168172
value={delay ?? properties.transitionDelay.initial}
169173
deleteProperty={() => {}}
170174
setValue={(value, options) => {

0 commit comments

Comments
 (0)