import { Select } from '@base-ui/react/select'; import { CheckIcon, ChevronsUpDownIcon, GitBranchIcon } from 'lucide-react'; import { branchRefs, shortRef, tagRefs } from '#/lib/git.js'; import { cn } from '#/lib/utils.js'; /** * The branch and tag switcher. Both groups come from the repository record, * so opening the menu costs nothing. Choosing a ref lands on that ref's root: * the path in view may not exist on it. * * `tags` off leaves the tags out, for a caller asking which branch rather * than which ref. A repository with nothing to choose between renders none * of this. */ export function RefSelect({ repo, value, onSelect, tags = true, className }) { const branches = branchRefs(repo).map((ref) => shortRef(ref.name)); const tagNames = tags ? tagRefs(repo).map((ref) => shortRef(ref.name)) : []; if (branches.length + tagNames.length === 0) return null; const groups = [ ['Branches', branches], ['Tags', tagNames], ].filter(([, names]) => names.length > 0); return ( {groups.map(([label, names]) => ( {label} {names.map((name) => ( {/* The indicator renders only for the selected item, so the fixed box keeps every label on one edge. */} {name} ))} ))} ); }