UI

Split bar

Single 100% horizontal stacked bar with hover widening, rolling readout, collision-avoiding leader lines, and interactive legend toggles.

import { SplitBar } from '@uthereal/ui/split-bar'

Split bar playground

Traffic by sourceLast 30 days across all public pages.

Traffic by source
SegmentValueShare
Organic search48,200 visits41.6%
Direct28,700 visits24.7%
Social18,400 visits15.9%
Email11,200 visits9.7%
Referral6,400 visits5.5%
Other3,100 visits2.7%
Total116,000 visits100.0%
Loading interactive preview…

Overview

A split bar divides one horizontal 100% track into proportional category shares. Pointing at or focusing a segment widens it gently so narrow segments can reveal their label while neighbors yield proportionally and dim. A live readout beside the title crossfades between the visible total and the highlighted segment's exact share, value, and unit. Labels sit inside segments when they fit (name and share, or share alone) and move into a leader-line lane underneath with collision avoidance when they do not. Legend buttons switch segments off and on so the remaining shares reflow to 100% on springs with rolling odometer digits. A native data table lists every segment, its value, its share, and the visible total.

Use a split bar for a compact part-to-whole breakdown of two to eight categories—such as traffic sources, budget lines, storage usage, or device mix—inside a card or dashboard header. To compare absolute magnitudes across many categories, use a bar chart. When the total in the center is the focal point, use a donut chart. For unit counts on a 10×10 grid, use a waffle chart. For shares tracked over time, use a streamgraph.

Usage

import { useState } from 'react'
import { SplitBar, type SplitSegment } from '@uthereal/ui/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: 'software', label: 'Software', value: 18_900 },
  { id: 'other', label: 'Other', value: 9_300 },
]

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

Keep segment id values stable across periods or filters so the bar reflows continuously instead of redrawing. Pass hidden and onHiddenChange to synchronize excluded categories with sibling charts or URL filters, and place catch-all shares such as Other last so they receive the neutral palette tones.

Examples

Currency budget with excluded segment and table toggle

Combine valueFormat for currency readouts, defaultHidden to start with a category excluded, a custom totalLabel, and tableToggle to reveal the accessible data table on demand.

Q4 operating budget

Q4 operating budget
SegmentValueShare
Payroll$412,00068.5%
Cloud$96,50016.0%
Marketing$74,20012.3%
Software$18,9003.1%
Other$9,300Hidden
Quarterly spend$601,600100.0%

Behavior

ConditionLayout and interaction behavior
Segment fits name + shareRenders name and 1-decimal percentage inside the clipped segment layer
Segment fits share onlyCollapses the name on a spring and keeps the rolling percentage inside
Segment narrower than shareMoves label into the 40 px lane beneath the bar with a morphed S-curve leader line
Multiple narrow segmentsSweeps callouts apart left-to-right and clamps from the end edge; drops names if named labels exceed bar width
Active segment hover / focusExpands by at least 4.5% of the bar (up to 42% to fit its full label, capped at 90%) while neighbors scale down
Last visible segment toggleRefuses to hide the final positive share, shakes its legend label once, and announces the reason

Text widths come from cached canvas metrics rather than DOM layout reads, and a ResizeObserver recalculates label placement as the container width changes. On containers 420 px or narrower, the readout wraps beneath the title. On touch devices, tapping a segment highlights it and tapping outside clears it without blocking vertical page scroll.

API reference

These serializable arguments and defaults come directly from the component schema.

ArgumentType / defaultDescription
titlestringDefault: "Split bar"Figure title. It names the chart for assistive technology and captions the data table.
descriptionstring—One or two sentences on what the chart shows, below the title; omit it when the title says enough.
labelstring—Accessible name for the bar group and legend list. Defaults to title when omitted.
segmentsSplitSegment[]Default: [{"id":"organic","label":"Organic search","value":48200},{"id":"direct","label":"Direct","value":28700},{"id":"social","label":"Social","value":18400},{"id":"email","label":"Email","value":11200},{"id":"referral","label":"Referral","value":6400},{"id":"other","label":"Other","value":3100}]Ordered shares (1–16, unique IDs). Zero values are omitted from the bar; keep IDs stable across updates so segments reflow continuously. Defaults to series1–series4 then muted and borderStrong for catch-all shares.
unitstring—Optional word appended after values in the readout, live announcements, and data table, such as "sessions" or "GB".
totalLabelstringDefault: "Total"Readout label shown beside the visible total when no segment is highlighted.
valueFormatNumberFormat—Intl number format for values in the readout, announcements, and data table (for example currency). Shares always format as percentages with one decimal.
defaultHiddenstring[]Default: []Segment IDs switched off initially when uncontrolled. Later edits do not reset a mounted instance; use hidden and onHiddenChange to control them.
legendbooleanDefault: trueShow interactive legend buttons below the bar. Each button toggles its segment off or on and highlights it on pointer hover.
tableTogglebooleanDefault: falseShow a button that reveals the data table. The table is always available to assistive technology.
tableLabelstringDefault: "Data table"Name of the data table button.
localestring—BCP 47 locale for numbers and dates. Omit it to inherit the application locale (en-US by default).
recipestudio | softDefault: "studio"Visual treatment. Both recipes use the same interaction behavior.
themeSplitBarTheme—Color mode, accent, and semantic tokens including series1–series4, mutedForeground, and borderStrong for default segment fills. See Theming.
motionnone | subtle | expressiveDefault: "subtle"Segment reflow, odometer digit, readout crossfade, and leader-line animation preset. System reduced-motion preferences take precedence.
motionOptionsSplitBarMotionOptions—morph overrides the spring or tween used for segment edge reflow, odometer wheels, and outside label gliding (smooth 400 ms zero-bounce spring by default); draw is accepted for shared chart presets.
dirltr | rtl—Reading direction for segment flow, inside labels, header readout, legend, and the data table. Omit to inherit the page direction.

