Skip to content

Commit

Permalink
feat: add icons to logo context menu and make it work on Firefox (#1085)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcklingen authored Dec 10, 2024
1 parent b9f1b98 commit 8e67d4f
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 30 deletions.
84 changes: 54 additions & 30 deletions components/LogoContextMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { DropdownMenuPortal } from "@radix-ui/react-dropdown-menu";
import {
DropdownMenuContent,
DropdownMenuTrigger,
Expand All @@ -11,39 +12,62 @@ const LogoContextMenu: React.FC<{
open: boolean;
setOpen: (open: boolean) => void;
}> = ({ open, setOpen }) => {
const handleAction = (
e: React.MouseEvent,
url: string,
isDownload: boolean
) => {
e.preventDefault();

if (isDownload) {
const link = document.createElement("a");
link.href = url;
link.download = url.split("/").pop() || ""; // Get filename from URL
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
} else {
window.open(url, "_blank", "noopener,noreferrer");
}
};

return (
<DropdownMenu open={open} onOpenChange={setOpen} modal={false}>
<DropdownMenuTrigger />
<DropdownMenuContent>
<DropdownMenuItem
onClick={(e) => {
e.preventDefault();
window.open("/", "_blank");
}}
>
<ExternalLink size={14} className="mr-2" />
Open in new tab
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => {
e.preventDefault();
window.open("/langfuse_logo.png", "_blank");
}}
>
<Download size={14} className="mr-2" />
Logo (png)
</DropdownMenuItem>
<DropdownMenuItem
onClick={(e) => {
e.preventDefault();
window.open("/langfuse_logo.svg", "_blank");
}}
>
<Download size={14} className="mr-2" />
Logo (svg)
</DropdownMenuItem>
</DropdownMenuContent>
<DropdownMenuPortal>
<DropdownMenuContent>
<DropdownMenuItem onClick={(e) => handleAction(e, "/", false)}>
<ExternalLink size={14} className="mr-2" />
Open in new tab
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => handleAction(e, "/langfuse_logo.png", true)}
>
<Download size={14} className="mr-2" />
Logo (png)
</DropdownMenuItem>
<DropdownMenuItem
onClick={(e) => handleAction(e, "/langfuse_logo.svg", true)}
>
<Download size={14} className="mr-2" />
Logo (svg)
</DropdownMenuItem>
<DropdownMenuSeparator />
<DropdownMenuItem
onClick={(e) => handleAction(e, "/langfuse_icon.png", true)}
>
<Download size={14} className="mr-2" />
Icon (png)
</DropdownMenuItem>
<DropdownMenuItem
onClick={(e) => handleAction(e, "/langfuse_icon.svg", true)}
>
<Download size={14} className="mr-2" />
Icon (svg)
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenuPortal>
</DropdownMenu>
);
};
Expand Down
Binary file added public/langfuse_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions public/langfuse_icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified public/langfuse_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 8e67d4f

Please sign in to comment.