Skip to Content
BBRICKSv0.7.4
BlocksGroups

CommissionRate

A commission rate as one isolated run of words: "15%" or "EGP 15 per item" ("15 ج.م على القطعة"). Use it wherever a group's or a creator's rate is shown (a table cell, a pill, a drawer tile) so every screen says it the same way.

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

Examples

Ask for a special commission

A percentage or an amount per item, and a reason; TRNDR reviews it, and until then the group keeps the standard rate.

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

function Ask() {
  return (
    <div style={{ maxWidth: 560 }}>
      <SpecialCommissionForm initial={{ kind: 'percent', value: '20' }} onSubmit={() => {}} onCancel={() => {}} onBackToStandard={() => {}} />
    </div>
  );
}

The commission input alone

A radio pair (percent or per item) and a number; commissionError returns the message for a value that is not allowed.

Code
import { CommissionInput, commissionError, useLanguage, type CommissionKind } from '@ergasti/bricks';
import { useState } from 'react';

function Input() {
  const language = useLanguage();
  const [kind, setKind] = useState<CommissionKind>('percent');
  const [value, setValue] = useState('120');
  return (
    <div style={{ maxWidth: 420 }}>
      <CommissionInput legend="Commission" kind={kind} value={value} onKindChange={setKind} onValueChange={setValue} error={commissionError(kind, value, language) ?? undefined} />
    </div>
  );
}

Sending and failed

saving locks the form while it is sent; error is the server's answer when sending failed. currency names the unit for "per item"; hint on CommissionInput adds a line under it.

Code
import { CommissionInput, SpecialCommissionForm, type CommissionKind } from '@ergasti/bricks';
import { useState } from 'react';

function States() {
  const [kind, setKind] = useState<CommissionKind>('per_item');
  const [value, setValue] = useState('35');
  return (
    <div style={{ display: 'grid', gap: 16, maxWidth: 560 }}>
      <SpecialCommissionForm initial={{ kind: 'per_item', value: '35' }} currency="SAR" saving onSubmit={() => {}} onCancel={() => {}} />
      <SpecialCommissionForm initial={{ kind: 'percent', value: '20' }} error="TRNDR could not receive the request. Try again." commissionLabels={{ percent: 'Share of sale' }} onSubmit={() => {}} onCancel={() => {}} />
      <CommissionInput legend="Suggested commission" kind={kind} value={value} onKindChange={setKind} onValueChange={setValue} currency="SAR" hint="Most groups get 30–40 per item." />
    </div>
  );
}

Set the special commission directly (mode="set", no TRNDR approval): a % of sale or EGP per item, "Set special commission"

note adds the optional "Why" field (sent as reason). namesRate makes the button name the rate and who it reaches ("Set 15% for 4 creators", "… for creators who join later" on an empty group). limits are the server's own bounds.

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

function SetRate() {
  return (
    <div style={{ display: 'grid', gap: 24, maxWidth: 560 }}>
      <SpecialCommissionForm mode="set" note members={4} initial={{ kind: 'percent', value: '15' }} limits={{ percent: { min: '0.01', max: 50 }, perItem: { min: '0.01', max: 10000 } }}
        hint="Enter a rate from 0.01 to 50." onSubmit={() => {}} onCancel={() => {}} onBackToStandard={() => {}} />
      <SpecialCommissionForm mode="set" namesRate members={0} initial={{ kind: 'per_item', value: '30' }} onSubmit={() => {}} onCancel={() => {}} />
    </div>
  );
}

Only the kinds the server allows

