Skip to Content
BBRICKSv0.7.4
KitCharts

Legend

The mock's .legend: a swatch, the label (often a term), the value.

import { Legend } from '@ergasti/bricks';

Examples

Commission status

One bar split by value, with the legend under it.

Code
import { Card, StackBar } from '@ergasti/bricks';

function Commission() {
  return (
    <div style={{ maxWidth: 520 }}>
      <Card>
        <Card.Header title="Commission status" />
        <StackBar
          parts={[
            { key: 'p', value: 96410, label: 'Pending', display: 'EGP 96,410.00', tone: 'butter' },
            { key: 'a', value: 141230, label: 'Approved', display: 'EGP 141,230.00', tone: 'rasp' },
            { key: 'd', value: 275000, label: 'Paid', display: 'EGP 275,000.00', tone: 'lime' },
          ]}
        />
      </Card>
    </div>
  );
}

A legend on its own

center centres it under a chart.

Code
import { Legend } from '@ergasti/bricks';

function Alone() {
  return <Legend center items={[{ key: 'a', label: 'Selected', display: '304', tone: 'rasp' }, { key: 'b', label: 'Remaining', display: '79', tone: 'track' }]} />;
}

Thinner bar

height sets the bar's thickness in px (default 14).

Code
import { StackBar } from '@ergasti/bricks';

function Thin() {
  return <div style={{ maxWidth: 520 }}><StackBar height={8} parts={[{ key: 'u', value: 304, label: 'Used', display: '304', tone: 'rasp' }, { key: 'f', value: 96, label: 'Free', display: '96', tone: 'track' }]} /></div>;
}

Props

Prop

Type

Design guidance

How the BRICKS design system uses Legend. Written in docs/content/components/Legend.md; the props above are read from the code, which wins where the two disagree.

A chart legend: a coloured swatch, a label and a value per item; use it under a chart, or on its own as a compact breakdown.

Legend is the mock's .legend: a wrapping row of items, each a 9px rounded swatch in a chart tone, the label (often a Term with a "?" tooltip) and the formatted value. StackBar renders it under its bar and Gauge draws the same markup centred; use Legend directly when you draw the figure yourself or only need the breakdown.

Anatomy

  1. List (ul.kit-legend): flex, wraps, 14px gap, --ink-2 12px.
  2. Item (li).
  3. Swatch (i.kit-sw): 9 × 9px, radius 3, background from tone.
  4. Label: any node.
  5. Value (span.kit-num, dir="ltr"): the display node.

Variants

PropValueLookWhen
centerfalse (default)Items start-alignedUnder a StackBar
centertrueItems centredUnder a centred figure (Gauge)

Item tone: 'rasp', 'rasp-soft', 'track', 'butter', 'lime', 'sky', 'ink'.

States

StateTriggerLook
DefaultitemsOne row of items
Wrappedtoo many items for the widthWraps to more lines
Emptyitems=[]An empty list

Types

LegendItem (items): { key: string; label: ReactNode; display: ReactNode; tone: ChartTone }.

Usage

<Legend center items={[
  { key: 'selected', label: 'Selected', display: '304', tone: 'rasp' },
  { key: 'reserved', label: 'Reserved', display: '17', tone: 'rasp-soft' },
  { key: 'remaining', label: 'Remaining', display: '79', tone: 'track' },
]} />

With money and terms:

<Legend items={[
  { key: 'pending', label: <Term tip="Orders still inside the return window">Pending</Term>, display: <Money value="96410.00" />, tone: 'butter' },
  { key: 'approved', label: 'Approved', display: <Money value="141230.00" />, tone: 'rasp' },
  { key: 'paid', label: 'Paid', display: <Money value="275000.00" />, tone: 'lime' },
]} />

Where it appears

  • Brand › Payments › Commissions › Commission card (via StackBar).
  • Brand › Home › Seat usage card (the Gauge's centred legend uses the same classes).
  • Screens: Payments › Wallet, Home.

Guidelines

Do

  • Use the same tone as the matching bar or arc segment.
  • Keep labels short (one or two words); put the explanation in a Term tip.

Don't

  • Don't use the legend as the only place a value lives when the user needs to act on it.
  • Don't mix more than 5 items.

RTL and Arabic

  • Items flow from the inline start; the swatch sits before the label (right side in Arabic), via margin-inline-end.
  • Values are dir="ltr".

Tokens

From CSS: --ink-2 (text). The swatch colours are set inline from TONE_COLOR (not from a CSS rule): var(--rasp), var(--rasp-soft), var(--track), var(--chart-butter), var(--chart-lime), var(--sky-ink), var(--ink) by tone.

Accessibility

  • A plain <ul>; every item is read as label then value, so the meaning never depends on the swatch colour.
  • The swatch is an empty <i> with no text: nothing extra is announced.

Found in the source

  • ARIA attributes set: aria-hidden.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

See also: Card · AreaTrend · BarChart · HBars

Source

src/kit/patterns/StackBar.tsx (line 20) on GitHub.

On this page