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.

use CSS for truncate

Sara Vieira560da01be0b7
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/asset-info.tsx b/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/asset-info.tsx
index 98bff6efd6..b3634fca7d 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/asset-info.tsx
+++ b/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/asset-info.tsx
@@ -8,11 +8,7 @@ import {
Button,
} from "@webstudio-is/design-system";
import type { Asset } from "@webstudio-is/prisma-client";
-import {
- getFormattedAspectRatio,
- getHumanReadableFileSize,
- getStartAndEndOfString,
-} from "./utils";
+import { getFormattedAspectRatio } from "./utils";
import {
CloudIcon,
AspectRatioIcon,
@@ -21,6 +17,26 @@ import {
TrashIcon,
} from "@webstudio-is/icons";
import { useSubmit } from "@remix-run/react";
+import prettyBytes from "pretty-bytes";
+
+const truncatedText = {
+ position: "relative",
+ maxWidth: 80,
+
+ div: {
+ whiteSpace: "nowrap",
+ textOverflow: "ellipsis",
+ overflow: "hidden",
+
+ "&:after": {
+ content: "attr(data-extension)",
+ position: "absolute",
+ left: "100%",
+ top: 0,
+ whiteSpace: "nowrap",
+ },
+ },
+};
type AssetInfoProps = Asset & {
onClose: () => void;
@@ -68,11 +84,17 @@ export const AssetInfo = ({
</Flex>
<Separator />
<Box css={{ p: "$2 $3" }}>
- <Grid columns={2}>
- <Text size="1">{getStartAndEndOfString(name)}</Text>
+ <Grid columns={2} align="center">
+ <Box css={{ width: 100 }}>
+ <Box css={truncatedText}>
+ <Text size="1" data-extension={name.split(".").pop()}>
+ {name}
+ </Text>
+ </Box>
+ </Box>
<Flex align="center" css={{ gap: "$1" }}>
<CloudIcon />
- <Text size="1">{getHumanReadableFileSize(size)}</Text>
+ <Text size="1">{prettyBytes(size)}</Text>
</Flex>
</Grid>
</Box>
diff --git a/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/utils.ts b/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/utils.ts
index 732681078f..e207d0986e 100644
--- a/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/utils.ts
+++ b/apps/designer/app/designer/features/sidebar-left/panels/asset-manager/utils.ts
@@ -1,16 +1,3 @@
-export const getHumanReadableFileSize = (size: number) => {
- const i = Math.floor(Math.log(size) / Math.log(1024));
- const types = ["B", "kB", "MB", "GB", "TB"];
- return `${(size / Math.pow(1024, i)).toFixed(2)} ${types[i]}`;
-};
-
-export const getStartAndEndOfString = (str: string) => {
- if (str.length > 20) {
- return str.substr(0, 10) + "..." + str.split(".").pop();
- }
- return str;
-};
-
const gcd = (a: number, b: number): number => {
return b ? gcd(b, a % b) : a;
};
diff --git a/apps/designer/package.json b/apps/designer/package.json
index 5c0baba219..4abc3a1067 100644
--- a/apps/designer/package.json
+++ b/apps/designer/package.json
@@ -47,6 +47,7 @@
"match-sorter": "^6.3.1",
"mitt": "^3.0.0",
"nanoid": "^3.2.0",
+ "pretty-bytes": "^6.0.0",
"react": "^17.0.2",
"react-color": "^2.19.3",
"react-dom": "^17.0.2",
diff --git a/apps/designer/remix.config.js b/apps/designer/remix.config.js
index 88fd6efdce..b243d8c175 100644
--- a/apps/designer/remix.config.js
+++ b/apps/designer/remix.config.js
@@ -12,7 +12,7 @@ module.exports = {
// This makes sure remix bundles monorepo packages which are always
// sym-linked and can't be hoisted. You could also manually name packages
// e.g. ["@webstudio-is/ui", ...]
- serverDependenciesToBundle: [/@webstudio-is\/.*/],
+ serverDependenciesToBundle: [/@webstudio-is\/.*/, "pretty-bytes"],
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
serverBuildPath: "api/index.js",
diff --git a/yarn.lock b/yarn.lock
index 22cf874352..f1f77b5130 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -14305,6 +14305,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb"
integrity sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg==
+pretty-bytes@^6.0.0:
+ version "6.0.0"
+ resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-6.0.0.tgz#928be2ad1f51a2e336add8ba764739f9776a8140"
+ integrity sha512-6UqkYefdogmzqAZWzJ7laYeJnaXDy2/J+ZqiiMtS7t7OfpXWTlaeGMwX8U6EFvPV/YWWEKRkS8hKS4k60WHTOg==
+
pretty-error@^2.1.1:
version "2.1.2"
resolved "https://registry.yarnpkg.com/pretty-error/-/pretty-error-2.1.2.tgz#be89f82d81b1c86ec8fdfbc385045882727f93b6"