Make worktree banner name clickable to copy to clipboard

Clicking the worktree name in the banner now copies it to clipboard
and shows "Copied\!" feedback for 1.5 seconds.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
dotta 2026-04-07 17:01:55 -05:00
parent 30dd2b78e5
commit db1279dc12

View file

@ -1,7 +1,18 @@
import { useCallback, useState } from "react";
import { getWorktreeUiBranding } from "../lib/worktree-branding";
export function WorktreeBanner() {
const branding = getWorktreeUiBranding();
const [copied, setCopied] = useState(false);
const handleCopyName = useCallback(() => {
if (!branding) return;
navigator.clipboard.writeText(branding.name).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 1500);
});
}, [branding]);
if (!branding) return null;
return (
@ -18,7 +29,14 @@ export function WorktreeBanner() {
<div className="flex items-center gap-2 overflow-hidden whitespace-nowrap">
<span className="shrink-0 opacity-70">Worktree</span>
<span className="h-1.5 w-1.5 shrink-0 rounded-full bg-current opacity-70" aria-hidden="true" />
<span className="truncate font-semibold tracking-[0.12em]">{branding.name}</span>
<button
type="button"
onClick={handleCopyName}
title="Click to copy worktree name"
className="truncate font-semibold tracking-[0.12em] cursor-pointer hover:opacity-80 transition-opacity bg-transparent border-none p-0 text-current uppercase text-[11px]"
>
{copied ? "Copied!" : branding.name}
</button>
</div>
</div>
);