@vectoriox/iox-ui 5.94.0 → 5.95.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/actions-core/index.d.ts +7 -2
- package/commerce-core/index.d.ts +312 -2
- package/composite-core/index.d.ts +290 -2
- package/design-core/index.d.ts +1049 -105
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs +15 -4
- package/fesm2022/vectoriox-iox-ui-actions-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs +527 -6
- package/fesm2022/vectoriox-iox-ui-commerce-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs +1170 -177
- package/fesm2022/vectoriox-iox-ui-composite-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-design-core.mjs +1147 -43
- package/fesm2022/vectoriox-iox-ui-design-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs +2 -2
- package/fesm2022/vectoriox-iox-ui-generation-core.mjs.map +1 -1
- package/fesm2022/vectoriox-iox-ui.mjs +8 -1
- package/fesm2022/vectoriox-iox-ui.mjs.map +1 -1
- package/generation-core/index.d.ts +2 -2
- package/index.d.ts +2 -0
- package/package.json +1 -1
- package/src/actions-core/action.model.ts +1 -1
- package/src/actions-core/element-actions.ts +17 -3
- package/src/commerce-core/cart-transport.ts +211 -0
- package/src/commerce-core/public-api.ts +4 -0
- package/src/commerce-core/quantity.ts +56 -0
- package/src/commerce-core/shop-display.ts +117 -0
- package/src/commerce-core/variants.ts +296 -0
- package/src/composite-core/exclusive-runtime.ts +20 -7
- package/src/composite-core/public-api.ts +2 -0
- package/src/composite-core/shop-runtime.ts +626 -0
- package/src/composite-core/shop.ts +433 -0
- package/src/design-core/flavor-spec.generated.ts +1147 -43
- package/src/generation-core/site-spec.generated.ts +2 -2
- package/styles/iox-design.css +95 -0
|
@@ -0,0 +1,433 @@
|
|
|
1
|
+
import { ShopWord, shopWord } from '@vectoriox/iox-ui/commerce-core';
|
|
2
|
+
import type { ProductOption } from '@vectoriox/iox-ui/commerce-core';
|
|
3
|
+
import { roleClass } from '@vectoriox/iox-ui/design-core';
|
|
4
|
+
|
|
5
|
+
import { CompositeNode, CompositeNodeFactory, makeCompositePart, writeProp } from './composite-node';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* THE SHOP PARTS (commerce E1c, C-D16 — commerce board 10). Not components: recipes of ordinary builder nodes, each part
|
|
9
|
+
* carrying a role, so every part is selectable on the canvas, in the layer tree and the breadcrumb, and wears its own
|
|
10
|
+
* element style (R2). ONE runtime (`shop-runtime.ts`, DOM only) fills them on the builder canvas and the live site:
|
|
11
|
+
*
|
|
12
|
+
* Price Container shop.price › Text shop.price-amount (`price`, $variant.price | money)
|
|
13
|
+
* · Text shop.price-compare (`price-compare`, $variant.compareAt | money)
|
|
14
|
+
* Options Container shop.variants › Container shop.variant-group (ONE template, stamped per option)
|
|
15
|
+
* › Text shop.variant-label · Container shop.variant-values (the option's radio group)
|
|
16
|
+
* › ButtonBlock shop.variant-value (`variant-chip`) › Text — the chip template
|
|
17
|
+
* · ButtonBlock shop.variant-swatch (`variant-swatch`) — the swatch template
|
|
18
|
+
* · Text shop.variant-note ("Charcoal is sold out")
|
|
19
|
+
* Quantity Container shop.quantity (`quantity`) › − · Text shop.quantity-value · +
|
|
20
|
+
* Add to cart ButtonBlock shop.add (`button-primary`, click → addToCart) › "Add to cart" · "Added ✓"
|
|
21
|
+
* Buy now ButtonBlock shop.buy-now (`button-secondary`, click → startCheckout)
|
|
22
|
+
* Cart button ButtonBlock shop.cart-button (`cart-button`) › Icon · Container shop.cart-count › Text $cart.count
|
|
23
|
+
* Cart drawer Dialog shop.cart-drawer (end edge; a bottom sheet on a phone) › head · lines (ONE line template)
|
|
24
|
+
* · issues · empty · free-delivery note · Subtotal ($cart.subtotal | money) · VAT note
|
|
25
|
+
* · Check out · Keep shopping
|
|
26
|
+
*
|
|
27
|
+
* A template part (an option group, a value, a cart line) is the FIRST instance the runtime shows; the rest are its
|
|
28
|
+
* copies (`data-iox-shop-clone`), so the template is what the author selects and styles, and every copy wears it.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
export enum ShopRole {
|
|
32
|
+
Price = 'shop.price',
|
|
33
|
+
PriceAmount = 'shop.price-amount',
|
|
34
|
+
PriceCompare = 'shop.price-compare',
|
|
35
|
+
Variants = 'shop.variants',
|
|
36
|
+
VariantGroup = 'shop.variant-group',
|
|
37
|
+
VariantLabel = 'shop.variant-label',
|
|
38
|
+
VariantValues = 'shop.variant-values',
|
|
39
|
+
VariantValue = 'shop.variant-value',
|
|
40
|
+
VariantSwatch = 'shop.variant-swatch',
|
|
41
|
+
VariantNote = 'shop.variant-note',
|
|
42
|
+
Quantity = 'shop.quantity',
|
|
43
|
+
QuantityDown = 'shop.quantity-down',
|
|
44
|
+
QuantityValue = 'shop.quantity-value',
|
|
45
|
+
QuantityUp = 'shop.quantity-up',
|
|
46
|
+
Add = 'shop.add',
|
|
47
|
+
AddLabel = 'shop.add-label',
|
|
48
|
+
AddedLabel = 'shop.added-label',
|
|
49
|
+
BuyNow = 'shop.buy-now',
|
|
50
|
+
CartButton = 'shop.cart-button',
|
|
51
|
+
CartCount = 'shop.cart-count',
|
|
52
|
+
CartDrawer = 'shop.cart-drawer',
|
|
53
|
+
CartTitle = 'shop.cart-title',
|
|
54
|
+
CartClose = 'shop.cart-close',
|
|
55
|
+
CartLines = 'shop.cart-lines',
|
|
56
|
+
CartLine = 'shop.cart-line',
|
|
57
|
+
CartLineImage = 'shop.cart-line-image',
|
|
58
|
+
CartLineTitle = 'shop.cart-line-title',
|
|
59
|
+
CartLineVariant = 'shop.cart-line-variant',
|
|
60
|
+
CartLineRemove = 'shop.cart-line-remove',
|
|
61
|
+
CartLineTotal = 'shop.cart-line-total',
|
|
62
|
+
CartIssues = 'shop.cart-issues',
|
|
63
|
+
CartEmpty = 'shop.cart-empty',
|
|
64
|
+
CartShippingNote = 'shop.cart-shipping-note',
|
|
65
|
+
CartSummary = 'shop.cart-summary',
|
|
66
|
+
CartSubtotal = 'shop.cart-subtotal',
|
|
67
|
+
CartVatNote = 'shop.cart-vat-note',
|
|
68
|
+
Checkout = 'shop.checkout',
|
|
69
|
+
KeepShopping = 'shop.keep-shopping',
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const SHOP_ROLES: ReadonlySet<string> = new Set(Object.values(ShopRole));
|
|
73
|
+
|
|
74
|
+
export function isShopRole(role: string | null | undefined): boolean {
|
|
75
|
+
return !!role && SHOP_ROLES.has(role);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/** The CSS selector of a shop role (`.iox-role-shop-price`). */
|
|
79
|
+
export function shopSelector(role: ShopRole): string {
|
|
80
|
+
return `.${roleClass(role)}`;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** The attributes the shop runtime writes (the shared CSS in `styles/iox-design.css` reads them). */
|
|
84
|
+
export const SHOP_CLONE_ATTRIBUTE = 'data-iox-shop-clone';
|
|
85
|
+
/** A template the current product does not use (the swatch template of a word option) — never shown, never a trigger. */
|
|
86
|
+
export const SHOP_UNUSED_ATTRIBUTE = 'data-iox-shop-unused';
|
|
87
|
+
/** "Added ✓" in place, for ADDED_HOLD_MS after a successful add. */
|
|
88
|
+
export const SHOP_ADDED_ATTRIBUTE = 'data-iox-added';
|
|
89
|
+
/** An empty bag: on the cart button (its count hides) and the drawer (its lines, summary and Check out hide). */
|
|
90
|
+
export const CART_EMPTY_ATTRIBUTE = 'data-iox-cart-empty';
|
|
91
|
+
/** A cart line's id (`cartLineId`) on its line element. */
|
|
92
|
+
export const CART_LINE_ATTRIBUTE = 'data-iox-line-id';
|
|
93
|
+
/** The count the runtime adds to the drawer's title ("Your bag (2)"). */
|
|
94
|
+
export const CART_TITLE_COUNT_ATTRIBUTE = 'data-iox-cart-title-count';
|
|
95
|
+
/** A part the runtime has no words for right now (a variant note with nothing sold out, a group with no option). */
|
|
96
|
+
export const SHOP_HIDDEN_ATTRIBUTE = 'data-iox-shop-hidden';
|
|
97
|
+
/** The native select a long option list becomes (T26). */
|
|
98
|
+
export const SHOP_SELECT_CLASS = 'iox-shop-select';
|
|
99
|
+
/** The polite live region the runtime announces "Added ✓" and refusals in. */
|
|
100
|
+
export const SHOP_LIVE_CLASS = 'iox-shop-live';
|
|
101
|
+
|
|
102
|
+
/** How long "Added ✓" holds before the button reads "Add to cart" again (Emil: long enough to read, never a wait). */
|
|
103
|
+
export const ADDED_HOLD_MS = 1600;
|
|
104
|
+
|
|
105
|
+
// ── the picker's kind (T26) ───────────────────────────────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
export enum ShopPickerKind {
|
|
108
|
+
/** Words in outlined chips — up to SHOP_CHIP_MAX values. */
|
|
109
|
+
Chips = 'chips',
|
|
110
|
+
/** Round swatches of each value's colour — a colour option whose every value has a colour. */
|
|
111
|
+
Swatches = 'swatches',
|
|
112
|
+
/** A native select — past SHOP_CHIP_MAX values a row of chips no longer fits a phone (T26). */
|
|
113
|
+
Select = 'select',
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/** The Segmented control's rule (Q40): four fit a phone row, five do not. */
|
|
117
|
+
export const SHOP_CHIP_MAX = 4;
|
|
118
|
+
|
|
119
|
+
/** The option names that ARE a colour (en, he). */
|
|
120
|
+
export const COLOUR_OPTION_NAMES: ReadonlyArray<string> = ['color', 'colour', 'colors', 'colours', 'צבע', 'צבעים'];
|
|
121
|
+
|
|
122
|
+
/** Colour words a value may be named by (en, he) — a value named "Navy" is drawn navy. Never a guess past these. */
|
|
123
|
+
export const NAMED_SWATCHES: Readonly<Record<string, string>> = Object.freeze({
|
|
124
|
+
black: '#111111', white: '#FFFFFF', grey: '#8A8F98', gray: '#8A8F98', red: '#C62828', green: '#2E7D32', blue: '#1F4FD6',
|
|
125
|
+
navy: '#1B2A4A', yellow: '#F2C94C', orange: '#E8833A', pink: '#E991B3', purple: '#7B4FA0', brown: '#7A5234', beige: '#D9C8A9',
|
|
126
|
+
cream: '#F3EBD9', gold: '#C9A54C', silver: '#C0C4CA',
|
|
127
|
+
'שחור': '#111111', 'לבן': '#FFFFFF', 'אפור': '#8A8F98', 'אדום': '#C62828', 'ירוק': '#2E7D32', 'כחול': '#1F4FD6',
|
|
128
|
+
'צהוב': '#F2C94C', 'כתום': '#E8833A', 'ורוד': '#E991B3', 'סגול': '#7B4FA0', 'חום': '#7A5234', "בז'": '#D9C8A9',
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
const CSS_COLOUR = /^(#[0-9a-f]{3,8}|(rgb|rgba|hsl|hsla|oklch|oklab)\([^)]*\))$/i;
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The fill a value is drawn with, or null: the host's own (the sample's glazes), else the value itself when it IS a CSS
|
|
135
|
+
* colour (`#3A3B3D`), else a colour word. A value with no fill is never drawn as a blank swatch.
|
|
136
|
+
*/
|
|
137
|
+
export function swatchFill(value: string, own?: Readonly<Record<string, string>> | null): string | null {
|
|
138
|
+
const word = String(value ?? '').trim();
|
|
139
|
+
if (!word) return null;
|
|
140
|
+
if (own?.[word]) return own[word];
|
|
141
|
+
if (CSS_COLOUR.test(word)) return word;
|
|
142
|
+
return NAMED_SWATCHES[word.toLowerCase()] ?? null;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* How one option is chosen (T26): swatches when every value has a fill AND the option is a colour (or every value is
|
|
147
|
+
* one — the sample's glazes), chips up to four values, a select past four.
|
|
148
|
+
*/
|
|
149
|
+
export function shopPickerKind(option: ProductOption, own?: Readonly<Record<string, string>> | null): ShopPickerKind {
|
|
150
|
+
const fills = option.values.map(v => swatchFill(v, own));
|
|
151
|
+
const colourName = COLOUR_OPTION_NAMES.includes(option.name.trim().toLowerCase());
|
|
152
|
+
const allFilled = option.values.length > 0 && fills.every(Boolean);
|
|
153
|
+
if (allFilled && (colourName || option.values.every(v => !!own?.[v]))) return ShopPickerKind.Swatches;
|
|
154
|
+
return option.values.length > SHOP_CHIP_MAX ? ShopPickerKind.Select : ShopPickerKind.Chips;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/** A group's label: "Glaze — Sand" when the chosen value has no words of its own on screen (a swatch), else "Size". */
|
|
158
|
+
export function variantGroupLabel(option: ProductOption, chosen: string | undefined, kind: ShopPickerKind): string {
|
|
159
|
+
return kind === ShopPickerKind.Swatches && chosen ? `${option.name} — ${chosen}` : option.name;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** The words under a swatch group: what is sold out ("Charcoal is sold out"), '' when nothing is or the values speak. */
|
|
163
|
+
export function variantGroupNote(soldOut: ReadonlyArray<string>, kind: ShopPickerKind, lang: string | null | undefined): string {
|
|
164
|
+
if (kind !== ShopPickerKind.Swatches || !soldOut.length) return '';
|
|
165
|
+
return soldOut.map(name => shopWord(ShopWord.ValueSoldOut, lang, { name })).join(' · ');
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
// ── recipes ─────────────────────────────────────────────────────────────────────────────────────
|
|
169
|
+
|
|
170
|
+
enum Type {
|
|
171
|
+
Container = 'Container',
|
|
172
|
+
ButtonBlock = 'ButtonBlock',
|
|
173
|
+
Text = 'Text',
|
|
174
|
+
Heading = 'Heading',
|
|
175
|
+
Icon = 'Icon',
|
|
176
|
+
Image = 'Image',
|
|
177
|
+
Dialog = 'Dialog',
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
enum Style {
|
|
181
|
+
Price = 'price',
|
|
182
|
+
PriceCompare = 'price-compare',
|
|
183
|
+
Small = 'small',
|
|
184
|
+
Body = 'body',
|
|
185
|
+
Chip = 'variant-chip',
|
|
186
|
+
Swatch = 'variant-swatch',
|
|
187
|
+
Quantity = 'quantity',
|
|
188
|
+
QuantityButton = 'quantity-button',
|
|
189
|
+
Label = 'button-label',
|
|
190
|
+
Primary = 'button-primary',
|
|
191
|
+
Secondary = 'button-secondary',
|
|
192
|
+
Ghost = 'button-ghost',
|
|
193
|
+
CartButton = 'cart-button',
|
|
194
|
+
CartCount = 'cart-count',
|
|
195
|
+
CartLine = 'cart-line',
|
|
196
|
+
CartNote = 'cart-note',
|
|
197
|
+
Dialog = 'dialog',
|
|
198
|
+
Media = 'media',
|
|
199
|
+
Icon = 'icon',
|
|
200
|
+
Title = 'h3',
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/** The words a fresh recipe shows (board 10's sample) — the runtime writes the product's own over them. */
|
|
204
|
+
export const SHOP_RECIPE_WORDS = Object.freeze({
|
|
205
|
+
price: '₪240.00',
|
|
206
|
+
compareAt: '₪280.00',
|
|
207
|
+
option: 'Glaze — Sand',
|
|
208
|
+
value: '32 cm',
|
|
209
|
+
note: 'Charcoal is sold out',
|
|
210
|
+
quantity: '1',
|
|
211
|
+
add: 'Add to cart',
|
|
212
|
+
added: 'Added ✓',
|
|
213
|
+
buyNow: 'Buy now',
|
|
214
|
+
cart: 'Bag',
|
|
215
|
+
count: '2',
|
|
216
|
+
drawer: 'Your bag',
|
|
217
|
+
close: 'Close',
|
|
218
|
+
lineTitle: 'Tall speckled vase',
|
|
219
|
+
lineVariant: 'Sand · 32 cm',
|
|
220
|
+
lineTotal: '₪240.00',
|
|
221
|
+
remove: 'Remove',
|
|
222
|
+
empty: 'Your bag is empty.',
|
|
223
|
+
shippingNote: 'Add ₪40.00 more for free delivery',
|
|
224
|
+
subtotalLabel: 'Subtotal',
|
|
225
|
+
subtotal: '₪360.00',
|
|
226
|
+
vatNote: 'Includes VAT. Delivery is chosen at checkout.',
|
|
227
|
+
checkout: 'Check out',
|
|
228
|
+
keepShopping: 'Keep shopping',
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
export const SHOP_LABELS = Object.freeze({
|
|
232
|
+
price: 'Price', variants: 'Options', quantity: 'Quantity', add: 'Add to cart', buyNow: 'Buy now', cartButton: 'Cart button', cartDrawer: 'Cart drawer',
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const ZERO = '0px 0px 0px 0px';
|
|
236
|
+
const WORDS: Readonly<Record<string, string>> = { width: 'auto', minHeight: 'auto', padding: ZERO, margin: ZERO };
|
|
237
|
+
const ROW = { display: 'flex', flexDirection: 'row', alignItems: 'center', width: 'auto', height: 'auto', minHeight: 'auto', padding: ZERO };
|
|
238
|
+
const COLUMN = { display: 'flex', flexDirection: 'column', alignItems: 'stretch', width: '100%', height: 'auto', minHeight: 'auto', padding: ZERO };
|
|
239
|
+
/** "Add to cart" and "Added ✓" share ONE grid cell, so the button never changes width as they swap (Emil: in place). */
|
|
240
|
+
const STACKED = { gridColumn: '1', gridRow: '1', ...WORDS };
|
|
241
|
+
|
|
242
|
+
interface WithInteractions { interactions?: unknown[]; bindings?: unknown[] }
|
|
243
|
+
|
|
244
|
+
/** A click on `node` runs one action (`target` '' = the runtime finds its own: the page's product, the page's drawer). */
|
|
245
|
+
function onClick(node: CompositeNode, type: string, target = ''): void {
|
|
246
|
+
(node as WithInteractions).interactions = [{
|
|
247
|
+
id: `${node.id ?? 'node'}-click`, trigger: 'click',
|
|
248
|
+
actions: [{ type, target, duration: 0, delay: 0, easing: 'ease' }],
|
|
249
|
+
}];
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** Bind `prop` to a shop slot path, through the money pipe when asked. */
|
|
253
|
+
function bindSlot(node: CompositeNode, prop: string, source: string, path: string, money = false): void {
|
|
254
|
+
const bindings = ((node as WithInteractions).bindings ?? []).filter(b => (b as { prop?: string }).prop !== prop);
|
|
255
|
+
bindings.push({ prop, source, path, ...(money ? { pipes: [{ name: 'money', args: [] }] } : {}) });
|
|
256
|
+
(node as WithInteractions).bindings = bindings;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function part(create: CompositeNodeFactory, key: string, type: Type, role: ShopRole | null, style: Style | null,
|
|
260
|
+
props: Record<string, unknown>, label: string, base?: Readonly<Record<string, string>>): CompositeNode {
|
|
261
|
+
return makeCompositePart(create, { key, type, props, elementStyle: style ?? undefined }, role, label, base);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
function text(create: CompositeNodeFactory, key: string, role: ShopRole | null, style: Style, words: string, label: string,
|
|
265
|
+
base: Readonly<Record<string, string>> = WORDS, tag = 'p'): CompositeNode {
|
|
266
|
+
return part(create, key, Type.Text, role, style, { content: words, tag }, label, base);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
function icon(create: CompositeNodeFactory, key: string, iconClass: string, size = '18px'): CompositeNode {
|
|
270
|
+
return part(create, key, Type.Icon, null, Style.Icon, { iconClass }, 'Icon', { fontSize: size, color: 'inherit' });
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function button(create: CompositeNodeFactory, key: string, role: ShopRole, style: Style, label: string, ariaLabel = '',
|
|
274
|
+
base: Readonly<Record<string, string>> = {}): CompositeNode {
|
|
275
|
+
return part(create, key, Type.ButtonBlock, role, style, { tag: 'button', type: 'button', ...(ariaLabel ? { ariaLabel } : {}) }, label, base);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/** Price: the variant's price and, when it is higher, its earlier price struck through (board 10). */
|
|
279
|
+
export function buildPriceRecipe(create: CompositeNodeFactory): CompositeNode {
|
|
280
|
+
const root = part(create, 'price', Type.Container, ShopRole.Price, null, {}, SHOP_LABELS.price,
|
|
281
|
+
{ ...ROW, alignItems: 'baseline', flexWrap: 'wrap', gap: '8px' });
|
|
282
|
+
const amount = text(create, 'price-amount', ShopRole.PriceAmount, Style.Price, SHOP_RECIPE_WORDS.price, 'Price');
|
|
283
|
+
bindSlot(amount, 'content', '$variant', 'price', true);
|
|
284
|
+
const compare = text(create, 'price-compare', ShopRole.PriceCompare, Style.PriceCompare, SHOP_RECIPE_WORDS.compareAt, 'Price before');
|
|
285
|
+
bindSlot(compare, 'content', '$variant', 'compareAt', true);
|
|
286
|
+
root.children = [amount, compare];
|
|
287
|
+
return root;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/** Options: one group per option, each a radio group of chips, swatches or a select (T26). */
|
|
291
|
+
export function buildVariantPickerRecipe(create: CompositeNodeFactory): CompositeNode {
|
|
292
|
+
const root = part(create, 'variants', Type.Container, ShopRole.Variants, null, {}, SHOP_LABELS.variants, { ...COLUMN, gap: '16px' });
|
|
293
|
+
const group = part(create, 'variant-group', Type.Container, ShopRole.VariantGroup, null, {}, 'Option', { ...COLUMN, gap: '6px' });
|
|
294
|
+
const label = text(create, 'variant-label', ShopRole.VariantLabel, Style.Small, SHOP_RECIPE_WORDS.option, 'Option name');
|
|
295
|
+
const values = part(create, 'variant-values', Type.Container, ShopRole.VariantValues, null, {}, 'Values',
|
|
296
|
+
{ ...ROW, flexWrap: 'wrap', gap: '8px' });
|
|
297
|
+
const chip = button(create, 'variant-value', ShopRole.VariantValue, Style.Chip, 'Value', '', { display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 'auto', height: 'auto' });
|
|
298
|
+
chip.children = [text(create, 'variant-value-text', null, Style.Label, SHOP_RECIPE_WORDS.value, 'Text', WORDS, 'span')];
|
|
299
|
+
const swatch = button(create, 'variant-swatch', ShopRole.VariantSwatch, Style.Swatch, 'Swatch', 'Sand', { padding: ZERO, minWidth: '0px', minHeight: '0px' });
|
|
300
|
+
values.children = [chip, swatch];
|
|
301
|
+
const note = text(create, 'variant-note', ShopRole.VariantNote, Style.Small, SHOP_RECIPE_WORDS.note, 'Sold-out note');
|
|
302
|
+
group.children = [label, values, note];
|
|
303
|
+
root.children = [group];
|
|
304
|
+
return root;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/** Quantity: − · the count · + (min 1, max from the variant's stock). `compact` = a cart line's. */
|
|
308
|
+
export function buildQuantityRecipe(create: CompositeNodeFactory, compact = false, key = 'quantity'): CompositeNode {
|
|
309
|
+
const size = compact ? '30px' : 'var(--iox-stepper-size)';
|
|
310
|
+
const root = part(create, key, Type.Container, ShopRole.Quantity, Style.Quantity, {}, SHOP_LABELS.quantity,
|
|
311
|
+
{ ...ROW, alignItems: 'stretch', gap: '0px', ...(compact ? { minHeight: size } : {}) });
|
|
312
|
+
const down = button(create, `${key}-down`, ShopRole.QuantityDown, Style.QuantityButton, 'Decrease', 'Decrease quantity',
|
|
313
|
+
{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minWidth: size, padding: ZERO });
|
|
314
|
+
down.children = [icon(create, `${key}-down-icon`, 'ph ph-minus', compact ? '14px' : '16px')];
|
|
315
|
+
const value = text(create, `${key}-value`, ShopRole.QuantityValue, Style.Body, SHOP_RECIPE_WORDS.quantity, 'Count',
|
|
316
|
+
{ ...WORDS, display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minWidth: compact ? '32px' : '40px', fontVariantNumeric: 'tabular-nums' }, 'span');
|
|
317
|
+
const up = button(create, `${key}-up`, ShopRole.QuantityUp, Style.QuantityButton, 'Increase', 'Increase quantity',
|
|
318
|
+
{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', minWidth: size, padding: ZERO });
|
|
319
|
+
up.children = [icon(create, `${key}-up-icon`, 'ph ph-plus', compact ? '14px' : '16px')];
|
|
320
|
+
root.children = [down, value, up];
|
|
321
|
+
return root;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/** Add to cart: presses on pointer-down (its element style), then reads "Added ✓" in place for ADDED_HOLD_MS. */
|
|
325
|
+
export function buildAddToCartRecipe(create: CompositeNodeFactory): CompositeNode {
|
|
326
|
+
const root = button(create, 'add', ShopRole.Add, Style.Primary, SHOP_LABELS.add, '',
|
|
327
|
+
{ display: 'inline-grid', alignItems: 'center', justifyItems: 'center', flexGrow: '1', width: 'auto', height: 'auto' });
|
|
328
|
+
root.children = [
|
|
329
|
+
text(create, 'add-label', ShopRole.AddLabel, Style.Label, SHOP_RECIPE_WORDS.add, 'Add', STACKED, 'span'),
|
|
330
|
+
text(create, 'added-label', ShopRole.AddedLabel, Style.Label, SHOP_RECIPE_WORDS.added, 'Added', STACKED, 'span'),
|
|
331
|
+
];
|
|
332
|
+
onClick(root, 'addToCart');
|
|
333
|
+
return root;
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
/** Buy now: straight to checkout with this variant (inert on the canvas). */
|
|
337
|
+
export function buildBuyNowRecipe(create: CompositeNodeFactory): CompositeNode {
|
|
338
|
+
const root = button(create, 'buy-now', ShopRole.BuyNow, Style.Secondary, SHOP_LABELS.buyNow, '',
|
|
339
|
+
{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 'auto', height: 'auto' });
|
|
340
|
+
root.children = [text(create, 'buy-now-label', null, Style.Label, SHOP_RECIPE_WORDS.buyNow, 'Text', WORDS, 'span')];
|
|
341
|
+
onClick(root, 'startCheckout');
|
|
342
|
+
return root;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/** The bag button with its live count ($cart.count); it opens the page's cart drawer. */
|
|
346
|
+
export function buildCartButtonRecipe(create: CompositeNodeFactory): CompositeNode {
|
|
347
|
+
const root = button(create, 'cart-button', ShopRole.CartButton, Style.CartButton, SHOP_LABELS.cartButton, SHOP_RECIPE_WORDS.cart,
|
|
348
|
+
{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 'auto', height: 'auto', padding: '6px 6px 6px 6px', position: 'relative' });
|
|
349
|
+
const count = part(create, 'cart-count', Type.Container, ShopRole.CartCount, Style.CartCount, {}, 'Count',
|
|
350
|
+
{ display: 'inline-flex', alignItems: 'center', justifyContent: 'center', width: 'auto', height: 'auto', minHeight: 'auto', padding: '0px 4px 0px 4px', position: 'absolute', top: '-5px', right: '-5px' });
|
|
351
|
+
const words = text(create, 'cart-count-text', null, Style.Label, SHOP_RECIPE_WORDS.count, 'Text', { ...WORDS, lineHeight: '1' }, 'span');
|
|
352
|
+
bindSlot(words, 'content', '$cart', 'count');
|
|
353
|
+
count.children = [words];
|
|
354
|
+
root.children = [icon(create, 'cart-icon', 'ph ph-handbag'), count];
|
|
355
|
+
return root;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
/** One cart line: thumbnail · title, variant, quantity and Remove · line total (board 10). */
|
|
359
|
+
function buildCartLine(create: CompositeNodeFactory): CompositeNode {
|
|
360
|
+
const line = part(create, 'cart-line', Type.Container, ShopRole.CartLine, Style.CartLine, {}, 'Line',
|
|
361
|
+
{ display: 'grid', gridTemplateColumns: 'var(--iox-cart-thumb-size) minmax(0, 1fr) auto', alignItems: 'start', gap: '12px', width: '100%', height: 'auto', minHeight: 'auto', padding: ZERO });
|
|
362
|
+
const image = part(create, 'cart-line-image', Type.Image, ShopRole.CartLineImage, Style.Media, { src: '', alt: '' }, 'Image',
|
|
363
|
+
{ width: 'var(--iox-cart-thumb-size)', height: 'var(--iox-cart-thumb-size)', minHeight: '0px', objectFit: 'cover', aspectRatio: '1 / 1' });
|
|
364
|
+
const info = part(create, 'cart-line-info', Type.Container, null, null, {}, 'Details', { ...COLUMN, gap: '2px', minWidth: '0px' });
|
|
365
|
+
const title = text(create, 'cart-line-title', ShopRole.CartLineTitle, Style.Body, SHOP_RECIPE_WORDS.lineTitle, 'Title', { ...WORDS, fontWeight: '500' });
|
|
366
|
+
const variant = text(create, 'cart-line-variant', ShopRole.CartLineVariant, Style.Small, SHOP_RECIPE_WORDS.lineVariant, 'Variant', { ...WORDS, margin: '0px 0px 6px 0px' });
|
|
367
|
+
const actions = part(create, 'cart-line-actions', Type.Container, null, null, {}, 'Actions', { ...ROW, gap: '12px' });
|
|
368
|
+
const remove = button(create, 'cart-line-remove', ShopRole.CartLineRemove, Style.Ghost, 'Remove', '', { padding: '4px 4px 4px 4px', width: 'auto', height: 'auto', minHeight: 'auto' });
|
|
369
|
+
remove.children = [text(create, 'cart-line-remove-text', null, Style.Small, SHOP_RECIPE_WORDS.remove, 'Text', WORDS, 'span')];
|
|
370
|
+
actions.children = [buildQuantityRecipe(create, true, 'cart-line-quantity'), remove];
|
|
371
|
+
info.children = [title, variant, actions];
|
|
372
|
+
const total = text(create, 'cart-line-total', ShopRole.CartLineTotal, Style.Price, SHOP_RECIPE_WORDS.lineTotal, 'Line total',
|
|
373
|
+
{ ...WORDS, fontSize: 'var(--iox-size-body)', textAlign: 'end' });
|
|
374
|
+
line.children = [image, info, total];
|
|
375
|
+
return line;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/** The cart drawer: a Dialog at the end edge (a bottom sheet on a phone — shared CSS), filled from the PRICED cart. */
|
|
379
|
+
export function buildCartDrawerRecipe(create: CompositeNodeFactory): CompositeNode {
|
|
380
|
+
const drawer = part(create, 'cart-drawer', Type.Dialog, ShopRole.CartDrawer, Style.Dialog, {}, SHOP_LABELS.cartDrawer,
|
|
381
|
+
{ width: '380px', maxWidth: '100%', display: 'flex', flexDirection: 'column', gap: '14px' });
|
|
382
|
+
writeProp(drawer, 'placement', 'end');
|
|
383
|
+
writeProp(drawer, 'closeOnBackdrop', true);
|
|
384
|
+
writeProp(drawer, 'showCloseButton', false);
|
|
385
|
+
writeProp(drawer, 'ariaLabel', SHOP_RECIPE_WORDS.drawer);
|
|
386
|
+
|
|
387
|
+
const head = part(create, 'cart-head', Type.Container, null, null, {}, 'Head', { ...ROW, width: '100%', justifyContent: 'space-between', gap: '12px' });
|
|
388
|
+
const title = part(create, 'cart-title', Type.Heading, ShopRole.CartTitle, Style.Title, { content: SHOP_RECIPE_WORDS.drawer, level: 'h2' }, 'Title', WORDS);
|
|
389
|
+
const close = button(create, 'cart-close', ShopRole.CartClose, Style.Ghost, 'Close', '', { padding: '4px 4px 4px 4px', width: 'auto', height: 'auto', minHeight: 'auto' });
|
|
390
|
+
close.children = [text(create, 'cart-close-text', null, Style.Small, SHOP_RECIPE_WORDS.close, 'Text', WORDS, 'span')];
|
|
391
|
+
onClick(close, 'closeDialog', drawer.id ?? '');
|
|
392
|
+
head.children = [title, close];
|
|
393
|
+
|
|
394
|
+
const lines = part(create, 'cart-lines', Type.Container, ShopRole.CartLines, null, {}, 'Lines', { ...COLUMN, gap: '16px' });
|
|
395
|
+
lines.children = [buildCartLine(create)];
|
|
396
|
+
const issues = text(create, 'cart-issues', ShopRole.CartIssues, Style.Small, '', 'Issues', { ...WORDS, color: 'var(--iox-danger)' });
|
|
397
|
+
const empty = text(create, 'cart-empty', ShopRole.CartEmpty, Style.Body, SHOP_RECIPE_WORDS.empty, 'Empty');
|
|
398
|
+
const note = text(create, 'cart-shipping-note', ShopRole.CartShippingNote, Style.CartNote, SHOP_RECIPE_WORDS.shippingNote, 'Free delivery note',
|
|
399
|
+
{ width: 'auto', minHeight: 'auto', margin: ZERO });
|
|
400
|
+
const summary = part(create, 'cart-summary', Type.Container, ShopRole.CartSummary, null, {}, 'Subtotal', { ...ROW, width: '100%', justifyContent: 'space-between', gap: '12px' });
|
|
401
|
+
const subtotal = text(create, 'cart-subtotal', ShopRole.CartSubtotal, Style.Body, SHOP_RECIPE_WORDS.subtotal, 'Amount', { ...WORDS, fontVariantNumeric: 'tabular-nums', fontWeight: '600' }, 'span');
|
|
402
|
+
bindSlot(subtotal, 'content', '$cart', 'subtotal', true);
|
|
403
|
+
summary.children = [text(create, 'cart-subtotal-label', null, Style.Body, SHOP_RECIPE_WORDS.subtotalLabel, 'Label', WORDS, 'span'), subtotal];
|
|
404
|
+
const vat = text(create, 'cart-vat-note', ShopRole.CartVatNote, Style.Small, SHOP_RECIPE_WORDS.vatNote, 'VAT note');
|
|
405
|
+
const checkout = button(create, 'checkout', ShopRole.Checkout, Style.Primary, 'Check out', '', { display: 'inline-flex', justifyContent: 'center', alignItems: 'center', width: '100%', height: 'auto' });
|
|
406
|
+
checkout.children = [text(create, 'checkout-label', null, Style.Label, SHOP_RECIPE_WORDS.checkout, 'Text', WORDS, 'span')];
|
|
407
|
+
const keep = button(create, 'keep-shopping', ShopRole.KeepShopping, Style.Secondary, 'Keep shopping', '', { display: 'inline-flex', justifyContent: 'center', alignItems: 'center', width: '100%', height: 'auto' });
|
|
408
|
+
keep.children = [text(create, 'keep-shopping-label', null, Style.Label, SHOP_RECIPE_WORDS.keepShopping, 'Text', WORDS, 'span')];
|
|
409
|
+
onClick(keep, 'closeDialog', drawer.id ?? '');
|
|
410
|
+
drawer.children = [head, lines, issues, empty, note, summary, vat, checkout, keep];
|
|
411
|
+
return drawer;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
/** The recipes the palette's Shop group offers, in its order. */
|
|
415
|
+
export enum ShopRecipe {
|
|
416
|
+
Price = 'price',
|
|
417
|
+
Variants = 'variants',
|
|
418
|
+
Quantity = 'quantity',
|
|
419
|
+
Add = 'add',
|
|
420
|
+
BuyNow = 'buyNow',
|
|
421
|
+
CartButton = 'cartButton',
|
|
422
|
+
CartDrawer = 'cartDrawer',
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
export const SHOP_RECIPES: Readonly<Record<ShopRecipe, (create: CompositeNodeFactory) => CompositeNode>> = Object.freeze({
|
|
426
|
+
[ShopRecipe.Price]: buildPriceRecipe,
|
|
427
|
+
[ShopRecipe.Variants]: buildVariantPickerRecipe,
|
|
428
|
+
[ShopRecipe.Quantity]: (create: CompositeNodeFactory) => buildQuantityRecipe(create),
|
|
429
|
+
[ShopRecipe.Add]: buildAddToCartRecipe,
|
|
430
|
+
[ShopRecipe.BuyNow]: buildBuyNowRecipe,
|
|
431
|
+
[ShopRecipe.CartButton]: buildCartButtonRecipe,
|
|
432
|
+
[ShopRecipe.CartDrawer]: buildCartDrawerRecipe,
|
|
433
|
+
});
|