@wix/headless-restaurants-olo 0.0.15 → 0.0.16

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.
Files changed (33) hide show
  1. package/cjs/dist/react/ItemDetails.d.ts +4 -131
  2. package/cjs/dist/react/ItemDetails.js +4 -55
  3. package/cjs/dist/react/ModifierGroup.d.ts +57 -0
  4. package/cjs/dist/react/ModifierGroup.js +61 -0
  5. package/cjs/dist/react/core/ItemDetails.d.ts +1 -11
  6. package/cjs/dist/react/core/ItemDetails.js +1 -20
  7. package/cjs/dist/react/core/ModifierGroup.d.ts +42 -0
  8. package/cjs/dist/react/core/ModifierGroup.js +67 -0
  9. package/cjs/dist/react/index.d.ts +1 -0
  10. package/cjs/dist/react/index.js +1 -0
  11. package/cjs/dist/services/common-types.d.ts +18 -0
  12. package/cjs/dist/services/common-types.js +10 -0
  13. package/cjs/dist/services/item-details-service.d.ts +2 -0
  14. package/cjs/dist/services/item-details-service.js +8 -1
  15. package/cjs/dist/services/utils.d.ts +17 -0
  16. package/cjs/dist/services/utils.js +104 -0
  17. package/dist/react/ItemDetails.d.ts +4 -131
  18. package/dist/react/ItemDetails.js +4 -55
  19. package/dist/react/ModifierGroup.d.ts +57 -0
  20. package/dist/react/ModifierGroup.js +61 -0
  21. package/dist/react/core/ItemDetails.d.ts +1 -11
  22. package/dist/react/core/ItemDetails.js +1 -20
  23. package/dist/react/core/ModifierGroup.d.ts +42 -0
  24. package/dist/react/core/ModifierGroup.js +67 -0
  25. package/dist/react/index.d.ts +1 -0
  26. package/dist/react/index.js +1 -0
  27. package/dist/services/common-types.d.ts +18 -0
  28. package/dist/services/common-types.js +10 -0
  29. package/dist/services/item-details-service.d.ts +2 -0
  30. package/dist/services/item-details-service.js +8 -1
  31. package/dist/services/utils.d.ts +17 -0
  32. package/dist/services/utils.js +104 -0
  33. package/package.json +5 -6
