Skip to Content
BBRICKSv0.7.4
Foundations

BricksProvider

Gives every component below it (kit, shell, blocks, pr, and the data hooks' DataProvider) a language, the statuses table, the named status tables (statusTables), the tiers, the currency, how money is shown (money for everything, moneyFor per slot), the platforms the app works with (platforms), the money "?" dictionary and label overrides (kit keys and package keys alike). The other props override the preset: statuses and tiers add or replace keys, currency and moneyNotes replace, labels merge per component and language. A component's own language prop still wins over the provider's. Renders no element of its own.

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

Examples

One preset or another

The same components under the TRNDR preset and under a preset of your own: no component has a language, currency or labels prop here, the provider supplies them. Nested providers extend the one above; a preset starts again from the generic core.

Code
import { BricksProvider, Money, ScoreRing, StatusPill, TierChip, trndrPreset, type BricksPreset } from '@ergasti/bricks';

const acme: BricksPreset = {
  statuses: { open: { tone: 'sky', en: 'Open', ar: 'مفتوح' }, closed: { tone: 'mute', en: 'Closed', ar: 'مقفول' } },
  tiers: { gold: { en: 'Gold', ar: 'ذهبي', bg: '#FFF0C9', ink: '#8A5A00' }, silver: { en: 'Silver', ar: 'فضي', bg: '#E6E8EE', ink: '#4A4D57' } },
  defaultTier: 'silver',
  currency: { code: 'SAR', label: { en: 'SAR', ar: 'ر.س' } },
  labels: { scoreRing: { en: { label: 'Acme score', title: (n) => `Acme score ${n} / 100` }, ar: { label: 'تقييم أكمي', title: (n) => `تقييم أكمي: ${n} من 100` } } },
};

function Presets() {
  return (
    <div style={{ display: 'grid', gap: 16 }}>
      <BricksProvider preset={trndrPreset}>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, alignItems: 'center' }}>
          <b>trndrPreset</b>
          <StatusPill status="paid" />
          <TierChip tier="elite" />
          <Money value="1500.50" />
          <ScoreRing value={74} />
        </div>
      </BricksProvider>
      <BricksProvider preset={acme}>
        <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, alignItems: 'center' }}>
          <b>Acme</b>
          <StatusPill status="open" />
          <TierChip tier="gold" />
          <Money value="1500.50" />
          <ScoreRing value={74} />
        </div>
      </BricksProvider>
    </div>
  );
}

Override a few words

labels merges per component and language; a component's own labels prop still wins. Here the save bar says "Publish" and the pager says "Newer" and "Older".

Code
import { BricksProvider, Pager, SaveBar } from '@ergasti/bricks';

function LabelOverrides() {
  return (
    <BricksProvider
      labels={{
        saveBar: { en: { save: 'Publish', unsaved: 'Draft not published' }, ar: { save: 'انشر' } },
        pager: { en: { previous: 'Newer', next: 'Older' } },
      }}
    >
      <div style={{ display: 'grid', gap: 16, maxWidth: 520 }}>
        <SaveBar dirty onSave={() => {}} onDiscard={() => {}} />
        <Pager page={2} lastPage={5} total={50} perPage={10} loading={false} label="Posts" onPage={() => {}} />
      </div>
    </BricksProvider>
  );
}

Add your own statuses

statuses adds to or replaces the preset's table.

Code
import { BricksProvider, StatusPill, trndrPreset } from '@ergasti/bricks';

function Statuses() {
  return (
    <BricksProvider preset={trndrPreset} statuses={{ scheduled: { tone: 'lilac', en: 'Scheduled', ar: 'متجدول' }, paid: { tone: 'lime', en: 'Settled', ar: 'اتسوّى' } }}>
      <div style={{ display: 'flex', gap: 8 }}>
        <StatusPill status="scheduled" />
        <StatusPill status="paid" />
        <StatusPill status="live" />
      </div>
    </BricksProvider>
  );
}

Single settings, without a preset

Each part of a preset is also a prop: tiers and defaultTier, currency, moneyNotes (the "?" texts per language), and statusTables for the tables that other packages read (the PR portal's pr table).

Code
import { BricksProvider, Money, PrStatusPill, TierChip } from '@ergasti/bricks';

function SingleProps() {
  return (
    <BricksProvider
      tiers={{ gold: { en: 'Gold', ar: 'ذهبي', bg: '#FFF0C9', ink: '#8A5A00' }, silver: { en: 'Silver', ar: 'فضي' } }}
      defaultTier="silver"
      currency={{ code: 'SAR', label: { en: 'SAR', ar: 'ر.س' } }}
      moneyNotes={{ sales: { label: 'Sales', includes: 'Orders with creator coupons.', excludes: 'Cancelled orders.' } }}
      statusTables={{ pr: { live: { tone: 'lime', en: 'On air', ar: 'شغال' } } }}
    >
      <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12, alignItems: 'center' }}>
        <TierChip tier="gold" />
        <TierChip tier="unknown" />
        <Money value="1500.50" />
        <PrStatusPill status="live" />
      </div>
    </BricksProvider>
  );
}

The platforms the app works with

platforms lists them once at the provider (default: Instagram, TikTok and YouTube). Follower cells, the creator cards and drawers, and the challenge request form then leave the others out: totals, glyphs and options alike. Set it when your app does not support a platform; the PR portal keeps all three. Below, the same creator with all three, then with platforms={['instagram', 'tiktok']}.

Code
import { BricksProvider, FollowersCell } from '@ergasti/bricks';

function Platforms() {
  const followers = { instagram: 24300, tiktok: 61000, youtube: 12800 };
  return (
    <div style={{ display: 'flex', gap: 32, alignItems: 'center', flexWrap: 'wrap' }}>
      <FollowersCell followers={followers} />
      <BricksProvider platforms={['instagram', 'tiktok']}>
        <FollowersCell followers={followers} />
      </BricksProvider>
    </div>
  );
}

Props

Prop

Type

Accessibility

  • Its tests cover: “a preset replaces the TRNDR tables: statuses, tiers (with inline colours or the theme tokens), default tier, currency, labels”; “props override the preset: statuses and tiers add keys, labels merge per component and language”; “currency: a custom formatter is used by Money, MoneyFigure and the HeroCard word follows the currency label (Arabic)”; “labels: per-component overrides reach the Pager and the coupon chip, in Arabic too”.

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

StatusPill · TierChip · Money · ScoreRing · SaveBar · Pager · PrStatusPill · FollowersCell

Source

src/kit/BricksProvider.tsx (line 38) on GitHub.

On this page