Xzero UI
Pro library

Split barPro

A single 100% bar split into shares: rest on a segment to widen it and read its exact figures, toggle segments from the legend and the rest reflow, with labels inside when they fit and on leader lines when they don't.

$ pnpm dlx shadcn@4.23.0 add @xzero-ui-pro/split-bar
Live · keyboard ready

When to use

When not to use

Installation

Register both Xzero UI namespaces in your project's components.json:

{
  "registries": {
    "@xzero-ui": "https://mcp.xzero.co.uk/r/{name}.json",
    "@xzero-ui-pro": "https://mcp.xzero.co.uk/r/pro/{name}.json"
  }
}
npx shadcn@4.23.0 add @xzero-ui-pro/split-bar

Install xzero-foundation once, and import @/components/xzero/foundation.css in your app root. No Xzero token is used by this snapshot. For sample portraits, photos, fonts, or logos, download https://mcp.xzero.co.uk/install-assets.mjs and run node xzero-install-assets.mjs <receiving-project>.

Usage

import { SplitBar, type SplitSegment } from "@/components/xzero/split-bar/split-bar";

const budget: SplitSegment[] = [
  { id: "payroll", label: "Payroll", value: 412_000 },
  { id: "cloud", label: "Cloud", value: 96_500 },
  { id: "marketing", label: "Marketing", value: 74_200 },
  { id: "tools", label: "Software", value: 18_900 },
  { id: "other", label: "Other", value: 9_300 },
];

export function BudgetSplit() {
  const [hidden, setHidden] = useState<string[]>([]);
  return (
    <SplitBar
      title="Q4 budget"
      segments={budget}
      format={{ style: "currency", currency: "USD", maximumFractionDigits: 0 }}
      hidden={hidden}
      onHiddenChange={setHidden}
    />
  );
}

API reference

SplitBar

One 100% bar split into shares, for traffic sources, budgets, storage or votes. Rest on a segment and it widens a little (small ones widen enough to show their own label) while the others give way proportionally and dim, and the readout above names it precisely: share, value and unit. Labels sit inside a segment when they fit, as name and percent or percent alone, and otherwise move to a lane under the bar with soft leader lines, pushed apart so they never overlap. The legend switches segments off and on: a hidden segment collapses in place and the rest reflow to fill the bar on springs, their percentages rolling to the new shares. New data does the same, so switching a period is one continuous reflow.

PropTypeDefaultDescription
segmentsreadonly SplitSegment[]–The shares in display order: { id, label, value, color? }. Shares are each value over the total of the visible segments; zero and negative values are left out. Segments are matched by id when the data changes.
segments[].colorstring–Any CSS color. Defaults to --series-1 to --series-4, then two neutrals meant for catch-all shares such as Referral or Other.
titlestring–Heading above the bar and the accessible name unless label is set.
descriptionstring–One line under the title.
formatIntl.NumberFormatOptions–Number format for values in the readout, such as currency for a budget. Shares always read as percentages with one decimal.
unitstring–Word after values in the readout, such as sessions.
totalLabelstring"Total"Label of the readout when nothing is highlighted.
hiddenreadonly string[]–Ids of segments that are switched off (controlled).
defaultHiddenreadonly string[][]Ids switched off at first (uncontrolled).
onHiddenChange(hidden: string[]) => void–Called with the new list when the legend or the keyboard switches a segment.
legendbooleantrueShow the legend. Each item toggles its segment and highlights it on hover.
localestring"en-US"Formatting locale. Fixed by default so server and client render the same digits.
labelstring–Accessible name. Defaults to the title.
classNamestring–Class on the root element.
styleCSSProperties–Inline styles on the root element.

Keyboard interactions

KeysAction
TabFocuses the bar, then each legend item.
Arrow Right / Arrow DownOn the bar: highlights the next visible segment, widening it and reading it out.
Arrow Left / Arrow UpOn the bar: highlights the previous visible segment.
Home / EndOn the bar: highlights the first or last visible segment.
Enter / SpaceOn the bar: switches the highlighted segment off. On a legend item: switches its segment off or back on.
EscapeClears the highlight.

Accessibility

Motion

Responsive behavior

Performance

Notes for AI

Also in charts

Guidance for AI tools

Split bar: A single 100% bar split into shares: rest on a segment to widen it and read its exact figures, toggle segments from the legend and the rest reflow, with labels inside when they fit and on leader lines when they don't. Follow the declared prop types and do not invent props. Keep keyboard access, reduced motion support, and both light and dark themes intact when adapting it.

Full library index: https://ui.xzero.co.uk/llms.txt

Browse all components