Skip to content

Commit b4cc9ff

Browse files
authored
refactor: hyphenate css-value-input (#5003)
Migrated all css-value-input internals and usages to hyphenated properties. Touched animation section a little.
1 parent bee9615 commit b4cc9ff

File tree

16 files changed

+73
-104
lines changed

16 files changed

+73
-104
lines changed

apps/builder/app/builder/features/settings-panel/props-section/animation/animation-keyframes.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ const OffsetInput = ({
6565
intermediateValue={intermediateValue}
6666
styleSource="default"
6767
/* same as offset has 0 - 100% */
68-
property={"fontStretch"}
68+
property={"font-stretch"}
6969
value={
7070
value !== undefined
7171
? {

apps/builder/app/builder/features/settings-panel/props-section/animation/animation-panel-content.tsx

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const RangeValueInput = ({
109109
styleSource="default"
110110
value={value}
111111
/* marginLeft to allow negative values */
112-
property={"marginLeft"}
112+
property={"margin-left"}
113113
unitOptions={unitOptions}
114114
intermediateValue={intermediateValue}
115115
onChange={(styleValue) => {
@@ -156,8 +156,6 @@ const EasingInput = ({
156156
StyleValue | IntermediateStyleValue
157157
>();
158158

159-
const property = "animationTimingFunction";
160-
161159
return (
162160
<CssValueInput
163161
id={id}
@@ -173,7 +171,7 @@ const EasingInput = ({
173171
value,
174172
})),
175173
]}
176-
property={property}
174+
property="animation-timing-function"
177175
intermediateValue={intermediateValue}
178176
onChange={(styleValue) => {
179177
setIntermediateValue(styleValue);

apps/builder/app/builder/features/settings-panel/props-section/animation/animation-section.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ const InsetValueInput = ({
115115
styleSource="default"
116116
value={value}
117117
/* marginLeft to allow negative values */
118-
property={"marginLeft"}
118+
property="margin-left"
119119
unitOptions={unitOptions}
120120
intermediateValue={intermediateValue}
121121
onChange={(styleValue) => {
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
import {
2-
hyphenateProperty,
3-
type CssProperty,
4-
type StyleProperty,
5-
} from "@webstudio-is/css-engine";
1+
import type { CssProperty } from "@webstudio-is/css-engine";
62
import { keywordValues } from "@webstudio-is/css-data";
73
import { ColorPicker } from "../../shared/color-picker";
84
import {
@@ -11,11 +7,7 @@ import {
117
} from "../../shared/model";
128
import { deleteProperty, setProperty } from "../../shared/use-style-data";
139

14-
export const ColorControl = ({
15-
property,
16-
}: {
17-
property: StyleProperty | CssProperty;
18-
}) => {
10+
export const ColorControl = ({ property }: { property: CssProperty }) => {
1911
const computedStyleDecl = useComputedStyleDecl(property);
2012
const value = computedStyleDecl.cascadedValue;
2113
const currentColor = computedStyleDecl.usedValue;
@@ -26,7 +18,7 @@ export const ColorControl = ({
2618
value={value}
2719
currentColor={currentColor}
2820
getOptions={() => [
29-
...(keywordValues[hyphenateProperty(property)] ?? []).map((item) => ({
21+
...(keywordValues[property] ?? []).map((item) => ({
3022
type: "keyword" as const,
3123
value: item,
3224
})),
@@ -35,9 +27,7 @@ export const ColorControl = ({
3527
onChange={(styleValue) => setValue(styleValue, { isEphemeral: true })}
3628
onChangeComplete={setValue}
3729
onAbort={() => deleteProperty(property, { isEphemeral: true })}
38-
onReset={() => {
39-
deleteProperty(property);
40-
}}
30+
onReset={() => deleteProperty(property)}
4131
/>
4232
);
4333
};

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

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@ import {
77
TupleValue,
88
TupleValueItem,
99
type StyleValue,
10-
type StyleProperty,
1110
type CssProperty,
12-
hyphenateProperty,
1311
} from "@webstudio-is/css-engine";
1412
import { Flex, Grid, PositionGrid } from "@webstudio-is/design-system";
1513
import type { ComputedStyleDecl } from "~/shared/style-object-model";
@@ -58,16 +56,14 @@ export const PositionControl = ({
5856
property,
5957
styleDecl,
6058
}: {
61-
property: StyleProperty | CssProperty;
59+
property: CssProperty;
6260
styleDecl: ComputedStyleDecl;
6361
}) => {
6462
const value = toTuple(styleDecl.cascadedValue);
65-
const keywords = (keywordValues[hyphenateProperty(property)] ?? []).map(
66-
(value) => ({
67-
type: "keyword" as const,
68-
value,
69-
})
70-
);
63+
const keywords = (keywordValues[property] ?? []).map((value) => ({
64+
type: "keyword" as const,
65+
value,
66+
}));
7167

7268
const setValue = setProperty(property);
7369

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

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
import { useState } from "react";
2-
import {
3-
hyphenateProperty,
4-
type CssProperty,
5-
type StyleProperty,
6-
type StyleValue,
7-
} from "@webstudio-is/css-engine";
2+
import type { CssProperty, StyleValue } from "@webstudio-is/css-engine";
83
import { keywordValues } from "@webstudio-is/css-data";
94
import {
105
CssValueInput,
@@ -16,11 +11,7 @@ import {
1611
useComputedStyleDecl,
1712
} from "../../shared/model";
1813

19-
export const TextControl = ({
20-
property,
21-
}: {
22-
property: StyleProperty | CssProperty;
23-
}) => {
14+
export const TextControl = ({ property }: { property: CssProperty }) => {
2415
const computedStyleDecl = useComputedStyleDecl(property);
2516
const value = computedStyleDecl.cascadedValue;
2617
const setValue = setProperty(property);
@@ -34,7 +25,7 @@ export const TextControl = ({
3425
value={value}
3526
intermediateValue={intermediateValue}
3627
getOptions={() => [
37-
...(keywordValues[hyphenateProperty(property)] ?? []).map((value) => ({
28+
...(keywordValues[property] ?? []).map((value) => ({
3829
type: "keyword" as const,
3930
value,
4031
})),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import type {
66
} from "@webstudio-is/css-engine";
77
import { toValue } from "@webstudio-is/css-engine";
88
import { numericScrubControl } from "@webstudio-is/design-system";
9-
import { camelCaseProperty, isValidDeclaration } from "@webstudio-is/css-data";
9+
import { isValidDeclaration } from "@webstudio-is/css-data";
1010
import { useModifierKeys } from "../../shared/modifier-keys";
1111
import type { StyleUpdateOptions } from "../../shared/use-style-data";
1212
import { parseIntermediateOrInvalidValue } from "../../shared/css-value-input/parse-intermediate-or-invalid-value";
@@ -85,7 +85,7 @@ export const useScrub = <P extends CssProperty>(props: {
8585
} as const;
8686

8787
if (isValidDeclaration(property, toValue(value)) === false) {
88-
value = parseIntermediateOrInvalidValue(camelCaseProperty(property), {
88+
value = parseIntermediateOrInvalidValue(property, {
8989
type: "intermediate",
9090
value: `${value.value}`,
9191
unit: value.unit,

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export const TransitionContent = ({ index }: { index: number }) => {
125125
<PropertyInlineLabel
126126
label="Property"
127127
description={propertyDescriptions.transitionProperty}
128-
properties={["transitionProperty"]}
128+
properties={["transition-property"]}
129129
/>
130130
<TransitionProperty
131131
value={property ?? propertiesData["transition-property"].initial}
@@ -138,10 +138,10 @@ export const TransitionContent = ({ index }: { index: number }) => {
138138
<PropertyInlineLabel
139139
label="Duration"
140140
description={propertyDescriptions.transitionDuration}
141-
properties={["transitionDuration"]}
141+
properties={["transition-duration"]}
142142
/>
143143
<CssValueInputContainer
144-
property="transitionDuration"
144+
property="transition-duration"
145145
styleSource="local"
146146
getOptions={() => $availableUnitVariables.get()}
147147
value={duration ?? propertiesData["transition-duration"].initial}
@@ -163,10 +163,10 @@ export const TransitionContent = ({ index }: { index: number }) => {
163163
<PropertyInlineLabel
164164
label="Delay"
165165
description={propertyDescriptions.transitionDelay}
166-
properties={["transitionDelay"]}
166+
properties={["transition-delay"]}
167167
/>
168168
<CssValueInputContainer
169-
property="transitionDelay"
169+
property="transition-delay"
170170
styleSource="local"
171171
getOptions={() => $availableUnitVariables.get()}
172172
value={delay ?? propertiesData["transition-delay"].initial}
@@ -188,10 +188,10 @@ export const TransitionContent = ({ index }: { index: number }) => {
188188
<PropertyInlineLabel
189189
label="Easing"
190190
description={propertyDescriptions.transitionTimingFunction}
191-
properties={["transitionTimingFunction"]}
191+
properties={["transition-timing-function"]}
192192
/>
193193
<CssValueInputContainer
194-
property="transitionTimingFunction"
194+
property="transition-timing-function"
195195
styleSource="local"
196196
getOptions={() => [
197197
{ type: "keyword", value: "linear" },

apps/builder/app/builder/features/style-panel/shared/color-picker.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { useDebouncedCallback } from "use-debounce";
55
import { RgbaColorPicker } from "react-colorful";
66
import { EyedropperIcon } from "@webstudio-is/icons";
77
import type {
8-
StyleProperty,
98
StyleValue,
109
KeywordValue,
1110
RgbValue,
@@ -175,7 +174,7 @@ type ColorPickerProps = {
175174
value: StyleValue;
176175
currentColor: StyleValue;
177176
getOptions?: () => Array<KeywordValue | VarValue>;
178-
property: StyleProperty | CssProperty;
177+
property: CssProperty;
179178
disabled?: boolean;
180179
};
181180

apps/builder/app/builder/features/style-panel/shared/css-value-input/css-value-input.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const WithIcons = () => {
6767
return (
6868
<CssValueInput
6969
styleSource="preset"
70-
property="alignItems"
70+
property="align-items"
7171
value={value}
7272
intermediateValue={intermediateValue}
7373
getOptions={() => [
@@ -116,7 +116,7 @@ export const WithUnits = () => {
116116
<Flex css={{ gap: theme.spacing[9] }}>
117117
<CssValueInput
118118
styleSource="preset"
119-
property="rowGap"
119+
property="row-gap"
120120
value={value}
121121
intermediateValue={intermediateValue}
122122
getOptions={() => [
@@ -172,7 +172,7 @@ export const Oversized = () => {
172172
<Flex css={{ width: 100 }}>
173173
<CssValueInput
174174
styleSource="preset"
175-
property="alignItems"
175+
property="align-items"
176176
value={value}
177177
intermediateValue={intermediateValue}
178178
onChange={(newValue) => {

0 commit comments

Comments
 (0)