import { Check, ChevronDown } from "lucide-react"; import { Button } from "./ui/button"; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "./ui/dropdown-menu"; interface FilterBarProps { repositories: { id: string; name: string }[]; labels: { name: string; color: string; description: string }[]; activeRepository: string | null; activeLabel: string | null; onRepositoryChange: (repository: string | null) => void; onLabelChange: (label: string | null) => void; } const VISIBLE_LABEL_LIMIT = 6; function labelStyle(label: { color: string }, active: boolean) { return { color: label.color, borderColor: `color-mix(in srgb, ${label.color} ${active ? 48 : 30}%, transparent)`, backgroundColor: `color-mix(in srgb, ${label.color} ${active ? 14 : 6}%, transparent)`, }; } function splitLabels(labels: FilterBarProps["labels"], activeLabel: string | null) { const visible = labels.slice(0, VISIBLE_LABEL_LIMIT); if (!activeLabel || visible.some((label) => label.name === activeLabel)) return { visible, overflow: labels.slice(VISIBLE_LABEL_LIMIT) }; const active = labels.find((label) => label.name === activeLabel); if (!active) return { visible, overflow: labels.slice(VISIBLE_LABEL_LIMIT) }; return { visible: [...visible.slice(0, VISIBLE_LABEL_LIMIT - 1), active], overflow: labels.filter( (label) => !visible.slice(0, VISIBLE_LABEL_LIMIT - 1).some((item) => item.name === label.name) && label.name !== activeLabel, ), }; } export function FilterBar({ repositories, labels, activeRepository, activeLabel, onRepositoryChange, onLabelChange }: FilterBarProps) { if (repositories.length === 0 && labels.length === 0) return null; const { visible, overflow } = splitLabels(labels, activeLabel); return (
{repositories.length > 0 && (
{repositories.map((r) => ( ))}
)} {labels.length > 0 && (
{visible.map((label) => { const active = activeLabel === label.name; return ( ); })} {overflow.length > 0 && ( } > More {overflow.map((label) => { const active = activeLabel === label.name; return ( onLabelChange(label.name)} title={label.description || label.name} > {label.name} {active && } ); })} )}
)}
); }