pixelize-design-library 3.3.3 → 3.3.5
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/CHANGELOG.md +25 -0
- package/COMPONENT-GOTCHAS.md +5 -0
- package/dist/Components/Commerce/commerceVariants.d.ts +2 -0
- package/dist/Components/Commerce/commerceVariants.js +5 -0
- package/dist/Components/NotificationCenter/row/NotificationRow.js +1 -1
- package/dist/Components/ProductCard/QuickAddSheet.js +6 -2
- package/dist/Components/ProductCard/QuickAddSheetProps.d.ts +2 -0
- package/dist/Components/VariantSelector/VariantSelector.js +2 -7
- package/dist/Components/VariantSelector/VariantSelectorProps.d.ts +1 -1
- package/dist/Components/VariantSelector/variantSelection.d.ts +2 -2
- package/dist/Components/VariantSelector/variantSelection.js +9 -6
- package/dist/esm/Components/Commerce/commerceVariants.js +4 -0
- package/dist/esm/Components/NotificationCenter/row/NotificationRow.js +1 -1
- package/dist/esm/Components/ProductCard/QuickAddSheet.js +7 -3
- package/dist/esm/Components/VariantSelector/VariantSelector.js +3 -8
- package/dist/esm/Components/VariantSelector/variantSelection.js +8 -5
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,31 @@ Found a bug or a gap? Report it as a GitHub issue and track it to closure — se
|
|
|
9
9
|
[COMPONENT-GOTCHAS.md](COMPONENT-GOTCHAS.md#found-a-gap-or-a-bug-report-it-then-track-it). A fix's
|
|
10
10
|
line below names its issue number.
|
|
11
11
|
|
|
12
|
+
## [3.3.5] — 2026-11-18
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **A closed `NotificationCenter` panel still caught clicks** (Bata: clicking a field in a drawer opened a
|
|
17
|
+
notification's link). The panel stays mounted after its first open and hides with `visibility: hidden`, but
|
|
18
|
+
every row set `visibility: visible` on itself, which overrides a hidden parent, so its invisible links sat over
|
|
19
|
+
whatever was below the bell. Rows now inherit the panel's visibility and only set `hidden` while collapsed.
|
|
20
|
+
|
|
21
|
+
## [3.3.4] — 2026-11-16
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- **A sold-out size could not be picked, so its price never showed** (Magil Naturals: "not able to select another
|
|
26
|
+
size to view its price"). `VariantSelector` swallowed a click, arrow, Home or End on a value sold out under every
|
|
27
|
+
combination. It now selects it: the chip stays struck through and announced "unavailable", `onValueChange` fires
|
|
28
|
+
with that variant, and `ProductDetails` shows its price, mrp and stock text with Notify me in place of Add to
|
|
29
|
+
bag, Buy now and the stepper. Picks a sold-out value cannot pair with at all are still dropped; a sold-out
|
|
30
|
+
pick is no longer cleared by choosing another axis while some variant carries both.
|
|
31
|
+
- **`QuickAddSheet` confirm is disabled, reading "Sold out", while the chosen variant is sold out**, so the new
|
|
32
|
+
selectable behaviour cannot add it to the bag. New label `soldOut` (default "Sold out") on `QuickAddSheetLabels`.
|
|
33
|
+
A consumer that builds a complete `QuickAddSheetLabels` object, rather than `Partial`, must add it.
|
|
34
|
+
- **Docs:** `onValueChange`'s variant may be out of stock; use `stockState` before a custom add-to-bag
|
|
35
|
+
(`COMPONENT-GOTCHAS.md`).
|
|
36
|
+
|
|
12
37
|
## [3.3.3] — 2026-11-13
|
|
13
38
|
|
|
14
39
|
### Fixed
|
package/COMPONENT-GOTCHAS.md
CHANGED
|
@@ -1158,6 +1158,11 @@ is no longer Chakra's style prop (omitted from the type) — use `p` for a raw v
|
|
|
1158
1158
|
there; the `!important` is needed because Chakra's slide sets an inline `max-width: 100vw`.
|
|
1159
1159
|
- **`OptionChip` `unavailable` is visual and announced only** — `onSelect` still fires so a parent
|
|
1160
1160
|
can re-derive the other axes. Guard it yourself if the pick must be refused.
|
|
1161
|
+
- **`VariantSelector` selects sold-out options, so the variant it reports can be out of stock** (3.3.4+). The chip
|
|
1162
|
+
stays struck through and announced "unavailable", but `onValueChange` fires and the variant's price, mrp and stock
|
|
1163
|
+
show. `ProductDetails` turns the primary action into Notify me and `QuickAddSheet` disables confirm; a custom
|
|
1164
|
+
consumer must check `stockState(variant) === "out-of-stock"` before adding to a bag. Earlier versions swallowed
|
|
1165
|
+
the click when a value was sold out under every combination.
|
|
1161
1166
|
- **`WishlistToggle` flips its default name and `aria-pressed` together** — on cards pass a fixed
|
|
1162
1167
|
`label` (`Save ${title}`).
|
|
1163
1168
|
- **Group children must be direct children.** `AddressCardGroup` / `PaymentOptionGroup` read the
|
|
@@ -5,6 +5,8 @@ export declare function selectionComplete(axes: OptionAxis[], selection: Variant
|
|
|
5
5
|
export declare function findVariant(axes: OptionAxis[], variants: ProductVariant[], selection: VariantSelection): ProductVariant | undefined;
|
|
6
6
|
/** A value is offered when some sellable variant has it alongside the other axes' current picks. */
|
|
7
7
|
export declare function isOptionAvailable(variants: ProductVariant[], selection: VariantSelection, axisId: string, valueId: string): boolean;
|
|
8
|
+
/** Some variant, in stock or not, carries every pick in `selection`. */
|
|
9
|
+
export declare function variantExists(variants: ProductVariant[], selection: VariantSelection): boolean;
|
|
8
10
|
export declare function remainingStock(variants: ProductVariant[], selection: VariantSelection, axisId: string, valueId: string): number | undefined;
|
|
9
11
|
export declare function priceRange(variants: ProductVariant[]): {
|
|
10
12
|
min: number;
|
|
@@ -5,6 +5,7 @@ exports.stockState = stockState;
|
|
|
5
5
|
exports.selectionComplete = selectionComplete;
|
|
6
6
|
exports.findVariant = findVariant;
|
|
7
7
|
exports.isOptionAvailable = isOptionAvailable;
|
|
8
|
+
exports.variantExists = variantExists;
|
|
8
9
|
exports.remainingStock = remainingStock;
|
|
9
10
|
exports.priceRange = priceRange;
|
|
10
11
|
exports.firstAvailableSelection = firstAvailableSelection;
|
|
@@ -31,6 +32,10 @@ function isOptionAvailable(variants, selection, axisId, valueId) {
|
|
|
31
32
|
const probe = { ...selection, [axisId]: valueId };
|
|
32
33
|
return variants.some((variant) => sellable(variant) && matches(variant, probe));
|
|
33
34
|
}
|
|
35
|
+
/** Some variant, in stock or not, carries every pick in `selection`. */
|
|
36
|
+
function variantExists(variants, selection) {
|
|
37
|
+
return variants.some((variant) => matches(variant, selection));
|
|
38
|
+
}
|
|
34
39
|
function remainingStock(variants, selection, axisId, valueId) {
|
|
35
40
|
const probe = { ...selection, [axisId]: valueId };
|
|
36
41
|
const hits = variants.filter((variant) => matches(variant, probe) && sellable(variant));
|
|
@@ -106,7 +106,7 @@ const NotificationRow = ({ item, variant = "panel", isSelected = false, isChecke
|
|
|
106
106
|
},
|
|
107
107
|
};
|
|
108
108
|
const linkBody = ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [isUnread && (0, jsx_runtime_1.jsx)(VisuallyHidden_1.default, { children: `${labels.unread}. ` }), entry.eyebrow && ((0, jsx_runtime_1.jsxs)(react_2.chakra.span, { fontFamily: "mono", fontSize: "xs", fontWeight: 500, color: colors.textMuted, children: [entry.eyebrow, " "] })), (0, jsx_runtime_1.jsx)(rowParts_1.TitleText, { parts: entry.title, isUnread: isUnread })] }));
|
|
109
|
-
return ((0, jsx_runtime_1.jsx)(react_2.chakra.li, { listStyleType: "none", display: "grid", gridTemplateRows: isHidden ? "0fr" : "1fr", opacity: isHidden ? 0 : 1, visibility: isHidden ? "hidden" :
|
|
109
|
+
return ((0, jsx_runtime_1.jsx)(react_2.chakra.li, { listStyleType: "none", display: "grid", gridTemplateRows: isHidden ? "0fr" : "1fr", opacity: isHidden ? 0 : 1, visibility: isHidden ? "hidden" : undefined, "aria-hidden": isHidden ? true : undefined, "data-testid": entry.testId, "data-notification-id": entry.id, "data-status": state.status, sx: {
|
|
110
110
|
transition: isHidden ? HIDE : SHOW,
|
|
111
111
|
contentVisibility: "auto",
|
|
112
112
|
containIntrinsicSize: "auto 4.5rem",
|
|
@@ -56,6 +56,7 @@ const DEFAULT_LABELS = {
|
|
|
56
56
|
confirm: "Add to bag",
|
|
57
57
|
confirmWithTotal: (total) => `Add to bag — ${total}`,
|
|
58
58
|
prompt: (axisLabel) => `Select a ${axisLabel}`,
|
|
59
|
+
soldOut: "Sold out",
|
|
59
60
|
};
|
|
60
61
|
const DESKTOP_QUERY = "(min-width: 48em)";
|
|
61
62
|
/** Bottom sheet on phones, centred panel on desktop; holds the option picker so a card never grows. */
|
|
@@ -80,7 +81,8 @@ const QuickAddSheet = ({ isOpen, onClose, title, brand, media, axes, variants, d
|
|
|
80
81
|
const variant = (0, commerceVariants_1.findVariant)(axes, variants, selection);
|
|
81
82
|
const range = (0, productCardModel_1.rangeOf)(variants);
|
|
82
83
|
const maxQuantity = (variant === null || variant === void 0 ? void 0 : variant.stock) !== undefined && variant.stock > 0 ? variant.stock : undefined;
|
|
83
|
-
const
|
|
84
|
+
const soldOut = variant !== undefined && (0, commerceVariants_1.stockState)(variant) === "out-of-stock";
|
|
85
|
+
const confirmLabel = soldOut ? copy.soldOut : variant ? copy.confirmWithTotal((0, price_1.formatPrice)(variant.price * quantity, fmt)) : copy.confirm;
|
|
84
86
|
const onSelect = (next) => {
|
|
85
87
|
setSelection(next);
|
|
86
88
|
setError(undefined);
|
|
@@ -95,11 +97,13 @@ const QuickAddSheet = ({ isOpen, onClose, title, brand, media, axes, variants, d
|
|
|
95
97
|
setError(copy.prompt(((_a = missing === null || missing === void 0 ? void 0 : missing.label) !== null && _a !== void 0 ? _a : "option").toLowerCase()));
|
|
96
98
|
return;
|
|
97
99
|
}
|
|
100
|
+
if (soldOut)
|
|
101
|
+
return;
|
|
98
102
|
onConfirm(variant, quantity);
|
|
99
103
|
};
|
|
100
104
|
const summary = ((0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", gap: 3, mb: 4, children: [media ? ((0, jsx_runtime_1.jsx)(react_2.Box, { as: "img", src: (_a = media.thumb) !== null && _a !== void 0 ? _a : media.src, alt: "", boxSize: "4.5rem", flexShrink: 0, borderRadius: "xl", objectFit: "cover", bg: colors.background[100] })) : null, (0, jsx_runtime_1.jsxs)(react_2.Flex, { direction: "column", gap: 0.5, minW: 0, children: [brand ? ((0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "xs", color: colors.textMuted, noOfLines: 1, children: brand })) : null, (0, jsx_runtime_1.jsx)(react_2.Text, { fontSize: "sm", fontWeight: 500, color: colors.header[900], noOfLines: 2, children: title }), (0, jsx_runtime_1.jsx)(PriceBlock_1.default, { size: "sm", price: (_b = variant === null || variant === void 0 ? void 0 : variant.price) !== null && _b !== void 0 ? _b : (_c = variants[0]) === null || _c === void 0 ? void 0 : _c.price, mrp: variant === null || variant === void 0 ? void 0 : variant.mrp, priceRange: variant ? undefined : range, currency: currency, locale: locale })] })] }));
|
|
101
105
|
const body = ((0, jsx_runtime_1.jsxs)(react_2.Flex, { direction: "column", gap: 5, "data-testid": testId, children: [summary, (0, jsx_runtime_1.jsx)(VariantSelector_1.default, { axes: axes, variants: variants, value: selection, onValueChange: onSelect, error: error, showSelectedLabel: true, showLowStock: true }), (0, jsx_runtime_1.jsxs)(react_2.Flex, { align: "center", justify: "space-between", gap: 3, children: [(0, jsx_runtime_1.jsx)(react_2.Text, { as: "span", fontSize: "sm", fontWeight: 600, color: colors.header[900], children: copy.quantity }), (0, jsx_runtime_1.jsx)(QuantityStepper_1.default, { value: quantity, min: 1, max: maxQuantity, onValueChange: setQuantity, itemLabel: title })] })] }));
|
|
102
|
-
const action = ((0, jsx_runtime_1.jsx)(Button_1.default, { size: "lg", width: "100%", onClick: confirm, children: confirmLabel }));
|
|
106
|
+
const action = ((0, jsx_runtime_1.jsx)(Button_1.default, { size: "lg", width: "100%", onClick: confirm, isDisabled: soldOut, children: confirmLabel }));
|
|
103
107
|
const asModal = presentation === "modal" || (presentation === "auto" && desktop);
|
|
104
108
|
if (asModal) {
|
|
105
109
|
return ((0, jsx_runtime_1.jsxs)(Modal_1.default, { size: "md", isOpen: isOpen, onClose: onClose, isCentered: true, title: copy.heading, children: [(0, jsx_runtime_1.jsx)(Modal_1.ModalBody, { children: body }), (0, jsx_runtime_1.jsx)(Modal_1.ModalFooter, { children: action })] }));
|
|
@@ -12,6 +12,8 @@ export interface QuickAddSheetLabels {
|
|
|
12
12
|
confirmWithTotal: (total: string) => string;
|
|
13
13
|
/** Prompt shown when confirming with an axis unpicked, given the lower-cased axis label ("size"). */
|
|
14
14
|
prompt: (axisLabel: string) => string;
|
|
15
|
+
/** Disabled confirm button text when the chosen variant is sold out. */
|
|
16
|
+
soldOut: string;
|
|
15
17
|
}
|
|
16
18
|
/** drawer slides up from the bottom edge, modal is a centred panel, auto picks modal from 48em up. */
|
|
17
19
|
export type QuickAddPresentation = "auto" | "drawer" | "modal";
|
|
@@ -37,11 +37,7 @@ const VariantSelector = ({ axes, variants, value, defaultValue, onValueChange, e
|
|
|
37
37
|
setInner(next);
|
|
38
38
|
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(next, (0, commerceVariants_1.findVariant)(axes, variants, next));
|
|
39
39
|
}, [axes, variants, selection, value, onValueChange]);
|
|
40
|
-
const choose = (axisId, valueId) =>
|
|
41
|
-
if ((0, variantSelection_1.isSoldOutEverywhere)(variants, axisId, valueId))
|
|
42
|
-
return;
|
|
43
|
-
commit((0, variantSelection_1.selectValue)(axes, variants, selection, axisId, valueId));
|
|
44
|
-
};
|
|
40
|
+
const choose = (axisId, valueId) => commit((0, variantSelection_1.selectValue)(axes, variants, selection, axisId, valueId));
|
|
45
41
|
const lowStockHint = (axis, option) => {
|
|
46
42
|
if (!showLowStock)
|
|
47
43
|
return undefined;
|
|
@@ -77,8 +73,7 @@ const VariantSelector = ({ axes, variants, value, defaultValue, onValueChange, e
|
|
|
77
73
|
const next = axis.values[target];
|
|
78
74
|
(_a = cells.current.get(cellKey(axis.id, next.id))) === null || _a === void 0 ? void 0 : _a.focus();
|
|
79
75
|
setFocus({ axisId: axis.id, valueId: next.id });
|
|
80
|
-
|
|
81
|
-
choose(axis.id, next.id);
|
|
76
|
+
choose(axis.id, next.id);
|
|
82
77
|
};
|
|
83
78
|
const containerStyles = (axis) => {
|
|
84
79
|
if (layout === "grid") {
|
|
@@ -12,7 +12,7 @@ export interface VariantSelectorProps {
|
|
|
12
12
|
value?: VariantSelection;
|
|
13
13
|
/** Initial selection when uncontrolled; ignored once `value` is passed. */
|
|
14
14
|
defaultValue?: VariantSelection;
|
|
15
|
-
/** Receives the new selection and the matching variant, or undefined while the selection is incomplete or has no variant. */
|
|
15
|
+
/** Receives the new selection and the matching variant (which may be sold out: check `stockState`), or undefined while the selection is incomplete or has no variant. */
|
|
16
16
|
onValueChange?: (selection: VariantSelection, variant: ProductVariant | undefined) => void;
|
|
17
17
|
/** Prompt such as "Select a size": shown as a status message and rings every axis still unpicked. */
|
|
18
18
|
error?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OptionAxis, ProductVariant, VariantSelection } from "../Commerce/commerceTypes";
|
|
2
|
-
/** Picks `valueId` on `axisId`, then drops every other pick that no sellable variant can pair with it. */
|
|
3
|
-
export declare const selectValue: (axes: OptionAxis[], variants: ProductVariant[], selection: VariantSelection, axisId: string, valueId: string) => VariantSelection;
|
|
4
2
|
/** Sold out under every combination, so picking it can never lead to a purchasable variant. */
|
|
5
3
|
export declare const isSoldOutEverywhere: (variants: ProductVariant[], axisId: string, valueId: string) => boolean;
|
|
4
|
+
/** Picks a value, dropping other picks it cannot pair with; sold-out-everywhere values only need some variant. */
|
|
5
|
+
export declare const selectValue: (axes: OptionAxis[], variants: ProductVariant[], selection: VariantSelection, axisId: string, valueId: string) => VariantSelection;
|
|
6
6
|
export declare const sameSelection: (a: VariantSelection, b: VariantSelection) => boolean;
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sameSelection = exports.
|
|
3
|
+
exports.sameSelection = exports.selectValue = exports.isSoldOutEverywhere = void 0;
|
|
4
4
|
const commerceVariants_1 = require("../Commerce/commerceVariants");
|
|
5
|
-
/**
|
|
5
|
+
/** Sold out under every combination, so picking it can never lead to a purchasable variant. */
|
|
6
|
+
const isSoldOutEverywhere = (variants, axisId, valueId) => !(0, commerceVariants_1.isOptionAvailable)(variants, {}, axisId, valueId);
|
|
7
|
+
exports.isSoldOutEverywhere = isSoldOutEverywhere;
|
|
8
|
+
/** Picks a value, dropping other picks it cannot pair with; sold-out-everywhere values only need some variant. */
|
|
6
9
|
const selectValue = (axes, variants, selection, axisId, valueId) => {
|
|
7
10
|
const next = { ...selection, [axisId]: valueId };
|
|
11
|
+
const pickedSoldOut = (0, exports.isSoldOutEverywhere)(variants, axisId, valueId);
|
|
8
12
|
for (const axis of axes) {
|
|
9
13
|
const pick = next[axis.id];
|
|
10
14
|
if (axis.id === axisId || pick === undefined)
|
|
11
15
|
continue;
|
|
12
|
-
|
|
16
|
+
const anyVariant = pickedSoldOut || (0, exports.isSoldOutEverywhere)(variants, axis.id, pick);
|
|
17
|
+
const pairs = anyVariant ? (0, commerceVariants_1.variantExists)(variants, next) : (0, commerceVariants_1.isOptionAvailable)(variants, next, axis.id, pick);
|
|
18
|
+
if (!pairs)
|
|
13
19
|
delete next[axis.id];
|
|
14
20
|
}
|
|
15
21
|
return next;
|
|
16
22
|
};
|
|
17
23
|
exports.selectValue = selectValue;
|
|
18
|
-
/** Sold out under every combination, so picking it can never lead to a purchasable variant. */
|
|
19
|
-
const isSoldOutEverywhere = (variants, axisId, valueId) => !(0, commerceVariants_1.isOptionAvailable)(variants, {}, axisId, valueId);
|
|
20
|
-
exports.isSoldOutEverywhere = isSoldOutEverywhere;
|
|
21
24
|
const sameSelection = (a, b) => {
|
|
22
25
|
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
23
26
|
return [...keys].every((key) => a[key] === b[key]);
|
|
@@ -21,6 +21,10 @@ export function isOptionAvailable(variants, selection, axisId, valueId) {
|
|
|
21
21
|
const probe = { ...selection, [axisId]: valueId };
|
|
22
22
|
return variants.some((variant) => sellable(variant) && matches(variant, probe));
|
|
23
23
|
}
|
|
24
|
+
/** Some variant, in stock or not, carries every pick in `selection`. */
|
|
25
|
+
export function variantExists(variants, selection) {
|
|
26
|
+
return variants.some((variant) => matches(variant, selection));
|
|
27
|
+
}
|
|
24
28
|
export function remainingStock(variants, selection, axisId, valueId) {
|
|
25
29
|
const probe = { ...selection, [axisId]: valueId };
|
|
26
30
|
const hits = variants.filter((variant) => matches(variant, probe) && sellable(variant));
|
|
@@ -101,7 +101,7 @@ const NotificationRow = ({ item, variant = "panel", isSelected = false, isChecke
|
|
|
101
101
|
},
|
|
102
102
|
};
|
|
103
103
|
const linkBody = (_jsxs(_Fragment, { children: [isUnread && _jsx(VisuallyHidden, { children: `${labels.unread}. ` }), entry.eyebrow && (_jsxs(chakra.span, { fontFamily: "mono", fontSize: "xs", fontWeight: 500, color: colors.textMuted, children: [entry.eyebrow, " "] })), _jsx(TitleText, { parts: entry.title, isUnread: isUnread })] }));
|
|
104
|
-
return (_jsx(chakra.li, { listStyleType: "none", display: "grid", gridTemplateRows: isHidden ? "0fr" : "1fr", opacity: isHidden ? 0 : 1, visibility: isHidden ? "hidden" :
|
|
104
|
+
return (_jsx(chakra.li, { listStyleType: "none", display: "grid", gridTemplateRows: isHidden ? "0fr" : "1fr", opacity: isHidden ? 0 : 1, visibility: isHidden ? "hidden" : undefined, "aria-hidden": isHidden ? true : undefined, "data-testid": entry.testId, "data-notification-id": entry.id, "data-status": state.status, sx: {
|
|
105
105
|
transition: isHidden ? HIDE : SHOW,
|
|
106
106
|
contentVisibility: "auto",
|
|
107
107
|
containIntrinsicSize: "auto 4.5rem",
|
|
@@ -9,7 +9,7 @@ import Modal, { ModalBody, ModalFooter } from "../Modal/Modal.js";
|
|
|
9
9
|
import PriceBlock from "../PriceBlock/PriceBlock.js";
|
|
10
10
|
import QuantityStepper from "../QuantityStepper/QuantityStepper.js";
|
|
11
11
|
import VariantSelector from "../VariantSelector/VariantSelector.js";
|
|
12
|
-
import { findVariant } from "../Commerce/commerceVariants.js";
|
|
12
|
+
import { findVariant, stockState } from "../Commerce/commerceVariants.js";
|
|
13
13
|
import { rangeOf, firstMissingAxis } from "./productCardModel.js";
|
|
14
14
|
import { useMatchMedia } from "../../Hooks/useMatchMedia.js";
|
|
15
15
|
const DEFAULT_LABELS = {
|
|
@@ -18,6 +18,7 @@ const DEFAULT_LABELS = {
|
|
|
18
18
|
confirm: "Add to bag",
|
|
19
19
|
confirmWithTotal: (total) => `Add to bag — ${total}`,
|
|
20
20
|
prompt: (axisLabel) => `Select a ${axisLabel}`,
|
|
21
|
+
soldOut: "Sold out",
|
|
21
22
|
};
|
|
22
23
|
const DESKTOP_QUERY = "(min-width: 48em)";
|
|
23
24
|
/** Bottom sheet on phones, centred panel on desktop; holds the option picker so a card never grows. */
|
|
@@ -42,7 +43,8 @@ const QuickAddSheet = ({ isOpen, onClose, title, brand, media, axes, variants, d
|
|
|
42
43
|
const variant = findVariant(axes, variants, selection);
|
|
43
44
|
const range = rangeOf(variants);
|
|
44
45
|
const maxQuantity = (variant === null || variant === void 0 ? void 0 : variant.stock) !== undefined && variant.stock > 0 ? variant.stock : undefined;
|
|
45
|
-
const
|
|
46
|
+
const soldOut = variant !== undefined && stockState(variant) === "out-of-stock";
|
|
47
|
+
const confirmLabel = soldOut ? copy.soldOut : variant ? copy.confirmWithTotal(formatPrice(variant.price * quantity, fmt)) : copy.confirm;
|
|
46
48
|
const onSelect = (next) => {
|
|
47
49
|
setSelection(next);
|
|
48
50
|
setError(undefined);
|
|
@@ -57,11 +59,13 @@ const QuickAddSheet = ({ isOpen, onClose, title, brand, media, axes, variants, d
|
|
|
57
59
|
setError(copy.prompt(((_a = missing === null || missing === void 0 ? void 0 : missing.label) !== null && _a !== void 0 ? _a : "option").toLowerCase()));
|
|
58
60
|
return;
|
|
59
61
|
}
|
|
62
|
+
if (soldOut)
|
|
63
|
+
return;
|
|
60
64
|
onConfirm(variant, quantity);
|
|
61
65
|
};
|
|
62
66
|
const summary = (_jsxs(Flex, { align: "center", gap: 3, mb: 4, children: [media ? (_jsx(Box, { as: "img", src: (_a = media.thumb) !== null && _a !== void 0 ? _a : media.src, alt: "", boxSize: "4.5rem", flexShrink: 0, borderRadius: "xl", objectFit: "cover", bg: colors.background[100] })) : null, _jsxs(Flex, { direction: "column", gap: 0.5, minW: 0, children: [brand ? (_jsx(Text, { fontSize: "xs", color: colors.textMuted, noOfLines: 1, children: brand })) : null, _jsx(Text, { fontSize: "sm", fontWeight: 500, color: colors.header[900], noOfLines: 2, children: title }), _jsx(PriceBlock, { size: "sm", price: (_b = variant === null || variant === void 0 ? void 0 : variant.price) !== null && _b !== void 0 ? _b : (_c = variants[0]) === null || _c === void 0 ? void 0 : _c.price, mrp: variant === null || variant === void 0 ? void 0 : variant.mrp, priceRange: variant ? undefined : range, currency: currency, locale: locale })] })] }));
|
|
63
67
|
const body = (_jsxs(Flex, { direction: "column", gap: 5, "data-testid": testId, children: [summary, _jsx(VariantSelector, { axes: axes, variants: variants, value: selection, onValueChange: onSelect, error: error, showSelectedLabel: true, showLowStock: true }), _jsxs(Flex, { align: "center", justify: "space-between", gap: 3, children: [_jsx(Text, { as: "span", fontSize: "sm", fontWeight: 600, color: colors.header[900], children: copy.quantity }), _jsx(QuantityStepper, { value: quantity, min: 1, max: maxQuantity, onValueChange: setQuantity, itemLabel: title })] })] }));
|
|
64
|
-
const action = (_jsx(Button, { size: "lg", width: "100%", onClick: confirm, children: confirmLabel }));
|
|
68
|
+
const action = (_jsx(Button, { size: "lg", width: "100%", onClick: confirm, isDisabled: soldOut, children: confirmLabel }));
|
|
65
69
|
const asModal = presentation === "modal" || (presentation === "auto" && desktop);
|
|
66
70
|
if (asModal) {
|
|
67
71
|
return (_jsxs(Modal, { size: "md", isOpen: isOpen, onClose: onClose, isCentered: true, title: copy.heading, children: [_jsx(ModalBody, { children: body }), _jsx(ModalFooter, { children: action })] }));
|
|
@@ -7,7 +7,7 @@ import { focusVisibleStyles } from "../../Theme/chakra/focusRing.styles.js";
|
|
|
7
7
|
import { scrollbarStyles } from "../../Theme/tokens/builders/scrollbar.js";
|
|
8
8
|
import OptionChip from "../OptionChip/OptionChip.js";
|
|
9
9
|
import { LOW_STOCK_THRESHOLD, findVariant, isOptionAvailable, remainingStock, } from "../Commerce/commerceVariants.js";
|
|
10
|
-
import {
|
|
10
|
+
import { sameSelection, selectValue } from "./variantSelection.js";
|
|
11
11
|
const GAP = "0.5rem";
|
|
12
12
|
const GRID_MIN = {
|
|
13
13
|
chip: "4rem",
|
|
@@ -32,11 +32,7 @@ const VariantSelector = ({ axes, variants, value, defaultValue, onValueChange, e
|
|
|
32
32
|
setInner(next);
|
|
33
33
|
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(next, findVariant(axes, variants, next));
|
|
34
34
|
}, [axes, variants, selection, value, onValueChange]);
|
|
35
|
-
const choose = (axisId, valueId) =>
|
|
36
|
-
if (isSoldOutEverywhere(variants, axisId, valueId))
|
|
37
|
-
return;
|
|
38
|
-
commit(selectValue(axes, variants, selection, axisId, valueId));
|
|
39
|
-
};
|
|
35
|
+
const choose = (axisId, valueId) => commit(selectValue(axes, variants, selection, axisId, valueId));
|
|
40
36
|
const lowStockHint = (axis, option) => {
|
|
41
37
|
if (!showLowStock)
|
|
42
38
|
return undefined;
|
|
@@ -72,8 +68,7 @@ const VariantSelector = ({ axes, variants, value, defaultValue, onValueChange, e
|
|
|
72
68
|
const next = axis.values[target];
|
|
73
69
|
(_a = cells.current.get(cellKey(axis.id, next.id))) === null || _a === void 0 ? void 0 : _a.focus();
|
|
74
70
|
setFocus({ axisId: axis.id, valueId: next.id });
|
|
75
|
-
|
|
76
|
-
choose(axis.id, next.id);
|
|
71
|
+
choose(axis.id, next.id);
|
|
77
72
|
};
|
|
78
73
|
const containerStyles = (axis) => {
|
|
79
74
|
if (layout === "grid") {
|
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import { isOptionAvailable } from "../Commerce/commerceVariants.js";
|
|
2
|
-
/**
|
|
1
|
+
import { isOptionAvailable, variantExists } from "../Commerce/commerceVariants.js";
|
|
2
|
+
/** Sold out under every combination, so picking it can never lead to a purchasable variant. */
|
|
3
|
+
export const isSoldOutEverywhere = (variants, axisId, valueId) => !isOptionAvailable(variants, {}, axisId, valueId);
|
|
4
|
+
/** Picks a value, dropping other picks it cannot pair with; sold-out-everywhere values only need some variant. */
|
|
3
5
|
export const selectValue = (axes, variants, selection, axisId, valueId) => {
|
|
4
6
|
const next = { ...selection, [axisId]: valueId };
|
|
7
|
+
const pickedSoldOut = isSoldOutEverywhere(variants, axisId, valueId);
|
|
5
8
|
for (const axis of axes) {
|
|
6
9
|
const pick = next[axis.id];
|
|
7
10
|
if (axis.id === axisId || pick === undefined)
|
|
8
11
|
continue;
|
|
9
|
-
|
|
12
|
+
const anyVariant = pickedSoldOut || isSoldOutEverywhere(variants, axis.id, pick);
|
|
13
|
+
const pairs = anyVariant ? variantExists(variants, next) : isOptionAvailable(variants, next, axis.id, pick);
|
|
14
|
+
if (!pairs)
|
|
10
15
|
delete next[axis.id];
|
|
11
16
|
}
|
|
12
17
|
return next;
|
|
13
18
|
};
|
|
14
|
-
/** Sold out under every combination, so picking it can never lead to a purchasable variant. */
|
|
15
|
-
export const isSoldOutEverywhere = (variants, axisId, valueId) => !isOptionAvailable(variants, {}, axisId, valueId);
|
|
16
19
|
export const sameSelection = (a, b) => {
|
|
17
20
|
const keys = new Set([...Object.keys(a), ...Object.keys(b)]);
|
|
18
21
|
return [...keys].every((key) => a[key] === b[key]);
|
package/package.json
CHANGED