Skip to content
Thrum

Category bar

One bar split into segments by share: traffic by source, budget by team, tickets by state. Running totals sit under the boundaries, a legend gives each share, and an optional pointer marks a value such as a target. For parts of a whole with a total in the middle, use the donut chart; for ranked rows, use the bar list.

Install

npx shadcn@latest add @thrum-pro/category-bar

This is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.

Data shape

Type
type CategoryBarSegment = {
  key?: string;         // default: name
  name: string;
  value: number | null; // 0, negative or null take no room
  color?: string;       // default: var(--chart-n) by position
};
Sample
[
  { name: "Search", value: 4210 },
  { name: "Direct", value: 2870 },
  { name: "Social", value: 1340 },
  { name: "Email", value: null },
]

Props

PropTypeDefaultDescription
datareadonly CategoryBarSegment[]RequiredThe segments, left to right. With more than five, the four largest keep their places and the rest join one “Other” segment at the end, in the muted colour.
labelstringRequiredWhat the bar splits. Starts the text that screen readers hear.
marker{ value: number; label?: string }–A pointer at one value along the bar, counted from its start in the unit of the values. Above it: the label, then the formatted value. A value past the end of the bar stops at the end.
boundariesbooleanDefault trueShow the running totals under the segment boundaries. The first and last always show; a middle one is left out where it would touch a neighbour.
legendbooleanDefault trueShow the legend with each segment's share.
formatIntl.NumberFormatOptionsDefault compactHow values, boundary totals and the marker are written. Shares are always percentages.
localestringDefault "en-US"Locale for number formatting.
soundbooleanDefault truePlay a soft tick as the pointer or keyboard cursor moves across segments, if the visitor has sound on.
emptyLabelstringDefault "No data"Text shown under an empty track when no segment has a value.
classNamestring–Merged onto the root. It fills the width it is given.

Motion and sound

Motion

  • First draw: each segment grows from its left edge in 250 ms, 40 ms after the one before. The pointer moves in from the start of the bar in 400 ms.
  • New data with the same number of segments: segments and the pointer move to their new places in 400 ms with no overshoot. A different number of segments is drawn again at once.
  • Reduced motion: everything appears in place at once.

Sound

  • A soft tick as the pointer or keyboard cursor moves between segments.

Sound is off until the visitor turns it on. Pass sound={false} to keep this component silent. How sound works

Accessibility

  • The whole bar is one image whose text lists every segment with its share and value, then the marker: “Traffic by source: Search 49.6%, 4.2K; Direct 33.8%, 2.9K. Target at 6K.”
  • Segments are separated by a 2 px gap and named in the legend in the same order, so they are never told apart by colour alone.
  • The pointer is a dark caret and tick with a ring of the background colour, so it shows on every segment in both themes.
  • Keyboard users can focus the bar and step through segments with the arrow keys, Home, End, and Esc to inspect each segment in the floating readout.
KeysAction
TabFocus the bar. The floating readout opens on the last segment.
← →Move between segments.
Home / EndJump to the first or last segment.
EscHide the readout.

Source

SourcePro

The source comes with Pro

TypeScript source · Copy-paste ready · MIT-compatible for client projects · Includes all dependencies

Files and dependencies

Adds
components/ui/category-bar.tsx
Packages
motion
Brings along
Chart foundationsMotion tokensSound engineChart tooltip

Changelog

  1. 1.0.0 · 2026-12-03First release.

Loading index…

Keyboard shortcuts

/Ctrl KSearch components, docs and actions
?Show this list
AAppearance studio
SSound on or off
MFull or reduced motion
TTheme: auto, light, dark
GSurface: solid or frosted
BBackdrop photograph (under glass)
CCorner radius: square to round
RReplay the demo, on a component page
DDraw new data, on a component page
←→HomeEndMove the cursor in a focused chart
EscClose a dialog, or leave a chart cursor