Skip to Content
BBRICKSv0.7.4
Getting started

Quick start

Load the styles, wrap the app in BricksProvider and draw a component.

1. Load the styles

Load the tokens first, then the component styles, once, near your entry point:

import '@ergasti/bricks/tokens.css';
import '@ergasti/bricks/styles.css';

A different project can load only the kit's styles, or add the PR theme; see Stylesheets.

2. Wrap the app in BricksProvider

import { BricksProvider, trndrPreset, Button, Money } from '@ergasti/bricks';

export function Root({ language, bootstrap }: { language: 'en' | 'ar'; bootstrap: { money_notes: Record<string, { label: string; includes: string; excludes: string }> } }) {
  return (
    <BricksProvider preset={trndrPreset} language={language} moneyNotes={bootstrap.money_notes}>
      <App />
    </BricksProvider>
  );
}

Below the provider no component needs a language, currency or labels prop; a component's own prop still wins. Without a provider every component draws the TRNDR preset in English. BricksProvider renders no element of its own, so set dir and lang on your own wrapper or on <html>:

<html lang={language} dir={language === 'ar' ? 'rtl' : 'ltr'}>

The provider also takes the platforms your app works with. platforms={['instagram', 'tiktok']} takes YouTube out of every follower count, card and form below it; left out, all three are shown. The provider and presets lists everything it holds.

3. Draw something

Variants

The looks of the mock's .btn family: default, ink, rasp, ghost and white. lime and on-dark have their own example below.

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

function Variants() {
  return (
    <div style={{ display: 'flex', flexWrap: 'wrap', gap: 12 }}>
      <Button>Default</Button>
      <Button variant="ink">Ink</Button>
      <Button variant="rasp">Rasp</Button>
      <Button variant="ghost">Ghost</Button>
      <Button variant="white">White</Button>
    </div>
  );
}

Money values

The server sends 2-decimal strings; Money formats them with the provider's currency word and keeps the digits left-to-right inside Arabic text. A negative value keeps its sign.

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

function Values() {
  return (
    <div style={{ display: 'grid', gap: 8 }}>
      <Money value="61840.00" />
      <Money value="-61200.00" />
      <Money value="184300.00" compact />
      <Money value={null} />
    </div>
  );
}

A few rules the kit expects

  • Numbers and money. Show a count with count(n, language) and an amount with <Money value="1234.50" />, never your own formatting. Amounts are strings with two decimals; do maths on them with addAmounts, divideAmount and the other money helpers, not with floats. See Money.
  • Links. A link built from API data goes through safeHref. A link that looks like a button is a ButtonLink (it checks its href the same way, and external adds the new-tab words), not an <a className="kit-btn">.
  • Every Switch has a name. Pass label, aria-labelledby, or rowLabelled inside a KeyValue row's control. A switch with none of them is a type error. See Accessibility.
import { ButtonLink, Switch } from '@ergasti/bricks';

<Switch label="Creators can pick gifts" checked={on} onChange={setOn} />
<ButtonLink href={csvUrl} size="sm" download>Export CSV</ButtonLink>

4. Load data

Data hooks take their HTTP client from a DataProvider (or a client option). Nothing in the library calls fetch on its own:

import { DataProvider, createHttpClient } from '@ergasti/bricks';

const client = createHttpClient({
  baseUrl: '/en/merchant/affiliate-brand-console/api',
  onUnauthorized: () => window.location.assign('/login'), // 401 and 419
});

<DataProvider client={client}>
  <App />
</DataProvider>;

See HTTP client and Load, page and save. The blocks' forms (ChallengeRequestForm, SpecialCommissionForm, GroupForm) show a 422's field errors on their own fields: pass the action's fieldErrors and saving.

Where next

On this page