SplitBar
A bar divided between two parties, each sized by its share.
Overview
Two sides of one total: a pot split between two goals, for and against.
Parties
Do
Debt 35%Renos 65%
import { Caption, Cluster, SplitBar, Stack } from "@hackcove/ui";
<Stack gap="xs">
<SplitBar a={35} b={65} label="Pot split" names={["Debt", "Renos"]} />
<Cluster justify="between">
<Caption>Debt 35%</Caption>
<Caption>Renos 65%</Caption>
</Cluster>
</Stack>names so a screen reader hears whose share is whose, and draw the names under the bar for everyone else.Don't
import { SplitBar } from "@hackcove/ui";
<SplitBar a={35} b={65} label="Pot split" />
names and nothing under the bar: the two colours are never explained, and a screen reader hears two bare percentages.Usage
ais the left party andbthe right; each is sized by its share ofa + b.- Give
namesas[left, right], and draw the same names under the bar yourself; the bar draws no text. toneAdefaults tonegativeandtoneBtopositive. Set both when neither side is good or bad, e.g.accentandwarn.sizeissm,mdorlg(default).- More than two parts are a
StackedBar; progress toward a total is aProgressBar.
Accessibility
- A SplitBar has
role="img"and anaria-labeloflabelfollowed by each side's whole percent. - With
namesit hears each name before its percent; without, only two bare percentages. - Colour alone does not name the parties, so draw their names under the bar.
API
SplitBar
A bar split between two parties, a on the left and b on the right, each sized by its share of a + b. label names the split for a screen reader, which hears both percentages; give names (left, right) so it hears whose is whose. Put the parties' names under the bar yourself.
a required- Type
number
b required- Type
number
label required- Type
string
namesThe left and right parties, spoken before their percentages.
- Type
readonly [string, string]
sizeDefaults to "lg".
- Type
"sm" | "md" | "lg"- Default
lg
toneADefaults to "negative".
- Type
"positive" | "warn" | "accent" | "negative"- Default
negative
toneBDefaults to "positive".
- Type
"positive" | "warn" | "accent" | "negative"- Default
positive