Skip to Content
BBRICKSv0.7.4
BlocksGroups

CommissionInput

The mock's commission control (special commission, suggested commission): a "% of sale / EGP per item" switch, the number and the unit in words. A fieldset: its legend names the switch and the number; the error is read with it.

import { CommissionInput } 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 CommissionInput. Written in docs/content/components/CommissionInput.md; the props above are read from the code, which wins where the two disagree.

The commission control: a "% of sale / EGP per item" switch, the value field and the unit in words, as one fieldset with hint and error; use it wherever a brand proposes a commission (special group commission, a challenge's suggested commission).

It is the mock's reqComm() commission row in the special commission modal on Brand › Creators › Groups and the suggested commission in "Request a challenge". The field is text with inputMode="decimal", not a number field, so Arabic-Indic digits reach the app as ASCII. commissionError() (exported with it) is the one validation rule both forms share; kinds limits the offered kinds to what the server allows.

Render it inside a block form (<form className="kit-blk kit-blk-form">), as SpecialCommissionForm and ChallengeRequestForm do: the value field's look (42px, line border, radius, focus ring, 120px width) comes only from .kit-blk-form input rules. Outside that context the field is a bare browser input.

Anatomy

  1. Fieldset: fieldset.kit-blk-fieldset.kit-blk-comm, described by hint and error.
  2. Legend: 13px / 700 ("Commission", "Suggested commission").
  3. Row: .kit-blk-comm-row, flex-wrap, 8px gap:
    1. Kind switch: Segmented "% of sale" / "EGP per item" (hidden with one kind);
    2. Value: text input, dir="ltr", placeholder "e.g. 20", named "Commission value";
    3. Unit: muted "% of each sale" / "EGP per item sold".
  4. Hint: .kit-hint; Error: .kit-field-err.

Variants

Prop valueLookWhen to use
kind="percent""% of each sale"Default rate type.
kind="per_item""EGP per item sold"Fixed amount per item.
kinds={['percent']}No switch, % field onlyServer allows one kind.
currencyCurrency word in the switch and unitDefault: provider currency (EGP / ج.م).

States

StateTrigger
Default—
Hinthint ("The standard rate is 15% of sale.").
Errorerror: message, aria-invalid on the field.
Disableddisabled: the whole fieldset.
Coerced kinda kind outside kinds: drawn as the first allowed kind, reported via onKindChange, value cleared (EGP 30 is not 30%).

Types

Helper: commissionError(kind, value, language, labels?, { limits?, currency? }) returns the error text or null (defaults: % from 1 to 100 with ≤ 2 decimals; per item > 0, ≤ 2 decimals; limits sets the server's range and the message names it).

CommissionCopy (labels): percent, perItem(c), unitPercent, unitItem(c), value, placeholder, the errors (errPercent, errAmount, errPercentRange(min, max), errAmountRange(min, max, c)), ratePercent…

Usage

const [kind, setKind] = useState<CommissionKind>('percent');
const [value, setValue] = useState('');
const error = submitted ? commissionError(kind, value, 'en') : null;

<CommissionInput legend="Special commission" kind={kind} value={value}
  onKindChange={setKind} onValueChange={setValue}
  hint="The standard rate is 15% of sale." error={error} />
// Server limits, % only
<CommissionInput legend="Suggested commission" kinds={['percent']} kind="percent" value={v}
  onKindChange={() => {}} onValueChange={setV}
  error={commissionError('percent', v, 'en', undefined, { limits: { percent: { min: '0.01', max: 50 } } })} />

Where it appears

  • Brand › Creators › Groups › special commission modal (SpecialCommissionForm) (BrandCreators).
  • Brand › Motivation › Request a challenge › suggested commission (ChallengeRequestForm) (BrandMotivation).

Guidelines

Do

Don't

  • Don't use type="number"; it loses Arabic digits.
  • Don't carry a value across kinds.

RTL and Arabic

  • The field stays LTR; switch and unit mirror. Arabic: "% من البيع", "ج.م على القطعة", "اكتب نسبة من 1 لـ 100". Arabic-Indic digits are converted to ASCII.

Tokens

Own: none beyond the fieldset's text (--ink-3 hint, --bad error). The value field takes its look from the surrounding block form (.kit-blk-form input): --line, --card, --ink, --rasp and --focus-ring-field on focus. Outside a .kit-blk-form the field is an unstyled input. The switch uses Segmented's tokens.

Accessibility

  • A fieldset + legend; the switch is named by the legend, the field "Commission value"; hint and error in aria-describedby; aria-invalid on error.

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 · GroupCard · GroupCommissionPill · GroupForm

Source

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

On this page