component
BarChart
A handful of figures side by side as bars, with a label under each: grey, and green for the one that matters now. For months, not for analysis.
Defaultimport { BarChart } from 'rost/components/bar-chart/BarChart'
<BarChart
label="Income by month"
data={months.map((m) => ({ label: m.short, value: m.income, valueText: euros(m.income) }))}
current={months.length - 1}
/> src/components/bar-chart/BarChart.tsx
import type { OlHTMLAttributes } from 'react'
import './bar-chart.css'
export interface Bar {
readonly label: string
readonly value: number
/** What a screen reader says for the value, like "€1,200". */
readonly valueText?: string
}
export interface BarChartProps extends Omit<OlHTMLAttributes<HTMLOListElement>, 'children'> {
/** The bars, in order. */
readonly data: readonly Bar[]
/** Which bar is now, by its place from 0. */
readonly current?: number
/** The value of a full-height bar. The largest value by default. */
readonly max?: number
/** The chart's height in px, labels included. */
readonly height?: number
/** What the chart shows. */
readonly label: string
}
const b = 'rost-bar-chart'
const hidden = { position: 'absolute', width: 1, height: 1, overflow: 'hidden', clipPath: 'inset(50%)', whiteSpace: 'nowrap' } as const
/**
* A few figures as bars, with the current one in green. No axis, on
* purpose. Built from contracts/bar-chart.contract.yaml.
*/
export function BarChart({ data, current, max, height = 160, label, className, style, ...rest }: BarChartProps) {
const top = max ?? Math.max(...data.map((d) => d.value), 0)
return (
<ol aria-label={label} className={[b, className].filter(Boolean).join(' ')} style={{ height, ...style }} {...rest}>
{data.map((d, i) => {
const now = i === current
const share = top > 0 ? Math.min(Math.max(d.value / top, 0), 1) : 0
return (
<li key={i} className={`${b}__item`} aria-current={now ? 'true' : undefined}>
<span className={`${b}__plot`} aria-hidden="true">
<span className={`${b}__${now ? 'current-bar' : 'bar'}`} style={{ height: `${share * 100}%` }} />
</span>
<span className={`${b}__${now ? 'current-label' : 'label'}`}>
{d.label}<span style={hidden}>: {d.valueText ?? d.value}</span>
</span>
</li>
)
})}
</ol>
)
}
The source for everything on this page: contracts/bar-chart.contract.yaml (opens in a new tab). The CSS, the docs and the checks in each app are built from it.
# yaml-language-server: $schema=../schema/component-contract.schema.json
schemaVersion: 2
id: bar-chart
name: BarChart
kind: component
status: review
summary: "A handful of figures side by side as bars, with a label under each: grey, and green for the one that matters now. For months, not for analysis."
category: display
related: [ stat, progress, table ]
source:
tool: figma
fileKey: 1Zy0wiWKXQAvsfDBX3KR0d
nodeId: "749:23"
url: https://www.figma.com/design/1Zy0wiWKXQAvsfDBX3KR0d/UI-Kit-v01?node-id=749-23
extractedAt: "2026-11-17"
extractedBy: hand
frozenAt: "2026-11-17"
props:
data: { type: node, required: true, notes: "The bars, in order: `{ label, value, valueText? }`. `valueText` is what a screen reader says, like €1,200." }
current: { type: number, notes: "Which bar is now, by its place from 0. It's green." }
max: { type: number, notes: "The value of a full-height bar. The largest value by default." }
height: { type: number, default: 160, notes: "The whole chart's height in px, labels included." }
label: { type: string, required: true, notes: "What the chart shows. Its accessible name." }
elements:
root:
notes: "An `<ol>`, one item per bar, side by side and sharing the width, 8px apart. Its height comes from the `height` prop."
styles:
display: { value: flex, assert: false }
gap: { token: spacing/gap/small, value: 8px }
margin: { token: spacing/gap/none, value: 0px }
padding: { token: spacing/gap/none, value: 0px }
list-style: { value: none, assert: false }
item:
notes: "An `<li>`: the bar's room, then its label, 8px apart."
styles:
display: { value: flex, assert: false }
flex-direction: { value: column, assert: false }
flex: { value: 1 1 0, assert: false }
gap: { token: spacing/gap/small, value: 8px }
min-width: { value: "0", assert: false }
plot:
notes: "The room a full bar would take. The bar stands at its bottom."
styles:
display: { value: flex, assert: false }
align-items: { value: flex-end }
flex-grow: { value: "1", assert: false }
bar:
notes: "A bar, as tall as its value out of `max`, in a field's edge grey, with 4px corners on top."
styles:
width: { value: 100%, assert: false }
border-top-left-radius: { token: spacing/radius/xsmall, value: 4px }
border-top-right-radius: { token: spacing/radius/xsmall, value: 4px }
background: { token: bar-chart/bar, value: "#747573" }
current-bar:
notes: "The bar for now: the same shape, in the primary green."
styles:
width: { value: 100%, assert: false }
border-top-left-radius: { token: spacing/radius/xsmall, value: 4px }
border-top-right-radius: { token: spacing/radius/xsmall, value: 4px }
background: { token: bar-chart/current, value: "#00d669" }
label:
notes: "Under each bar, centred, in label type and the tertiary grey."
styles:
text-align: { value: center, assert: false }
white-space: { value: nowrap, assert: false }
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/label/font-weight/regular, value: "400" }
font-size: { token: typography/label/font-size, value: 12px }
line-height: { token: typography/label/line-height, value: 14px }
letter-spacing: { token: typography/label/letter-spacing, value: 0px }
color: { token: bar-chart/label, value: "#999999" }
current-label:
notes: "The label for now, medium weight in the main text colour."
styles:
text-align: { value: center, assert: false }
white-space: { value: nowrap, assert: false }
font-family: { token: font-family/base, value: "'General Sans Variable'" }
font-weight: { token: typography/label/font-weight/medium, value: "500" }
font-size: { token: typography/label/font-size, value: 12px }
line-height: { token: typography/label/line-height, value: 14px }
letter-spacing: { token: typography/label/letter-spacing, value: 0px }
color: { token: bar-chart/current-label, value: "#ededed" }
guidance:
status: proposed
use:
- title: How this month compares
text: "Income for the last six months, with this one in green. The Stat above it says the number; the bars say whether it's up."
avoid:
- title: Many bars
text: "Past about twelve the labels don't fit and the bars blur. Use a **Table**."
- title: Exact comparisons
text: "Bars without an axis show shape, not amounts. When the amounts matter, write them."
behaviour: "Each bar's height is its value out of `max`, which is the largest value unless you set it. It has no axis, gridlines or tooltips, on purpose."
accessibility:
element: "`<ol>` with an `aria-label`, so it's read as a list of so many items. Each `<li>` says its label and value in words."
name: "`label`: what the chart shows, like Income by month."
colour: "The grey bars are 4.3:1 on the dark page and the green one 10:1. The current label is also heavier, so the colour isn't the only sign."
content: "Short labels, like Jun or Q3. Give `valueText` in the units people read, like €1,200."
Install
npx github:Runceanu/rost add bar-chart It lands in src/rost/bar-chart/, with what it needs and its contract. Install has the rest.
When to use
How this month compares
Income for the last six months, with this one in green. The Stat above it says the number; the bars say whether it's up.
When not to use
Many bars
Past about twelve the labels don't fit and the bars blur. Use a Table.
Exact comparisons
Bars without an axis show shape, not amounts. When the amounts matter, write them.
Behaviour
Each bar's height is its value out of max, which is the largest value unless you set it. It has no axis, gridlines or tooltips, on purpose.
Accessibility
- Element
<ol>with anaria-label, so it's read as a list of so many items. Each<li>says its label and value in words. - Name
label: what the chart shows, like Income by month. - Colour
The grey bars are 4.3:1 on the dark page and the green one 10:1. The current label is also heavier, so the colour isn't the only sign.
Content
Short labels, like Jun or Q3. Give valueText in the units people read, like €1,200.
Props
| Prop | Type | Values | Default |
|---|---|---|---|
data | node | | |
current | number | | |
max | number | | |
height | number | | 160 |
label | string | | |
Values
Straight from the contract. Each value sits next to its token, because six tokens here all come out as #3a3a3a and the colour alone can't tell you which one is right.
Never changes
root
-
gap8pxspacing/gap/small -
margin0pxspacing/gap/none -
padding0pxspacing/gap/none
displayflex · list-stylenone
item
-
gap8pxspacing/gap/small
displayflex · flex-directioncolumn · flex1 1 0 · min-width0
plot
displayflex · align-itemsflex-end · flex-grow1
bar
-
border-top-left-radius4pxspacing/radius/xsmall -
border-top-right-radius4pxspacing/radius/xsmall -
background#747573bar-chart/bar
width100%
current-bar
-
border-top-left-radius4pxspacing/radius/xsmall -
border-top-right-radius4pxspacing/radius/xsmall -
background#00d669bar-chart/current
width100%
label
-
font-family'General Sans Variable'font-family/base -
font-weight400typography/label/font-weight/regular -
font-size12pxtypography/label/font-size -
line-height14pxtypography/label/line-height -
letter-spacing0pxtypography/label/letter-spacing -
color#999999bar-chart/label
text-aligncenter · white-spacenowrap
current-label
-
font-family'General Sans Variable'font-family/base -
font-weight500typography/label/font-weight/medium -
font-size12pxtypography/label/font-size -
line-height14pxtypography/label/line-height -
letter-spacing0pxtypography/label/letter-spacing -
color#edededbar-chart/current-label
text-aligncenter · white-spacenowrap