Skip to Content
BBRICKSv0.7.4
PR PortalLeaderboard

Leaderboard

The PR mock's challenge leaderboard (.rows of .rowi.lb): rank medal, creator, delivered sales with a bar against #1, orders, when it was reached, and a remove button; the dashed raspberry "Winners above this line" cut after the winners (movable with onWinnersChange), rows under it faded. Ties are marked and explained under the table, the way the mock's footnote does. A table: the cut is a full-width row. For the PR mock's exact look pass rankSize="lg", rankStyle="highlight", textSize="lg", cutTone="rasp", noteSize="sm", tieDetail and showPercent={false}.

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

Examples

Challenge leaderboard

Ranked by sales (or orders) with the winners cut drawn as a line: change how many win and the cut moves. Ties are shown as shared or resolved by who reached the figure first.

Code
import { useState } from 'react';
import { Card, Leaderboard } from '@ergasti/bricks';
import { leaderboard } from './pr';

function Winners() {
  const [winners, setWinners] = useState(10);
  return <Card><Leaderboard rows={leaderboard} winners={winners} onWinnersChange={setWinners} ties="first_reached" onOpen={() => {}} onRemove={() => {}} /></Card>;
}

Loading, error and empty

Code
import { Card, Leaderboard } from '@ergasti/bricks';
import { leaderboard } from './pr';

function States() {
  return (
    <div style={{ display: 'grid', gap: 16 }}>
      <Card><Leaderboard rows={[]} loading /></Card>
      <Card><Leaderboard rows={[]} error="We could not load the leaderboard." onRetry={() => {}} /></Card>
      <Card><Leaderboard rows={[]} empty="Nobody has sold yet." /></Card>
    </div>
  );
}

Ranked by orders

rankBy="orders" moves the bar, the bold column and the tie check to orders; ties="shared" gives equal values the same rank.

Code
import { Card, Leaderboard } from '@ergasti/bricks';
import { leaderboard } from './pr';

function ByOrders() {
  const rows = [...leaderboard].sort((a, b) => b.orders - a.orders).slice(0, 5);
  return <Card><Leaderboard rows={rows} rankBy="orders" ties="shared" winners={3} /></Card>;
}

Without the share figure

The mock's board draws only the bar under each value; showPercent={false} leaves out the "% of #1" figure (the bar keeps its screen-reader text). Default true.

Code
import { Card, Leaderboard } from '@ergasti/bricks';
import { leaderboard } from './pr';

function BarOnly() {
  return <Card><Leaderboard rows={leaderboard.slice(0, 5)} winners={3} showPercent={false} onOpen={() => {}} onRemove={() => {}} /></Card>;
}

Mock look

The PR portal mock's board: rankSize="lg" draws 30px rounded-square ranks, rankStyle="highlight" drops the gold/silver/bronze medals and colours every rank up to highlightTop (default 10) lime with the rest on the card colour, textSize="lg" sets the rows to 14px, and showPercent={false} keeps the bar without its figure. Every one defaults to today's look.

Code
import { useState } from 'react';
import { Card, Leaderboard } from '@ergasti/bricks';
import { leaderboard } from './pr';

function MockLook() {
  const [winners, setWinners] = useState(10);
  return (
    <Card>
      <Leaderboard rows={leaderboard} winners={winners} onWinnersChange={setWinners} rankSize="lg" rankStyle="highlight" highlightTop={10} textSize="lg" showPercent={false} onOpen={() => {}} onRemove={() => {}} />
    </Card>
  );
}

Cut line and tie note

Sara Ali and Hana Rami both sold EGP 31,900, so the note under the board says so; tieDetail also names what the tie is on: "… are tied on sales. Sara Ali ranks higher because they reached it first." cutTone="rasp" draws the winners cut in the PR mock's raspberry (5.2:1 on the card) and noteSize="sm" sets the tie note in the mock's 12px; the defaults are the deeper 'deep' line and a 13px note, for the brand dashboard. Default on top, the PR look below.

Code
import { Card, Leaderboard } from '@ergasti/bricks';
import { leaderboard } from './pr';

function CutAndTieNote() {
  const rows = leaderboard.slice(0, 5);
  return (
    <div style={{ display: 'grid', gap: 16 }}>
      <Card><Leaderboard rows={rows} winners={3} ties="first_reached" /></Card>
      <Card><Leaderboard rows={rows} winners={3} ties="first_reached" tieDetail cutTone="rasp" noteSize="sm" rankSize="lg" rankStyle="highlight" textSize="lg" showPercent={false} /></Card>
    </div>
  );
}

Tied on orders, in Arabic

Ranked by orders with ties="shared" and tieDetail: the note names what the tie is on ("متعادلين في الطلبات") and the tied creators share the rank.

Pinned to Arabic
Code
import { Card, Leaderboard } from '@ergasti/bricks';

