Skip to content

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.json

Top 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

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

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.tsx
  • components/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.

BarList

PropTypeDefaultDescription
data (required)readonly BarListItem[]NoneOne row per item: { name: "Searchly", value: 4821 }. Negative values draw no bar.
colorChartColor1Hue of the bars: a palette slot (1–8). One list, one hue.
sortOrder"none" | "ascending" | "descending""descending"Row order. "none" keeps the order of data.
limitnumberNoneRows shown before "Show more". Omit to show every row.
format((n: number) => string)formatCompact in localeFormats a value for the labels, tooltips and data table: takes the number, returns the text shown.
formatPercent((ratio: number) => string)percentages in localeFormats a share of the total for the labels, tooltips and data table: takes the share, returns the text shown.
localestring"en"Locale of the default number formats.
showSharebooleanfalsePrint each row's share of the total after its value.
nameHeaderReactNodeNoneColumn captions above the rows, e.g. "Source" / "Visits".
valueHeaderReactNodeNoneColumn caption above the values, e.g. "Visits".
onValueChange((item: BarListItem) => void)NoneMakes every row a button.
emptyStateReactNodeNoneShown when there are no rows.
labelsPartial<BarListLabels>defaultBarListLabelsOverride the "Show more", "Show less" and "of total" strings (i18n). Every other string, for translation: labels={{ showMore: "…" }}; omitted keys keep the English of defaultBarListLabels. All 3 keys of BarListLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the list for assistive tech.
classNamestringNoneAdds extra classes to the outer element.
BarListLabels keys and English defaults (3)
Pass any key in labels; the rest keep the defaults of defaultBarListLabels.
KeyEnglish default
showMore(hidden) => `Show ${hidden} more`
showLessShow less
ofTotalof total

BarListTable

PropTypeDefaultDescription
data (required)readonly BarListItem[]NoneOne row per item: { name: "Searchly", value: 4821 }. Negative values draw no bar.
format((n: number) => string)formatCompact in localeFormats a value for the labels, tooltips and data table: takes the number, returns the text shown.
localestring"en"Locale of the default number formats.
sortOrder"none" | "ascending" | "descending""descending"Row order. "none" keeps the order of data.
formatPercent((ratio: number) => string)percentages in localeFormats a share of the total for the labels, tooltips and data table: takes the share, returns the text shown.
captionstringNoneHidden caption that names the table for screen readers.
headersPartial<{ name: string; value: string; share: string; }>NoneOverride the column headers: { name, value, share }.
emptyStateReactNodeNoneShown when there are no rows.

Keyboard

KeysAction
TabMove to each row that is a button (onValueChange) or a link (href), and to “Show more”. A plain list has no tab stops.
Enter/Spaceon a button rowActivate it (for example, filter by that row).
Enteron a link rowFollow the link.
Enter/Spaceon Show moreReveal the remaining rows.

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

48 charts pages in all: browse them on Charts.

By Lokendra Singh Rathore (GitHub, opens in a new tab). Published , updated .