/** * @file The git bar's "Branches & tags" icon button, which owns the Branches * panel (`BranchManager`) it opens — portalled to `document.body`, so no * scrolling or transformed ancestor of the Changes panel can clip it. The * panel closes when the bar starts showing another workspace. * @author Nguyễn Ngọc Trí Vĩ */ import { useState } from "react"; import { createPortal } from "react-dom"; import { useTranslation } from "react-i18next"; import { Tags } from "lucide-react"; import type { GitSource } from "../../../lib/api"; import { BranchManager } from "./BranchManager"; export function BranchesButton({ laneId, session, source, dirty, merging, disabled, onChanged, }: { laneId: number; session?: string; source?: GitSource; dirty: number; merging: boolean; disabled?: boolean; onChanged: () => void; }) { const { t } = useTranslation(["gitRefs"]); const [open, setOpen] = useState(false); const [shown, setShown] = useState(`${laneId}|${session ?? ""}|${source ?? ""}`); const key = `${laneId}|${session ?? ""}|${source ?? ""}`; if (shown !== key) { setShown(key); setOpen(false); } return ( <> {open && createPortal( setOpen(false)} onChanged={onChanged} />, document.body )} ); } export default BranchesButton;