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-barThis is a Pro component. The command works once your project has a licence key: set up Pro or see pricing.
Data shape
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
};[
{ name: "Search", value: 4210 },
{ name: "Direct", value: 2870 },
{ name: "Social", value: 1340 },
{ name: "Email", value: null },
]Props
| Prop | Type | Default | Description |
|---|---|---|---|
data | readonly CategoryBarSegment[] | Required | The 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. |
label | string | Required | What 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. |
boundaries | boolean | Default true | Show 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. |
legend | boolean | Default true | Show the legend with each segment's share. |
format | Intl.NumberFormatOptions | Default compact | How values, boundary totals and the marker are written. Shares are always percentages. |
locale | string | Default "en-US" | Locale for number formatting. |
sound | boolean | Default true | Play a soft tick as the pointer or keyboard cursor moves across segments, if the visitor has sound on. |
emptyLabel | string | Default "No data" | Text shown under an empty track when no segment has a value. |
className | string | – | 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.
| Keys | Action |
|---|---|
| Tab | Focus the bar. The floating readout opens on the last segment. |
| ← → | Move between segments. |
| Home / End | Jump to the first or last segment. |
| Esc | Hide the readout. |
Source
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.0.0 · 2026-12-03First release.