Skip to Content
BBRICKSv0.7.4
KitCharts

HBars

Horizontal bars: label, a decorative track, the value LTR. A list, so each row is read as text. v3: onSelect makes each row a button (Sales by challenge → the challenge drawer); a row with selectable: false stays plain.

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

Examples

Bar chart

Vertical bars with a total line; format writes each value.

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

function Columns() {
  return (
    <div style={{ maxWidth: 520, background: 'var(--card)', borderRadius: 22, padding: 16 }}>
      <BarChart
        label="Orders per week"
        totalText="Total 1,284"
        data={[{ label: 'W1', value: 240 }, { label: 'W2', value: 310 }, { label: 'W3', value: 280 }, { label: 'W4', value: 454 }]}
        format={(n) => n.toLocaleString('en-US')}
      />
    </div>
  );
}

Horizontal bars

Rows with a label, a bar and a display value; with onSelect a row is a button (set selectable: false on one to keep it plain).

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

function Rows() {
  return (
    <div style={{ maxWidth: 380, background: 'var(--card)', borderRadius: 22, padding: 16 }}>
      <HBars
        label="Sales by challenge"
        onSelect={() => {}}
        rows={[
          { label: 'Winter glow launch', value: 184300, display: 'EGP 184.3K' },
          { label: 'Always-on', value: 126000, display: 'EGP 126.0K', tone: 'butter', selectable: false },
          { label: 'Back to campus', value: 2100, display: 'EGP 2.1K', tone: 'lime' },
        ]}
      />
    </div>
  );
}

Row variants

variant="rows" (the default) draws each row as a soft rounded tile: the bold label, the bar in the middle and the value at the end; under 600px it stacks. variant="stacked" is the 0.2 look, the label and value above a thin full-width bar. A row's display can be a node such as <Money compact />.

Code
import { HBars, Money } from '@ergasti/bricks';

function Variants() {
  const rows = [
    { label: 'Winter glow launch', value: 184300, display: <Money value="184300.00" compact /> },
    { label: 'Always-on', value: 126000, display: <Money value="126000.00" compact />, tone: 'butter' as const },
    { label: 'Back to campus', value: 2100, display: <Money value="2100.00" compact />, tone: 'lime' as const },
  ];
  return (
    <div style={{ display: 'grid', gap: 20, gridTemplateColumns: 'repeat(auto-fit, minmax(320px, 1fr))' }}>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        <p className="kit-muted">variant="rows"</p>
        <HBars label="Sales by challenge" variant="rows" rows={rows} />
      </div>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        <p className="kit-muted">variant="stacked"</p>
        <HBars label="Sales by challenge (stacked)" variant="stacked" rows={rows} />
      </div>
    </div>
  );
}

No data yet

An empty data draws emptyText in place of the bars; HBars has no empty state of its own, so show your own line (here the kit's ListState) when there are no rows.

Code
import { BarChart, HBars, ListState } from '@ergasti/bricks';

function Empty() {
  const rows: { label: string; value: number; display: string }[] = [];
  return (
    <div style={{ display: 'grid', gap: 16, gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))' }}>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        <BarChart label="Orders per week" totalText="Total 0" data={[]} format={(n) => String(n)} emptyText="No orders in this period yet." />
      </div>
      <div style={{ background: 'var(--card)', borderRadius: 22, padding: 16 }}>
        {rows.length ? <HBars label="Sales by challenge" rows={rows} /> : <ListState loading={false} error={null} empty emptyText="No challenge sales yet." onRetry={() => {}} />}
      </div>
    </div>
  );
}

Two rows with one label

id is the row's key when two rows can share a label (two challenges both named "Winter glow", one per year); without it the label is the key and React would warn. Pass the server's id whenever labels are not unique.

Code
import { HBars, Money } from '@ergasti/bricks';

function SameLabel() {
  return (
    <div style={{ maxWidth: 520 }}>
      <HBars label="Sales by challenge" rows={[
        { id: 'c-2026', label: 'Winter glow', value: 184300, display: <Money value="184300.00" compact /> },
        { id: 'c-2025', label: 'Winter glow', value: 121750, display: <Money value="121750.00" compact />, tone: 'sky' },
        { id: 'c-aon', label: 'Always-on', value: 18900, display: <Money value="18900.00" compact />, tone: 'butter' },
      ]} />
    </div>
  );
}

Props

Prop

Type

Design guidance

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

Horizontal bars that compare named items by one value (label, bar, value); use it for "Sales by challenge", optionally with each row opening a detail drawer.

HBars draws a list where each row has the item's label, a decorative track scaled to the largest value and the formatted value at the end. In the default 'rows' layout each row is a soft rounded tile (the v3 screenshot's Sales by challenge); 'stacked' puts label and value above a thin full-width bar. With onSelect every row becomes a button that opens the item; selectable: false keeps a row plain (Always-on has no challenge to open).

