Skip to content

Commit b762a92

Browse files
authored
fix: Option list changes width on hover (#4363)
## Description closes #4300 Also simplified types instead of unions with 2300+ strings ## Steps for reproduction 1. click button 2. expect xyz ## Code Review - [ ] hi @kof, I need you to do - conceptual review (architecture, feature-correctness) - detailed review (read every line) - test it on preview ## Before requesting a review - [ ] made a self-review - [ ] added inline comments where things may be not obvious (the "why", not "what") ## Before merging - [ ] tested locally and on preview environment (preview dev login: 5de6) - [ ] updated [test cases](https://github.com/webstudio-is/webstudio/blob/main/apps/builder/docs/test-cases.md) document - [ ] added tests - [ ] if any new env variables are added, added them to `.env` file
1 parent 5fbda47 commit b762a92

File tree

10 files changed

+35
-38
lines changed

10 files changed

+35
-38
lines changed

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ export const PositionControl = ({
7979
<Flex direction="column" gap="1">
8080
<PropertyInlineLabel
8181
label="Position"
82-
description={
83-
propertyDescriptions[property as keyof typeof propertyDescriptions]
84-
}
82+
description={propertyDescriptions[property]}
8583
properties={[property]}
8684
/>
8785
<Flex gap="6">

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
getRepeatedStyleItem,
1818
setRepeatedStyleItem,
1919
} from "../../shared/repeated-style";
20+
import { noCase } from "change-case";
2021

2122
export const SelectControl = ({
2223
property,
@@ -50,6 +51,12 @@ export const SelectControl = ({
5051
options.push(valueString);
5152
}
5253

54+
const hasDescription =
55+
options.length > 0 &&
56+
options.some(
57+
(option) => declarationDescriptions[`${property}:${option}`] !== undefined
58+
);
59+
5360
return (
5461
<Select
5562
// Show empty field instead of radix placeholder like css value input does.
@@ -77,15 +84,16 @@ export const SelectControl = ({
7784
}
7885
}}
7986
getDescription={(option) => {
80-
const description =
81-
declarationDescriptions[
82-
`${property}:${option}` as keyof typeof declarationDescriptions
83-
];
84-
85-
if (description === undefined) {
87+
if (hasDescription === false) {
8688
return;
8789
}
88-
return <Box css={{ width: theme.spacing[26] }}>{description}</Box>;
90+
91+
const description = declarationDescriptions[`${property}:${option}`];
92+
return (
93+
<Box css={{ width: theme.spacing[26] }}>
94+
{description ?? `The ${noCase(property)} is ${option}`}
95+
</Box>
96+
);
8997
}}
9098
getItemProps={() => ({ text: "sentence" })}
9199
/>

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
@@ -37,7 +37,7 @@ export const ToggleGroupTooltip = ({
3737
isSelected: boolean;
3838
label?: string;
3939
code?: string;
40-
description: string;
40+
description: string | undefined;
4141
properties: StyleProperty[];
4242
isAdvanced?: boolean;
4343
children: ReactNode;

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ export const PropertyLabel = ({
219219
properties,
220220
}: {
221221
label: string;
222-
description: string;
222+
description?: string;
223223
properties: [StyleProperty, ...StyleProperty[]];
224224
}) => {
225225
const styles = useComputedStyles(properties);
@@ -277,7 +277,7 @@ export const PropertySectionLabel = ({
277277
properties,
278278
}: {
279279
label: string;
280-
description: string;
280+
description: string | undefined;
281281
properties: [StyleProperty, ...StyleProperty[]];
282282
}) => {
283283
const styles = useComputedStyles(properties);
@@ -344,7 +344,7 @@ export const PropertyInlineLabel = ({
344344
}: {
345345
label: string;
346346
title?: string;
347-
description: string;
347+
description?: string;
348348
properties?: [StyleProperty, ...StyleProperty[]];
349349
disabled?: boolean;
350350
}) => {
@@ -400,7 +400,7 @@ export const PropertyValueTooltip = ({
400400
children,
401401
}: {
402402
label: string;
403-
description: string;
403+
description: string | undefined;
404404
properties: [StyleProperty, ...StyleProperty[]];
405405
isAdvanced?: boolean;
406406
children: ReactNode;

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,9 @@ const matchOrSuggestToCreate = (
138138
};
139139

140140
const getNewPropertyDescription = (item: null | SearchItem) => {
141-
let description = `Create CSS variable.`;
141+
let description: string | undefined = `Create CSS variable.`;
142142
if (item && item.value in propertyDescriptions) {
143-
description =
144-
propertyDescriptions[item.value as keyof typeof propertyDescriptions];
143+
description = propertyDescriptions[item.value];
145144
}
146145
return <Box css={{ width: theme.spacing[28] }}>{description}</Box>;
147146
};
@@ -261,8 +260,7 @@ const AdvancedSearch = ({
261260
const AdvancedPropertyLabel = ({ property }: { property: StyleProperty }) => {
262261
const styleDecl = useComputedStyleDecl(property);
263262
const label = hyphenateProperty(property);
264-
const description =
265-
propertyDescriptions[property as keyof typeof propertyDescriptions];
263+
const description = propertyDescriptions[property];
266264
const color =
267265
styleDecl.source.name === "default" ? "code" : styleDecl.source.name;
268266
const [isOpen, setIsOpen] = useState(false);

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ const GapTooltip = ({
8686
children: ReactNode;
8787
}) => {
8888
const [isOpen, setIsOpen] = useState(false);
89-
const description =
90-
propertyDescriptions[
91-
styleDecl.property as keyof typeof propertyDescriptions
92-
];
89+
const description = propertyDescriptions[styleDecl.property];
9390
return (
9491
<Tooltip
9592
open={isOpen}

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ const SizeProperty = ({ property }: { property: StyleProperty }) => {
2929
<Grid gap={1}>
3030
<PropertyLabel
3131
label={humanizeString(property)}
32-
description={
33-
propertyDescriptions[property as keyof typeof propertyDescriptions]
34-
}
32+
description={propertyDescriptions[property]}
3533
properties={[property]}
3634
/>
3735
<TextControl property={property} />

apps/builder/app/builder/features/style-panel/sections/transforms/transform-and-perspective-origin.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,7 @@ export const TransformAndPerspectiveOrigin = ({
153153
<Grid gap="2">
154154
<PropertyLabel
155155
label={label}
156-
description={
157-
propertyDescriptions[property as keyof typeof propertyDescriptions]
158-
}
156+
description={propertyDescriptions[property]}
159157
properties={[property]}
160158
/>
161159
<Flex gap="6">

packages/css-data/bin/property-value-descriptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function writeFile(descriptions: Record<string, unknown>) {
331331
([binding, value]) =>
332332
`export const ${binding} = ` +
333333
(typeof value === "string" ? value : JSON.stringify(value, null, 2)) +
334-
" as const;"
334+
" as Record<string, string | undefined>;"
335335
)
336336
.join("\n\n");
337337

packages/css-data/src/__generated__/property-value-descriptions.ts

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)