kinds limits the switch (the bootstrap's group_commission.kinds); with one kind there is no switch, and a starting value of another kind starts empty on the allowed one. Default: both.

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

function OneKind() {
  return (
    <div style={{ maxWidth: 560 }}>
      <SpecialCommissionForm mode="set" kinds={['percent']} members={4} onSubmit={() => {}} onCancel={() => {}} />
    </div>
  );
}

A rate in words

CommissionRate says a rate the same way on every screen: "15%" or "EGP 30 per item", trailing zeros dropped, in the provider's currency. form="long" reads "15% of sale" for a pill or a drawer row where the rate stands alone; keep the default short form in a table cell. Per item reads the same in both forms.

Code
import { CommissionRate, useLanguage } from '@ergasti/bricks';

function RateInWords() {
  const language = useLanguage();
  const rows = [['percent', '15.00'], ['per_item', '30.00'], ['percent', '12.5']] as const;
  return (
    <table className="kit-muted" style={{ borderCollapse: 'collapse' }}>
      <thead><tr><th style={{ textAlign: 'start', paddingInlineEnd: 24 }}>{language === 'ar' ? 'قصير (الافتراضي)' : 'Short (default)'}</th><th style={{ textAlign: 'start' }}>form="long"</th></tr></thead>
      <tbody>
        {rows.map(([kind, value]) => (
          <tr key={kind + value}>
            <td style={{ paddingInlineEnd: 24 }}><CommissionRate kind={kind} value={value} /></td>
            <td><CommissionRate kind={kind} value={value} form="long" /></td>
          </tr>
        ))}
      </tbody>
    </table>
  );
}

A hint that follows the kind

hint as a function gets the chosen kind, so the line under the rate can name each kind's range. A string works as before.

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

function HintByKind() {
  return (
    <div style={{ maxWidth: 560 }}>
      <SpecialCommissionForm mode="set" members={6} initial={{ kind: 'percent', value: '18' }} onSubmit={() => {}} onCancel={() => {}}
        hint={(kind) => (kind === 'per_item' ? 'From EGP 0.01 to EGP 10,000 per item.' : 'From 0.01% to 50% of each sale.')} />
    </div>
  );
}

The server's field errors

fieldErrors takes the 422 map (commission.value, kind, reason): each message sits on its field, marked invalid and focused, applied once the save ends. error is still the form-level line for an answer that has no field. Press Set special commission: the save runs, then the server refuses the rate.

Code
import { SpecialCommissionForm } from '@ergasti/bricks';
import { useState } from 'react';

function ServerErrors() {
  const [saving, setSaving] = useState(false);
  const [errors, setErrors] = useState<Record<string, string> | undefined>();
  const send = () => {
    setSaving(true);
    setTimeout(() => { setErrors({ 'commission.value': 'This group already has creators on a higher rate. Use at most 20%.' }); setSaving(false); }, 600);
  };
  return (
    <div style={{ maxWidth: 560 }}>
      <SpecialCommissionForm mode="set" members={4} initial={{ kind: 'percent', value: '25' }} saving={saving} fieldErrors={errors} onSubmit={send} onCancel={() => setErrors(undefined)} />
    </div>
  );
}

A locked input

CommissionInput disabled locks the switch and the number (the form sets it while saving); use it when the rate is shown but cannot change now.

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

function InputDisabled() {
  return (
    <div style={{ maxWidth: 420 }}>
      <CommissionInput legend="Commission" kind="percent" value="15" onKindChange={() => {}} onValueChange={() => {}} disabled hint="Locked while the change is with TRNDR." />
    </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 commissionInput, or with the component's own prop where it has one. A {name} is a value the component fills in.

commissionInput
KeyEnglishArabic
percent% of sale% من البيع
perItem{c} per item{c} على القطعة
unitPercent% of each sale% من كل بيعة
unitItem{c} per item sold{c} على كل قطعة بتتباع
valueCommission valueقيمة العمولة
placeholdere.g. 20مثلاً 20
errPercentEnter a % between 1 and 100اكتب نسبة من 1 لـ 100
errAmountEnter an amount above 0اكتب مبلغ أكبر من صفر
errPercentRangeEnter a % from {min} to {max}اكتب نسبة من {min} لـ {max}
errAmountRangeEnter {c} {min} to {max} per itemاكتب من {min} لـ {max} {c} على القطعة
ratePercent{v}%{v}%
ratePerItem{c} {v} per item{v} {c} على القطعة
ratePercentLong{v}% of sale{v}% من البيع

Design guidance

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

A commission rate in words as one isolated run ("15%", "15% of sale", "EGP 30 per item"); use it wherever a group's or creator's rate is shown so every screen says it the same way.

It formats the stored or typed value (trailing zeros dropped: "15.00" → "15") with the provider's currency word. A short % is laid out LTR as a number; the long form and per-item words take their own direction. GroupCommissionPill and GroupCard use it.

Anatomy

  1. A <bdi>: dir="ltr" with kit-num for a short % ("15%"); otherwise isolated words.

Variants

PropsText (en)Text (ar)When
kind="percent", form="short" (default)"15%""15%"Table cells, tight spots.
kind="percent", form="long""15% of sale""15% من البيع"Group pill, drawer Commission row.
kind="per_item""EGP 30 per item""30 ج.م على القطعة"Fixed rates (same in both forms).
currency="SAR""SAR 12.5 per item"—Another currency.

States

Static.

Types

commissionRateText(kind, value, currency, copy, form?) returns the same string for non-React use.

CommissionCopy (labels): this component reads ratePercent, ratePerItem, ratePercentLong.

Usage

<CommissionRate kind="percent" value="15.00" />                 {/* 15% */}
<CommissionRate kind="percent" value="20.00" form="long" />     {/* 20% of sale */}
<CommissionRate kind="per_item" value="30.00" />                {/* EGP 30 per item */}
// A table column
type GroupRow = { id: string; name: string; kind: CommissionKind; rate: string };
const columns: DataColumn<GroupRow>[] = [
  { key: 'rate', label: 'Commission', render: (g) => <CommissionRate kind={g.kind} value={g.rate} /> },
];

Where it appears

Guidelines

Do

  • Pass the stored value; let it trim zeros.

Don't

  • Don't format rates by hand with template strings.

RTL and Arabic

  • Short % stays LTR; words follow their script, so "30 ج.م على القطعة" reads correctly.

Tokens

None (inherits text styles; kit-num for tabular digits).

Accessibility

  • Plain text in a <bdi>, not interactive and with no role: screen readers read it as written ("15%", "15% of sale", "EGP 30 per item").
  • The short % is dir="ltr" with tabular digits, so "15%" is never read or drawn as "%15" on an Arabic page; the long and per-item forms take their own direction ("30 ج.م على القطعة").
  • The words carry the unit, so the rate is understandable out of context (a pill, a table cell, a drawer row).
  • Colour and contrast come from where you place it (a Pill, a cell).

Found in the source

  • ARIA attributes set: aria-describedby, aria-label, aria-invalid.

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

See also: Segmented · useBricks · useLanguage · SpecialCommissionForm · GroupCard · GroupForm

Source

src/blocks/groups/CommissionInput.tsx (line 149) on GitHub.

On this page