Skip to content

armgit / Cap

Public Imported from GitHub
0

Open source Loom alternative. Beautiful, shareable screen recordings.

Truncate long name (#676)

Ameer Al Ashhab2ec5a3acc1fe
diff --git a/apps/desktop/src/routes/editor/Header.tsx b/apps/desktop/src/routes/editor/Header.tsx
index 240dd123d..93fc4a01c 100644
--- a/apps/desktop/src/routes/editor/Header.tsx
+++ b/apps/desktop/src/routes/editor/Header.tsx
@@ -5,10 +5,11 @@ import { remove } from "@tauri-apps/plugin-fs";
import { revealItemInDir } from "@tauri-apps/plugin-opener";
import { type as ostype } from "@tauri-apps/plugin-os";
import { cx } from "cva";
-import { ComponentProps, onCleanup, onMount } from "solid-js";
+import { ComponentProps, createEffect, createSignal, onCleanup, onMount } from "solid-js";
import { Button } from "@cap/ui-solid";
import CaptionControlsWindows11 from "~/components/titlebar/controls/CaptionControlsWindows11";
+import Tooltip from "~/components/Tooltip";
import { trackEvent } from "~/utils/analytics";
import { initializeTitlebar } from "~/utils/titlebar-state";
import { useEditorContext } from "./context";
@@ -51,6 +52,16 @@ export function Header() {
});
onCleanup(() => unlistenTitlebar?.());
+ const [truncated, setTruncated] = createSignal(false);
+ let prettyNameRef: HTMLParagraphElement | undefined;
+
+ createEffect(() => {
+ if (!prettyNameRef) return;
+ const width = prettyNameRef.offsetWidth;
+ const scrollWidth = prettyNameRef.scrollWidth;
+ setTruncated(width < scrollWidth);
+ });
+
return (
<div
data-tauri-drag-region
@@ -81,10 +92,17 @@ export function Header() {
leftIcon={<IconLucideFolder class="w-5" />}
/>
- <p class="text-sm text-gray-12">
- {meta().prettyName}
+ <div class="flex flex-row items-center">
+ <Tooltip
+ disabled={!truncated()}
+ content={meta().prettyName}
+ >
+ <p ref={prettyNameRef} class="text-sm truncate text-gray-12 max-w-[300px] cursor-default">
+ {meta().prettyName}
+ </p>
+ </Tooltip>
<span class="text-sm text-gray-11">.cap</span>
- </p>
+ </div>
{/* <ErrorBoundary fallback={<></>}>
<Suspense>
<span