Skip to content

Commit 85f83b6

Browse files
authored
refactor: accept both camel and hyphen properties everywhere (#4943)
Here improved all reusable logic to accept both camel and hyphen cases in properties. This will ease migration to hyphen style.
1 parent bdf4463 commit 85f83b6

File tree

19 files changed

+210
-102
lines changed

19 files changed

+210
-102
lines changed

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import type { StyleProperty } from "@webstudio-is/css-engine";
1+
import type { CssProperty, StyleProperty } from "@webstudio-is/css-engine";
22
import { ColorPicker } from "../../shared/color-picker";
33
import { styleConfigByName } from "../../shared/configs";
44
import {
@@ -7,7 +7,11 @@ import {
77
} from "../../shared/model";
88
import { deleteProperty, setProperty } from "../../shared/use-style-data";
99

10-
export const ColorControl = ({ property }: { property: StyleProperty }) => {
10+
export const ColorControl = ({
11+
property,
12+
}: {
13+
property: StyleProperty | CssProperty;
14+
}) => {
1115
const computedStyleDecl = useComputedStyleDecl(property);
1216
const value = computedStyleDecl.cascadedValue;
1317
const currentColor = computedStyleDecl.usedValue;

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ import {
88
import { $assets } from "~/shared/nano-states";
99
import { ImageManager } from "~/builder/shared/image-manager";
1010
import { useEffect, useState } from "react";
11-
import type { InvalidValue, StyleProperty } from "@webstudio-is/css-engine";
11+
import type {
12+
CssProperty,
13+
InvalidValue,
14+
StyleProperty,
15+
} from "@webstudio-is/css-engine";
1216
import { useComputedStyleDecl } from "../../shared/model";
1317
import {
1418
getRepeatedStyleItem,
@@ -32,7 +36,7 @@ export const ImageControl = ({
3236
property,
3337
index,
3438
}: {
35-
property: StyleProperty;
39+
property: StyleProperty | CssProperty;
3640
index: number;
3741
}) => {
3842
const assets = useStore($assets);

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { useState } from "react";
2-
import { toValue, type StyleProperty } from "@webstudio-is/css-engine";
2+
import {
3+
toValue,
4+
type CssProperty,
5+
type StyleProperty,
6+
} from "@webstudio-is/css-engine";
37
import type { IconComponent } from "@webstudio-is/icons";
48
import {
59
Box,
@@ -15,7 +19,10 @@ import {
1519
MenuCheckedIcon,
1620
theme,
1721
} from "@webstudio-is/design-system";
18-
import { declarationDescriptions } from "@webstudio-is/css-data";
22+
import {
23+
camelCaseProperty,
24+
declarationDescriptions,
25+
} from "@webstudio-is/css-data";
1926
import { humanizeString } from "~/shared/string-utils";
2027
import { setProperty } from "../../shared/use-style-data";
2128
import { useComputedStyleDecl } from "../../shared/model";
@@ -25,7 +32,7 @@ export const MenuControl = ({
2532
property,
2633
items,
2734
}: {
28-
property: StyleProperty;
35+
property: StyleProperty | CssProperty;
2936
items: Array<{
3037
name: string;
3138
label: string;
@@ -41,7 +48,7 @@ export const MenuControl = ({
4148
const Icon = currentItem?.icon ?? items[0].icon;
4249
const description =
4350
declarationDescriptions[
44-
`${property}:${
51+
`${camelCaseProperty(property)}:${
4552
descriptionValue ?? currentValue
4653
}` as keyof typeof declarationDescriptions
4754
];

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { propertyDescriptions } from "@webstudio-is/css-data";
1+
import {
2+
camelCaseProperty,
3+
propertyDescriptions,
4+
} from "@webstudio-is/css-data";
25
import {
36
TupleValue,
47
TupleValueItem,
58
type StyleValue,
69
type StyleProperty,
10+
type CssProperty,
711
} from "@webstudio-is/css-engine";
812
import { Flex, Grid, PositionGrid } from "@webstudio-is/design-system";
913
import type { ComputedStyleDecl } from "~/shared/style-object-model";
@@ -53,7 +57,7 @@ export const PositionControl = ({
5357
property,
5458
styleDecl,
5559
}: {
56-
property: StyleProperty;
60+
property: StyleProperty | CssProperty;
5761
styleDecl: ComputedStyleDecl;
5862
}) => {
5963
const { items } = styleConfigByName(property);
@@ -79,7 +83,7 @@ export const PositionControl = ({
7983
<Flex direction="column" gap="1">
8084
<PropertyInlineLabel
8185
label="Position"
82-
description={propertyDescriptions[property]}
86+
description={propertyDescriptions[camelCaseProperty(property)]}
8387
properties={[property]}
8488
/>
8589
<Flex gap="6">

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
1-
import { declarationDescriptions, parseCssValue } from "@webstudio-is/css-data";
1+
import {
2+
camelCaseProperty,
3+
declarationDescriptions,
4+
parseCssValue,
5+
} from "@webstudio-is/css-data";
26
import {
37
StyleValue,
48
toValue,
9+
type CssProperty,
510
type StyleProperty,
611
} from "@webstudio-is/css-engine";
712
import { Box, Select, theme } from "@webstudio-is/design-system";
@@ -24,7 +29,7 @@ export const SelectControl = ({
2429
index,
2530
items = styleConfigByName(property).items,
2631
}: {
27-
property: StyleProperty;
32+
property: StyleProperty | CssProperty;
2833
index?: number;
2934
items?: Array<{ label: string; name: string }>;
3035
}) => {
@@ -54,7 +59,9 @@ export const SelectControl = ({
5459
const hasDescription =
5560
options.length > 0 &&
5661
options.some(
57-
(option) => declarationDescriptions[`${property}:${option}`] !== undefined
62+
(option) =>
63+
declarationDescriptions[`${camelCaseProperty(property)}:${option}`] !==
64+
undefined
5865
);
5966

6067
return (
@@ -74,7 +81,7 @@ export const SelectControl = ({
7481
return;
7582
}
7683
// Preview on mouse enter or focus.
77-
const nextValue = parseCssValue(property, name);
84+
const nextValue = parseCssValue(camelCaseProperty(property), name);
7885
setValue(nextValue, { isEphemeral: true });
7986
}}
8087
onOpenChange={(isOpen) => {
@@ -88,7 +95,8 @@ export const SelectControl = ({
8895
return;
8996
}
9097

91-
const description = declarationDescriptions[`${property}:${option}`];
98+
const description =
99+
declarationDescriptions[`${camelCaseProperty(property)}:${option}`];
92100
return (
93101
<Box css={{ width: theme.spacing[26] }}>
94102
{description ?? `The ${noCase(property)} is ${option}`}

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
import { useState } from "react";
2-
import type { StyleProperty, StyleValue } from "@webstudio-is/css-engine";
2+
import type {
3+
CssProperty,
4+
StyleProperty,
5+
StyleValue,
6+
} from "@webstudio-is/css-engine";
37
import {
48
CssValueInput,
59
type IntermediateStyleValue,
@@ -11,7 +15,11 @@ import {
1115
useComputedStyleDecl,
1216
} from "../../shared/model";
1317

14-
export const TextControl = ({ property }: { property: StyleProperty }) => {
18+
export const TextControl = ({
19+
property,
20+
}: {
21+
property: StyleProperty | CssProperty;
22+
}) => {
1523
const computedStyleDecl = useComputedStyleDecl(property);
1624
const value = computedStyleDecl.cascadedValue;
1725
const setValue = setProperty(property);

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { useState, type JSX, type ReactNode } from "react";
2-
import { declarationDescriptions } from "@webstudio-is/css-data";
2+
import {
3+
camelCaseProperty,
4+
declarationDescriptions,
5+
} from "@webstudio-is/css-data";
36
import { AlertIcon } from "@webstudio-is/icons";
47
import {
58
Flex,
@@ -11,6 +14,7 @@ import {
1114
import {
1215
hyphenateProperty,
1316
toValue,
17+
type CssProperty,
1418
type StyleProperty,
1519
} from "@webstudio-is/css-engine";
1620
import { humanizeString } from "~/shared/string-utils";
@@ -38,7 +42,7 @@ export const ToggleGroupTooltip = ({
3842
label?: string;
3943
code?: string;
4044
description: string | undefined;
41-
properties: StyleProperty[];
45+
properties: (StyleProperty | CssProperty)[];
4246
isAdvanced?: boolean;
4347
children: ReactNode;
4448
}) => {
@@ -152,7 +156,7 @@ export const ToggleGroupControl = ({
152156
description={
153157
item.description ??
154158
declarationDescriptions[
155-
`${properties[0]}:${item.value}` as keyof typeof declarationDescriptions
159+
`${camelCaseProperty(properties[0])}:${item.value}` as keyof typeof declarationDescriptions
156160
]
157161
}
158162
properties={properties}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import { ToggleButton } from "@webstudio-is/design-system";
2-
import { declarationDescriptions } from "@webstudio-is/css-data";
3-
import { toValue, type StyleProperty } from "@webstudio-is/css-engine";
2+
import {
3+
camelCaseProperty,
4+
declarationDescriptions,
5+
} from "@webstudio-is/css-data";
6+
import {
7+
toValue,
8+
type CssProperty,
9+
type StyleProperty,
10+
} from "@webstudio-is/css-engine";
411
import type { IconComponent } from "@webstudio-is/icons";
512
import { humanizeString } from "~/shared/string-utils";
613
import { setProperty } from "../../shared/use-style-data";
@@ -11,7 +18,7 @@ export const ToggleControl = ({
1118
property,
1219
items,
1320
}: {
14-
property: StyleProperty;
21+
property: StyleProperty | CssProperty;
1522
items: Array<{
1623
name: string;
1724
label: string;
@@ -32,7 +39,7 @@ export const ToggleControl = ({
3239
computedStyleDecl.source.name !== "default" && currentItem === undefined;
3340
const description =
3441
declarationDescriptions[
35-
`${property}:${currentValue}` as keyof typeof declarationDescriptions
42+
`${camelCaseProperty(property)}:${currentValue}` as keyof typeof declarationDescriptions
3643
];
3744

3845
return (

apps/builder/app/builder/features/style-panel/property-label.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { AlertIcon, ResetIcon } from "@webstudio-is/icons";
55
import {
66
hyphenateProperty,
77
toValue,
8+
type CssProperty,
89
type StyleProperty,
910
} from "@webstudio-is/css-engine";
1011
import {
@@ -238,7 +239,7 @@ export const PropertyLabel = ({
238239
}: {
239240
label: string;
240241
description?: string;
241-
properties: [StyleProperty, ...StyleProperty[]];
242+
properties: [StyleProperty | CssProperty, ...(StyleProperty | CssProperty)[]];
242243
}) => {
243244
const styles = useComputedStyles(properties);
244245
const styleValueSourceColor = getPriorityStyleValueSource(styles);
@@ -301,7 +302,7 @@ export const PropertySectionLabel = ({
301302
}: {
302303
label: string;
303304
description: string | undefined;
304-
properties: [StyleProperty, ...StyleProperty[]];
305+
properties: [StyleProperty | CssProperty, ...(StyleProperty | CssProperty)[]];
305306
}) => {
306307
const styles = useComputedStyles(properties);
307308
const styleValueSourceColor = getPriorityStyleValueSource(styles);
@@ -371,7 +372,10 @@ export const PropertyInlineLabel = ({
371372
label: string;
372373
title?: string;
373374
description?: string;
374-
properties?: [StyleProperty, ...StyleProperty[]];
375+
properties?: [
376+
StyleProperty | CssProperty,
377+
...(StyleProperty | CssProperty)[],
378+
];
375379
disabled?: boolean;
376380
}) => {
377381
const [isOpen, setIsOpen] = useState(false);
@@ -427,7 +431,7 @@ export const PropertyValueTooltip = ({
427431
}: {
428432
label: string;
429433
description: string | undefined;
430-
properties: [StyleProperty, ...StyleProperty[]];
434+
properties: [StyleProperty | CssProperty, ...(StyleProperty | CssProperty)[]];
431435
isAdvanced?: boolean;
432436
children: ReactNode;
433437
}) => {

0 commit comments

Comments
 (0)