@wix/headless-restaurants-olo 0.0.15 → 0.0.17
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/cjs/dist/react/ItemDetails.d.ts +4 -131
- package/cjs/dist/react/ItemDetails.js +4 -55
- package/cjs/dist/react/ModifierGroup.d.ts +57 -0
- package/cjs/dist/react/ModifierGroup.js +61 -0
- package/cjs/dist/react/core/ItemDetails.d.ts +1 -11
- package/cjs/dist/react/core/ItemDetails.js +1 -20
- package/cjs/dist/react/core/ModifierGroup.d.ts +42 -0
- package/cjs/dist/react/core/ModifierGroup.js +67 -0
- package/cjs/dist/react/index.d.ts +1 -0
- package/cjs/dist/react/index.js +1 -0
- package/cjs/dist/services/common-types.d.ts +18 -0
- package/cjs/dist/services/common-types.js +10 -0
- package/cjs/dist/services/item-details-service.d.ts +2 -0
- package/cjs/dist/services/item-details-service.js +8 -1
- package/cjs/dist/services/utils.d.ts +17 -0
- package/cjs/dist/services/utils.js +104 -0
- package/dist/react/ItemDetails.d.ts +4 -131
- package/dist/react/ItemDetails.js +4 -55
- package/dist/react/ModifierGroup.d.ts +57 -0
- package/dist/react/ModifierGroup.js +61 -0
- package/dist/react/core/ItemDetails.d.ts +1 -11
- package/dist/react/core/ItemDetails.js +1 -20
- package/dist/react/core/ModifierGroup.d.ts +42 -0
- package/dist/react/core/ModifierGroup.js +67 -0
- package/dist/react/index.d.ts +1 -0
- package/dist/react/index.js +1 -0
- package/dist/services/common-types.d.ts +18 -0
- package/dist/services/common-types.js +10 -0
- package/dist/services/item-details-service.d.ts +2 -0
- package/dist/services/item-details-service.js +8 -1
- package/dist/services/utils.d.ts +17 -0
- package/dist/services/utils.js +104 -0
- package/package.json +5 -6
|
@@ -1,4 +1,10 @@
|
|
|
1
1
|
import type { EnhancedModifier, EnhancedModifierGroup } from '@wix/headless-restaurants-menus/services';
|
|
2
|
+
import { RuleType, RuleTypeMap } from './common-types.js';
|
|
3
|
+
interface ruleUtilsArgs {
|
|
4
|
+
required: boolean;
|
|
5
|
+
minSelections: number;
|
|
6
|
+
maxSelections?: number | null;
|
|
7
|
+
}
|
|
2
8
|
export declare const getModifiersInitState: (modifierGroups: EnhancedModifierGroup[]) => Record<string, string[]>;
|
|
3
9
|
export declare const isSingleSelectRule: (rule: NonNullable<EnhancedModifierGroup["rule"]>) => boolean | null | undefined;
|
|
4
10
|
export declare const getFirstPreSelectedModifier: (modifiers: EnhancedModifier[]) => string | null | undefined;
|
|
@@ -18,3 +24,14 @@ export declare const convertModifierToFormModifier: (modifier: EnhancedModifier,
|
|
|
18
24
|
};
|
|
19
25
|
preSelected?: boolean;
|
|
20
26
|
};
|
|
27
|
+
export declare const getModifierGroupRuleType: (modifierGroupRule: EnhancedModifierGroup["rule"]) => RuleType;
|
|
28
|
+
export declare const hasNoLimit: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
|
|
29
|
+
export declare const canChooseOne: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
|
|
30
|
+
export declare const hasToChooseOne: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
|
|
31
|
+
export declare const hasToChooseX: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean | 0 | null | undefined;
|
|
32
|
+
export declare const hasToChooseAtLeastOne: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
|
|
33
|
+
export declare const hasToChooseAtLeastX: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
|
|
34
|
+
export declare const chooseUpToX: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
|
|
35
|
+
export declare const hasToChooseBetweenXAndY: ({ required, minSelections, maxSelections, }: ruleUtilsArgs) => boolean;
|
|
36
|
+
export declare const getRuleTypeMapValue: (ruleTypeMap: RuleTypeMap, ruleType: RuleType, modifierGroupName: string, rule: EnhancedModifierGroup["rule"]) => string | undefined;
|
|
37
|
+
export {};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { RuleType } from './common-types.js';
|
|
1
2
|
export const getModifiersInitState = (modifierGroups) => {
|
|
2
3
|
const initialSelectedModifiers = {};
|
|
3
4
|
modifierGroups.forEach((group) => {
|
|
@@ -32,3 +33,106 @@ export const convertModifierToFormModifier = (modifier, index) => {
|
|
|
32
33
|
_id: `${modifier._id}~${index}`,
|
|
33
34
|
};
|
|
34
35
|
};
|
|
36
|
+
export const getModifierGroupRuleType = (modifierGroupRule) => {
|
|
37
|
+
const required = modifierGroupRule?.required ?? false;
|
|
38
|
+
const minSelections = modifierGroupRule?.minSelections ?? 0;
|
|
39
|
+
const maxSelections = modifierGroupRule?.maxSelections;
|
|
40
|
+
const ruleFields = { required, minSelections, maxSelections };
|
|
41
|
+
if (hasNoLimit(ruleFields)) {
|
|
42
|
+
return RuleType.NO_LIMIT;
|
|
43
|
+
}
|
|
44
|
+
if (hasToChooseOne(ruleFields) || canChooseOne(ruleFields)) {
|
|
45
|
+
return RuleType.CHOOSE_ONE;
|
|
46
|
+
}
|
|
47
|
+
if (hasToChooseX(ruleFields)) {
|
|
48
|
+
return RuleType.CHOOSE_X;
|
|
49
|
+
}
|
|
50
|
+
if (hasToChooseAtLeastOne(ruleFields)) {
|
|
51
|
+
return RuleType.CHOOSE_AT_LEAST_ONE;
|
|
52
|
+
}
|
|
53
|
+
if (hasToChooseAtLeastX(ruleFields)) {
|
|
54
|
+
return RuleType.CHOOSE_AT_LEAST_X;
|
|
55
|
+
}
|
|
56
|
+
if (chooseUpToX(ruleFields)) {
|
|
57
|
+
return RuleType.CHOOSE_UP_TO_X;
|
|
58
|
+
}
|
|
59
|
+
if (hasToChooseBetweenXAndY(ruleFields)) {
|
|
60
|
+
return RuleType.CHOOSE_BETWEEN_X_AND_Y;
|
|
61
|
+
}
|
|
62
|
+
return RuleType.NO_LIMIT;
|
|
63
|
+
};
|
|
64
|
+
const hasNoValue = (variable) => variable === null || variable === undefined;
|
|
65
|
+
export const hasNoLimit = ({ required, minSelections, maxSelections, }) => !required && minSelections < 1 && (maxSelections ? maxSelections < 1 : true);
|
|
66
|
+
export const canChooseOne = ({ required, minSelections, maxSelections, }) => !required &&
|
|
67
|
+
minSelections === 0 &&
|
|
68
|
+
(maxSelections ? maxSelections === 1 : false);
|
|
69
|
+
export const hasToChooseOne = ({ required, minSelections, maxSelections, }) => required &&
|
|
70
|
+
minSelections === 1 &&
|
|
71
|
+
(maxSelections ? maxSelections === 1 : false);
|
|
72
|
+
export const hasToChooseX = ({ required, minSelections, maxSelections, }) => required ? maxSelections && minSelections === maxSelections : false;
|
|
73
|
+
export const hasToChooseAtLeastOne = ({ required, minSelections, maxSelections, }) => required ? minSelections === 1 && hasNoValue(maxSelections) : false;
|
|
74
|
+
export const hasToChooseAtLeastX = ({ required, minSelections, maxSelections, }) => required ? minSelections > 1 && hasNoValue(maxSelections) : false;
|
|
75
|
+
export const chooseUpToX = ({ required, minSelections, maxSelections, }) => !required &&
|
|
76
|
+
minSelections === 0 &&
|
|
77
|
+
(maxSelections ? maxSelections > 1 : false);
|
|
78
|
+
export const hasToChooseBetweenXAndY = ({ required, minSelections, maxSelections, }) => required
|
|
79
|
+
? maxSelections
|
|
80
|
+
? minSelections > 0 && maxSelections > minSelections
|
|
81
|
+
: false
|
|
82
|
+
: false;
|
|
83
|
+
export const getRuleTypeMapValue = (ruleTypeMap, ruleType, modifierGroupName, rule) => {
|
|
84
|
+
const minSelections = rule?.minSelections ?? 0;
|
|
85
|
+
const maxSelections = rule?.maxSelections;
|
|
86
|
+
switch (ruleType) {
|
|
87
|
+
case RuleType.NO_LIMIT: {
|
|
88
|
+
const callback = ruleTypeMap[RuleType.NO_LIMIT];
|
|
89
|
+
if (callback) {
|
|
90
|
+
return callback(modifierGroupName);
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
case RuleType.CHOOSE_ONE: {
|
|
95
|
+
const callback = ruleTypeMap[RuleType.CHOOSE_ONE];
|
|
96
|
+
if (callback) {
|
|
97
|
+
return callback(modifierGroupName);
|
|
98
|
+
}
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
case RuleType.CHOOSE_X: {
|
|
102
|
+
const callback = ruleTypeMap[RuleType.CHOOSE_X];
|
|
103
|
+
if (callback) {
|
|
104
|
+
return callback(modifierGroupName, minSelections);
|
|
105
|
+
}
|
|
106
|
+
break;
|
|
107
|
+
}
|
|
108
|
+
case RuleType.CHOOSE_AT_LEAST_ONE: {
|
|
109
|
+
const callback = ruleTypeMap[RuleType.CHOOSE_AT_LEAST_ONE];
|
|
110
|
+
if (callback) {
|
|
111
|
+
return callback(modifierGroupName);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
case RuleType.CHOOSE_AT_LEAST_X: {
|
|
116
|
+
const callback = ruleTypeMap[RuleType.CHOOSE_AT_LEAST_X];
|
|
117
|
+
if (callback) {
|
|
118
|
+
return callback(modifierGroupName, minSelections);
|
|
119
|
+
}
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
case RuleType.CHOOSE_UP_TO_X: {
|
|
123
|
+
const callback = ruleTypeMap[RuleType.CHOOSE_UP_TO_X];
|
|
124
|
+
if (callback && maxSelections) {
|
|
125
|
+
return callback(modifierGroupName, maxSelections);
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
case RuleType.CHOOSE_BETWEEN_X_AND_Y: {
|
|
130
|
+
const callback = ruleTypeMap[RuleType.CHOOSE_BETWEEN_X_AND_Y];
|
|
131
|
+
if (callback && maxSelections) {
|
|
132
|
+
return callback(modifierGroupName, minSelections, maxSelections);
|
|
133
|
+
}
|
|
134
|
+
break;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return undefined;
|
|
138
|
+
};
|
|
@@ -2,7 +2,7 @@ import React from 'react';
|
|
|
2
2
|
import { Commerce } from '@wix/ecom/components';
|
|
3
3
|
import { type AsChildChildren } from '@wix/headless-utils/react';
|
|
4
4
|
import { ItemServiceConfig } from '../services/item-details-service.js';
|
|
5
|
-
import {
|
|
5
|
+
import { EnhancedVariant } from '@wix/headless-restaurants-menus/services';
|
|
6
6
|
import { AvailabilityStatus, AvailabilityStatusMap } from '../services/common-types.js';
|
|
7
7
|
/**
|
|
8
8
|
* Root component for menu item display and interaction.
|
|
@@ -25,136 +25,6 @@ export interface RootProps {
|
|
|
25
25
|
itemDetailsServiceConfig?: ItemServiceConfig;
|
|
26
26
|
}
|
|
27
27
|
export declare const Root: ({ children, itemDetailsServiceConfig }: RootProps) => import("react/jsx-runtime").JSX.Element;
|
|
28
|
-
/**
|
|
29
|
-
* Displays the item name with customizable rendering.
|
|
30
|
-
*
|
|
31
|
-
* @component
|
|
32
|
-
* @example
|
|
33
|
-
* ```tsx
|
|
34
|
-
* <ItemDetails.Name />
|
|
35
|
-
* <ItemDetails.Name asChild>
|
|
36
|
-
* <h2 className="font-heading text-lg" />
|
|
37
|
-
* </ItemDetails.Name>
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
export interface ItemDetailsNameProps {
|
|
41
|
-
asChild?: boolean;
|
|
42
|
-
/** Custom render function when using asChild */
|
|
43
|
-
children?: AsChildChildren<{
|
|
44
|
-
name: string;
|
|
45
|
-
}>;
|
|
46
|
-
/** CSS classes to apply to the default element */
|
|
47
|
-
className?: string;
|
|
48
|
-
}
|
|
49
|
-
export declare const Name: React.ForwardRefExoticComponent<ItemDetailsNameProps & React.RefAttributes<HTMLElement>>;
|
|
50
|
-
/**
|
|
51
|
-
* Displays the item price with customizable rendering.
|
|
52
|
-
*
|
|
53
|
-
* @component
|
|
54
|
-
* @example
|
|
55
|
-
* ```tsx
|
|
56
|
-
* <ItemDetails.Price />
|
|
57
|
-
* <ItemDetails.Price asChild>
|
|
58
|
-
* <span className="font-semibold text-lg" />
|
|
59
|
-
* </ItemDetails.Price>
|
|
60
|
-
* ```
|
|
61
|
-
*/
|
|
62
|
-
export interface ItemDetailsPriceProps {
|
|
63
|
-
asChild?: boolean;
|
|
64
|
-
/** CSS classes to apply to the default element */
|
|
65
|
-
className?: string;
|
|
66
|
-
}
|
|
67
|
-
export declare const Price: React.ForwardRefExoticComponent<ItemDetailsPriceProps & React.RefAttributes<HTMLElement>>;
|
|
68
|
-
/**
|
|
69
|
-
* Displays the item description with customizable rendering.
|
|
70
|
-
*
|
|
71
|
-
* @component
|
|
72
|
-
* @example
|
|
73
|
-
* ```tsx
|
|
74
|
-
* <ItemDetails.Description />
|
|
75
|
-
* <ItemDetails.Description asChild>
|
|
76
|
-
* <p className="text-sm" />
|
|
77
|
-
* </ItemDetails.Description>
|
|
78
|
-
* ```
|
|
79
|
-
*/
|
|
80
|
-
export interface ItemDetailsDescriptionProps {
|
|
81
|
-
asChild?: boolean;
|
|
82
|
-
/** CSS classes to apply to the default element */
|
|
83
|
-
className?: string;
|
|
84
|
-
}
|
|
85
|
-
export declare const Description: React.ForwardRefExoticComponent<ItemDetailsDescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
86
|
-
/**
|
|
87
|
-
* Wrapper component for CoreItemDetails.ModifierComponent.
|
|
88
|
-
* Renders a single modifier with checkbox functionality.
|
|
89
|
-
*
|
|
90
|
-
* @component
|
|
91
|
-
* @example
|
|
92
|
-
* ```tsx
|
|
93
|
-
* <ItemDetails.Modifier>
|
|
94
|
-
* {({ modifier, isSelected, onToggle }) => (
|
|
95
|
-
* <div style={{ display: "flex", alignItems: "center" }}>
|
|
96
|
-
* <CheckboxPrimitive.Root
|
|
97
|
-
* className="CheckboxRoot"
|
|
98
|
-
* checked={isSelected}
|
|
99
|
-
* onCheckedChange={onToggle}
|
|
100
|
-
* id={modifier._id}
|
|
101
|
-
* >
|
|
102
|
-
* <CheckboxPrimitive.Indicator className="CheckboxIndicator">
|
|
103
|
-
* <CheckIcon />
|
|
104
|
-
* </CheckboxPrimitive.Indicator>
|
|
105
|
-
* </CheckboxPrimitive.Root>
|
|
106
|
-
* <label className="Label" htmlFor={modifier._id}>
|
|
107
|
-
* {modifier.name}
|
|
108
|
-
* </label>
|
|
109
|
-
* </div>
|
|
110
|
-
* )}
|
|
111
|
-
* </ItemDetails.Modifier>
|
|
112
|
-
* ```
|
|
113
|
-
*/
|
|
114
|
-
export interface ItemDetailsModifiersSingleSelectProps {
|
|
115
|
-
children?: AsChildChildren<{
|
|
116
|
-
selectedModifierIds: string[];
|
|
117
|
-
onToggle: (modifierId: string) => void;
|
|
118
|
-
modifierGroup: EnhancedModifierGroup;
|
|
119
|
-
modifiers: EnhancedModifier[];
|
|
120
|
-
}>;
|
|
121
|
-
className?: string;
|
|
122
|
-
asChild?: boolean;
|
|
123
|
-
modifierNameClassName?: string;
|
|
124
|
-
modifierPriceClassName?: string;
|
|
125
|
-
}
|
|
126
|
-
export interface ModifierCheckboxProps {
|
|
127
|
-
selectedModifierIds: string[];
|
|
128
|
-
onToggle: (modifierId: string) => void;
|
|
129
|
-
className?: string;
|
|
130
|
-
asChild?: boolean;
|
|
131
|
-
modifierNameClassName?: string;
|
|
132
|
-
modifierPriceClassName?: string;
|
|
133
|
-
children?: AsChildChildren<{
|
|
134
|
-
selectedModifierIds: string[];
|
|
135
|
-
onToggle: (modifierId: string) => void;
|
|
136
|
-
}>;
|
|
137
|
-
}
|
|
138
|
-
export declare const ModifierCheckbox: React.ForwardRefExoticComponent<ModifierCheckboxProps & React.RefAttributes<HTMLElement>>;
|
|
139
|
-
export interface ModifierRadioProps {
|
|
140
|
-
modifierNameClassName?: string;
|
|
141
|
-
modifierPriceClassName?: string;
|
|
142
|
-
}
|
|
143
|
-
export declare const ModifierRadio: React.ForwardRefExoticComponent<ModifierRadioProps & React.RefAttributes<HTMLElement>>;
|
|
144
|
-
export declare const ModifiersSingleSelect: React.ForwardRefExoticComponent<ItemDetailsModifiersSingleSelectProps & React.RefAttributes<HTMLElement>>;
|
|
145
|
-
export interface ItemDetailsModifiersMultiSelectProps {
|
|
146
|
-
children?: AsChildChildren<{
|
|
147
|
-
selectedModifierIds: string[];
|
|
148
|
-
onToggle: (modifierId: string) => void;
|
|
149
|
-
modifierGroup: EnhancedModifierGroup;
|
|
150
|
-
modifiers: EnhancedModifier[];
|
|
151
|
-
}>;
|
|
152
|
-
className?: string;
|
|
153
|
-
asChild?: boolean;
|
|
154
|
-
modifierNameClassName?: string;
|
|
155
|
-
modifierPriceClassName?: string;
|
|
156
|
-
}
|
|
157
|
-
export declare const ModifiersMultiSelect: React.ForwardRefExoticComponent<ItemDetailsModifiersMultiSelectProps & React.RefAttributes<HTMLElement>>;
|
|
158
28
|
/**
|
|
159
29
|
* Wrapper component for CoreItemDetails.VariantsComponent.
|
|
160
30
|
* Renders the variants for the item using Radix UI RadioGroup.
|
|
@@ -169,7 +39,9 @@ export declare const ModifiersMultiSelect: React.ForwardRefExoticComponent<ItemD
|
|
|
169
39
|
*/
|
|
170
40
|
export interface ItemDetailsVariantsProps {
|
|
171
41
|
children?: AsChildChildren<{
|
|
42
|
+
variant: EnhancedVariant;
|
|
172
43
|
variants: EnhancedVariant[];
|
|
44
|
+
hasVariants: boolean;
|
|
173
45
|
selectedVariantId?: string;
|
|
174
46
|
onVariantChange?: (variantId: string) => void;
|
|
175
47
|
}>;
|
|
@@ -177,6 +49,7 @@ export interface ItemDetailsVariantsProps {
|
|
|
177
49
|
asChild?: boolean;
|
|
178
50
|
variantNameClassName?: string;
|
|
179
51
|
variantPriceClassName?: string;
|
|
52
|
+
emptyState?: React.ReactNode;
|
|
180
53
|
}
|
|
181
54
|
export declare const Variants: React.ForwardRefExoticComponent<ItemDetailsVariantsProps & React.RefAttributes<HTMLElement>>;
|
|
182
55
|
/**
|
|
@@ -4,8 +4,7 @@ import { Commerce } from '@wix/ecom/components';
|
|
|
4
4
|
import { AsChildSlot } from '@wix/headless-utils/react';
|
|
5
5
|
import { Quantity as QuantityComponent } from '@wix/headless-components/react';
|
|
6
6
|
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
7
|
-
import
|
|
8
|
-
import { Item, Modifier, ModifierGroup, useModifierContext, } from '@wix/headless-restaurants-menus/react';
|
|
7
|
+
import { Item } from '@wix/headless-restaurants-menus/react';
|
|
9
8
|
import * as CoreItemDetails from './core/ItemDetails.js';
|
|
10
9
|
import { AvailabilityStatus, } from '../services/common-types.js';
|
|
11
10
|
var TestIds;
|
|
@@ -18,69 +17,19 @@ var TestIds;
|
|
|
18
17
|
TestIds["itemSpecialRequest"] = "item-special-request";
|
|
19
18
|
TestIds["itemLabels"] = "item-labels";
|
|
20
19
|
TestIds["itemVariants"] = "item-variants";
|
|
21
|
-
TestIds["itemModifier"] = "item-modifier";
|
|
22
20
|
TestIds["itemAvailability"] = "item-availability";
|
|
23
21
|
})(TestIds || (TestIds = {}));
|
|
24
|
-
const CheckIcon = () => (_jsx("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z", fill: "currentColor" }) }));
|
|
25
22
|
export const Root = ({ children, itemDetailsServiceConfig }) => {
|
|
26
23
|
return (_jsx(CoreItemDetails.Root, { itemDetailsServiceConfig: itemDetailsServiceConfig, children: ({ item }) => _jsx(Item.Root, { item: item, children: children }) }));
|
|
27
24
|
};
|
|
28
|
-
export const
|
|
29
|
-
return (_jsx(Item.Name, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.itemName, ...rest, children: children }));
|
|
30
|
-
});
|
|
31
|
-
Name.displayName = 'ItemDetails.Name';
|
|
32
|
-
export const Price = React.forwardRef(({ asChild, className, ...rest }, ref) => {
|
|
33
|
-
return (_jsx(Item.Price, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.itemPrice, ...rest }));
|
|
34
|
-
});
|
|
35
|
-
Price.displayName = 'ItemDetails.Price';
|
|
36
|
-
export const Description = React.forwardRef(({ asChild, className, ...rest }, ref) => {
|
|
37
|
-
return (_jsx(Item.Description, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.itemDescription, ...rest }));
|
|
38
|
-
});
|
|
39
|
-
Description.displayName = 'ItemDetails.Description';
|
|
40
|
-
export const ModifierCheckbox = React.forwardRef(({ selectedModifierIds, onToggle, className, asChild, modifierNameClassName, modifierPriceClassName, children, ...rest }) => {
|
|
41
|
-
const { modifier } = useModifierContext();
|
|
42
|
-
const isSelected = selectedModifierIds.includes(modifier._id || '');
|
|
43
|
-
return (_jsx(AsChildSlot, { asChild: asChild, testId: TestIds.itemModifier, className: className, customElement: children, customElementProps: {
|
|
44
|
-
selectedModifierIds,
|
|
45
|
-
onToggle,
|
|
46
|
-
}, ...rest, children: _jsxs("div", { style: { display: 'flex', alignItems: 'center' }, children: [_jsx(CheckboxPrimitive.Root, { className: "CheckboxRoot", checked: isSelected, onCheckedChange: () => onToggle(modifier._id || ''), id: modifier._id || undefined, children: _jsx(CheckboxPrimitive.Indicator, { className: "CheckboxIndicator", children: _jsx(CheckIcon, {}) }) }), _jsxs("label", { className: "Label", htmlFor: modifier._id || undefined, children: [_jsx(Modifier.Name, { className: modifierNameClassName }), _jsx(Modifier.Price, { className: modifierPriceClassName })] })] }) }));
|
|
47
|
-
});
|
|
48
|
-
ModifierCheckbox.displayName = 'ItemDetails.ModifierCheckbox';
|
|
49
|
-
export const ModifierRadio = React.forwardRef(({ modifierNameClassName, modifierPriceClassName }) => {
|
|
50
|
-
const { modifier } = useModifierContext();
|
|
51
|
-
return (_jsx(RadioGroupPrimitive.Item, { className: "RadioGroupItem", value: modifier._id || '', id: modifier._id || undefined, children: _jsxs("div", { style: { display: 'flex', alignItems: 'center' }, children: [_jsx(RadioGroupPrimitive.Indicator, { className: "RadioGroupIndicator" }), _jsxs("label", { className: "Label", htmlFor: modifier._id || undefined, children: [_jsx(Modifier.Name, { className: modifierNameClassName }), _jsx(Modifier.Price, { className: modifierPriceClassName })] })] }) }));
|
|
52
|
-
});
|
|
53
|
-
ModifierRadio.displayName = 'ItemDetails.ModifierRadio';
|
|
54
|
-
export const ModifiersSingleSelect = React.forwardRef(({ children, className, asChild, modifierNameClassName, modifierPriceClassName, ...rest }) => {
|
|
55
|
-
return (_jsx(CoreItemDetails.ModifiersComponent, { singleSelect: true, children: ({ selectedModifierIds, onToggle, modifierGroup, modifiers }) => {
|
|
56
|
-
const selectedModifierId = selectedModifierIds.length > 0 ? selectedModifierIds[0] : '';
|
|
57
|
-
return (_jsx(AsChildSlot, { asChild: asChild, testId: TestIds.itemModifier, className: className, customElement: children, customElementProps: {
|
|
58
|
-
selectedModifierIds,
|
|
59
|
-
onToggle,
|
|
60
|
-
modifierGroup,
|
|
61
|
-
modifiers,
|
|
62
|
-
}, ...rest, children: _jsx(RadioGroupPrimitive.Root, { value: selectedModifierId, onValueChange: onToggle, children: _jsx(ModifierGroup.ModifiersRepeater, { children: _jsx(ModifierRadio, { modifierNameClassName: modifierNameClassName, modifierPriceClassName: modifierPriceClassName }) }) }) }));
|
|
63
|
-
} }));
|
|
64
|
-
});
|
|
65
|
-
ModifiersSingleSelect.displayName = 'ItemDetails.ModifiersSingleSelect';
|
|
66
|
-
export const ModifiersMultiSelect = React.forwardRef(({ children, className, asChild, modifierNameClassName, modifierPriceClassName, ...rest }) => {
|
|
67
|
-
return (_jsx(CoreItemDetails.ModifiersComponent, { singleSelect: false, children: ({ selectedModifierIds, onToggle, modifierGroup, modifiers }) => {
|
|
68
|
-
return (_jsx(AsChildSlot, { asChild: asChild, testId: TestIds.itemModifier, className: className, customElement: children, customElementProps: {
|
|
69
|
-
selectedModifierIds,
|
|
70
|
-
onToggle,
|
|
71
|
-
modifierGroup,
|
|
72
|
-
modifiers,
|
|
73
|
-
}, ...rest, children: _jsx(ModifierGroup.ModifiersRepeater, { children: _jsx(ModifierCheckbox, { selectedModifierIds: selectedModifierIds, onToggle: onToggle, modifierNameClassName: modifierNameClassName, modifierPriceClassName: modifierPriceClassName }) }) }));
|
|
74
|
-
} }));
|
|
75
|
-
});
|
|
76
|
-
ModifiersMultiSelect.displayName = 'ItemDetails.ModifiersMultiSelect';
|
|
77
|
-
export const Variants = React.forwardRef(({ children, className, asChild, variantNameClassName, variantPriceClassName, }, ref) => {
|
|
25
|
+
export const Variants = React.forwardRef(({ children, className, asChild, variantNameClassName, variantPriceClassName, emptyState, }, ref) => {
|
|
78
26
|
return (_jsx(CoreItemDetails.VariantsComponent, { children: ({ variants, hasVariants, selectedVariantId, onVariantChange }) => {
|
|
79
27
|
if (!hasVariants) {
|
|
80
|
-
return null;
|
|
28
|
+
return emptyState || null;
|
|
81
29
|
}
|
|
82
30
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, testId: TestIds.itemVariants, className: className, customElement: children, customElementProps: {
|
|
83
31
|
variants,
|
|
32
|
+
hasVariants,
|
|
84
33
|
selectedVariantId,
|
|
85
34
|
onVariantChange,
|
|
86
35
|
}, children: _jsx(RadioGroupPrimitive.Root, { value: selectedVariantId, onValueChange: onVariantChange, children: variants.map((variant) => (_jsx(RadioGroupPrimitive.Item, { value: variant._id ?? '', children: _jsxs("div", { children: [_jsx("div", { className: variantNameClassName, children: variant.name }), _jsx("div", { className: variantPriceClassName, children: variant.priceInfo?.formattedPrice ||
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type AsChildChildren } from '@wix/headless-utils/react';
|
|
3
|
+
import { EnhancedModifier, EnhancedModifierGroup } from '@wix/headless-restaurants-menus/services';
|
|
4
|
+
import { RuleTypeMap } from '../services/common-types.js';
|
|
5
|
+
export interface ItemDetailsModifierGroupProps {
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export interface ModifiersProps {
|
|
9
|
+
className?: string;
|
|
10
|
+
asChild?: boolean;
|
|
11
|
+
modifierNameClassName?: string;
|
|
12
|
+
modifierPriceClassName?: string;
|
|
13
|
+
children?: AsChildChildren<{
|
|
14
|
+
selectedModifierIds: string[];
|
|
15
|
+
onToggle: (modifierId: string) => void;
|
|
16
|
+
modifierGroup: EnhancedModifierGroup;
|
|
17
|
+
modifiers: EnhancedModifier[];
|
|
18
|
+
isSingleSelect: boolean;
|
|
19
|
+
}>;
|
|
20
|
+
}
|
|
21
|
+
export interface ModifierCheckboxProps {
|
|
22
|
+
selectedModifierIds: string[];
|
|
23
|
+
onToggle: (modifierId: string) => void;
|
|
24
|
+
className?: string;
|
|
25
|
+
modifierNameClassName?: string;
|
|
26
|
+
modifierPriceClassName?: string;
|
|
27
|
+
}
|
|
28
|
+
export interface ModifierRadioProps {
|
|
29
|
+
modifierNameClassName?: string;
|
|
30
|
+
modifierPriceClassName?: string;
|
|
31
|
+
}
|
|
32
|
+
export declare const Root: React.ForwardRefExoticComponent<ItemDetailsModifierGroupProps & React.RefAttributes<HTMLElement>>;
|
|
33
|
+
export declare const Modifiers: React.ForwardRefExoticComponent<ModifiersProps & React.RefAttributes<HTMLElement>>;
|
|
34
|
+
export interface DescriptionProps {
|
|
35
|
+
ruleTypeMap: RuleTypeMap;
|
|
36
|
+
className?: string;
|
|
37
|
+
asChild?: boolean;
|
|
38
|
+
children?: AsChildChildren<{
|
|
39
|
+
description: string;
|
|
40
|
+
}>;
|
|
41
|
+
}
|
|
42
|
+
export declare const Description: React.ForwardRefExoticComponent<DescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
43
|
+
export interface ErrorProps {
|
|
44
|
+
ruleTypeMap: RuleTypeMap;
|
|
45
|
+
className?: string;
|
|
46
|
+
asChild?: boolean;
|
|
47
|
+
children?: AsChildChildren<{
|
|
48
|
+
error: string;
|
|
49
|
+
}>;
|
|
50
|
+
}
|
|
51
|
+
export declare const Error: React.ForwardRefExoticComponent<ErrorProps & React.RefAttributes<HTMLElement>>;
|
|
52
|
+
export declare const ModifierGroup: {
|
|
53
|
+
readonly Root: React.ForwardRefExoticComponent<ItemDetailsModifierGroupProps & React.RefAttributes<HTMLElement>>;
|
|
54
|
+
readonly Modifiers: React.ForwardRefExoticComponent<ModifiersProps & React.RefAttributes<HTMLElement>>;
|
|
55
|
+
readonly Description: React.ForwardRefExoticComponent<DescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
56
|
+
readonly Error: React.ForwardRefExoticComponent<ErrorProps & React.RefAttributes<HTMLElement>>;
|
|
57
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { AsChildSlot } from '@wix/headless-utils/react';
|
|
4
|
+
import * as RadioGroupPrimitive from '@radix-ui/react-radio-group';
|
|
5
|
+
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
6
|
+
import { Modifier, ModifierGroup as ModifierGroupComponents, useModifierContext, } from '@wix/headless-restaurants-menus/react';
|
|
7
|
+
import { ModifierGroupComponent, ModifiersComponent, Description as DescriptionComponent, GroupError, } from './core/ModifierGroup.js';
|
|
8
|
+
var TestIds;
|
|
9
|
+
(function (TestIds) {
|
|
10
|
+
TestIds["modifiers"] = "modifiers";
|
|
11
|
+
TestIds["modifierGroupDescription"] = "modifier-group-description";
|
|
12
|
+
TestIds["modifierGroupError"] = "modifier-group-error";
|
|
13
|
+
})(TestIds || (TestIds = {}));
|
|
14
|
+
const CheckIcon = () => (_jsx("svg", { width: "15", height: "15", viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: _jsx("path", { d: "M11.4669 3.72684C11.7558 3.91574 11.8369 4.30308 11.648 4.59198L7.39799 11.092C7.29783 11.2452 7.13556 11.3467 6.95402 11.3699C6.77247 11.3931 6.58989 11.3355 6.45446 11.2124L3.70446 8.71241C3.44905 8.48022 3.43023 8.08494 3.66242 7.82953C3.89461 7.57412 4.28989 7.55529 4.5453 7.78749L6.75292 9.79441L10.6018 3.90792C10.7907 3.61902 11.178 3.53795 11.4669 3.72684Z", fill: "currentColor" }) }));
|
|
15
|
+
export const Root = React.forwardRef(({ children }) => {
|
|
16
|
+
return _jsx(ModifierGroupComponent, { children: children });
|
|
17
|
+
});
|
|
18
|
+
Root.displayName = 'ItemDetailsModifierGroup.Root';
|
|
19
|
+
export const Modifiers = React.forwardRef(({ className, asChild, modifierNameClassName, modifierPriceClassName, children, }, ref) => {
|
|
20
|
+
return (_jsx(ModifiersComponent, { children: ({ selectedModifierIds, onToggle, modifierGroup, modifiers, isSingleSelect, singleSelectedModifierId, }) => (_jsx(AsChildSlot, { ref: ref, asChild: asChild, testId: TestIds.modifiers, className: className, customElement: children, customElementProps: {
|
|
21
|
+
selectedModifierIds,
|
|
22
|
+
onToggle,
|
|
23
|
+
modifierGroup,
|
|
24
|
+
modifiers,
|
|
25
|
+
isSingleSelect,
|
|
26
|
+
}, children: isSingleSelect ? (_jsx(RadioGroupPrimitive.Root, { value: singleSelectedModifierId, onValueChange: onToggle, children: _jsx(ModifierGroupComponents.ModifiersRepeater, { children: _jsx(ModifierRadio, { modifierNameClassName: modifierNameClassName, modifierPriceClassName: modifierPriceClassName }) }) })) : (_jsx(ModifierGroupComponents.ModifiersRepeater, { children: _jsx(ModifierCheckbox, { selectedModifierIds: selectedModifierIds, onToggle: onToggle, modifierNameClassName: modifierNameClassName, modifierPriceClassName: modifierPriceClassName }) })) })) }));
|
|
27
|
+
});
|
|
28
|
+
Modifiers.displayName = 'ItemDetailsModifierGroup.Modifiers';
|
|
29
|
+
const ModifierCheckbox = ({ selectedModifierIds, onToggle, className, modifierNameClassName, modifierPriceClassName, }) => {
|
|
30
|
+
const { modifier } = useModifierContext();
|
|
31
|
+
const isSelected = selectedModifierIds.includes(modifier._id || '');
|
|
32
|
+
return (_jsxs("div", { className: className, style: { display: 'flex', alignItems: 'center' }, children: [_jsx(CheckboxPrimitive.Root, { className: "CheckboxRoot", checked: isSelected, onCheckedChange: () => onToggle(modifier._id || ''), id: modifier._id || undefined, disabled: !modifier.inStock, children: _jsx(CheckboxPrimitive.Indicator, { className: "CheckboxIndicator", children: _jsx(CheckIcon, {}) }) }), _jsxs("label", { className: "Label", htmlFor: modifier._id || undefined, children: [_jsx(Modifier.Name, { className: modifierNameClassName }), _jsx(Modifier.Price, { className: modifierPriceClassName })] })] }));
|
|
33
|
+
};
|
|
34
|
+
const ModifierRadio = ({ modifierNameClassName, modifierPriceClassName, }) => {
|
|
35
|
+
const { modifier } = useModifierContext();
|
|
36
|
+
return (_jsx(RadioGroupPrimitive.Item, { className: "RadioGroupItem", value: modifier._id || '', id: modifier._id || undefined, disabled: !modifier.inStock, children: _jsxs("div", { style: { display: 'flex', alignItems: 'center' }, children: [_jsx(RadioGroupPrimitive.Indicator, { className: "RadioGroupIndicator" }), _jsxs("label", { className: "Label", htmlFor: modifier._id || undefined, children: [_jsx(Modifier.Name, { className: modifierNameClassName }), _jsx(Modifier.Price, { className: modifierPriceClassName })] })] }) }));
|
|
37
|
+
};
|
|
38
|
+
export const Description = React.forwardRef(({ ruleTypeMap, className, asChild, children }, ref) => {
|
|
39
|
+
return (_jsx(DescriptionComponent, { ruleTypeMap: ruleTypeMap, children: ({ description }) => {
|
|
40
|
+
if (!description) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, testId: TestIds.modifierGroupDescription, className: className, customElement: children, customElementProps: { description }, children: _jsx("p", { className: className, children: description }) }));
|
|
44
|
+
} }));
|
|
45
|
+
});
|
|
46
|
+
Description.displayName = 'ItemDetailsModifierGroup.Description';
|
|
47
|
+
export const Error = React.forwardRef(({ ruleTypeMap, className, asChild, children }, ref) => {
|
|
48
|
+
return (_jsx(GroupError, { ruleTypeMap: ruleTypeMap, children: ({ error }) => {
|
|
49
|
+
if (!error) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, testId: TestIds.modifierGroupError, className: className, customElement: children, customElementProps: { error }, children: _jsx("p", { className: className, children: error }) }));
|
|
53
|
+
} }));
|
|
54
|
+
});
|
|
55
|
+
Error.displayName = 'ItemDetailsModifierGroup.Error';
|
|
56
|
+
export const ModifierGroup = {
|
|
57
|
+
Root,
|
|
58
|
+
Modifiers,
|
|
59
|
+
Description,
|
|
60
|
+
Error,
|
|
61
|
+
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { type LineItem } from '@wix/ecom/services';
|
|
3
3
|
import { ItemServiceConfig } from '../../services/item-details-service.js';
|
|
4
|
-
import {
|
|
4
|
+
import { EnhancedVariant } from '@wix/headless-restaurants-menus/services';
|
|
5
5
|
import { AvailabilityStatus, AvailabilityStatusMap } from '../../services/common-types.js';
|
|
6
6
|
interface ItemDetailsRootProps {
|
|
7
7
|
children: (props: {
|
|
@@ -45,16 +45,6 @@ interface ItemDetailsVariantsProps {
|
|
|
45
45
|
}) => React.ReactNode;
|
|
46
46
|
}
|
|
47
47
|
export declare const VariantsComponent: React.FC<ItemDetailsVariantsProps>;
|
|
48
|
-
interface ItemDetailsModifiersProps {
|
|
49
|
-
children: (props: {
|
|
50
|
-
selectedModifierIds: string[];
|
|
51
|
-
onToggle: (modifierId: string) => void;
|
|
52
|
-
modifierGroup: EnhancedModifierGroup;
|
|
53
|
-
modifiers: EnhancedModifier[];
|
|
54
|
-
}) => React.ReactNode;
|
|
55
|
-
singleSelect?: boolean;
|
|
56
|
-
}
|
|
57
|
-
export declare const ModifiersComponent: React.FC<ItemDetailsModifiersProps>;
|
|
58
48
|
interface ItemDetailsAvailabilityProps {
|
|
59
49
|
availabilityStatusMap: AvailabilityStatusMap;
|
|
60
50
|
children: (props: {
|
|
@@ -4,9 +4,8 @@ import { useService, WixServices } from '@wix/services-manager-react';
|
|
|
4
4
|
import { createServicesMap } from '@wix/services-manager';
|
|
5
5
|
import { ItemService, ItemServiceDefinition, loadItemServiceConfig, } from '../../services/item-details-service.js';
|
|
6
6
|
import { OLOSettingsServiceDefinition } from '../../services/olo-settings-service.js';
|
|
7
|
-
import { useItemContext
|
|
7
|
+
import { useItemContext } from '@wix/headless-restaurants-menus/react';
|
|
8
8
|
import { AvailabilityStatus, } from '../../services/common-types.js';
|
|
9
|
-
import { convertModifierToFormModifier } from '../../services/utils.js';
|
|
10
9
|
export const Root = ({ children, itemDetailsServiceConfig, }) => {
|
|
11
10
|
const service = useService(OLOSettingsServiceDefinition);
|
|
12
11
|
const selectedItem = service.selectedItem?.get();
|
|
@@ -88,24 +87,6 @@ export const VariantsComponent = ({ children, }) => {
|
|
|
88
87
|
selectedVariant,
|
|
89
88
|
});
|
|
90
89
|
};
|
|
91
|
-
export const ModifiersComponent = ({ children, singleSelect, }) => {
|
|
92
|
-
const service = useService(ItemServiceDefinition);
|
|
93
|
-
const { modifierGroup } = useModifierGroupContext();
|
|
94
|
-
// Get selected modifier IDs for this group
|
|
95
|
-
const groupId = modifierGroup._id;
|
|
96
|
-
const groupSelectedModifierIds = service.getSelectedModifiers?.(groupId ?? '');
|
|
97
|
-
const onToggle = (modifierId) => {
|
|
98
|
-
if (groupId) {
|
|
99
|
-
service.toggleModifier?.(groupId, modifierId, singleSelect);
|
|
100
|
-
}
|
|
101
|
-
};
|
|
102
|
-
return children({
|
|
103
|
-
selectedModifierIds: groupSelectedModifierIds,
|
|
104
|
-
onToggle,
|
|
105
|
-
modifierGroup,
|
|
106
|
-
modifiers: modifierGroup.modifiers.map(convertModifierToFormModifier),
|
|
107
|
-
});
|
|
108
|
-
};
|
|
109
90
|
export const AvailabilityComponent = ({ children, availabilityStatusMap, }) => {
|
|
110
91
|
const oloSettingsService = useService(OLOSettingsServiceDefinition);
|
|
111
92
|
const availabilityDispatchAction = oloSettingsService.availabilityDispatchAction?.get?.();
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EnhancedModifier, EnhancedModifierGroup } from '@wix/headless-restaurants-menus/services';
|
|
3
|
+
import { RuleType, RuleTypeMap } from '../../services/common-types.js';
|
|
4
|
+
interface ModifiersContextValue {
|
|
5
|
+
selectedModifierIds: string[];
|
|
6
|
+
onToggle: (modifierId: string) => void;
|
|
7
|
+
modifierGroup: EnhancedModifierGroup;
|
|
8
|
+
modifiers: EnhancedModifier[];
|
|
9
|
+
ruleType: RuleType;
|
|
10
|
+
isSingleSelect: boolean;
|
|
11
|
+
}
|
|
12
|
+
export declare function useModifiersContext(): ModifiersContextValue;
|
|
13
|
+
interface ModifierGroupComponentProps {
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
export declare const ModifierGroupComponent: React.FC<ModifierGroupComponentProps>;
|
|
17
|
+
interface ModifiersComponentProps {
|
|
18
|
+
children: (props: {
|
|
19
|
+
selectedModifierIds: string[];
|
|
20
|
+
onToggle: (modifierId: string) => void;
|
|
21
|
+
modifierGroup: EnhancedModifierGroup;
|
|
22
|
+
modifiers: EnhancedModifier[];
|
|
23
|
+
isSingleSelect: boolean;
|
|
24
|
+
singleSelectedModifierId: string;
|
|
25
|
+
}) => React.ReactNode;
|
|
26
|
+
}
|
|
27
|
+
export declare const ModifiersComponent: React.FC<ModifiersComponentProps>;
|
|
28
|
+
interface DescriptionProps {
|
|
29
|
+
ruleTypeMap: RuleTypeMap;
|
|
30
|
+
children: (props: {
|
|
31
|
+
description: string | undefined;
|
|
32
|
+
}) => React.ReactNode;
|
|
33
|
+
}
|
|
34
|
+
export declare const Description: React.FC<DescriptionProps>;
|
|
35
|
+
interface GroupErrorProps {
|
|
36
|
+
ruleTypeMap: RuleTypeMap;
|
|
37
|
+
children: (props: {
|
|
38
|
+
error: string | undefined;
|
|
39
|
+
}) => React.ReactNode;
|
|
40
|
+
}
|
|
41
|
+
export declare const GroupError: React.FC<GroupErrorProps>;
|
|
42
|
+
export {};
|