Rost

← All components

component

Legend

What a chart's colours mean: a small square of each, its name and, if it helps, its value, in a row that wraps.

In code Contract: review Guidance: proposed Contract on GitHub Figma 753:25 As markdown
  • Earlier months
  • November€2,760
Default

Install

npx github:Runceanu/rost add legend

It lands in src/rost/legend/, with what it needs and its contract. Install has the rest.

When to use

  • Under a chart

    Under a BarChart, saying that green is this month and grey the ones before, with this month's total.

When not to use

  • One colour

    A chart with one colour needs a title, not a legend.

Behaviour

It lists what each colour means, in the order the chart uses them. It doesn't draw the chart or know about it.

Accessibility

  • Element

    <ul>; the squares are drawing, hidden from screen readers, so each item reads as its name and value.

  • Colour

    The names are 11:1 and the values 17:1 on the dark page. The squares are 4.3:1 and 10:1.

Content

Name what the colour stands for (This month, Earlier), not the colour.

Props

PropTypeValuesDefault
items node

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

  • column-gap 16px spacing/gap/medium
  • row-gap 8px spacing/gap/small
  • margin 0px spacing/gap/none
  • padding 0px spacing/gap/none

displayflex · flex-wrapwrap · list-stylenone

item

  • gap 6px spacing/gap/xsmall

displayinline-flex · align-itemscenter

swatch

  • width 8px spacing/gap/small
  • height 8px spacing/gap/small
  • border-radius 2px spacing/radius/2xsmall
  • background #747573 legend/swatch

displayblock · flex-shrink0

current-swatch

  • width 8px spacing/gap/small
  • height 8px spacing/gap/small
  • border-radius 2px spacing/radius/2xsmall
  • background #00d669 legend/current-swatch

displayblock · flex-shrink0

label

  • font-family 'General Sans Variable' font-family/base
  • font-weight 400 typography/label/font-weight/regular
  • font-size 12px typography/label/font-size
  • line-height 14px typography/label/line-height
  • letter-spacing 0px typography/label/letter-spacing
  • color #d3d9d5 legend/label

value

  • font-family 'General Sans Variable' font-family/base
  • font-weight 500 typography/label/font-weight/medium
  • font-size 12px typography/label/font-size
  • line-height 14px typography/label/line-height
  • letter-spacing 0px typography/label/letter-spacing
  • color #ededed legend/value