Money
A money figure as text: LTR, tabular. Its label and "?" belong to MoneyFigure / MoneyNote. The currency and the formatter come from the BricksProvider (EGP with no provider); how it is shown from money, then the provider.
import { Money } from '@ergasti/bricks';Examples
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>
);
}Formatting without a component
formatMoney is what Money calls; use it for text such as an aria-label.
Code
import { formatMoney } from '@ergasti/bricks';
function AsText() {
return <p>{formatMoney('1500.50', { language: 'en' })} · {formatMoney('1500.50', { language: 'ar' })}</p>;
}How it is shown
money takes the display options: showCurrency, decimals (2, 0 or 'auto'), compact and sign. compact alone is shorthand. The provider can set the same for every figure: see the Money display guide.
Code
import { Money } from '@ergasti/bricks';
function Options() {
return (
<div style={{ display: 'grid', gap: 8 }}>
<Money value="43390.00" money={{ decimals: 'auto' }} />
<Money value="43390.45" money={{ decimals: 0 }} />
<Money value="27645.00" money={{ showCurrency: false }} />
<Money value="250000.00" money={{ sign: 'always' }} />
<Money value="11200000.00" money={{ compact: true }} />
</div>
);
}Money maths without floats
divideAmount, addAmounts, subtractAmounts, compareAmounts and percentOf work on the server's 2-dp strings in whole cents, so no figure loses a cent; each returns null when an input is not an amount. Here a product drawer: the average price is divideAmount(sales, units), and its row carries the product_avg_price money "?" (the app's dictionary needs that entry). Use these whenever you derive a figure; never Number() a money string.
Code
import { KeyValue, Money, MoneyNotesProvider, Pill, addAmounts, compareAmounts, count, divideAmount, percentOf, subtractAmounts, useLanguage } from '@ergasti/bricks';
import { moneyNotes } from './sample-data';
function Maths() {
const language = useLanguage();
const sales = '184000.00';
const units = 708;
const lastMonth = '161250.40';
const target = '200000.00';
const average = divideAmount(sales, units);
const change = subtractAmounts(sales, lastMonth);
const both = addAmounts(sales, lastMonth);
const vsTarget = compareAmounts(sales, target);
const ar = language === 'ar';
return (
<MoneyNotesProvider notes={moneyNotes(language)}>
<div style={{ maxWidth: 520 }}>
<KeyValue items={[
{ label: ar ? 'المبيعات بكوبونات صنّاع المحتوى' : 'Sales with creator coupons', figure: 'sales', value: <Money value={sales} /> },
{ label: ar ? 'متوسط السعر' : 'Avg. price', figure: 'product_avg_price', value: <Money value={average} /> },
{ label: ar ? 'التغيير عن الشهر اللي فات' : 'Change on last month', value: <Money value={change} money={{ sign: 'always' }} /> },
{ label: ar ? 'الشهرين مع بعض' : 'Both months', value: <Money value={both} /> },
{ label: ar ? 'من الهدف' : 'Of the target', value: <>{count(percentOf(sales, target) ?? 0, language)}% <Pill tone={vsTarget === -1 ? 'warn' : 'ok'}>{vsTarget === -1 ? (ar ? 'تحت الهدف' : 'Below target') : (ar ? 'وصل للهدف' : 'Target met')}</Pill></> },
]} />
</div>
</MoneyNotesProvider>
);
}Props
Prop
Type
Design guidance
How the BRICKS design system uses Money. Written in docs/content/components/Money.md; the props above are read from the code, which wins where the two disagree.
A money figure as text ("EGP 1,234.50", "EGP 184.3K"), left to right with tabular digits; use it for every amount the server sends.
Money formats a server 2-dp string with the provider's currency and formatter. It never does arithmetic: the browser only displays what the API returns. How it is shown (currency word, decimals, compact, sign) resolves from the most specific setting: the money prop → the provider's moneyFor[slot] → the provider's money → the slot's default ({ showCurrency: true, decimals: 2, compact: false } for a bare figure). A null or invalid value shows "—". Labels and the "?" explanation belong to MoneyNote / MoneyFigure, not to Money.
Anatomy
- Span (
span.kit-num,dir="ltr"): the formatted text, tabular numerals.
Variants
| Prop | Value | Look | When |
|---|---|---|---|
| default | — | "EGP 1,234.50" | Tables, facts |
compact | true | "EGP 184.3K" | Tiles, HBars values, charts |
money.decimals | e.g. 0 | "EGP 1,235" | Large round figures |
money.showCurrency | false | "1,234.50" | Columns where the header names the currency |
money.sign | 'always' / 'negative' | "+ EGP 500.00" / "− EGP 500.00" (the sign, then a space) | Ledger in/out |
money.decimals | 'auto' | "EGP 43,390"; cents only when non-zero ("EGP 43,390.50") | Hero and summary figures |
language | 'ar' | Arabic currency word | Arabic screens |
States
| State | Trigger | Look |
|---|---|---|
| Value | valid 2-dp string | Formatted figure |
| Missing | null or an invalid string | "—" |
| Negative | "-500.00" | Minus sign per sign |
Types
Also exported: formatMoney(value, options) and formatAmount for strings outside JSX.
MoneyDisplay (money): { showCurrency?, decimals?, compact?, sign? }, over the provider settings.
Usage
<Money value="312400.00" /> {/* EGP 312,400.00 */}
<Money value="184300.00" compact /> {/* EGP 184.3K */}
<Money value={null} /> {/* — */}In a sortable table column with the total in the header:
<Card.Header title={<>Commission · <Money value="512640.00" /></>} sub="All time, earned by your creators" />
<DataTable label="Orders" rowKey={(o) => o.no} rows={orders} columns={[
{ key: 'value', label: 'Order value', sortKey: 'value', align: 'end', render: (o) => <Money value={o.value} /> },
{ key: 'comm', label: 'Commission', sortKey: 'comm', align: 'end', render: (o) => <b><Money value={o.commission} /></b> },
]} />App-wide display rules:
<BricksProvider preset={trndrPreset} money={{ decimals: 2 }} moneyFor={{ 'heroCard.big': { compact: false } }}>
…
</BricksProvider>Where it appears
Every money figure in both dashboards: Brand › Home hero balance and tiles, Brand › Payments wallet and ledger, Brand › Analytics tables and HBars, Brand › Coupons sales, PR Portal › Brands (wallet card, "Adjust {brand}'s wallet"), Creators sales, Affiliate programs budgets. Screens: all Brand and PR screens.
Guidelines
Do
- Pass the API's string as is; never
parseFloatand re-format. - Use
compactin tiles and charts, full figures in tables and receipts. - Put labels and explanations in
MoneyNote.
Don't
- Don't compute totals in the browser.
- Don't concatenate "EGP" yourself; the provider owns the currency word.
RTL and Arabic
- Always
dir="ltr". In Arabic the provider's currency word foraris used; digits stay Latin per the preset.
Tokens
None of its own; inherits font. .kit-num sets tabular numerals.
Accessibility
- Plain text; screen readers read the formatted figure.
dir="ltr"keeps currency and digits in order inside Arabic sentences.
Found in the source
- No roles, ARIA attributes or key handling are set in this component's own source; it renders native elements and the components it composes.
Read from the component's source and tests. See Accessibility for the patterns the library follows.
Related
MoneyNote/MoneyFigure: a money label with its "?" explanation.Strong: a bold figure with ok/bad tone.Delta: the change next to a figure.
See also: useBricks · useMoneyDisplay · useLanguage · MoneyNotesProvider · KeyValue · Pill · Avatar · AvatarStack · Button · ButtonLink
Source
src/kit/primitives/Money.tsx (line 32) on GitHub.