pixelize-design-library 3.3.2 → 3.3.4
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 +31 -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/DatePicker/CalendarPanel.js +12 -33
- package/dist/Components/DatePicker/RangeDatePicker.js +2 -2
- package/dist/Components/DatePicker/SingleDatePicker.js +37 -5
- package/dist/Components/ProductCard/QuickAddSheet.js +6 -2
- package/dist/Components/ProductCard/QuickAddSheetProps.d.ts +2 -0
- package/dist/Components/Select/SelectPopup.js +1 -1
- 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/Hooks/exclusiveOverlay.d.ts +4 -1
- package/dist/Hooks/exclusiveOverlay.js +14 -9
- package/dist/Hooks/useExclusiveOverlay.d.ts +2 -1
- package/dist/Hooks/useExclusiveOverlay.js +7 -4
- package/dist/Hooks/useOutsideMouseDown.js +16 -1
- package/dist/esm/Components/Commerce/commerceVariants.js +4 -0
- package/dist/esm/Components/DatePicker/CalendarPanel.js +12 -33
- package/dist/esm/Components/DatePicker/RangeDatePicker.js +2 -2
- package/dist/esm/Components/DatePicker/SingleDatePicker.js +37 -5
- package/dist/esm/Components/ProductCard/QuickAddSheet.js +7 -3
- package/dist/esm/Components/Select/SelectPopup.js +1 -1
- package/dist/esm/Components/VariantSelector/VariantSelector.js +3 -8
- package/dist/esm/Components/VariantSelector/variantSelection.js +8 -5
- package/dist/esm/Hooks/exclusiveOverlay.js +14 -9
- package/dist/esm/Hooks/useExclusiveOverlay.js +7 -4
- package/dist/esm/Hooks/useOutsideMouseDown.js +16 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,37 @@ 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.4] — 2026-11-16
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- **A sold-out size could not be picked, so its price never showed** (Magil Naturals: "not able to select another
|
|
17
|
+
size to view its price"). `VariantSelector` swallowed a click, arrow, Home or End on a value sold out under every
|
|
18
|
+
combination. It now selects it: the chip stays struck through and announced "unavailable", `onValueChange` fires
|
|
19
|
+
with that variant, and `ProductDetails` shows its price, mrp and stock text with Notify me in place of Add to
|
|
20
|
+
bag, Buy now and the stepper. Picks a sold-out value cannot pair with at all are still dropped; a sold-out
|
|
21
|
+
pick is no longer cleared by choosing another axis while some variant carries both.
|
|
22
|
+
- **`QuickAddSheet` confirm is disabled, reading "Sold out", while the chosen variant is sold out**, so the new
|
|
23
|
+
selectable behaviour cannot add it to the bag. New label `soldOut` (default "Sold out") on `QuickAddSheetLabels`.
|
|
24
|
+
A consumer that builds a complete `QuickAddSheetLabels` object, rather than `Partial`, must add it.
|
|
25
|
+
- **Docs:** `onValueChange`'s variant may be out of stock; use `stockState` before a custom add-to-bag
|
|
26
|
+
(`COMPONENT-GOTCHAS.md`).
|
|
27
|
+
|
|
28
|
+
## [3.3.3] — 2026-11-13
|
|
29
|
+
|
|
30
|
+
### Fixed
|
|
31
|
+
|
|
32
|
+
- **`DatePicker` dropped the first digit typed right after focusing an empty field** (`24` became `04`): the
|
|
33
|
+
deferred first-segment select reset the typing buffer. It now skips once a key has been typed.
|
|
34
|
+
- **`DatePicker` select-all + Delete/Backspace cleared only the last segment**, and cut or a programmatic fill
|
|
35
|
+
of `""` was ignored. Both now clear the whole field.
|
|
36
|
+
- **`DatePicker` calendar month and year pickers were browser-native `<select>`s.** They are now the library
|
|
37
|
+
`Select` (`native={false}`), so they match every other field. Tests that drove them with `selectOption` should
|
|
38
|
+
click the `Month` / `Year` combobox and then the option by name.
|
|
39
|
+
- **Opening a dropdown inside another popup closed the outer one.** The one-overlay-at-a-time rule now lets an
|
|
40
|
+
overlay opened from inside another (the month list inside the calendar) keep its parent open, and a picker's
|
|
41
|
+
outside-click check treats a popup its field owns (`aria-controls` / `aria-owns`) as inside.
|
|
42
|
+
|
|
12
43
|
## [3.3.2] — 2026-11-13
|
|
13
44
|
|
|
14
45
|
### 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));
|
|
@@ -9,11 +9,13 @@ const react_1 = require("@chakra-ui/react");
|
|
|
9
9
|
const date_fns_1 = require("date-fns");
|
|
10
10
|
const lucide_react_1 = require("lucide-react");
|
|
11
11
|
const Button_1 = __importDefault(require("../Button/Button"));
|
|
12
|
+
const Select_1 = __importDefault(require("../Select/Select"));
|
|
12
13
|
const useCustomTheme_1 = require("../../Theme/useCustomTheme");
|
|
13
14
|
const filledSurface_1 = require("../../Theme/tokens/builders/filledSurface");
|
|
14
|
-
const focusRing_styles_1 = require("../../Theme/chakra/focusRing.styles");
|
|
15
15
|
const dayStates_1 = require("./dayStates");
|
|
16
16
|
const motion_1 = require("../../Theme/tokens/primitives/motion");
|
|
17
|
+
const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({ id: i, label: (0, date_fns_1.format)(new Date(2000, i, 1), "MMMM") }));
|
|
18
|
+
const yearOptions = (thisYear) => Array.from({ length: 100 }, (_, i) => ({ id: thisYear - 50 + i, label: String(thisYear - 50 + i) }));
|
|
17
19
|
const BACKGROUND_COLOR_TRANSITION = (0, motion_1.transitionFor)(["background", "color"]);
|
|
18
20
|
/** Internal month grid shared by Single/RangeDatePicker; not published from index.ts, so only reachable via a deep import. */
|
|
19
21
|
const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate, tempRangeStart, tempRangeEnd, isSameDay, isBefore, isAfter, minDate, maxDate, disablePastDates, disableFutureDates, disableToday, onDaySelect, hoveredDate, onDayHover, renderWeekdays, dayStates, renderDayContent, }) => {
|
|
@@ -29,28 +31,6 @@ const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate
|
|
|
29
31
|
const rangeEnd = tempRangeEnd !== null && tempRangeEnd !== void 0 ? tempRangeEnd : tentativeEnd;
|
|
30
32
|
const isTentative = !tempRangeEnd && !!tentativeEnd;
|
|
31
33
|
const hasRange = !!(rangeStart && rangeEnd && !isSameDay(rangeStart, rangeEnd));
|
|
32
|
-
const selectStyles = {
|
|
33
|
-
border: "1px solid",
|
|
34
|
-
// boxborder[500] is the control-outline rung the sibling pickers already use; boxborder[200]
|
|
35
|
-
// is decorative and measured 1.85:1 on the dark canvas — the select read as borderless.
|
|
36
|
-
borderColor: theme.colors.boxborder[500],
|
|
37
|
-
borderRadius: "md",
|
|
38
|
-
px: 2,
|
|
39
|
-
py: 1,
|
|
40
|
-
fontSize: "xs",
|
|
41
|
-
fontWeight: 600,
|
|
42
|
-
color: theme.colors.text[700],
|
|
43
|
-
cursor: "pointer",
|
|
44
|
-
bg: theme.colors.background[50],
|
|
45
|
-
outline: "none",
|
|
46
|
-
_hover: { borderColor: theme.colors.primary[300] },
|
|
47
|
-
_focus: { borderColor: theme.colors.primary[500], ...(0, focusRing_styles_1.fieldFocusVisible)(theme.colors) },
|
|
48
|
-
style: {
|
|
49
|
-
WebkitAppearance: "menulist",
|
|
50
|
-
MozAppearance: "menulist",
|
|
51
|
-
appearance: "menulist",
|
|
52
|
-
},
|
|
53
|
-
};
|
|
54
34
|
const renderDays = () => {
|
|
55
35
|
var _a;
|
|
56
36
|
const monthStart = (0, date_fns_1.startOfMonth)(currentMonth);
|
|
@@ -139,16 +119,15 @@ const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate
|
|
|
139
119
|
}
|
|
140
120
|
return rows;
|
|
141
121
|
};
|
|
142
|
-
return ((0, jsx_runtime_1.jsxs)(react_1.Box, { children: [(0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [(0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronLeftIcon, { size: 16 }) }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [(0, jsx_runtime_1.jsx)(
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}) })] }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && ((0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", onClick: () => {
|
|
122
|
+
return ((0, jsx_runtime_1.jsxs)(react_1.Box, { children: [(0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [(0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: (0, jsx_runtime_1.jsx)(lucide_react_1.ChevronLeftIcon, { size: 16 }) }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [(0, jsx_runtime_1.jsx)(Select_1.default, { native: false, size: "xs", width: "7.5rem", "aria-label": "Month", options: MONTH_OPTIONS, value: currentMonth.getMonth(), onChange: (option) => {
|
|
123
|
+
if (option === undefined)
|
|
124
|
+
return;
|
|
125
|
+
setCurrentMonth((prev) => new Date(prev.getFullYear(), Number(option.id), 1));
|
|
126
|
+
} }), (0, jsx_runtime_1.jsx)(Select_1.default, { native: false, size: "xs", width: "5.5rem", "aria-label": "Year", options: yearOptions(new Date().getFullYear()), value: currentMonth.getFullYear(), onChange: (option) => {
|
|
127
|
+
if (option === undefined)
|
|
128
|
+
return;
|
|
129
|
+
setCurrentMonth((prev) => new Date(Number(option.id), prev.getMonth(), 1));
|
|
130
|
+
} })] }), (0, jsx_runtime_1.jsxs)(react_1.Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && ((0, jsx_runtime_1.jsx)(Button_1.default, { variant: "ghost", size: "xs", onClick: () => {
|
|
152
131
|
setCurrentMonth(() => new Date(today.getFullYear(), today.getMonth(), 1));
|
|
153
132
|
if (!disableToday) {
|
|
154
133
|
onDaySelect(new Date(today));
|
|
@@ -73,13 +73,13 @@ exports.RangeDatePicker = (0, react_1.forwardRef)(function RangeDatePicker(props
|
|
|
73
73
|
const calendarIconPx = (0, textInputIconSize_1.getTextInputIconSizePx)(sizeKey);
|
|
74
74
|
const calendarIconWrapperSx = (0, textInputIconSize_1.getTextInputIconWrapperSx)(sizeKey);
|
|
75
75
|
const { isOpen, onOpen, onClose } = (0, react_2.useDisclosure)();
|
|
76
|
-
const
|
|
76
|
+
const popoverRef = (0, react_1.useRef)(null);
|
|
77
|
+
const requestExclusiveOpen = (0, useExclusiveOverlay_1.useExclusiveOverlay)(isOpen, onClose, popoverRef);
|
|
77
78
|
const pickerPortal = (0, PickerPortal_1.usePickerPortal)(isOpen);
|
|
78
79
|
const calendarLabel = label !== null && label !== void 0 ? label : "Choose date range";
|
|
79
80
|
const inputRef = (0, react_1.useRef)(null);
|
|
80
81
|
const mergedInputRef = (0, react_2.useMergeRefs)(inputRef, ref);
|
|
81
82
|
const triggerRef = (0, react_1.useRef)(null);
|
|
82
|
-
const popoverRef = (0, react_1.useRef)(null);
|
|
83
83
|
const today = new Date();
|
|
84
84
|
const placeholder = (0, react_1.useMemo)(() => placeholderText || `${dateFormat} - ${dateFormat}`, [placeholderText, dateFormat]);
|
|
85
85
|
const selectedRange = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.selectedDate) !== null && _b !== void 0 ? _b : null;
|
|
@@ -232,12 +232,12 @@ function SingleDatePickerInner(props, ref) {
|
|
|
232
232
|
const calendarIconPx = (0, textInputIconSize_1.getTextInputIconSizePx)(sizeKey);
|
|
233
233
|
const calendarIconWrapperSx = (0, textInputIconSize_1.getTextInputIconWrapperSx)(sizeKey);
|
|
234
234
|
const { isOpen, onOpen, onClose } = (0, react_2.useDisclosure)();
|
|
235
|
-
const
|
|
235
|
+
const popoverRef = (0, react_1.useRef)(null);
|
|
236
|
+
const requestExclusiveOpen = (0, useExclusiveOverlay_1.useExclusiveOverlay)(isOpen, onClose, popoverRef);
|
|
236
237
|
const pickerPortal = (0, PickerPortal_1.usePickerPortal)(isOpen);
|
|
237
238
|
const calendarLabel = label !== null && label !== void 0 ? label : "Choose date";
|
|
238
239
|
const inputRef = (0, react_1.useRef)(null);
|
|
239
240
|
const mergedInputRef = (0, react_2.useMergeRefs)(inputRef, ref);
|
|
240
|
-
const popoverRef = (0, react_1.useRef)(null);
|
|
241
241
|
const triggerRef = (0, react_1.useRef)(null);
|
|
242
242
|
const resolvedPickerType = pickerType !== null && pickerType !== void 0 ? pickerType : (0, pickerField_1.inferPickerTypeFromFormat)(dateFormat);
|
|
243
243
|
const resolvedDateFormat = getFormatForPickerType(pickerType, dateFormat);
|
|
@@ -285,6 +285,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
285
285
|
const pendingSegmentNavigationRef = (0, react_1.useRef)(null);
|
|
286
286
|
const restoreSelectionRef = (0, react_1.useRef)(null);
|
|
287
287
|
const segmentInputBufferRef = (0, react_1.useRef)("");
|
|
288
|
+
const keystrokeSeqRef = (0, react_1.useRef)(0);
|
|
288
289
|
const maskInsertedRef = (0, react_1.useRef)(false);
|
|
289
290
|
const today = new Date();
|
|
290
291
|
const tomorrow = (0, date_fns_1.addDays)(today, 1);
|
|
@@ -417,6 +418,8 @@ function SingleDatePickerInner(props, ref) {
|
|
|
417
418
|
};
|
|
418
419
|
const handleInputChange = (e) => {
|
|
419
420
|
if (enableMask && isMaskActive) {
|
|
421
|
+
if (e.target.value === "")
|
|
422
|
+
clearAllSegments();
|
|
420
423
|
return;
|
|
421
424
|
}
|
|
422
425
|
let value = e.target.value;
|
|
@@ -583,6 +586,29 @@ function SingleDatePickerInner(props, ref) {
|
|
|
583
586
|
const clamped = Math.max(0, Math.min(tokenSegments.length - 1, nextIndex));
|
|
584
587
|
selectSegment(clamped);
|
|
585
588
|
}, [enableMask, selectSegment, tokenSegments.length]);
|
|
589
|
+
const deferSelectSegment = (index) => {
|
|
590
|
+
const seq = keystrokeSeqRef.current;
|
|
591
|
+
requestAnimationFrame(() => {
|
|
592
|
+
if (keystrokeSeqRef.current === seq)
|
|
593
|
+
selectSegment(index);
|
|
594
|
+
});
|
|
595
|
+
};
|
|
596
|
+
const clearAllSegments = () => {
|
|
597
|
+
keystrokeSeqRef.current += 1;
|
|
598
|
+
segmentInputBufferRef.current = "";
|
|
599
|
+
maskInsertedRef.current = true;
|
|
600
|
+
setInputValue(maskPlaceholder);
|
|
601
|
+
setTempDate(null);
|
|
602
|
+
setIsTyping(true);
|
|
603
|
+
const inputEl = inputRef.current;
|
|
604
|
+
if (inputEl && tokenSegments.length > 0) {
|
|
605
|
+
inputEl.value = maskPlaceholder;
|
|
606
|
+
lastSegmentIndexRef.current = 0;
|
|
607
|
+
setCurrentSegmentIndex(0);
|
|
608
|
+
restoreSelectionRef.current = { start: tokenSegments[0].start, end: tokenSegments[0].end };
|
|
609
|
+
inputEl.setSelectionRange(tokenSegments[0].start, tokenSegments[0].end);
|
|
610
|
+
}
|
|
611
|
+
};
|
|
586
612
|
const getTokenIndexForCaret = (caret, tokens) => {
|
|
587
613
|
if (tokens.length === 0)
|
|
588
614
|
return 0;
|
|
@@ -688,7 +714,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
688
714
|
maskInsertedRef.current = false;
|
|
689
715
|
}
|
|
690
716
|
segmentInputBufferRef.current = "";
|
|
691
|
-
|
|
717
|
+
deferSelectSegment(0);
|
|
692
718
|
};
|
|
693
719
|
const handleInputClick = (e) => {
|
|
694
720
|
var _a;
|
|
@@ -706,7 +732,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
706
732
|
? 0
|
|
707
733
|
: tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
|
|
708
734
|
if (index >= 0) {
|
|
709
|
-
|
|
735
|
+
deferSelectSegment(index);
|
|
710
736
|
}
|
|
711
737
|
};
|
|
712
738
|
const handleKeyDown = (e) => {
|
|
@@ -799,6 +825,11 @@ function SingleDatePickerInner(props, ref) {
|
|
|
799
825
|
}
|
|
800
826
|
if (key === "Backspace" || key === "Delete") {
|
|
801
827
|
e.preventDefault();
|
|
828
|
+
if (inputEl && selStart === 0 && selEnd > 0 && selEnd >= inputEl.value.length) {
|
|
829
|
+
clearAllSegments();
|
|
830
|
+
return;
|
|
831
|
+
}
|
|
832
|
+
keystrokeSeqRef.current += 1;
|
|
802
833
|
const baseValue = ensureMaskValue();
|
|
803
834
|
const newValue = baseValue.slice(0, segment.start) + segment.placeholder + baseValue.slice(segment.end);
|
|
804
835
|
setInputValue(newValue);
|
|
@@ -806,7 +837,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
806
837
|
maskInsertedRef.current = false;
|
|
807
838
|
segmentInputBufferRef.current = "";
|
|
808
839
|
updateTempDateFromMask(newValue);
|
|
809
|
-
|
|
840
|
+
deferSelectSegment(activeIdx);
|
|
810
841
|
return;
|
|
811
842
|
}
|
|
812
843
|
if (e.ctrlKey || e.metaKey) {
|
|
@@ -818,6 +849,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
818
849
|
const isDigit = /^[0-9]$/.test(key);
|
|
819
850
|
if (isDigit || separatorKeys.includes(key)) {
|
|
820
851
|
e.preventDefault();
|
|
852
|
+
keystrokeSeqRef.current += 1;
|
|
821
853
|
const baseValue = ensureMaskValue();
|
|
822
854
|
const buffered = segmentInputBufferRef.current !== "";
|
|
823
855
|
const typingIdx = buffered ? lastSegmentIndexRef.current : isMaskEmpty(baseValue) ? 0 : activeIdx;
|
|
@@ -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";
|
|
@@ -183,7 +183,7 @@ const SelectPopup = (0, react_1.forwardRef)(function SelectPopup(props, ref) {
|
|
|
183
183
|
const handleOpen = () => {
|
|
184
184
|
if (!isInteractive)
|
|
185
185
|
return;
|
|
186
|
-
requestExclusiveOpen();
|
|
186
|
+
requestExclusiveOpen(triggerRef.current);
|
|
187
187
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
188
188
|
onOpen();
|
|
189
189
|
const firstSelected = props.isMulti
|
|
@@ -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]);
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
export declare const exclusiveOpen: (id: string, close: () => void
|
|
1
|
+
export declare const exclusiveOpen: (id: string, close: () => void, options?: {
|
|
2
|
+
anchor?: Node | null;
|
|
3
|
+
contains?: (node: Node) => boolean;
|
|
4
|
+
}) => void;
|
|
2
5
|
export declare const exclusiveClose: (id: string) => void;
|
|
3
6
|
/** Test-only reset — not exported from the package root. */
|
|
4
7
|
export declare const resetExclusiveOverlay: () => void;
|
|
@@ -1,22 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resetExclusiveOverlay = exports.exclusiveClose = exports.exclusiveOpen = void 0;
|
|
4
|
-
let
|
|
5
|
-
const exclusiveOpen = (id, close) => {
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
let stack = [];
|
|
5
|
+
const exclusiveOpen = (id, close, options = {}) => {
|
|
6
|
+
var _a;
|
|
7
|
+
stack = stack.filter((entry) => entry.id !== id);
|
|
8
|
+
const { anchor } = options;
|
|
9
|
+
while (stack.length > 0) {
|
|
10
|
+
const top = stack[stack.length - 1];
|
|
11
|
+
if (anchor && ((_a = top.contains) === null || _a === void 0 ? void 0 : _a.call(top, anchor)))
|
|
12
|
+
break;
|
|
13
|
+
stack.pop();
|
|
14
|
+
top.close();
|
|
8
15
|
}
|
|
9
|
-
|
|
16
|
+
stack.push({ id, close, contains: options.contains });
|
|
10
17
|
};
|
|
11
18
|
exports.exclusiveOpen = exclusiveOpen;
|
|
12
19
|
const exclusiveClose = (id) => {
|
|
13
|
-
|
|
14
|
-
active = null;
|
|
15
|
-
}
|
|
20
|
+
stack = stack.filter((entry) => entry.id !== id);
|
|
16
21
|
};
|
|
17
22
|
exports.exclusiveClose = exclusiveClose;
|
|
18
23
|
/** Test-only reset — not exported from the package root. */
|
|
19
24
|
const resetExclusiveOverlay = () => {
|
|
20
|
-
|
|
25
|
+
stack = [];
|
|
21
26
|
};
|
|
22
27
|
exports.resetExclusiveOverlay = resetExclusiveOverlay;
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
export declare const useExclusiveOverlay: (isOpen: boolean, onClose: () => void, contentRef?: RefObject<Element | null>) => (anchor?: Node | null) => void;
|
|
@@ -4,13 +4,16 @@ exports.useExclusiveOverlay = void 0;
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const exclusiveOverlay_1 = require("./exclusiveOverlay");
|
|
6
6
|
// NOTE: registers with the global dismiss coordinator — call requestOpen() before opening.
|
|
7
|
-
const useExclusiveOverlay = (isOpen, onClose) => {
|
|
7
|
+
const useExclusiveOverlay = (isOpen, onClose, contentRef) => {
|
|
8
8
|
const id = (0, react_1.useId)();
|
|
9
9
|
const onCloseRef = (0, react_1.useRef)(onClose);
|
|
10
10
|
onCloseRef.current = onClose;
|
|
11
|
-
const requestOpen = (0, react_1.useCallback)(() => {
|
|
12
|
-
(0, exclusiveOverlay_1.exclusiveOpen)(id, () => onCloseRef.current()
|
|
13
|
-
|
|
11
|
+
const requestOpen = (0, react_1.useCallback)((anchor) => {
|
|
12
|
+
(0, exclusiveOverlay_1.exclusiveOpen)(id, () => onCloseRef.current(), {
|
|
13
|
+
anchor,
|
|
14
|
+
contains: contentRef ? (node) => { var _a; return Boolean((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(node)); } : undefined,
|
|
15
|
+
});
|
|
16
|
+
}, [id, contentRef]);
|
|
14
17
|
(0, react_1.useEffect)(() => {
|
|
15
18
|
if (!isOpen) {
|
|
16
19
|
(0, exclusiveOverlay_1.exclusiveClose)(id);
|
|
@@ -2,6 +2,19 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.useOutsideMouseDown = void 0;
|
|
4
4
|
const react_1 = require("react");
|
|
5
|
+
const ownedIds = (root) => Array.from(root.querySelectorAll("[aria-controls], [aria-owns]")).flatMap((el) => { var _a, _b; return `${(_a = el.getAttribute("aria-controls")) !== null && _a !== void 0 ? _a : ""} ${(_b = el.getAttribute("aria-owns")) !== null && _b !== void 0 ? _b : ""}`.split(/\s+/).filter(Boolean); });
|
|
6
|
+
const ownsTarget = (root, target) => {
|
|
7
|
+
if (!root)
|
|
8
|
+
return false;
|
|
9
|
+
const ids = ownedIds(root);
|
|
10
|
+
if (ids.length === 0)
|
|
11
|
+
return false;
|
|
12
|
+
for (let node = target instanceof Element ? target : target.parentElement; node; node = node.parentElement) {
|
|
13
|
+
if (node.id && ids.includes(node.id))
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
return false;
|
|
17
|
+
};
|
|
5
18
|
/** Calls `onOutside` for a document `mousedown` outside every ref; a null ref contains nothing. Unlike Chakra's `useOutsideClick` it never waits for `mouseup`. */
|
|
6
19
|
const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture = false, includeClick = false } = {}) => {
|
|
7
20
|
const latest = (0, react_1.useRef)({ refs, onOutside });
|
|
@@ -13,7 +26,9 @@ const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture = false,
|
|
|
13
26
|
return;
|
|
14
27
|
const handle = (event) => {
|
|
15
28
|
const target = event.target;
|
|
16
|
-
if (
|
|
29
|
+
if (!target.isConnected)
|
|
30
|
+
return;
|
|
31
|
+
if (latest.current.refs.some((ref) => { var _a; return ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target)) || ownsTarget(ref.current, target); }))
|
|
17
32
|
return;
|
|
18
33
|
latest.current.onOutside(event);
|
|
19
34
|
};
|
|
@@ -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));
|
|
@@ -3,11 +3,13 @@ import { Box } from "@chakra-ui/react";
|
|
|
3
3
|
import { format, startOfMonth, endOfMonth, startOfWeek, endOfWeek, addDays } from "date-fns";
|
|
4
4
|
import { ChevronLeftIcon, ChevronRightIcon } from "lucide-react";
|
|
5
5
|
import Button from "../Button/Button.js";
|
|
6
|
+
import Select from "../Select/Select.js";
|
|
6
7
|
import { useCustomTheme } from "../../Theme/useCustomTheme.js";
|
|
7
8
|
import { resolveFilledSurface } from "../../Theme/tokens/builders/filledSurface.js";
|
|
8
|
-
import { fieldFocusVisible } from "../../Theme/chakra/focusRing.styles.js";
|
|
9
9
|
import { DAY_CLASS, dayAccessibleName, dayStateClassName, resolveDayStateVisual, } from "./dayStates.js";
|
|
10
10
|
import { transitionFor } from "../../Theme/tokens/primitives/motion.js";
|
|
11
|
+
const MONTH_OPTIONS = Array.from({ length: 12 }, (_, i) => ({ id: i, label: format(new Date(2000, i, 1), "MMMM") }));
|
|
12
|
+
const yearOptions = (thisYear) => Array.from({ length: 100 }, (_, i) => ({ id: thisYear - 50 + i, label: String(thisYear - 50 + i) }));
|
|
11
13
|
const BACKGROUND_COLOR_TRANSITION = transitionFor(["background", "color"]);
|
|
12
14
|
/** Internal month grid shared by Single/RangeDatePicker; not published from index.ts, so only reachable via a deep import. */
|
|
13
15
|
export const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, tempDate, tempRangeStart, tempRangeEnd, isSameDay, isBefore, isAfter, minDate, maxDate, disablePastDates, disableFutureDates, disableToday, onDaySelect, hoveredDate, onDayHover, renderWeekdays, dayStates, renderDayContent, }) => {
|
|
@@ -23,28 +25,6 @@ export const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, t
|
|
|
23
25
|
const rangeEnd = tempRangeEnd !== null && tempRangeEnd !== void 0 ? tempRangeEnd : tentativeEnd;
|
|
24
26
|
const isTentative = !tempRangeEnd && !!tentativeEnd;
|
|
25
27
|
const hasRange = !!(rangeStart && rangeEnd && !isSameDay(rangeStart, rangeEnd));
|
|
26
|
-
const selectStyles = {
|
|
27
|
-
border: "1px solid",
|
|
28
|
-
// boxborder[500] is the control-outline rung the sibling pickers already use; boxborder[200]
|
|
29
|
-
// is decorative and measured 1.85:1 on the dark canvas — the select read as borderless.
|
|
30
|
-
borderColor: theme.colors.boxborder[500],
|
|
31
|
-
borderRadius: "md",
|
|
32
|
-
px: 2,
|
|
33
|
-
py: 1,
|
|
34
|
-
fontSize: "xs",
|
|
35
|
-
fontWeight: 600,
|
|
36
|
-
color: theme.colors.text[700],
|
|
37
|
-
cursor: "pointer",
|
|
38
|
-
bg: theme.colors.background[50],
|
|
39
|
-
outline: "none",
|
|
40
|
-
_hover: { borderColor: theme.colors.primary[300] },
|
|
41
|
-
_focus: { borderColor: theme.colors.primary[500], ...fieldFocusVisible(theme.colors) },
|
|
42
|
-
style: {
|
|
43
|
-
WebkitAppearance: "menulist",
|
|
44
|
-
MozAppearance: "menulist",
|
|
45
|
-
appearance: "menulist",
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
28
|
const renderDays = () => {
|
|
49
29
|
var _a;
|
|
50
30
|
const monthStart = startOfMonth(currentMonth);
|
|
@@ -133,16 +113,15 @@ export const CalendarPanel = ({ currentMonth, setCurrentMonth, today, isRange, t
|
|
|
133
113
|
}
|
|
134
114
|
return rows;
|
|
135
115
|
};
|
|
136
|
-
return (_jsxs(Box, { children: [_jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [_jsx(Button, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: _jsx(ChevronLeftIcon, { size: 16 }) }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [_jsx(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
}) })] }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && (_jsx(Button, { variant: "ghost", size: "xs", onClick: () => {
|
|
116
|
+
return (_jsxs(Box, { children: [_jsxs(Box, { display: "flex", alignItems: "center", justifyContent: "space-between", mb: 2, gap: 1, children: [_jsx(Button, { variant: "ghost", size: "xs", sx: { flexShrink: 0 }, onClick: () => setCurrentMonth((prev) => new Date(prev.getFullYear(), prev.getMonth() - 1, 1)), "aria-label": "Previous month", children: _jsx(ChevronLeftIcon, { size: 16 }) }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1.5, minW: 0, children: [_jsx(Select, { native: false, size: "xs", width: "7.5rem", "aria-label": "Month", options: MONTH_OPTIONS, value: currentMonth.getMonth(), onChange: (option) => {
|
|
117
|
+
if (option === undefined)
|
|
118
|
+
return;
|
|
119
|
+
setCurrentMonth((prev) => new Date(prev.getFullYear(), Number(option.id), 1));
|
|
120
|
+
} }), _jsx(Select, { native: false, size: "xs", width: "5.5rem", "aria-label": "Year", options: yearOptions(new Date().getFullYear()), value: currentMonth.getFullYear(), onChange: (option) => {
|
|
121
|
+
if (option === undefined)
|
|
122
|
+
return;
|
|
123
|
+
setCurrentMonth((prev) => new Date(Number(option.id), prev.getMonth(), 1));
|
|
124
|
+
} })] }), _jsxs(Box, { display: "flex", alignItems: "center", gap: 1, flexShrink: 0, children: [!isRange && !isViewingCurrentMonth && (_jsx(Button, { variant: "ghost", size: "xs", onClick: () => {
|
|
146
125
|
setCurrentMonth(() => new Date(today.getFullYear(), today.getMonth(), 1));
|
|
147
126
|
if (!disableToday) {
|
|
148
127
|
onDaySelect(new Date(today));
|
|
@@ -34,13 +34,13 @@ export const RangeDatePicker = forwardRef(function RangeDatePicker(props, ref) {
|
|
|
34
34
|
const calendarIconPx = getTextInputIconSizePx(sizeKey);
|
|
35
35
|
const calendarIconWrapperSx = getTextInputIconWrapperSx(sizeKey);
|
|
36
36
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
37
|
-
const
|
|
37
|
+
const popoverRef = useRef(null);
|
|
38
|
+
const requestExclusiveOpen = useExclusiveOverlay(isOpen, onClose, popoverRef);
|
|
38
39
|
const pickerPortal = usePickerPortal(isOpen);
|
|
39
40
|
const calendarLabel = label !== null && label !== void 0 ? label : "Choose date range";
|
|
40
41
|
const inputRef = useRef(null);
|
|
41
42
|
const mergedInputRef = useMergeRefs(inputRef, ref);
|
|
42
43
|
const triggerRef = useRef(null);
|
|
43
|
-
const popoverRef = useRef(null);
|
|
44
44
|
const today = new Date();
|
|
45
45
|
const placeholder = useMemo(() => placeholderText || `${dateFormat} - ${dateFormat}`, [placeholderText, dateFormat]);
|
|
46
46
|
const selectedRange = (_b = (_a = props.value) !== null && _a !== void 0 ? _a : props.selectedDate) !== null && _b !== void 0 ? _b : null;
|
|
@@ -193,12 +193,12 @@ function SingleDatePickerInner(props, ref) {
|
|
|
193
193
|
const calendarIconPx = getTextInputIconSizePx(sizeKey);
|
|
194
194
|
const calendarIconWrapperSx = getTextInputIconWrapperSx(sizeKey);
|
|
195
195
|
const { isOpen, onOpen, onClose } = useDisclosure();
|
|
196
|
-
const
|
|
196
|
+
const popoverRef = useRef(null);
|
|
197
|
+
const requestExclusiveOpen = useExclusiveOverlay(isOpen, onClose, popoverRef);
|
|
197
198
|
const pickerPortal = usePickerPortal(isOpen);
|
|
198
199
|
const calendarLabel = label !== null && label !== void 0 ? label : "Choose date";
|
|
199
200
|
const inputRef = useRef(null);
|
|
200
201
|
const mergedInputRef = useMergeRefs(inputRef, ref);
|
|
201
|
-
const popoverRef = useRef(null);
|
|
202
202
|
const triggerRef = useRef(null);
|
|
203
203
|
const resolvedPickerType = pickerType !== null && pickerType !== void 0 ? pickerType : inferPickerTypeFromFormat(dateFormat);
|
|
204
204
|
const resolvedDateFormat = getFormatForPickerType(pickerType, dateFormat);
|
|
@@ -246,6 +246,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
246
246
|
const pendingSegmentNavigationRef = useRef(null);
|
|
247
247
|
const restoreSelectionRef = useRef(null);
|
|
248
248
|
const segmentInputBufferRef = useRef("");
|
|
249
|
+
const keystrokeSeqRef = useRef(0);
|
|
249
250
|
const maskInsertedRef = useRef(false);
|
|
250
251
|
const today = new Date();
|
|
251
252
|
const tomorrow = addDays(today, 1);
|
|
@@ -378,6 +379,8 @@ function SingleDatePickerInner(props, ref) {
|
|
|
378
379
|
};
|
|
379
380
|
const handleInputChange = (e) => {
|
|
380
381
|
if (enableMask && isMaskActive) {
|
|
382
|
+
if (e.target.value === "")
|
|
383
|
+
clearAllSegments();
|
|
381
384
|
return;
|
|
382
385
|
}
|
|
383
386
|
let value = e.target.value;
|
|
@@ -544,6 +547,29 @@ function SingleDatePickerInner(props, ref) {
|
|
|
544
547
|
const clamped = Math.max(0, Math.min(tokenSegments.length - 1, nextIndex));
|
|
545
548
|
selectSegment(clamped);
|
|
546
549
|
}, [enableMask, selectSegment, tokenSegments.length]);
|
|
550
|
+
const deferSelectSegment = (index) => {
|
|
551
|
+
const seq = keystrokeSeqRef.current;
|
|
552
|
+
requestAnimationFrame(() => {
|
|
553
|
+
if (keystrokeSeqRef.current === seq)
|
|
554
|
+
selectSegment(index);
|
|
555
|
+
});
|
|
556
|
+
};
|
|
557
|
+
const clearAllSegments = () => {
|
|
558
|
+
keystrokeSeqRef.current += 1;
|
|
559
|
+
segmentInputBufferRef.current = "";
|
|
560
|
+
maskInsertedRef.current = true;
|
|
561
|
+
setInputValue(maskPlaceholder);
|
|
562
|
+
setTempDate(null);
|
|
563
|
+
setIsTyping(true);
|
|
564
|
+
const inputEl = inputRef.current;
|
|
565
|
+
if (inputEl && tokenSegments.length > 0) {
|
|
566
|
+
inputEl.value = maskPlaceholder;
|
|
567
|
+
lastSegmentIndexRef.current = 0;
|
|
568
|
+
setCurrentSegmentIndex(0);
|
|
569
|
+
restoreSelectionRef.current = { start: tokenSegments[0].start, end: tokenSegments[0].end };
|
|
570
|
+
inputEl.setSelectionRange(tokenSegments[0].start, tokenSegments[0].end);
|
|
571
|
+
}
|
|
572
|
+
};
|
|
547
573
|
const getTokenIndexForCaret = (caret, tokens) => {
|
|
548
574
|
if (tokens.length === 0)
|
|
549
575
|
return 0;
|
|
@@ -649,7 +675,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
649
675
|
maskInsertedRef.current = false;
|
|
650
676
|
}
|
|
651
677
|
segmentInputBufferRef.current = "";
|
|
652
|
-
|
|
678
|
+
deferSelectSegment(0);
|
|
653
679
|
};
|
|
654
680
|
const handleInputClick = (e) => {
|
|
655
681
|
var _a;
|
|
@@ -667,7 +693,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
667
693
|
? 0
|
|
668
694
|
: tokenSegments.findIndex((segment) => caret >= segment.start && caret <= segment.end);
|
|
669
695
|
if (index >= 0) {
|
|
670
|
-
|
|
696
|
+
deferSelectSegment(index);
|
|
671
697
|
}
|
|
672
698
|
};
|
|
673
699
|
const handleKeyDown = (e) => {
|
|
@@ -760,6 +786,11 @@ function SingleDatePickerInner(props, ref) {
|
|
|
760
786
|
}
|
|
761
787
|
if (key === "Backspace" || key === "Delete") {
|
|
762
788
|
e.preventDefault();
|
|
789
|
+
if (inputEl && selStart === 0 && selEnd > 0 && selEnd >= inputEl.value.length) {
|
|
790
|
+
clearAllSegments();
|
|
791
|
+
return;
|
|
792
|
+
}
|
|
793
|
+
keystrokeSeqRef.current += 1;
|
|
763
794
|
const baseValue = ensureMaskValue();
|
|
764
795
|
const newValue = baseValue.slice(0, segment.start) + segment.placeholder + baseValue.slice(segment.end);
|
|
765
796
|
setInputValue(newValue);
|
|
@@ -767,7 +798,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
767
798
|
maskInsertedRef.current = false;
|
|
768
799
|
segmentInputBufferRef.current = "";
|
|
769
800
|
updateTempDateFromMask(newValue);
|
|
770
|
-
|
|
801
|
+
deferSelectSegment(activeIdx);
|
|
771
802
|
return;
|
|
772
803
|
}
|
|
773
804
|
if (e.ctrlKey || e.metaKey) {
|
|
@@ -779,6 +810,7 @@ function SingleDatePickerInner(props, ref) {
|
|
|
779
810
|
const isDigit = /^[0-9]$/.test(key);
|
|
780
811
|
if (isDigit || separatorKeys.includes(key)) {
|
|
781
812
|
e.preventDefault();
|
|
813
|
+
keystrokeSeqRef.current += 1;
|
|
782
814
|
const baseValue = ensureMaskValue();
|
|
783
815
|
const buffered = segmentInputBufferRef.current !== "";
|
|
784
816
|
const typingIdx = buffered ? lastSegmentIndexRef.current : isMaskEmpty(baseValue) ? 0 : activeIdx;
|
|
@@ -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 })] }));
|
|
@@ -145,7 +145,7 @@ const SelectPopup = forwardRef(function SelectPopup(props, ref) {
|
|
|
145
145
|
const handleOpen = () => {
|
|
146
146
|
if (!isInteractive)
|
|
147
147
|
return;
|
|
148
|
-
requestExclusiveOpen();
|
|
148
|
+
requestExclusiveOpen(triggerRef.current);
|
|
149
149
|
onFocus === null || onFocus === void 0 ? void 0 : onFocus();
|
|
150
150
|
onOpen();
|
|
151
151
|
const firstSelected = props.isMulti
|
|
@@ -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]);
|
|
@@ -1,16 +1,21 @@
|
|
|
1
|
-
let
|
|
2
|
-
export const exclusiveOpen = (id, close) => {
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
let stack = [];
|
|
2
|
+
export const exclusiveOpen = (id, close, options = {}) => {
|
|
3
|
+
var _a;
|
|
4
|
+
stack = stack.filter((entry) => entry.id !== id);
|
|
5
|
+
const { anchor } = options;
|
|
6
|
+
while (stack.length > 0) {
|
|
7
|
+
const top = stack[stack.length - 1];
|
|
8
|
+
if (anchor && ((_a = top.contains) === null || _a === void 0 ? void 0 : _a.call(top, anchor)))
|
|
9
|
+
break;
|
|
10
|
+
stack.pop();
|
|
11
|
+
top.close();
|
|
5
12
|
}
|
|
6
|
-
|
|
13
|
+
stack.push({ id, close, contains: options.contains });
|
|
7
14
|
};
|
|
8
15
|
export const exclusiveClose = (id) => {
|
|
9
|
-
|
|
10
|
-
active = null;
|
|
11
|
-
}
|
|
16
|
+
stack = stack.filter((entry) => entry.id !== id);
|
|
12
17
|
};
|
|
13
18
|
/** Test-only reset — not exported from the package root. */
|
|
14
19
|
export const resetExclusiveOverlay = () => {
|
|
15
|
-
|
|
20
|
+
stack = [];
|
|
16
21
|
};
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import { useCallback, useEffect, useId, useRef } from "react";
|
|
2
2
|
import { exclusiveClose, exclusiveOpen } from "./exclusiveOverlay.js";
|
|
3
3
|
// NOTE: registers with the global dismiss coordinator — call requestOpen() before opening.
|
|
4
|
-
export const useExclusiveOverlay = (isOpen, onClose) => {
|
|
4
|
+
export const useExclusiveOverlay = (isOpen, onClose, contentRef) => {
|
|
5
5
|
const id = useId();
|
|
6
6
|
const onCloseRef = useRef(onClose);
|
|
7
7
|
onCloseRef.current = onClose;
|
|
8
|
-
const requestOpen = useCallback(() => {
|
|
9
|
-
exclusiveOpen(id, () => onCloseRef.current()
|
|
10
|
-
|
|
8
|
+
const requestOpen = useCallback((anchor) => {
|
|
9
|
+
exclusiveOpen(id, () => onCloseRef.current(), {
|
|
10
|
+
anchor,
|
|
11
|
+
contains: contentRef ? (node) => { var _a; return Boolean((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.contains(node)); } : undefined,
|
|
12
|
+
});
|
|
13
|
+
}, [id, contentRef]);
|
|
11
14
|
useEffect(() => {
|
|
12
15
|
if (!isOpen) {
|
|
13
16
|
exclusiveClose(id);
|
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
import { useEffect, useRef } from "react";
|
|
2
|
+
const ownedIds = (root) => Array.from(root.querySelectorAll("[aria-controls], [aria-owns]")).flatMap((el) => { var _a, _b; return `${(_a = el.getAttribute("aria-controls")) !== null && _a !== void 0 ? _a : ""} ${(_b = el.getAttribute("aria-owns")) !== null && _b !== void 0 ? _b : ""}`.split(/\s+/).filter(Boolean); });
|
|
3
|
+
const ownsTarget = (root, target) => {
|
|
4
|
+
if (!root)
|
|
5
|
+
return false;
|
|
6
|
+
const ids = ownedIds(root);
|
|
7
|
+
if (ids.length === 0)
|
|
8
|
+
return false;
|
|
9
|
+
for (let node = target instanceof Element ? target : target.parentElement; node; node = node.parentElement) {
|
|
10
|
+
if (node.id && ids.includes(node.id))
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
return false;
|
|
14
|
+
};
|
|
2
15
|
/** Calls `onOutside` for a document `mousedown` outside every ref; a null ref contains nothing. Unlike Chakra's `useOutsideClick` it never waits for `mouseup`. */
|
|
3
16
|
export const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture = false, includeClick = false } = {}) => {
|
|
4
17
|
const latest = useRef({ refs, onOutside });
|
|
@@ -10,7 +23,9 @@ export const useOutsideMouseDown = (refs, onOutside, { enabled = true, capture =
|
|
|
10
23
|
return;
|
|
11
24
|
const handle = (event) => {
|
|
12
25
|
const target = event.target;
|
|
13
|
-
if (
|
|
26
|
+
if (!target.isConnected)
|
|
27
|
+
return;
|
|
28
|
+
if (latest.current.refs.some((ref) => { var _a; return ((_a = ref.current) === null || _a === void 0 ? void 0 : _a.contains(target)) || ownsTarget(ref.current, target); }))
|
|
14
29
|
return;
|
|
15
30
|
latest.current.onOutside(event);
|
|
16
31
|
};
|
package/package.json
CHANGED