Cómo funciona
Every row is a three-column grid: a track holding the bar with the label on top of it, the share and the value. The bar is a light tint of the series colour, so the label stays in ink and readable over it, and a long label simply runs past the end of a short bar. Bar widths are a custom property transitioned on the reveal curve: they grow from zero after the first frame with a 45ms stagger, and switching data remounts the list so the new ranking grows in. Hovering or focusing a row deepens its bar and slides in its share of the total. With limit, a quiet button shows the remaining rows.
Úsalo para
- Top-N breakdowns in analytics: pages, referrers, countries, devices, search terms.
- Any ranking where the names are long and should be read in full width.
Busca otra opción cuando
- Values over time, or negative values: use a bar or line chart.
Uso
import { BarList } from './BarList.jsx'
export function TopPages({ pages, onOpen }) {
return (
<BarList
label="Top pages"
items={pages.map((p) => ({ key: p.path, name: p.path, value: p.visitors }))}
limit={5}
onSelect={(item) => onOpen(item.key)}
/>
)
}Propiedades
| Propiedad | Tipo | Por defecto | Qué hace |
|---|---|---|---|
items | { key?: string, name: ReactNode, value: number, icon?: ReactNode }[] | — | Rows. Bars are scaled to the largest value; the share is of the total. |
sort | 'desc' | 'asc' | 'none' | 'desc' | Order by value, or keep yours. |
limit / labels | number / { more(n), less } | — | Show the first rows and a button for the rest. |
tone / color | 1-8 / string | 1 | Series colour for the bars, used as a soft tint. |
showShare / formatShare / formatValue | boolean / (pct) => string / (v) => string | true | The share appears on hover or focus (always on touch screens). |
onSelect | (item) => void | — | Makes each row a button. |
label | string | 'Ranking' | Accessible name of the list. |
Accesibilidad
- The rows are an ordered list with an accessible name; bars are decorative and every row reads its name, share and value as text.
- With onSelect each row is a button with a visible focus ring; the share appears on focus as well as hover.
- The more button reports aria-expanded.
- Reduced motion removes the growth and the share slide; colour changes stay.
Movimiento
Bars: 760ms on the reveal curve with a 45ms stagger. Share: 160ms fade and 240ms slide. Hover tint: 160ms.
Añádelo a tu proyecto
Copia la instrucción en Codex o Claude Code. El agente lee el código publicado, te muestra lo que va a escribir y añade el componente junto a los tuyos.
BarList.jsxbar-list.csstokens.cssREADME.md
Los dos archivos se instalan juntos. La hoja de estilos lee las variables de tokens.css y lleva valores de reserva, así que también funciona sola.

