From 05ab9cdc81dbd574dbb5f2733c1abad50c1070fd Mon Sep 17 00:00:00 2001 From: Jaya Krishna Namburu Date: Tue, 3 Dec 2024 10:24:13 +0530 Subject: [PATCH] fix: truncate text for while showing text for padding and margin tokens (#4485) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## 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. Screenshot 2024-11-30 at 6 09 12 PM ## 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) --- .../sections/shared/value-text.tsx | 24 ++++++++++++++----- .../style-panel/sections/space/space.tsx | 3 +++ 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/apps/builder/app/builder/features/style-panel/sections/shared/value-text.tsx b/apps/builder/app/builder/features/style-panel/sections/shared/value-text.tsx index 783909db06..83a46cf300 100644 --- a/apps/builder/app/builder/features/style-panel/sections/shared/value-text.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/shared/value-text.tsx @@ -52,13 +52,21 @@ const Container = styled("button", { export const ValueText = ({ value, source, + truncate = false, ...rest -}: { value: StyleValue } & Omit, "value">) => { +}: { value: StyleValue; truncate?: boolean } & Omit< + ComponentProps, + "value" +>) => { const children = useMemo(() => { if (value.type === "unit") { // we want to show "0" rather than "0px" for default values for cleaner UI if (source === "default" && value.unit === "px" && value.value === 0) { - return {value.value}; + return ( + + {value.value} + + ); } /** @@ -68,7 +76,7 @@ export const ValueText = ({ return ( <> - + {value.value} --{value.value}; + return ( + + --{value.value} + + ); } return ( - + {toValue(value)} ); - }, [value, source]); + }, [value, source, truncate]); return ( diff --git a/apps/builder/app/builder/features/style-panel/sections/space/space.tsx b/apps/builder/app/builder/features/style-panel/sections/space/space.tsx index 44515c89b1..7589bb2fb8 100644 --- a/apps/builder/app/builder/features/style-panel/sections/space/space.tsx +++ b/apps/builder/app/builder/features/style-panel/sections/space/space.tsx @@ -11,6 +11,7 @@ import { movementMapSpace, useKeyboardNavigation } from "../shared/keyboard"; import { useComputedStyleDecl, useComputedStyles } from "../../shared/model"; import { createBatchUpdate, deleteProperty } from "../../shared/use-style-data"; import { useModifierKeys } from "../../shared/modifier-keys"; +import { theme } from "@webstudio-is/design-system"; const Cell = ({ isPopoverOpen, @@ -44,6 +45,7 @@ const Cell = ({ />