AllocationBar
A share-split pill with legend chips; selecting a segment changes the inspected item.
Usage
AllocationBar
Inventory allocation
Segmented bar, legend and detail panel, with the selection held by the host.
Best Practices
- Keep it to three to five segments and fold the tail into an "other"; the default ladder has four steps (accent plus three inks), so give the fifth segment an explicit
color. Anything under ~2% is neither clickable nor readable. - The default ladder already paints the headline share with the accent and leaves the rest in receding inks; pass
coloronly when the segments have real category colours — colouring everything erases the point of the bar. - Colour is never the only carrier: the legend always shows the code and the percentage, and the detail panel names the segment in full.
- Render the headline figure (
$51,785) yourself, reading it offsegmentsbymodelValue, so the card's height does not change with the selection. - A progress bar expresses one advancing quantity and this expresses composition; they look alike but are not interchangeable.
API Reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
segments | AllocationSegment[] | — | The segments, described below. |
modelValue | string | — | Selected segment key. Omit and the first one reads as active. |
legend | boolean | true | Renders the legend chips underneath. |
detail | boolean | false | Renders the detail panel (active segment's label and description). |
ariaLabel | string | 'Allocation segments' | Accessible name for the segment group. |
percentFormatter | (percent: number) => string | — | Overrides the default ${percent}%. |
AllocationSegment is { key, label, short?, percent, amount?, color?, description? }. short is the legend code (falling back to label), and percent runs 0–100.
Events
| Event | Payload | Description |
|---|---|---|
update:modelValue | (key: string) | A different segment was selected. |
change | (segment: AllocationSegment) | The same move, carrying the whole segment. |
Selecting Is Inspecting
The bar is not a read-only chart: clicking a segment — or its legend chip — or dragging across it changes which one you are inspecting, without the bar itself moving. That is what separates it from a progress bar: it says what the whole is made of, not how far along it is.
The selection is fully controlled. With no modelValue the first segment reads as active, but a click or a drag still only emits — the host either binds v-model or handles change itself.
amount travels with the data but the bar never paints it: it belongs to the card's headline figure, laid out by the host (see the example).
Overview
- The segments and the legend are two sets of controls over one value inside a single radio group: the wrapper is
role="radiogroup"with anaria-label, every segment and chip isrole="radio"reportingaria-checked, and only the selected item keepstabindex="0"; arrow keys move focus and the selection within the set that has focus (wrapping). The segments addaria-label="{label}: {percent}". - Pressing and dragging along the bar selects the segment under the pointer as it goes: one event per segment crossed, a gap goes to the nearer side, and past either end the end segment holds; focus follows when it is inside the group. Releasing keeps the last selection without a click, and Escape or a cancelled pointer returns to where the drag started. On touch a sideways drag selects and a vertical swipe still scrolls the page; transitions are off during the drag, so the selection tracks the pointer 1:1.
- Clicking the active segment again emits nothing — there is no "deselect" here.
- A segment without
colorfalls back through an accent-then-receding-ink ladder by position:--tx-bui-accent→--tx-bui-ink→--tx-bui-ink-2→--tx-bui-ink-3, reusing the last step past four segments. That is how upstream expresses "colour the headline share, leave the rest grey"; the greys are the ink ramp rather than--tx-bui-line*because those sit a ΔRGB of 5–18 (≈1.03:1) from the track's--tx-bui-fieldand read as bare track in both themes. - Segment width stays exactly proportional to
percent: the track spends 2px of padding and a 2px gap, and each segment's slice of that gap budget is subtracted from its width up front (width: calc(percent% - its share of the gaps)), so the separators cost fixed pixels without redrawing the data; if the shares overrun 100% flex still shrinks them proportionally rather than clipping the last one. - The selected sheen is class-driven, not animation-driven: with motion reduced the transition is dropped and the sheen still appears immediately, with no blank gap.
- The easing is
cubic-bezier(0.16, 1, 0.3, 1)(upstream's--ease-link), heavier than this family's usual--tx-ease-out-strong. That difference is deliberate.
Technologies
- Component source and types:
packages/tuffex/packages/components/src/allocation-bar/src/(TxAllocationBar.vue,types.ts). - Drag selection reuses
packages/tuffex/packages/utils/press-scrub.ts, shared with MonoChart and DitherChart.- Adapted from Beautiful UI (https://www.beautifului.dev), © 2026 Shane Levine, MIT.