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.
| Key | English | Arabic |
|---|---|---|
list | Gift products | منتجات الهدايا |
offer | Offer {n} as a gift | اعرض {n} كهدية |
units | Units of {n} | عدد قطع {n} |
alreadyPicked | {n} already picked | اتاخد منه {n} |
unitsError | A whole number from {a} to {b} | رقم صحيح من {a} لـ {b} |
belowPicked | Not below the {n} already picked | مينفعش أقل من الـ {n} اللي اتاخدوا |
noneChosen | Choose at least one product | اختار منتج واحد على الأقل |
cancel | Cancel | إلغاء |
save | Save gift list | احفظ قايمة الهدايا |
saving | Saving… | جاري الحفظ… |
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
- List:
ul.kit-blk-gpicknamed "Gift products", one row per product:- Tick: checkbox in a label that is its hit area (44px at ≤1024px), named "Offer Red lipstick as a gift";
- Thumb:
ProductThumb40px; - Text: name (bold), "RL-004 · 22 already picked", row error;
- Units: number input
dir="ltr", min = max(1, picked), named "Units of Red lipstick".
- None chosen error: "Choose at least one product".
- Error alert and actions: Cancel, "Save gift list" ("Saving…").
Variants
| Setup | When |
|---|---|
units set on a product | Already on the gift list (ticked). |
units undefined | Not on the list (unticked, starts at defaultUnits when ticked). |
States
| State | Trigger |
|---|---|
| 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. |
| Saving | saving. |
| Server error | error. |
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
pickedso 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.
Related
See also: Button · useLanguage · BonusCard · BonusDetail · ChallengeCard · ChallengeDetail
Source
src/blocks/motivation/GiftProductsPicker.tsx (line 70) on GitHub.