VisorVisor
ComponentsData Display

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.

  • On a package 92.25 h
  • Outside a package 41.5 h
  • Covered 18 h
  • Investment 21.5 h
  • Not billable 4 h
  • Unresolved 9.25 h

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.

  • Invoiced $12,455
  • Waiting $9,025
  • Written off $0

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.

Hours
  • On a package 92.25 h
  • Outside a package 41.5 h
  • Covered 18 h
  • Investment 21.5 h
  • Not billable 4 h
  • Unresolved 9.25 h
Money
  • Invoiced $12,455
  • Waiting $9,025
  • Written off $0

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.

  • fill-1 3
  • fill-2 3
  • fill-3 3
  • fill-4 3
  • hatched 3
  • striped 3
  • alert 3
  • sliver 0.05

Empty

When nothing is measured, the bar draws one neutral track.

  • Earned $0

Theming

Every colour is a proportion-bar component token (components.proportion-bar in .visor.yaml). Unbound, the default fills read the chart palette.

TokenDrivesUnbound
--proportion-bar-fill-1 … -4Default part fills by position--chart-1 … --chart-4
--proportion-bar-hatch-color, --proportion-bar-hatch-gapThe hatched strokes and the ground between them--text-tertiary, the card at 70%
--proportion-bar-stripe-a, --proportion-bar-stripe-bThe striped bands--color-success-500, --color-success-600
--proportion-bar-alert-bg, --proportion-bar-alert-textThe alert fill and its legend text--interactive-destructive-bg, --text-error
--proportion-bar-track-bgThe 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-bar

This copies two files into your project:

  • components/ui/proportion-bar/proportion-bar.tsx — the component
  • components/ui/proportion-bar/proportion-bar.module.css — the styles

API Reference

ProportionBarProps

PropTypeDefaultDescription
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.
legendbooleanfalseDraw the legend row under the bar: swatch, label, value. The alert part reads in --proportion-bar-alert-text.
formatValue(value: number) => stringStringFormats every value in the legend, the summary and the part tooltips.
summarystring—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, …". Pass summary to say it differently.
  • The legend is a plain list after the bar, readable as text.
  • Each part carries a title with 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.