2026-05-08 15:31:52 +00:00
|
|
|
import { Menu, Moon, Sun } from "lucide-react";
|
2026-06-06 19:49:33 +08:00
|
|
|
import type { ReactNode } from "react";
|
2026-04-19 06:39:06 +00:00
|
|
|
import { useTranslation } from "react-i18next";
|
2026-04-18 18:51:53 +00:00
|
|
|
|
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
|
import { cn } from "@/lib/utils";
|
|
|
|
|
|
|
|
|
|
interface ThreadHeaderProps {
|
|
|
|
|
title: string;
|
|
|
|
|
onToggleSidebar: () => void;
|
2026-05-06 14:15:36 +00:00
|
|
|
theme: "light" | "dark";
|
|
|
|
|
onToggleTheme: () => void;
|
2026-05-29 03:42:53 +08:00
|
|
|
hideSidebarToggleForHostChrome?: boolean;
|
2026-06-06 19:49:33 +08:00
|
|
|
hostChromeTitleInset?: boolean;
|
2026-05-31 17:00:42 +08:00
|
|
|
hideThemeButton?: boolean;
|
2026-05-06 14:15:36 +00:00
|
|
|
minimal?: boolean;
|
2026-06-06 19:49:33 +08:00
|
|
|
promptNavigatorAction?: ReactNode;
|
|
|
|
|
sessionInfoAction?: ReactNode;
|
2026-04-18 18:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function ThreadHeader({
|
|
|
|
|
title,
|
|
|
|
|
onToggleSidebar,
|
2026-05-06 14:15:36 +00:00
|
|
|
theme,
|
|
|
|
|
onToggleTheme,
|
2026-05-29 03:42:53 +08:00
|
|
|
hideSidebarToggleForHostChrome = false,
|
2026-06-06 19:49:33 +08:00
|
|
|
hostChromeTitleInset = false,
|
2026-05-31 17:00:42 +08:00
|
|
|
hideThemeButton = false,
|
2026-05-06 14:15:36 +00:00
|
|
|
minimal = false,
|
2026-06-06 19:49:33 +08:00
|
|
|
promptNavigatorAction,
|
|
|
|
|
sessionInfoAction,
|
2026-04-18 18:51:53 +00:00
|
|
|
}: ThreadHeaderProps) {
|
2026-04-19 06:39:06 +00:00
|
|
|
const { t } = useTranslation();
|
2026-05-06 14:15:36 +00:00
|
|
|
|
2026-04-18 18:51:53 +00:00
|
|
|
return (
|
2026-06-06 19:49:33 +08:00
|
|
|
<div
|
|
|
|
|
className={cn(
|
|
|
|
|
"relative z-10 flex items-center justify-between gap-3 px-3 py-2",
|
|
|
|
|
minimal && "h-11",
|
|
|
|
|
!minimal && hostChromeTitleInset && "lg:pl-[128px]",
|
|
|
|
|
)}
|
|
|
|
|
>
|
2026-04-18 18:51:53 +00:00
|
|
|
<div className="relative flex min-w-0 items-center gap-2">
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
2026-04-19 06:39:06 +00:00
|
|
|
aria-label={t("thread.header.toggleSidebar")}
|
2026-04-18 18:51:53 +00:00
|
|
|
onClick={onToggleSidebar}
|
|
|
|
|
className={cn(
|
|
|
|
|
"h-7 w-7 rounded-md text-muted-foreground hover:bg-accent/35 hover:text-foreground",
|
2026-05-29 03:42:53 +08:00
|
|
|
hideSidebarToggleForHostChrome && "lg:hidden",
|
2026-04-18 18:51:53 +00:00
|
|
|
)}
|
|
|
|
|
>
|
2026-05-08 13:28:34 +00:00
|
|
|
<Menu className="h-3.5 w-3.5" />
|
2026-04-18 18:51:53 +00:00
|
|
|
</Button>
|
2026-06-06 19:49:33 +08:00
|
|
|
{!minimal ? (
|
|
|
|
|
<div className="flex min-w-0 items-center rounded-md px-1.5 py-1 text-[12px] font-medium text-muted-foreground">
|
|
|
|
|
<span className="max-w-[min(60vw,32rem)] truncate">{title}</span>
|
|
|
|
|
</div>
|
|
|
|
|
) : null}
|
2026-05-06 14:15:36 +00:00
|
|
|
</div>
|
|
|
|
|
|
2026-06-06 19:49:33 +08:00
|
|
|
<div className="ml-auto flex shrink-0 items-center gap-1">
|
|
|
|
|
{sessionInfoAction}
|
|
|
|
|
{promptNavigatorAction}
|
|
|
|
|
{!hideThemeButton ? (
|
|
|
|
|
<ThemeButton
|
|
|
|
|
theme={theme}
|
|
|
|
|
onToggleTheme={onToggleTheme}
|
|
|
|
|
label={t("thread.header.toggleTheme")}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
</div>
|
2026-04-18 18:51:53 +00:00
|
|
|
|
2026-06-06 19:49:33 +08:00
|
|
|
{!minimal ? (
|
|
|
|
|
<div aria-hidden className="pointer-events-none absolute inset-x-0 top-full h-4" />
|
|
|
|
|
) : null}
|
2026-04-18 18:51:53 +00:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
2026-05-08 15:31:52 +00:00
|
|
|
|
|
|
|
|
function ThemeButton({
|
|
|
|
|
theme,
|
|
|
|
|
onToggleTheme,
|
|
|
|
|
label,
|
2026-05-22 00:31:55 +08:00
|
|
|
className,
|
2026-05-08 15:31:52 +00:00
|
|
|
}: {
|
|
|
|
|
theme: "light" | "dark";
|
|
|
|
|
onToggleTheme: () => void;
|
|
|
|
|
label: string;
|
2026-05-22 00:31:55 +08:00
|
|
|
className?: string;
|
2026-05-08 15:31:52 +00:00
|
|
|
}) {
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
|
|
|
|
size="icon"
|
|
|
|
|
aria-label={label}
|
|
|
|
|
onClick={onToggleTheme}
|
2026-05-22 00:31:55 +08:00
|
|
|
className={cn(
|
2026-05-31 17:00:42 +08:00
|
|
|
"host-no-drag h-8 w-8 rounded-full text-muted-foreground/85 hover:bg-accent/40 hover:text-foreground",
|
2026-05-22 00:31:55 +08:00
|
|
|
className,
|
|
|
|
|
)}
|
2026-05-08 15:31:52 +00:00
|
|
|
>
|
|
|
|
|
{theme === "dark" ? (
|
|
|
|
|
<Sun className="h-4 w-4" />
|
|
|
|
|
) : (
|
|
|
|
|
<Moon className="h-4 w-4" />
|
|
|
|
|
)}
|
|
|
|
|
</Button>
|
|
|
|
|
);
|
|
|
|
|
}
|