Bar List for React
A React bar list draws each value as a soft bar behind its name: the most compact way to rank many named values in a card. Pass data as readonly BarListItem[]: one row per item: { name: "Google", value: 4821 }.
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/bar-list.jsonTop referrers
- Searchly: 4,82131.7% of total
- Direct: 3,40722.4% of total
- codehost.example: 2,11813.9% of total
- Hacker News: 1,64010.8% of total
- Short posts: 9126% of total
BarListBarListTabledefaultBarListLabels- +1 more
Top referrers, top 5
Shows the top five; “Show more” reveals the rest without rescaling the bars, since every bar shares the list's largest value. Rows are buttons here: click or press Enter to filter by a source.
Top referrers
Visitors, last 7 days
import { useState } from "react";
import { BarListTable, BarList, type BarListItem } from "@/components/sheenui/charts/bar-list";
import { ChartCard } from "@/components/sheenui/charts/chart-parts/chart-card";
// Package build (after the first npm release, or a packed tarball): import { ChartCard, BarListTable, BarList, type BarListItem } from "@sheenui/theme";
const referrers: BarListItem[] = [
{ name: "Searchly", value: 4821 },
{ name: "Direct", value: 3207 },
{ name: "codehost.example", value: 1342 },
{ name: "Hacker News", value: 655 },
{ name: "Lookup", value: 287 },
{ name: "Newsletter", value: 214 },
];
export function Example() {
const [filter, setFilter] = useState<string | null>(null);
return (
<ChartCard title="Top referrers" description={filter ? "Filtered by " + filter : "All sources"} table={<BarListTable data={referrers} />}>
<BarList
data={referrers}
limit={5}
showShare
nameHeader="Source"
valueHeader="Visitors"
onValueChange={(item) => setFilter(item.name)}
aria-label="Visitors by referrer"
/>
</ChartCard>
);
}Files to copy
14 folders · 30 files · 4 packages
- From
theme/src/ components/charts/{bar-list.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}components/button/components/charts/chart-parts/components/charts/heatmap/components/drawer/parts/sheet.tsxcomponents/kbd/components/menu/components/skeleton/components/spinner/components/status-icons/hooks/{use-controllable.ts, use-intersection.ts, use-latest.ts, use-magnetic.ts, use-media-query.ts, use-preferences.ts}motion/{gate.ts, tokens.ts}lib/{cn.ts, csv.ts, form.ts, glide-highlight.tsx, heading.ts, math.ts, popup-a11y.ts, popup-motion.ts, state-light.tsx, warn-once.ts}styles/
- shadcn CLI
npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/bar-list.jsonRegistry item: bar-list. The styles need the Tailwind v4 glass UI setup.- Packages
pnpm add @base-ui/react clsx motion tailwind-merge
Next.js: samples here pass functions (formatters, seriesLegend, a dashboard's load), so put them in a file that starts with "use client".
Top pages, linked and re-ranked
Each row is a link (the whole row is its hit area) with an icon. Switch the range: rows glide to their new rank and bars resize, with transform-only animation that's instant under reduced motion. Where a short bar would end inside a name, its solid end becomes two ticks above and below the text.
import { BarList, type BarListItem } from "@/components/sheenui/charts/bar-list";
// Package build (after the first npm release, or a packed tarball): import { BarList, type BarListItem } from "@sheenui/theme";
const pageIcon = (
<svg viewBox="0 0 16 16" fill="none" stroke="currentColor" strokeWidth={1.4} strokeLinejoin="round">
<path d="M4 1.75h5.25L12.5 5v9.25H4z" />
<path d="M9 1.75V5.25h3.5" />
</svg>
);
const pages: BarListItem[] = [
{ name: "/docs/getting-started", value: 2140, href: "/docs/getting-started", icon: pageIcon },
{ name: "/components/button", value: 1380, href: "/components/button", icon: pageIcon },
{ name: "/charts", value: 920, href: "/charts", icon: pageIcon },
{ name: "/foundations", value: 480, href: "/foundations", icon: pageIcon },
];
export function Example() {
return <BarList data={pages} color={3} nameHeader="Page" valueHeader="Views" aria-label="Most viewed pages" />;
}BarList
BarListLabels keys and English defaults (3)
BarListTable
Keyboard
Accessibility
- The list is a real <ul>, so screen readers read each row's name, value and (with showShare) share as text. aria-label names the list and is required.
- Interactive rows have a solid inset focus ring and are ordinary tab stops.
- For a non-visual reading, give ChartCard's table prop a BarListTable; the Chart / Table tabs then expose each value as plain table cells.
- Under reduced motion nothing morphs: the bars render at their final lengths and new data replaces the old at once.
All exports on this page
BarList— A ranked list with each value drawn as a soft bar behind its label (Tremor style): the most compact way to compare many named values.BarListTable— Every row with its value and share of the total, in the list's order.defaultBarListLabels— The built-in English strings of BarList; spread it into your own labels and change what you need.
When to use the bar list
- Use it as a ranked list chart for a top-referrers or top-pages card in an analytics dashboard, where five to ten named rows need a visible size comparison but a full bar chart would eat the whole card. It works as a tremor bar list alternative: ranked horizontal bars with a text table behind them.
- Use it for ranked leaderboards such as best-selling products, busiest API endpoints or support tickets by team, with a Show more button once you set limit so the card stays short.
- Make rows interactive when the list doubles as a filter: onValueChange turns each row into a button that sets a dashboard filter, while an item with an href becomes a link (onValueChange wins if you set both).
- Skip it when the values change over time or the categories have no natural ranking, because a Bar chart or Line chart shows trends and groups far better than a sorted list does.
- Pair it with ChartCard and BarListTable so the card gets a chart and table switch, and with SegmentedControl to flip the same list between a 7-day and 30-day range.
Frequently asked questions
Related pages
48 charts pages in all: browse them on Charts.
By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .