import type React from 'react' interface HorizontalBarsRow { label: string count: number } interface HorizontalBarsProps { rows: R[] max: number onActivate?: (row: R) => void } export function HorizontalBars( { rows, max, onActivate }: HorizontalBarsProps, ): React.JSX.Element { const safeMax = max > 0 ? max : 1 return (
{rows.map((row, i) => { const ratio = row.count / safeMax const activatable = onActivate != null const labelStyle: React.CSSProperties = { fontSize: 11, ...(activatable ? { color: 'var(--accent-ink)', cursor: 'pointer' } : {}), } const label = ( onActivate(row) : undefined} role={activatable ? 'button' : undefined} tabIndex={activatable ? 0 : undefined} onKeyDown={activatable ? (e) => { if (e.key === 'Enter') onActivate(row) } : undefined} > {row.label} ) return (
{label}
{row.count}
) })}
) }