Skip to content

Commit 05ab9cd

Browse files
fix: truncate text for while showing text for padding and margin tokens (#4485)
## Description fixes #4439 While displaying tokens in the spacing section, it gets too cluttered if the css-variable names are long. This PR will truncate text, to make it less cluttered. <img width="238" alt="Screenshot 2024-11-30 at 6 09 12 PM" src="https://github.com/user-attachments/assets/864fdef7-84ae-4f95-8d5d-4a7863da8097"> ## Steps for reproduction - Create a super long css-variable. - Now, use the variable for padding/margin. ## Code Review - [x] 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 - [x] made a self-review ## Before merging - [x] tested locally and on preview environment (preview dev login: 0000)
1 parent 3a87233 commit 05ab9cd

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,21 @@ const Container = styled("button", {
5252
export const ValueText = ({
5353
value,
5454
source,
55+
truncate = false,
5556
...rest
56-
}: { value: StyleValue } & Omit<ComponentProps<typeof Container>, "value">) => {
57+
}: { value: StyleValue; truncate?: boolean } & Omit<
58+
ComponentProps<typeof Container>,
59+
"value"
60+
>) => {
5761
const children = useMemo(() => {
5862
if (value.type === "unit") {
5963
// we want to show "0" rather than "0px" for default values for cleaner UI
6064
if (source === "default" && value.unit === "px" && value.value === 0) {
61-
return <Text variant="spaceSectionValueText">{value.value}</Text>;
65+
return (
66+
<Text truncate={truncate} variant="spaceSectionValueText">
67+
{value.value}
68+
</Text>
69+
);
6270
}
6371

6472
/**
@@ -68,7 +76,7 @@ export const ValueText = ({
6876

6977
return (
7078
<>
71-
<Text variant="spaceSectionValueText">
79+
<Text truncate={truncate} variant="spaceSectionValueText">
7280
{value.value}
7381
<Text
7482
variant="spaceSectionValueText"
@@ -85,15 +93,19 @@ export const ValueText = ({
8593
}
8694

8795
if (value.type === "var") {
88-
return <Text variant="spaceSectionValueText">--{value.value}</Text>;
96+
return (
97+
<Text truncate={truncate} variant="spaceSectionValueText">
98+
--{value.value}
99+
</Text>
100+
);
89101
}
90102

91103
return (
92-
<Text css={{}} variant="spaceSectionValueText">
104+
<Text truncate={truncate} variant="spaceSectionValueText">
93105
{toValue(value)}
94106
</Text>
95107
);
96-
}, [value, source]);
108+
}, [value, source, truncate]);
97109

98110
return (
99111
<Container source={source} {...rest} tabIndex={-1}>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { movementMapSpace, useKeyboardNavigation } from "../shared/keyboard";
1111
import { useComputedStyleDecl, useComputedStyles } from "../../shared/model";
1212
import { createBatchUpdate, deleteProperty } from "../../shared/use-style-data";
1313
import { useModifierKeys } from "../../shared/modifier-keys";
14+
import { theme } from "@webstudio-is/design-system";
1415

1516
const Cell = ({
1617
isPopoverOpen,
@@ -44,6 +45,7 @@ const Cell = ({
4445
/>
4546
<SpaceTooltip property={property} preventOpen={scrubStatus.isActive}>
4647
<ValueText
48+
truncate
4749
css={{
4850
// We want value to have `default` cursor to indicate that it's clickable,
4951
// unlike the rest of the value area that has cursor that indicates scrubbing.
@@ -52,6 +54,7 @@ const Cell = ({
5254
// In order to have control over cursor we're setting pointerEvents to "all" here
5355
// because SpaceLayout sets it to "none" for cells' content.
5456
pointerEvents: "all",
57+
maxWidth: theme.spacing[18],
5558
}}
5659
value={finalValue}
5760
source={styleDecl.source.name}

0 commit comments

Comments
 (0)