@@ -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 { EnhancedModifier, EnhancedModifierGroup, EnhancedVariant } from '@wix/headless-restaurants-menus/services';
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 * as CheckboxPrimitive from '@radix-ui/react-checkbox';
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 Name = React.forwardRef(({ asChild, children, className, ...rest }, ref) => {
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 { EnhancedModifier, EnhancedModifierGroup, EnhancedVariant } from '@wix/headless-restaurants-menus/services';
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, useModifierGroupContext, } from '@wix/headless-restaurants-menus/react';
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 {};
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import React, { createContext } from 'react';
3
+ import { useService } from '@wix/services-manager-react';
4
+ import { useModifierGroupContext } from '@wix/headless-restaurants-menus/react';
5
+ import { convertModifierToFormModifier, getModifierGroupRuleType, getRuleTypeMapValue, isSingleSelectRule, } from '../../services/utils.js';
6
+ import { ItemServiceDefinition } from '../../services/item-details-service.js';
7
+ const ModifiersContext = createContext(null);
8
+ export function useModifiersContext() {
9
+ const context = React.useContext(ModifiersContext);
10
+ if (!context) {
11
+ throw new Error('useModifiersContext must be used within a ModifierGroupComponent');
12
+ }
13
+ return context;
14
+ }
15
+ export const ModifierGroupComponent = ({ children, }) => {
16
+ const service = useService(ItemServiceDefinition);
17
+ const { modifierGroup } = useModifierGroupContext();
18
+ const rule = modifierGroup.rule;
19
+ const isSingleSelect = Boolean(rule ? isSingleSelectRule(rule) : false);
20
+ const groupId = modifierGroup._id;
21
+ const groupSelectedModifierIds = service.getSelectedModifiers?.(groupId ?? '');
22
+ const onToggle = (modifierId) => {
23
+ if (groupId) {
24
+ service.toggleModifier?.(groupId, modifierId, isSingleSelect);
25
+ }
26
+ };
27
+ const ruleType = getModifierGroupRuleType(modifierGroup.rule);
28
+ const contextValue = {
29
+ selectedModifierIds: groupSelectedModifierIds,
30
+ onToggle,
31
+ modifierGroup,
32
+ modifiers: modifierGroup.modifiers.map(convertModifierToFormModifier),
33
+ isSingleSelect,
34
+ ruleType,
35
+ };
36
+ return (_jsx(ModifiersContext.Provider, { value: contextValue, children: children }));
37
+ };
38
+ export const ModifiersComponent = ({ children, }) => {
39
+ const { selectedModifierIds, onToggle, modifierGroup, modifiers, isSingleSelect, } = useModifiersContext();
40
+ const singleSelectedModifierId = selectedModifierIds.length > 0 ? (selectedModifierIds[0] ?? '') : '';
41
+ return children({
42
+ selectedModifierIds,
43
+ onToggle,
44
+ modifierGroup,
45
+ modifiers,
46
+ isSingleSelect,
47
+ singleSelectedModifierId,
48
+ });
49
+ };
50
+ export const Description = ({ ruleTypeMap, children, }) => {
51
+ const { ruleType, modifierGroup } = useModifiersContext();
52
+ const modifierGroupName = modifierGroup.name || '';
53
+ const description = getRuleTypeMapValue(ruleTypeMap, ruleType, modifierGroupName, modifierGroup.rule);
54
+ return children({ description });
55
+ };
56
+ export const GroupError = ({ ruleTypeMap, children, }) => {
57
+ const service = useService(ItemServiceDefinition);
58
+ const { ruleType, modifierGroup } = useModifiersContext();
59
+ const groupId = modifierGroup._id || '';
60
+ const modifierGroupErrors = service.modifierGroupError?.get() || {};
61
+ const modifierGroupName = modifierGroup.name || '';
62
+ let error;
63
+ if (modifierGroupErrors[groupId]) {
64
+ error = getRuleTypeMapValue(ruleTypeMap, ruleType, modifierGroupName, modifierGroup.rule);
65
+ }
66
+ return children({ error });
67
+ };
@@ -1,4 +1,5 @@
1
1
  export * as ItemDetails from './ItemDetails.js';
2
+ export * as ModifierGroup from './ModifierGroup.js';
2
3
  export * as ClickableItem from './ClickableItem.js';
3
4
  export * as OLO from './OLO.js';
4
5
  export * as Settings from './Settings.js';
@@ -1,4 +1,5 @@
1
1
  export * as ItemDetails from './ItemDetails.js';
2
+ export * as ModifierGroup from './ModifierGroup.js';
2
3
  export * as ClickableItem from './ClickableItem.js';
3
4
  export * as OLO from './OLO.js';
4
5
  export * as Settings from './Settings.js';
@@ -1,6 +1,24 @@
1
1
  import * as currentCart from '@wix/auto_sdk_ecom_current-cart';
2
2
  export type LineItem = currentCart.LineItem;
3
3
  export type DescriptionLine = currentCart.DescriptionLine;
4
+ export declare enum RuleType {
5
+ NO_LIMIT = "NO_LIMIT",
6
+ CHOOSE_ONE = "CHOOSE_ONE",
7
+ CHOOSE_X = "CHOOSE_X",
8
+ CHOOSE_AT_LEAST_ONE = "CHOOSE_AT_LEAST_ONE",
9
+ CHOOSE_AT_LEAST_X = "CHOOSE_AT_LEAST_X",
10
+ CHOOSE_UP_TO_X = "CHOOSE_UP_TO_X",
11
+ CHOOSE_BETWEEN_X_AND_Y = "CHOOSE_BETWEEN_X_AND_Y"
12
+ }
13
+ export interface RuleTypeMap {
14
+ [RuleType.NO_LIMIT]?: (modifierGroupName: string) => string;
15
+ [RuleType.CHOOSE_ONE]?: (modifierGroupName: string) => string;
16
+ [RuleType.CHOOSE_X]?: (modifierGroupName: string, x: number) => string;
17
+ [RuleType.CHOOSE_AT_LEAST_ONE]?: (modifierGroupName: string) => string;
18
+ [RuleType.CHOOSE_AT_LEAST_X]?: (modifierGroupName: string, x: number) => string;
19
+ [RuleType.CHOOSE_UP_TO_X]?: (modifierGroupName: string, x: number) => string;
20
+ [RuleType.CHOOSE_BETWEEN_X_AND_Y]?: (modifierGroupName: string, x: number, y: number) => string;
21
+ }
4
22
  export declare enum AvailabilityStatus {
5
23
  AVAILABLE = 0,
6
24
  NOT_AVAILABLE = 1,
@@ -1,3 +1,13 @@
1
+ export var RuleType;
2
+ (function (RuleType) {
3
+ RuleType["NO_LIMIT"] = "NO_LIMIT";
4
+ RuleType["CHOOSE_ONE"] = "CHOOSE_ONE";
5
+ RuleType["CHOOSE_X"] = "CHOOSE_X";
6
+ RuleType["CHOOSE_AT_LEAST_ONE"] = "CHOOSE_AT_LEAST_ONE";
7
+ RuleType["CHOOSE_AT_LEAST_X"] = "CHOOSE_AT_LEAST_X";
8
+ RuleType["CHOOSE_UP_TO_X"] = "CHOOSE_UP_TO_X";
9
+ RuleType["CHOOSE_BETWEEN_X_AND_Y"] = "CHOOSE_BETWEEN_X_AND_Y";
10
+ })(RuleType || (RuleType = {}));
1
11
  export var AvailabilityStatus;
2
12
  (function (AvailabilityStatus) {
3
13
  AvailabilityStatus[AvailabilityStatus["AVAILABLE"] = 0] = "AVAILABLE";
@@ -23,6 +23,8 @@ export interface ItemServiceAPI {
23
23
  isLoading: Signal<boolean>;
24
24
  /** Reactive signal containing any error message, or null if no error */
25
25
  error: Signal<string | null>;
26
+ /** Reactive signal containing error state for each modifier group */
27
+ modifierGroupError: Signal<Record<string, boolean>>;
26
28
  /** Function to update the quantity of the item */
27
29
  updateQuantity: (quantity: number) => void;
28
30
  /** Function to update the special request of the item */
@@ -58,7 +58,13 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
58
58
  const modifierGroups = config.item?.modifierGroups || [];
59
59
  const initialSelectedModifiers = getModifiersInitState(modifierGroups);
60
60
  const selectedModifiers = signalsService.signal(initialSelectedModifiers);
61
- console.log('config.item', config.item);
61
+ const initialModifierGroupError = modifierGroups.reduce((acc, group) => {
62
+ if (group._id) {
63
+ acc[group._id] = false;
64
+ }
65
+ return acc;
66
+ }, {});
67
+ const modifierGroupError = signalsService.signal(initialModifierGroupError);
62
68
  if (config.item) {
63
69
  lineItem.set({
64
70
  quantity: quantity.get(),
@@ -150,6 +156,7 @@ export const ItemService = implementService.withConfig()(ItemServiceDefinition,
150
156
  selectedModifiers,
151
157
  availabilityStatus,
152
158
  getSelectedModifiers,
159
+ modifierGroupError,
153
160
  };
154
161
  });
155
162
  /**