Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

2.9 KB
Raw Blame
import { type ReactNode } from "react";
import { useSession } from "next-auth/react";
import { Menu } from "@langfuse/icons";
import { Button } from "@/src/components/ui/button";
import { useSidebar } from "@/src/components/ui/sidebar";
import { TopbarBrand } from "@/src/components/nav/TopbarBrand";
import { useHasAppSidebar } from "@/src/components/nav/SidebarPresenceProvider";
import { TopbarAccount } from "@/src/components/nav/TopbarAccount";
import { InAppAiAgentButton } from "@/src/components/nav/InAppAiAgentButton";
import { EnvLabelBadge } from "@/src/components/EnvLabelBadge";
import { useEnvLabel } from "@/src/hooks/useEnvLabel";
import { useIsInAppAgentLauncherVisible } from "@/src/features/in-app-agent/components/InAppAiAgentProvider";

/**
 * Slim mobile top chrome for the minimal-chrome shell: hamburger · centered
 * Langfuse wordmark · account. Everything page-specific (title, actions,
 * controls, tabs) lives below in the scrollable content (see MobilePageTitle),
 * so this stays a thin, sticky brand bar.
 *
 * Rendered only below `md` (the caller hides it on desktop, where PageHeader
 * takes over). On the sidebar-less MinimalLayout (public shares) there is no
 * hamburger to show — the page's own leadingControl takes the left slot.
 */
export const MobileTopBar = ({
  showSidebarTrigger = true,
  leadingControl,
}: {
  showSidebarTrigger?: boolean;
  leadingControl?: ReactNode;
}) => {
  const { toggleSidebar } = useSidebar();
  const session = useSession();
  const hasAppSidebar = useHasAppSidebar();
  const envLabel = useEnvLabel();
  const isInAppAgentLauncherVisible = useIsInAppAgentLauncherVisible();
  const showHamburger = showSidebarTrigger && hasAppSidebar;

  return (
    <div className="bg-background flex h-12 items-center gap-2 border-b px-2">
      {/* Left: hamburger (opens the nav sheet) or the page's leading control. */}
      <div className="flex min-w-0 flex-1 items-center gap-2">
        {showHamburger ? (
          <Button
            variant="ghost"
            size="icon"
            className="h-9 w-9"
            aria-label="Open menu"
            onClick={() => toggleSidebar()}
          >
            <Menu size="lg" color="default" />
          </Button>
        ) : (
          leadingControl
        )}
        {envLabel.visible && (
          <EnvLabelBadge
            region={envLabel.region}
            onDismiss={envLabel.dismiss}
          />
        )}
      </div>

      {/* Center: the Langfuse wordmark. */}
      {hasAppSidebar && <TopbarBrand variant="wordmark" />}

      {/* Right: the assistant launcher (prominent, gradient-bordered so it
          reads as a real entry point here) + account. Balances the left slot
          so the brand stays centered. */}
      <div className="flex min-w-0 flex-1 items-center justify-end gap-1">
        {isInAppAgentLauncherVisible && <InAppAiAgentButton prominent />}
        {session.data?.user && <TopbarAccount user={session.data.user} />}
      </div>
    </div>
  );
};