function TieOnOrdersArabic() {
  const rows = [
    { id: 1, name: 'نور حسن', sales: '58200.00', orders: 190, reachedAt: '12 نوفمبر · 14:02', tier: 'elite' },
    { id: 2, name: 'سارة علي', sales: '31900.00', orders: 102, reachedAt: '13 نوفمبر · 09:40', tier: 'elite' },
    { id: 3, name: 'هنا رامي', sales: '29400.00', orders: 102, reachedAt: '13 نوفمبر · 18:15', tier: 'established' },
    { id: 4, name: 'يوسف عادل', sales: '24800.00', orders: 80, reachedAt: '11 نوفمبر · 20:31', tier: 'established' },
  ];
  return <Card><Leaderboard rows={rows} rankBy="orders" ties="shared" tieDetail winners={3} cutTone="rasp" noteSize="sm" /></Card>;
}

Props

Prop

Type

Labels

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

prLeaderboard
KeyEnglishArabic
boardLeaderboardلوحة الترتيب
rank##
creatorCreatorصانع المحتوى
salesDelivered salesالمبيعات اللي اتسلمت
ordersOrdersالطلبات
reachedReached atوصل إمتى
actionsActionsالإجراءات
cutWinners above this lineالكسبانين فوق الخط ده
upMove the line up (one winner fewer)طلّع الخط لفوق (كسبان أقل)
downMove the line down (one winner more)نزّل الخط لتحت (كسبان زيادة)
winners{n} winners{n} كسبانين
tiedTiedمتعادل
removeRemove {n} from the challengeشيل {n} من التحدي
winnerwinnerكسبان
tieFirst{names} are tied on {on}. {first} ranks higher because they reached it first.{names} متعادلين في {on}. {first} قبلهم عشان وصل للرقم الأول.
tieShared{names} are tied on {on} and share the rank.{names} متعادلين في {on} وواخدين نفس الترتيب.
tieOn.salessalesالمبيعات
tieOn.ordersordersالطلبات
emptyNo one on the board yetلسه مفيش حد على اللوحة
emptyTextProgress shows here as orders are delivered.الترتيب بيظهر هنا لما الطلبات تتسلم.
errorCouldn’t load the leaderboard.مقدرناش نحمّل لوحة الترتيب.
retryTry againجرّب تاني
loadingLoading the leaderboardبنحمّل لوحة الترتيب

Design guidance

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

A challenge's ranked table of creators with sales bars, a "Winners above this line" cut, tie notes and remove buttons; use it on the PR Portal's challenge detail to see and adjust who wins.

Leaderboard is the PR mock's .rows of .rowi.lb. Each row has a rank medal, the creator, delivered sales (or orders) with a bar against #1, the other figure, when the value was reached and an optional ✕. A dashed raspberry line sits after the last winner; rows below it fade. PR can move the line with onWinnersChange. Ties are marked "Tied" and explained under the table, either as "first to reach it ranks higher" or as shared ranks (1, 2, 2, 4). Values are compared in exact cents, never floats.

Anatomy

  1. Table: a real <table> with a hidden caption "Leaderboard"; columns #, Creator, Delivered sales (with its money note), Orders, Reached at (when any row has it), Actions (with onRemove).
  2. Rank: RankMedal: 28px round medal (md) or 30px rounded square (lg); gold, silver, bronze for 1-3 and lime for other winners, or lime for the top N (highlight).
  3. Creator: CreatorCell (photo, name, tier; a button with onOpen) and a butter "Tied" tag.
  4. Value: the bold figure and a ShareBar against #1 (with "55%" unless showPercent={false}).
  5. Other figure, Reached at (muted, dir="auto"), Remove ✕ (kit-pr-ib).
  6. Cut row: a full-width row after the last winner: "Winners above this line" in --rasp-d (or --rasp), with ▲ "{n} winners" ▼ buttons when movable.
  7. Tie notes: one muted line per tie group under the table (13px, or 12px with noteSize="sm").

Variants

PropValueLook / effectWhen to use
rankBysales (default)Sales bold with bar, orders secondMost challenges
ordersOrders bold with bar, sales secondOrder-count challenges
tiesfirst_reached (default)Ranks 1, 2, 3; "Tied" mark; note says who reached it firstThe mock's rule
sharedRanks 1, 2, 2, 4; a tie at the cut lets every tied row winShared-prize rules
rankSizemd (default) / lg28px round / 30px square rankslg for the mock's look
rankStylemedals (default) / highlightMedals for 1-3 / lime for ranks ≤ highlightTop (default 10)highlight for the mock
textSizemd (13.5px) / lg (14px)Row text size
cutTonedeep (default, 7.1:1) / rasp (5.2:1)Cut words colourrasp matches the mock
noteSizemd (13px) / sm (12px)Tie note size
tieDetailfalse / true"… are tied." / "… are tied on sales."
showPercenttrue / falseBar with "55%" / bar alonefalse matches the v3 mock

Mock look: rankSize="lg" rankStyle="highlight" textSize="lg" cutTone="rasp" noteSize="sm" tieDetail showPercent={false}.

States