Anatomy

  1. List (ul.kit-hb, aria-label).
  2. Row (li): in 'rows' a 16px-radius --soft tile, grid 200px 1fr 110px, padding 12px 16px.
  3. Label (.kit-hb-l): bold in 'rows', ellipsis on overflow.
  4. Track and fill (aria-hidden): 10px pill, --track, fill width = value / max, colour from tone (raspberry default).
  5. Value (.kit-num, dir="ltr"): the display node, end-aligned, no wrap.
  6. Row button (with onSelect): wraps 2–4, full width, hover background.

Variants

variantLookWhen
'rows' (default)Each row a soft tile: label · bar · value on one line; under 600px the bar drops to its own linev3 Analytics › Sales by challenge
'stacked'Label and value on one line, a full-width bar below, tabular numbersNarrow cards, the 0.2 look

Row tone (ChartTone): 'rasp' (default), 'rasp-soft', 'track', 'butter', 'lime', 'sky', 'ink'; the mock colours each challenge.

States

StateTriggerLook
Staticno onSelectPlain list items
ClickableonSelect setEach row a <button>; hover --color-surface-hover (rows) / --soft (stacked)
Plain row in a clickable listselectable: falseThat row is not a button
Focus-visibleTab to a row button--focus-ring box-shadow
Long labeltext wider than the label columnEllipsis
Emptyrows=[]An empty list (nothing drawn); add your own empty text

Types

HBarRow:

FieldTypeRequiredDescription
idstring | numbernoKey when two rows share a label. Default: the label.
labelstringyesRow name.
valuenumberyesRaw value for the bar length.
displayReactNodeyesShown value: text or <Money value="184300.00" compact />.
toneChartTonenoBar colour; raspberry by default.
selectablebooleannoWith onSelect: false keeps this row plain.

Usage

<Card>
  <Card.Header title="Sales by challenge" />
  <HBars label="Sales by challenge" onSelect={(row) => openChallenge(row.id)} rows={[
    { id: 41, label: 'Winter glow launch', value: 184300, display: <Money value="184300.00" compact /> },
    { id: 'always', label: 'Always-on', value: 126000, display: <Money value="126000.00" compact />, tone: 'butter', selectable: false },
    { id: 42, label: 'Back to campus', value: 2100, display: <Money value="2100.00" compact />, tone: 'lime' },
  ]} />
</Card>

The stacked look in a narrow side card:

<HBars variant="stacked" label="Orders by platform" rows={[
  { label: 'Instagram', value: 812, display: '812' },
  { label: 'TikTok', value: 472, display: '472', tone: 'ink' },
]} />

Where it appears

  • Brand › Analytics › Sales by challenge (bottom card; rows open the challenge drawer, Always-on stays plain).
  • Screen: Analytics.

Guidelines

Do

  • Sort rows by value, largest first.
  • Pass money as <Money compact> so Arabic gets its own currency word.
  • Give id when labels can repeat.
  • Give 'rows' at least ~420px: its label and value columns are fixed (200px and 110px) and it only stacks below a 600px viewport, so in a narrow card on a wide screen the bar collapses to nothing and the value overflows the card (the 360px stories show this). Use 'stacked' in narrow cards.

Don't

  • Don't use more than ~8 rows; use a DataTable for long lists.
  • Don't make some rows clickable by omitting onSelect; use selectable: false per row.
  • Don't encode meaning only in tone; the label says what the row is.

RTL and Arabic

  • The row grid mirrors: label at the right, value at the left in Arabic; the bar fills from the inline start.
  • The value is dir="ltr" so "EGP 184.3K" keeps its order; <Money> switches to the Arabic currency word.

Tokens

--soft (row tile, stacked hover), --color-surface-hover (rows hover), --track (track), --rasp and the ChartTone tokens (fill), --focus-ring.

Accessibility

  • A <ul> named by label; each row is read as label then value. The track is aria-hidden.
  • With onSelect, each row is a type="button" reachable with Tab and activated with Enter or Space; its name is the label plus the value.
  • The row button meets the touch-target size (box-sizing rules in kit.css).

Found in the source

  • Roles in the markup: img.
  • ARIA attributes set: aria-label, aria-hidden.

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

  • RankList: ranked people with avatars and optional bars.
  • ShareBar: one share as a bar with its percentage.
  • StackBar: parts of one whole.

See also: BarChart · Money · ListState · AreaTrend · Gauge · Legend

Source

src/kit/Charts.tsx (line 80) on GitHub.

On this page