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
- List (
ul.kit-legend): flex, wraps, 14px gap,--ink-212px. - Item (
li). - Swatch (
i.kit-sw): 9 × 9px, radius 3, background fromtone. - Label: any node.
- Value (
span.kit-num,dir="ltr"): thedisplaynode.
Variants
| Prop | Value | Look | When |
|---|---|---|---|
center | false (default) | Items start-aligned | Under a StackBar |
center | true | Items centred | Under a centred figure (Gauge) |
Item tone: 'rasp', 'rasp-soft', 'track', 'butter', 'lime', 'sky', 'ink'.
States
| State | Trigger | Look |
|---|---|---|
| Default | items | One row of items |
| Wrapped | too many items for the width | Wraps to more lines |
| Empty | items=[] | 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
toneas the matching bar or arc segment. - Keep labels short (one or two words); put the explanation in a
Termtip.
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.
Related
See also: Card · AreaTrend · BarChart · HBars
Source
src/kit/patterns/StackBar.tsx (line 20) on GitHub.