StateTrigger
Loadingloading: 5 skeleton rows, role="status"
Errorerror (true for the default words): alert card with "Try again" (onRetry)
Emptyno rows: PrEmpty "No one on the board yet · Progress shows here as orders are delivered." (or empty)
Winnerswinners > 0: cut after the last winner; winners get "winner" in hidden text
Movable cutonWinnersChange: ▲ disabled at 1 winner, ▼ disabled at the last row; count is live
Tiesequal values: "Tied" tag and notes
Read-onlyno onWinnersChange, no onRemove

Types

LeaderboardRow (rows), in rank order: { id, name, identity?, tier?, sales (2-dp), orders, reachedAt? }.

Usage

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

<Leaderboard
  rows={[
    { id: 4, name: 'Nour Hassan', tier: 'elite', sales: '48200.00', orders: 152, reachedAt: '13 Nov · 09:40' },
    { id: 1, name: 'Hana Rami', tier: 'influential', sales: '26500.00', orders: 81, reachedAt: '13 Nov · 11:02' },
    { id: 7, name: 'Omar Khaled', tier: 'established', sales: '26500.00', orders: 79, reachedAt: '13 Nov · 15:30' },
  ]}
  winners={10}
  onWinnersChange={setWinners}
  onOpen={(r) => openCreator(r.id)}
  onRemove={(r) => askRemove(r)}
/>
// Challenge detail (Winter top 10): stat tiles, then the board in the mock's look
<KpiGrid>
  <Tile size="stat" tone="rasp" label="Delivered sales" value={<Money value="184300.00" />} />
  <Tile size="stat" tone="lime" label="Creators joined" value="42" />
  <Tile size="stat" tone="sky" label="Days left" value="15" />
  <Tile size="stat" tone="lilac" label="Prize pool" value={<Money value="20000.00" />} />
</KpiGrid>
<Card title="Leaderboard">
  <Leaderboard rows={board} winners={10} rankSize="lg" rankStyle="highlight" textSize="lg" cutTone="rasp" noteSize="sm" tieDetail showPercent={false} />
</Card>

Cut line and tie note. Sara Ali and Hana Rami both sold EGP 31,900, so the note under the board says so; tieDetail also names what the tie is on: "… are tied on sales. Sara Ali ranks higher because they reached it first." cutTone="rasp" draws the winners cut in the PR mock's raspberry (5.2:1 on the card) and noteSize="sm" sets the tie note in the mock's 12px; the defaults are the deeper 'deep' line and a 13px note, for the brand dashboard. Default on top, the PR look below. (docs example CutAndTieNote)

import { Card, Leaderboard } from '@ergasti/bricks';
// leaderboard: the docs' sample rows (docs/examples/_pr.ts)

export function CutAndTieNote() {
  const rows = leaderboard.slice(0, 5);
  return (
    <div style={{ display: 'grid', gap: 16 }}>
      <Card><Leaderboard rows={rows} winners={3} ties="first_reached" /></Card>
      <Card><Leaderboard rows={rows} winners={3} ties="first_reached" tieDetail cutTone="rasp" noteSize="sm" rankSize="lg" rankStyle="highlight" textSize="lg" showPercent={false} /></Card>
    </div>
  );
}

Where it appears

  • PR Portal › Affiliate programs › Challenges › a challenge's page › Leaderboard card (Winter top 10, Weekend sprint).

Guidelines

Do

  • Send rows already ranked by the server (ties broken under first_reached).
  • Show reachedAt whenever ties are broken by time, so the note makes sense.
  • Ask for confirmation before onRemove actually removes a creator.

Don't

  • Don't sort client-side by the displayed money: the component compares exact cents only for ties and bars.
  • Don't hide the cut when there are winners; it is the decision PR makes here.
  • Don't combine rankStyle="highlight" with a highlightTop larger than the winners unless that is the rule.

RTL and Arabic

The table mirrors; bars fill from the right; reached-at uses dir="auto". Arabic words: "لوحة الترتيب", "الكسبانين فوق الخط ده", "متعادل", "{names} متعادلين. {first} قبلهم عشان وصل للرقم الأول."; name lists join with "، " and "و".

Tokens

--rasp, --rasp-d, --rasp-100, --lime, --olive, --butter, --butter-ink, --card, --soft, --ink, --ink-2, --ink-3, --radius-lg, --color-control-border-hover.

Accessibility

  • A real table with column headers and a caption; the cut is a full-width row.
  • Winners say ", winner" after the rank; "Tied" is text, and the notes explain the tie in words.
  • Cut buttons are labelled ("Move the line down (one winner more)") and the winner count is aria-live.
  • The ✕ is "Remove Nour Hassan from the challenge". Cut words pass AA in both tones.

Found in the source

  • Roles in the markup: status, alert.
  • ARIA attributes set: aria-label, aria-hidden, aria-live.
  • Its tests cover: “a movable cut: buttons move it by one, by keyboard; they stop at the ends”; “labels: tieOn and a two-argument tieFirst override (written before tieOn existed) still work”.

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

See also: Button · CreatorCell · Money · MoneyNote · Skeleton · useLanguage · PrEmpty · PrIcon · Card

Source

src/pr/leaderboard/Leaderboard.tsx (line 139) on GitHub.

On this page