Skip to content

Category Bar for React

A React category bar splits one bar into named bands and pins where a value sits, such as a credit score or an NPS. Pass data as readonly CategoryBarItem[]: the bands, start to end.

npx shadcn@latest add https://lokendra-builds.github.io/sheenui/r/category-bar.json

Credit score

Use the arrow keys to read each band.

Poor 300–580. Fair 580–670. Good 670–740. Very good 740–800. Exceptional 800–850. Your score: 724, in Good

  • CategoryBar
  • CategoryBarTable
  • defaultCategoryBarLabels
  • +1 more

Score with a marker

Bands on a 300–850 scale. Switch the month: the pin glides to the new score and its number rolls. Focus the bar and use the arrow keys to read each band.

Credit score

FICO® bands on the 300–850 scale

Use the arrow keys to read each band.

Poor 300–580. Fair 580–670. Good 670–740. Very good 740–800. Exceptional 800–850. Your score: 724, in Good

Files to copy

15 folders · 32 files · 4 packages
From theme/src/
  • components/charts/{category-bar.tsx, chart-export-menu.tsx, chart-export.ts, chart-figure.tsx, chart-fit.tsx, chart-icons.tsx, chart-parts.tsx, chart-patterns.tsx, chart-pointer.tsx, chart-tip.tsx, chart-utils.ts, heatmap.tsx}
  • components/button/
  • components/charts/category-bar/
  • 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-direction.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/category-bar.jsonRegistry item: category-bar. 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".

Budgets and scores

Custom formats, a scale that starts below zero, and the compact size. Long boundary values drop out before they could touch.

Checkout latency

p95 over the last hour

Use the arrow keys to read each band.

Fast 0 ms–200 ms. Acceptable 200 ms–500 ms. Slow 500 ms–1,000 ms. Critical 1,000 ms–1,500 ms. p95: 342 ms, in Acceptable

Net promoter score

Q3 survey, 1,284 replies

Use the arrow keys to read each band.

Needs work −100 – 0. Good 0–30. Great 30–70. Excellent 70–100. NPS: 46, in Great

Props

PropTypeDefaultDescription
data (required)readonly CategoryBarItem[]NoneThe bands, start to end. Their values are widths on one scale.
startnumber0Where the scale starts (e.g. 300 for a credit score).
markernumber | nullnullA value on the same scale to point at (e.g. the current score). A value past either end keeps its real number (bubble, announcement, table) while the pin waits at that end with an arrow.
markerLabelstringNoneText in the marker's bubble, before its value (e.g. "Your score").
showValuesbooleantruePrint the values at the band boundaries under the bar.
showLegendbooleanfalsePrint each band's colour key and name under the bar.
size"sm" | "md" | "lg""md"Bar thickness: "sm" 6px, "md" 8px (default), "lg" 12px.
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 format.
emptyStateReactNodeNoneShown when there are no bands.
labelsPartial<CategoryBarLabels>defaultCategoryBarLabelsEvery other string, for translation: labels={{ instructions: "…" }}; omitted keys keep the English of defaultCategoryBarLabels. All 11 keys of CategoryBarLabels are listed in the key table under the props table.
aria-label (required)stringNoneNames the bar for assistive tech (e.g. "Credit score bands").
classNamestringNoneAdds extra classes to the outer element.
CategoryBarLabels keys and English defaults (11)
Pass any key in labels; the rest keep the defaults of defaultCategoryBarLabels.
KeyEnglish default
instructionsUse the arrow keys to read each band.
range(low, high) => (/^[-−]/.test(low) || /^[-−]/.test(high) ? `${low} – ${high}` : `${low}–${high}`)
markerMarker
markerIn(value, band) => `${value}, in ${band}`
markerAbove(value) => `${value}, above the scale`
markerBelow(value) => `${value}, below the scale`
bandBand
fromFrom
toTo
shareShare
emptyNo data

CategoryBarTable props

PropTypeDefaultDescription
data (required)readonly CategoryBarItem[]NoneThe bands, start to end. Their values are widths on one scale.
markernumber | nullNoneA value on the same scale to point at (e.g. the current score). A value past either end keeps its real number (bubble, announcement, table) while the pin waits at that end with an arrow.
format((n: number) => string)formatCompact in localeFormats a value for the labels, tooltips and data table: takes the number, returns the text shown.
startnumber0Where the scale starts (e.g. 300 for a credit score).
labelsPartial<CategoryBarLabels>defaultCategoryBarLabelsEvery other string, for translation: labels={{ instructions: "…" }}; omitted keys keep the English of defaultCategoryBarLabels. All 11 keys of CategoryBarLabels are listed in the key table under the props table.
localestring"en"Locale of the default number format.
markerLabelstringNoneText in the marker's bubble, before its value (e.g. "Your score").
formatPercent((ratio: number) => string)percentages in localeFormats a share of the total for the data table cells: takes the share, returns the text shown.
captionstringNoneHidden caption that names the table for screen readers.

Keyboard

KeysAction
TabFocus the bar (one tab stop).
→/↓Next band (← in right-to-left layouts).
←/↑Previous band.
Home/EndFirst / last band.
EscapeStop reading.

Accessibility

  • The bar is one focusable figure with a role description of “chart”; its description is the keyboard hint, and its description lists every band and where the marker falls.
  • Moving through the bands announces each span once through a polite live region; pointer hovers stay silent.
  • Bands are named in the legend, the tooltip and the table: color is never the only cue. Boundary values thin out instead of overlapping.
  • On touch screens the hit area grows to 44px without moving anything; forced colors outline every band and the pin.
  • Reduced motion: bands, pin and number appear in place, with no slide or roll.

All exports on this page

  • CategoryBar — A single bar split into bands, with an optional marker: where a score, a reading or a forecast sits on a scale of named ranges (Tremor's CategoryBar).
  • CategoryBarTable — Every band with its span and share of the scale, then where the marker falls.
  • defaultCategoryBarLabels — The built-in English strings of CategoryBar; spread it into your own labels and change what you need.

When to use the category bar chart

  • Use it as a credit score bar to place a score, risk rating or health reading on a scale of named bands such as Poor, Fair, Good and Excellent, with the marker showing where the person sits now. Use it as a segmented bar chart when one total splits into a few named bands, such as a score ranging from low to high.
  • Use it as a compact forecast bar inside a table row or settings card: bands sized to real values, boundary numbers underneath, and one pin with a label and value bubble.
  • Set start when the scale does not begin at zero, for example 300 for a credit score, and marker to a value outside the scale to see it pinned to an end with an arrow.
  • Skip it when the segments are parts of a whole that must sum to something, where a Percent bar chart or Donut chart fits, or when you rank many items, where Bar list is the better tool.
  • Pair it with ChartCard and CategoryBarTable for a text view, plus a Badge next to it to name the current band in words for readers who skip charts.

Frequently asked questions

48 charts pages in all: browse them on Charts.

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