import { ReactNode } from 'react'; import clsx from 'clsx'; import { FilterBarButton, Color } from './FilterBarButton'; import { FilterBarActiveIndicator } from './FilterBarActiveIndicator'; export interface StatusSegment { key: TValue; label: string; count: number; color: Color; } interface Props { total: number; segments: Array>; value: TValue | null; onChange: (filter: TValue | null) => void; radioGroupName?: string; ariaLabel?: string; isLoading?: boolean; 'data-cy'?: string; rightSlot?: ReactNode; } export function StatusSummaryBar({ total, segments, value, onChange, radioGroupName = 'status-summary-filter', ariaLabel = 'Filter by status', isLoading = false, 'data-cy': dataCy = 'status-summary-bar', rightSlot, }: Props) { const isAllSelected = !value || value === 'all' || value === 'custom'; const activeLabel = segments.find((s) => s.key === value)?.label; function handleSegmentClick(key: TValue) { onChange(value === key ? null : key); } return (
onChange(null)} name={radioGroupName} isLoading={isLoading} data-cy={`${dataCy}-total`} /> {segments.map(({ key, label, count, color }) => ( handleSegmentClick(key)} name={radioGroupName} data-cy={`${dataCy}-${key}`} /> ))} {rightSlot ? (
{rightSlot}
) : ( activeLabel && (
onChange(null)} />
) )}
); } function Separator() { return (