Skip to content

Open source website builder and Webflow alternative. Webstudio is an advanced visual builder that connects to any headless CMS, supports all CSS properties, and can be hosted anywhere, including with us.

add a `truncate` variant to Text

Roman Pominovf3a5662939f8
diff --git a/packages/design-system/src/components/text.tsx b/packages/design-system/src/components/text.tsx
index b8f3931900..152019c8bc 100644
--- a/packages/design-system/src/components/text.tsx
+++ b/packages/design-system/src/components/text.tsx
@@ -53,6 +53,25 @@ export const Text = styled("div", {
color: "$loContrast",
},
},
+ truncate: {
+ true: {
+ whiteSpace: "nowrap",
+ textOverflow: "ellipsis",
+ flexBasis: 0,
+ flexGrow: 1,
+
+ // We want to use overflow-x:clip to make sure the text is not clipped vertically.
+ // overflow:hidden is a fallback for when `clip` is not supported,
+ // the text may be clipped vertically in these browsers.
+ overflow: "hidden",
+ overflowX: "clip",
+ overflowY: "visible",
+
+ // For some reason flexBasis:0 is not enough
+ // to stop it from growing past the container
+ width: 0,
+ },
+ },
},
defaultVariants: {
diff --git a/packages/design-system/src/components/tree/tree-node.tsx b/packages/design-system/src/components/tree/tree-node.tsx
index 431d39b232..b1a99a17c7 100644
--- a/packages/design-system/src/components/tree/tree-node.tsx
+++ b/packages/design-system/src/components/tree/tree-node.tsx
@@ -270,24 +270,7 @@ export const TreeNode = <Data extends { id: string }>({
);
};
-const Label = styled(Text, {
- whiteSpace: "nowrap",
- overflow: "hidden",
- textOverflow: "ellipsis",
- flexBasis: 0,
- flexGrow: 1,
-
- // With the default lineHeight and overflow:hidden letters like "g" get clipped
- lineHeight: 1.4,
-
- // For some reason flexBasis:0 is not enough
- // to stop it from growing past the container
- width: 0,
-
- variants: {
- withIcon: { true: { ml: "$1" } },
- },
-});
+const Label = styled(Text, { variants: { withIcon: { true: { ml: "$1" } } } });
export const TreeNodeLabel = ({
text,
@@ -298,7 +281,11 @@ export const TreeNodeLabel = ({
isSelected: boolean;
withIcon?: boolean;
}) => (
- <Label color={isSelected ? "loContrast" : "contrast"} withIcon={withIcon}>
+ <Label
+ color={isSelected ? "loContrast" : "contrast"}
+ withIcon={withIcon}
+ truncate
+ >
{text}
</Label>
);