仕組み
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.
向いている場面
- 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.
向かない場面
- Values over time, or negative values: use a bar or line chart.
使い方
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)}
/>
)
}プロパティ
| プロパティ | 型 | 既定値 | 説明 |
|---|---|---|---|
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. |
アクセシビリティ
- 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.
モーション
Bars: 760ms on the reveal curve with a 45ms stagger. Share: 160ms fade and 240ms slide. Hover tint: 160ms.
プロジェクトに追加
プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。
BarList.jsxbar-list.csstokens.cssREADME.md
2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

