Skip to Content
BBRICKSv0.7.4
BlocksMotivation

GiftProductsPicker

The "Choose gift products" modal body: every store product with a tick, its picture, SKU and what was already picked, and the units offered (a whole number 1–999, never below what was picked). Errors sit on their row and focus moves to the first; at least one product must be ticked.

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

Examples

Choose the gift products

Tick store products and set units for each (defaultUnits, up to maxUnits); the picker reports { id, units } for the ticked ones.

Code
import { GiftProductsPicker } from '@ergasti/bricks';
import { blocksData } from './sample-data';

function Pick() {
  const products = blocksData.PRODUCTS.map((p) => {
    const stock = blocksData.GIFT_STOCK.find((s) => s.id === p.id);
    return { ...p, picked: stock?.picked, units: stock?.total };
  });
  return <div style={{ maxWidth: 660 }}><GiftProductsPicker products={products} onSubmit={() => {}} onCancel={() => {}} /></div>;
}

Units, saving and a failed save

defaultUnits is what a newly ticked product starts with and maxUnits caps it; saving locks the picker; error shows the server's answer.

Code
import { GiftProductsPicker } from '@ergasti/bricks';
import { blocksData } from './sample-data';

function States() {
  const products = blocksData.PRODUCTS.slice(0, 3);
  return (
    <div style={{ display: 'grid', gap: 16, maxWidth: 660 }}>
      <GiftProductsPicker products={products} defaultUnits={5} maxUnits={50} onSubmit={() => {}} onCancel={() => {}} />
      <GiftProductsPicker products={products} saving onSubmit={() => {}} onCancel={() => {}} />
      <GiftProductsPicker products={products} error="Stock changed while you were choosing. Check the units and save again." onSubmit={() => {}} onCancel={() => {}} />
    </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 giftProductsPicker, or with the component's own prop where it has one. A {name} is a value the component fills in.

giftProductsPicker
KeyEnglishArabic
listGift productsمنتجات الهدايا
offerOffer {n} as a giftاعرض {n} كهدية
unitsUnits of {n}عدد قطع {n}
alreadyPicked{n} already pickedاتاخد منه {n}
unitsErrorA whole number from {a} to {b}رقم صحيح من {a} لـ {b}
belowPickedNot below the {n} already pickedمينفعش أقل من الـ {n} اللي اتاخدوا
noneChosenChoose at least one productاختار منتج واحد على الأقل
cancelCancelإلغاء
saveSave gift listاحفظ قايمة الهدايا
savingSaving…جاري الحفظ…

Design guidance

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

The "Choose gift products" modal body: every store product with a tick, its picture, SKU and units already picked, and the units offered as a gift; use it to edit the brand's gift list.

It is the mock's chooseGifts() / saveGifts() modal on Brand › Motivation › Gifts. Gift stock is kept by TRNDR; the brand chooses which products creators can pick and how many units. Units are a whole number from 1 to maxUnits (999) and never below what creators already picked. Errors sit on their row and focus moves to the first; at least one product must be ticked.

Anatomy

  1. List: ul.kit-blk-gpick named "Gift products", one row per product:
    1. Tick: checkbox in a label that is its hit area (44px at ≤1024px), named "Offer Red lipstick as a gift";
    2. Thumb: ProductThumb 40px;
    3. Text: name (bold), "RL-004 · 22 already picked", row error;
    4. Units: number input dir="ltr", min = max(1, picked), named "Units of Red lipstick".
  2. None chosen error: "Choose at least one product".
  3. Error alert and actions: Cancel, "Save gift list" ("Saving…").

Variants

SetupWhen
units set on a productAlready on the gift list (ticked).
units undefinedNot on the list (unticked, starts at defaultUnits when ticked).

States

StateTrigger
Units out of range"A whole number from 1 to 999".
Below picked"Not below the 22 already picked".
Nothing picked"Choose at least one product", focus on the first tick.
Savingsaving.
Server errorerror.

Types

GiftProduct (products): { id, name, sku?, imageUrl?, picked?, units? }.

Usage

// Brand › Motivation › Gifts › "Choose gift products"
<Modal open title="Choose gift products" onClose={close}>
  <GiftProductsPicker
    products={[
      { id: 0, name: 'Eyeshadow palette', sku: 'EP-012' },
      { id: 1, name: 'Red lipstick', sku: 'RL-004', picked: 34, units: 50 },
      { id: 2, name: 'Lash mascara', sku: 'LM-020', picked: 22, units: 30 },
    ]}
    onSubmit={(picks) => save.run(picks)} onCancel={close} saving={save.pending} error={save.error?.message} />
</Modal>

Where it appears

  • Brand › Motivation › Gifts › Choose gift products modal (BrandMotivation), opened from GiftStockList.

Guidelines

Do

  • Send picked so the floor is enforced.
  • Toast "Gift list saved · N products" on success (the mock's wording).

Don't

  • Don't let the brand set shipping or addresses here; TRNDR ships.

RTL and Arabic

  • Mirrors; unit fields LTR. Arabic: "اعرض … كهدية", "احفظ قايمة الهدايا", "مينفعش أقل من الـ 22 اللي اتاخدوا".

Tokens

--line, --card, --rasp, --focus-ring-field, --bad, --ink-3.

Accessibility

  • Every checkbox and number field is named by the product; row errors are tied with aria-describedby; focus moves to the first error.

Found in the source

  • Roles in the markup: alert.
  • ARIA attributes set: aria-label, aria-invalid, aria-describedby.
  • It moves focus in code.

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

See also: Button · useLanguage · BonusCard · BonusDetail · ChallengeCard · ChallengeDetail

Source

src/blocks/motivation/GiftProductsPicker.tsx (line 70) on GitHub.

On this page