Proportion Bar
One measured total split into named parts, widths proportional to value, with hatched, striped and alert fills and an optional legend.
Default
Pass parts, each a label and a value. Each part's width is its share of the total. Parts are
told apart by the ground showing between them, never by a line, and only the outer ends round.
legend adds a row under the bar: swatch, label, value. formatValue formats every value the bar
shows or says.
Thin
size="thin" draws the bar 8px tall with full pill ends, for a summary inside a card. The default
is 30px, for a main balance.
A part of zero draws nothing in the bar and keeps its line in the legend ("Written off $0").
Two bars on one axis
Stack two bars in a grid with a label column, and both share one width: hours above money.
Fills
Without fill, a part takes --proportion-bar-fill-1 to -4 by its position (the fifth takes
fill-1 again). Three fills are built in:
hatched: diagonal strokes, for time or money that does not count (not billable, written off).striped: two close tones in alternating bands, for money earned and not yet collected.alert: the theme's alert fill, for the one part that needs a decision. Its legend label and value read in the alert text colour, so the part is named in text as well as by its fill.
Any other string is used as the part's CSS background: a colour, a var(), or a gradient. A part
narrower than 4px still draws at 4px so it can be hovered (the last part below); its value is in
the legend and its tooltip.
Empty
When nothing is measured, the bar draws one neutral track.
Theming
Every colour is a proportion-bar component token (components.proportion-bar in .visor.yaml).
Unbound, the default fills read the chart palette.
| Token | Drives | Unbound |
|---|---|---|
--proportion-bar-fill-1 … -4 | Default part fills by position | --chart-1 … --chart-4 |
--proportion-bar-hatch-color, --proportion-bar-hatch-gap | The hatched strokes and the ground between them | --text-tertiary, the card at 70% |
--proportion-bar-stripe-a, --proportion-bar-stripe-b | The striped bands | --color-success-500, --color-success-600 |
--proportion-bar-alert-bg, --proportion-bar-alert-text | The alert fill and its legend text | --interactive-destructive-bg, --text-error |
--proportion-bar-track-bg | The empty track | --surface-muted |
Paper binds them to its money and hours colours: Slate in light and Deep ocean at night for the
fills, Tide for fill-4, Emerald stripes for striped, and coral for alert. Every fill but coral
clears 3:1 on the card; coral is under 3:1 on the light card, which is why the legend names it in
text.
Installation
npx visor add proportion-barThis copies two files into your project:
components/ui/proportion-bar/proportion-bar.tsx— the componentcomponents/ui/proportion-bar/proportion-bar.module.css— the styles
API Reference
ProportionBarProps
| Prop | Type | Default | Description |
|---|---|---|---|
parts* | { label: string; value: number; fill?: string | 'hatched' | 'striped' | 'alert' }[] | — | The parts, left to right. A part of zero or less is left out of the bar and kept in the legend. Without `fill` a part takes --proportion-bar-fill-1 to -4 by position; any other string is its CSS background. |
size | 'default' | 'thin' | 'default' | Bar height: 30px for a main balance, 8px inside a card. |
legend | boolean | false | Draw the legend row under the bar: swatch, label, value. The alert part reads in --proportion-bar-alert-text. |
formatValue | (value: number) => string | String | Formats every value in the legend, the summary and the part tooltips. |
summary | string | — | The accessible text of the bar (a role="img"). Defaults to "186.5 h: On a package 92.25 h, …". |
The component also accepts all standard <div> HTML attributes, on the root.
Accessibility
- The bar is one
role="img"whose accessible name sums it: "186.5 h: On a package 92.25 h, Outside a package 41.5 h, …". Passsummaryto say it differently. - The legend is a plain list after the bar, readable as text.
- Each part carries a
titlewith its label and value, so a sliver can be hovered. - The alert part is named in the alert text colour, never by its fill alone.