Skip to content

Commit 0f3a308

Browse files
authored
refactor: migrate layout and size to hyphenated properties (#4946)
First style sections migrated from camel case to hyphenated style properties.
1 parent 238e300 commit 0f3a308

File tree

9 files changed

+106
-118
lines changed

9 files changed

+106
-118
lines changed

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
import { useState } from "react";
2-
import {
3-
toValue,
4-
type CssProperty,
5-
type StyleProperty,
6-
} from "@webstudio-is/css-engine";
2+
import { toValue, type CssProperty } from "@webstudio-is/css-engine";
73
import type { IconComponent } from "@webstudio-is/icons";
84
import {
95
Box,
@@ -32,7 +28,7 @@ export const MenuControl = ({
3228
property,
3329
items,
3430
}: {
35-
property: StyleProperty | CssProperty;
31+
property: CssProperty;
3632
items: Array<{
3733
name: string;
3834
label: string;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ export const ToggleGroupControl = ({
103103
items,
104104
}: {
105105
label?: string;
106-
properties: [StyleProperty, ...StyleProperty[]];
106+
properties: [CssProperty | StyleProperty, ...(CssProperty | StyleProperty)[]];
107107
items: Array<{
108108
child: JSX.Element;
109109
value: string;

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,7 @@ import {
33
camelCaseProperty,
44
declarationDescriptions,
55
} from "@webstudio-is/css-data";
6-
import {
7-
toValue,
8-
type CssProperty,
9-
type StyleProperty,
10-
} from "@webstudio-is/css-engine";
6+
import { toValue, type CssProperty } from "@webstudio-is/css-engine";
117
import type { IconComponent } from "@webstudio-is/icons";
128
import { humanizeString } from "~/shared/string-utils";
139
import { setProperty } from "../../shared/use-style-data";
@@ -18,7 +14,7 @@ export const ToggleControl = ({
1814
property,
1915
items,
2016
}: {
21-
property: StyleProperty | CssProperty;
17+
property: CssProperty;
2218
items: Array<{
2319
name: string;
2420
label: string;

apps/builder/app/builder/features/style-panel/sections/advanced/stores.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,12 +60,12 @@ export const $advancedStylesLonghands = computed(
6060
const visualProperties = new Set<CssProperty>([]);
6161
for (const { properties } of sections.values()) {
6262
for (const property of properties) {
63-
visualProperties.add(hyphenateProperty(property) as CssProperty);
63+
visualProperties.add(hyphenateProperty(property));
6464
}
6565
}
6666
for (const style of definedStyles) {
6767
const { property, value, listed } = style;
68-
const hyphenatedProperty = hyphenateProperty(property) as CssProperty;
68+
const hyphenatedProperty = hyphenateProperty(property);
6969
// When property is listed, it was added from advanced panel.
7070
// If we are in advanced mode, we show them all.
7171
if (

apps/builder/app/builder/features/style-panel/sections/flex-child/flex-child.tsx

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
FloatingPanel,
88
} from "@webstudio-is/design-system";
99
import { toValue } from "@webstudio-is/css-engine";
10-
import type { StyleProperty } from "@webstudio-is/css-engine";
10+
import type { CssProperty } from "@webstudio-is/css-engine";
1111
import {
1212
ToggleGroupControl,
1313
ToggleGroupTooltip,
@@ -37,12 +37,12 @@ import { useComputedStyleDecl, useComputedStyles } from "../../shared/model";
3737
import { createBatchUpdate, setProperty } from "../../shared/use-style-data";
3838

3939
export const properties = [
40-
"flexShrink",
41-
"flexGrow",
42-
"flexBasis",
43-
"alignSelf",
40+
"flex-shrink",
41+
"flex-grow",
42+
"flex-basis",
43+
"align-self",
4444
"order",
45-
] satisfies [StyleProperty, ...StyleProperty[]];
45+
] satisfies [CssProperty, ...CssProperty[]];
4646

4747
export const Section = () => {
4848
return (
@@ -62,11 +62,11 @@ const FlexChildSectionAlign = () => {
6262
<PropertyLabel
6363
label="Align"
6464
description={propertyDescriptions.alignSelf}
65-
properties={["alignSelf"]}
65+
properties={["align-self"]}
6666
/>
6767
<ToggleGroupControl
6868
label="Align"
69-
properties={["alignSelf"]}
69+
properties={["align-self"]}
7070
items={[
7171
{
7272
child: <XSmallIcon />,
@@ -122,7 +122,7 @@ const getSizingValue = (flexGrow: string, flexShrink: string) => {
122122
};
123123

124124
const FlexChildSectionSizing = () => {
125-
const styles = useComputedStyles(["flexGrow", "flexShrink", "flexBasis"]);
125+
const styles = useComputedStyles(["flex-grow", "flex-shrink", "flex-basis"]);
126126
const [flexGrow, flexShrink, flexBasis] = styles;
127127
const styleValueSource = getPriorityStyleValueSource(styles);
128128
const selectedValue = getSizingValue(
@@ -176,7 +176,7 @@ const FlexChildSectionSizing = () => {
176176
<PropertyLabel
177177
label="Sizing"
178178
description="Specifies the ability of a flex item to grow, shrink, or set its initial size within a flex container."
179-
properties={["flexGrow", "flexShrink", "flexBasis"]}
179+
properties={["flex-grow", "flex-shrink", "flex-basis"]}
180180
/>
181181

182182
{/* We don't support "flex" shorthand and
@@ -202,12 +202,12 @@ const FlexChildSectionSizing = () => {
202202
flexShrink = 1;
203203
}
204204
if (flexGrow !== undefined && flexShrink !== undefined) {
205-
batch.setProperty("flexGrow")({
205+
batch.setProperty("flex-grow")({
206206
type: "unit",
207207
value: flexGrow,
208208
unit: "number",
209209
});
210-
batch.setProperty("flexShrink")({
210+
batch.setProperty("flex-shrink")({
211211
type: "unit",
212212
value: flexShrink,
213213
unit: "number",
@@ -227,7 +227,7 @@ const FlexChildSectionSizing = () => {
227227
label="Sizing"
228228
code={item.codeLines.join("\n")}
229229
description={item.description}
230-
properties={["flexGrow", "flexShrink", "flexBasis"]}
230+
properties={["flex-grow", "flex-shrink", "flex-basis"]}
231231
>
232232
<ToggleGroupButton
233233
aria-checked={item.value === selectedValue}
@@ -263,27 +263,27 @@ const FlexChildSectionSizingPopover = () => {
263263
>
264264
<Grid css={{ gridTemplateColumns: "auto", gap: theme.spacing[3] }}>
265265
<PropertyLabel
266-
properties={["flexGrow"]}
266+
properties={["flex-grow"]}
267267
description={propertyDescriptions.flexGrow}
268268
label="Grow"
269269
/>
270-
<TextControl property="flexGrow" />
270+
<TextControl property="flex-grow" />
271271
</Grid>
272272
<Grid css={{ gridTemplateColumns: "auto", gap: theme.spacing[3] }}>
273273
<PropertyLabel
274274
label="Shrink"
275275
description={propertyDescriptions.flexShrink}
276-
properties={["flexShrink"]}
276+
properties={["flex-shrink"]}
277277
/>
278-
<TextControl property="flexShrink" />
278+
<TextControl property="flex-shrink" />
279279
</Grid>
280280
<Grid css={{ gridTemplateColumns: "auto", gap: theme.spacing[3] }}>
281281
<PropertyLabel
282282
label="Basis"
283283
description={propertyDescriptions.flexBasis}
284-
properties={["flexBasis"]}
284+
properties={["flex-basis"]}
285285
/>
286-
<TextControl property="flexBasis" />
286+
<TextControl property="flex-basis" />
287287
</Grid>
288288
</Grid>
289289
}
@@ -367,7 +367,7 @@ const FlexChildSectionOrder = () => {
367367
label="Sizing"
368368
code={item.code}
369369
description={item.description}
370-
properties={["flexGrow", "flexShrink", "flexBasis"]}
370+
properties={["flex-grow", "flex-shrink", "flex-basis"]}
371371
>
372372
<ToggleGroupButton
373373
aria-checked={

0 commit comments

Comments
 (0)