React integration

PropPurpose
hiddenControlled array of hidden segment IDs
onHiddenChangeFires with the next hidden segment ID list when toggled from the bar or legend
presetApplication defaults, overridden by explicit instance props
tokensCSS variables applied after the typed theme
refRef forwarded to the root <figure>
className, styleApplied to the root <figure>
Native attributesid, data-*, and remaining <figure> attributes forwarded to the root

Keyboard & accessibility

KeyInteraction
TabFocus the bar group, then each legend toggle button, then the optional data table toggle
ArrowRight, ArrowDownOn the bar: highlight the next visible segment (ArrowLeft, ArrowDown in dir="rtl")
ArrowLeft, ArrowUpOn the bar: highlight the previous visible segment (ArrowRight, ArrowUp in dir="rtl")
Home, EndOn the bar: highlight the first or last visible segment
Enter, SpaceOn the bar: hide the highlighted segment; on a legend button: toggle that segment
EscapeClear the active segment highlight

The chart renders a <figure> named by title and linked via aria-details to a native data table listing Segment, Value, Share (or Hidden), and the visible total row. Inside labels, outside callouts, leader lines, and rolling digit wheels are hidden from assistive technology; the bar role="group" (aria-roledescription="split bar") carries the full share summary in its accessible name, and keyboard navigation updates a polite role="status" live region with the segment's name, share, value, and unit.

Legend items are native toggle buttons with aria-pressed and non-color state cues when off (hollow outlined swatch, struck-through label, and Off readout). Segment flow, clip-paths, trailing caps, inside labels, leader anchors, readout alignment, and horizontal arrow keys mirror cleanly in dir="rtl". Under forced-colors: active, system colors (Canvas, CanvasText, Highlight, HighlightText, GrayText) replace tinted segment fills and swatches.

Motion and theming

Each segment renders as a full-width layer clipped via an animated clip-path on a smooth zero-bounce spring (400 ms by default, configurable via motionOptions.morph), so reflow never triggers layout and mid-flight targets keep their velocity. Inside segment names open and close on a morph spring, outside callouts glide into place while their S-curve leaders morph, the header readout crossfades with subtle vertical travel and blur, and all shares and totals roll digit by digit like an odometer.

Under prefers-reduced-motion: reduce, segments, outside labels, and digits jump immediately without travel, blur, or refusal shakes while readouts and legend shares crossfade cleanly in 120 ms. Setting motion="none" turns all motion and CSS transitions to 0 ms.

theme accepts a mode, an accent, and semantic tokens across the core, control, and chart token groups (series1–series4 tint the first four shares, followed by mutedForeground and borderStrong for catch-all shares). An application-wide UtherealProvider supplies defaults.

Composition

In an agent composition, SplitBar is a leaf with no actions. Hidden segment IDs persist as host state at /components/instance-<id>/hidden, initialized from defaultHidden and reconciled to keep valid IDs and at least one visible positive share. The host updates segments through composition updates. See Building with agents.

{
  "type": "SplitBar",
  "props": {
    "title": "Traffic by source",
    "unit": "visits",
    "segments": [
      { "id": "organic", "label": "Organic search", "value": 48200 },
      { "id": "direct", "label": "Direct", "value": 28700 },
      { "id": "social", "label": "Social", "value": 18400 },
      { "id": "email", "label": "Email", "value": 11200 },
      { "id": "referral", "label": "Referral", "value": 6400 },
      { "id": "other", "label": "Other", "value": 3100 }
    ]
  },
  "children": []
}

On this page