Skip to Content
BBRICKSv0.7.4
KitPrimitives

ShareBar

The v3 mock's .share ("vs #1"): a 6px bar sized against the leader (never under 2% so a row always shows) and the muted percent beside it (34px, as the brand mock's Analytics "vs #1" column). The read-out ("38% of #1") is the text for AT; label replaces it when the column means more. showValue={false} drops the visible percent (the PR mock's leaderboard draws the bar alone); the read-out stays.

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

Examples

Share of a maximum

A thin bar and the percentage of value out of max.

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

function Shares() {
  return (
    <div style={{ display: 'grid', gap: 12, maxWidth: 260 }}>
      <ShareBar value={98400} max={154000} />
      <ShareBar value={30000} max={154000} tone="butter" label="Sales share" />
    </div>
  );
}

Percent shown or hidden

By default the muted "64%" sits beside the bar, as the brand Analytics "vs #1" column; showValue={false} draws the bar alone (the PR leaderboard), and screen readers still hear "64% of #1".

Code (not run)
import { ShareBar } from '@ergasti/bricks';

function ShowValue() {
  return (
    <div style={{ display: 'grid', gap: 12, maxWidth: 260 }}>
      <ShareBar value={64} max={100} />
      <ShareBar value={64} max={100} showValue={false} />
    </div>
  );
}

Props

Prop

Type

Labels

Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key shareBar, or with the component's own prop where it has one. A {name} is a value the component fills in.

shareBar
KeyEnglishArabic
ofTop{p}% of #1{p}% من الأول

Design guidance

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

A thin bar sized against the leader with the muted percent beside it ("vs #1"); use it in ranked tables to show how far each row is from the top.

ShareBar is the v3 mock's .share: a 6px pill track filled to value / max (never under 2 %, so every row shows a sliver) and a 34px end-aligned muted "38%". The read-out for assistive tech is "38% of #1" unless label replaces it. showValue={false} draws the bar alone, as the PR leaderboard does; the read-out stays.

Anatomy

  1. Wrapper (span.kit-share): flex, 8px gap, min-width 120px.
  2. Bar (.kit-share-bar, aria-hidden): 6px, --track; fill in tone (raspberry default).
  3. Percent (.kit-share-n, aria-hidden, dir="ltr", optional): 12px --ink-3.
  4. Read-out (.kit-sr): "38% of #1" / "38% من الأول", or label.

Variants

PropValueLookWhen
showValuetrue (default)Bar + "38%"Brand Analytics "vs #1"
showValuefalseBar onlyPR leaderboard
toneChartToneFill colour ('rasp' default, 'lime', 'butter', 'sky', 'ink', 'rasp-soft', 'track')Match the table's accent

States

StateTriggerLook
Leadervalue === maxFull bar, "100%"
Partial0 < value < maxRounded percent
Zerovalue 0 or max 02 % sliver, "0%"

Types

Also exported: sharePercent(value, max).

Usage

interface Ranked { id: number; name: string; sales: string }
const ranked: Ranked[] = [{ id: 1, name: 'Laila Saeed', sales: '98400.00' }, { id: 2, name: 'Karim Hosny', sales: '48210.00' }];
const columns: DataColumn<Ranked>[] = [
  { key: 'rank', label: '#', render: (c) => <RankMedal rank={ranked.indexOf(c) + 1} /> },
  { key: 'name', label: 'Creator', primary: true, render: (c) => <b>{c.name}</b> },
  { key: 'share', label: 'vs #1', render: (c) => <ShareBar value={Number(c.sales)} max={Number(ranked[0].sales)} /> },
];

PR leaderboard style:

<ShareBar value={142} max={310} showValue={false} tone="lime" label="142 orders, 46% of the leader" />

Where it appears

  • Brand › Analytics › Best creators table ("vs #1" column).
  • Brand › Home › Top creators (via RankList bars).
  • PR Portal › Affiliate programs › Challenges › challenge detail › "Leaderboard" (bar only).
  • Screens: Analytics, Home, PR · Affiliate programs.

Guidelines

Do

  • Compare against the leader of the same list, not a global maximum.
  • Use label when the comparison is not "of #1".

Don't

RTL and Arabic

  • The bar fills from the inline start (right in Arabic); the percent is LTR.

Tokens

--track, --rasp and the chart tone tokens, --ink-3.

Accessibility

  • Bar and visible percent are hidden; one read-out sentence is spoken.

Found in the source

  • ARIA attributes set: aria-hidden.
  • Its tests cover: “Arabic read-out; the visible percent LTR in RTL; a custom label replaces the read-out”; “is not focusable”.

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

  • RankMedal: the rank cell beside it.
  • RankList: ranked rows with built-in bars.
  • HBars: comparison bars with labels.

See also: Avatar · AvatarStack · Button · ButtonLink

Source

src/kit/primitives/ShareBar.tsx (line 17) on GitHub.

On this page