StackBar
The mock's .bar split into parts (commission status, wallet free / held). The legend carries the meaning.
import { StackBar } from '@ergasti/bricks';Examples
Commission status
One bar split by value, with the legend under it.
Code
import { Card, StackBar } from '@ergasti/bricks';
function Commission() {
return (
<div style={{ maxWidth: 520 }}>
<Card>
<Card.Header title="Commission status" />
<StackBar
parts={[
{ key: 'p', value: 96410, label: 'Pending', display: 'EGP 96,410.00', tone: 'butter' },
{ key: 'a', value: 141230, label: 'Approved', display: 'EGP 141,230.00', tone: 'rasp' },
{ key: 'd', value: 275000, label: 'Paid', display: 'EGP 275,000.00', tone: 'lime' },
]}
/>
</Card>
</div>
);
}A legend on its own
center centres it under a chart.
Code
import { Legend } from '@ergasti/bricks';
function Alone() {
return <Legend center items={[{ key: 'a', label: 'Selected', display: '304', tone: 'rasp' }, { key: 'b', label: 'Remaining', display: '79', tone: 'track' }]} />;
}Thinner bar
height sets the bar's thickness in px (default 14).
Code
import { StackBar } from '@ergasti/bricks';
function Thin() {
return <div style={{ maxWidth: 520 }}><StackBar height={8} parts={[{ key: 'u', value: 304, label: 'Used', display: '304', tone: 'rasp' }, { key: 'f', value: 96, label: 'Free', display: '96', tone: 'track' }]} /></div>;
}Props
Prop
Type
Design guidance
How the BRICKS design system uses StackBar. Written in docs/content/components/StackBar.md; the props above are read from the code, which wins where the two disagree.
One horizontal bar split into coloured parts, with a legend underneath; use it to show how a total divides (commission pending / approved / paid, wallet free / held).
StackBar is the mock's commBar(): a rounded pill (14px tall by default) on a grey track, each part's width its share of the sum, and a Legend below that carries the meaning and the formatted figures. Part values can be 2-dp money strings; the share is computed only for the width (display geometry, never a shown figure).
Anatomy
- Bar (
.kit-bar,aria-hidden): 99px radius,--trackbackground, overflow hidden. - Parts (
i): width = part / total (0–100 %), colour fromtone, in array order from the inline start. - Legend (
ul.kit-legend): swatch, label,displayper part.
Variants
| Prop | Value | Look | When |
|---|---|---|---|
height | 14 (default) | The mock's commission bar | Card summaries |
height | any number | Thicker or thinner bar (the Tall story uses 24) | Hero summaries |
Part tone: 'rasp', 'rasp-soft', 'track', 'butter', 'lime', 'sky', 'ink'. The mock uses butter = pending, rasp = approved, lime = paid.
States
| State | Trigger | Look |
|---|---|---|
| Default | several parts | Segments side by side |
| One part | one item | Full bar in one colour |
| All zero / invalid | total ≤ 0 or non-numeric values | Empty grey track; the legend still shows display |
| Negative part | value < 0 | Counted as 0 |
Types
StackPart (parts): { key; label: ReactNode; display: ReactNode; tone: ChartTone; value: string | number }. value is only used for the share.
Usage
The Payments › Commissions card:
<Card>
<Card.Header title={<>Commission · <Money value="512640.00" /></>} sub="All time, earned by your creators" />
<StackBar parts={[
{ key: 'pending', label: 'Pending', value: '96410.00', display: <Money value="96410.00" />, tone: 'butter' },
{ key: 'approved', label: 'Approved', value: '141230.00', display: <Money value="141230.00" />, tone: 'rasp' },
{ key: 'paid', label: 'Paid', value: '275000.00', display: <Money value="275000.00" />, tone: 'lime' },
]} />
</Card>Followed by the orders table, as on the screen:
<Card><StackBar parts={parts} /></Card>
<Card>
<ListToolbar search={search} sort={sort} />
<DataTable label="Orders" columns={columns} rows={orders} rowKey={(o) => o.no} footer={<Pager {...pager} />} />
</Card>Where it appears
- Brand › Payments › Commissions › Commission card at the top of the tab.
- Screen: Payments › Wallet (Payments).
Guidelines
Do
- Pass money as the 2-dp string the API returns for both
valueand<Money value>. - Keep the legend order equal to the bar order.
- Use 2 to 4 parts.
Don't
- Don't format the share as a percentage in the label; the legend shows the amounts.
- Don't use it for progress toward a goal; use
ShareBarorProgressRow.
RTL and Arabic
- The bar fills from the inline start: the first part is on the right in Arabic.
- Legend values stay
dir="ltr";<Money>gives Arabic its currency word.
Tokens
From CSS: --track (the bar), --ink-2 (legend text). The part and swatch colours are set inline from TONE_COLOR: var(--rasp), var(--rasp-soft), var(--chart-butter), var(--chart-lime), var(--sky-ink), var(--ink) by tone.
Accessibility
- The bar is
aria-hidden; the legend list carries every label and value as text. - No interactive parts.
Found in the source
- ARIA attributes set:
aria-hidden.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
Legend: the legend alone.Gauge: the semi-circle version for capacity.ShareBar: a single share with its percentage.
See also: Card · AreaTrend · BarChart · HBars
Source
src/kit/patterns/StackBar.tsx (line 29) on GitHub.