@wix/headless-restaurants-olo 0.0.14 → 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 (85) hide show
  1. package/cjs/dist/mappers/operation-mapper.d.ts +3 -0
  2. package/cjs/dist/mappers/operation-mapper.js +95 -0
  3. package/cjs/dist/react/ItemDetails.d.ts +4 -162
  4. package/cjs/dist/react/ItemDetails.js +6 -78
  5. package/cjs/dist/react/ModifierGroup.d.ts +57 -0
  6. package/cjs/dist/react/ModifierGroup.js +61 -0
  7. package/cjs/dist/react/OLO.d.ts +3 -2
  8. package/cjs/dist/react/OLOMenus.d.ts +20 -0
  9. package/cjs/dist/react/OLOMenus.js +22 -0
  10. package/cjs/dist/react/Settings.d.ts +160 -0
  11. package/cjs/dist/react/Settings.js +94 -0
  12. package/cjs/dist/react/core/ItemDetails.d.ts +1 -11
  13. package/cjs/dist/react/core/ItemDetails.js +4 -21
  14. package/cjs/dist/react/core/ModifierGroup.d.ts +42 -0
  15. package/cjs/dist/react/core/ModifierGroup.js +67 -0
  16. package/cjs/dist/react/core/OLO.js +16 -2
  17. package/cjs/dist/react/core/OLOMenus.d.ts +7 -0
  18. package/cjs/dist/react/core/OLOMenus.js +12 -0
  19. package/cjs/dist/react/core/Settings.d.ts +157 -0
  20. package/cjs/dist/react/core/Settings.js +192 -0
  21. package/cjs/dist/react/core/index.d.ts +1 -0
  22. package/cjs/dist/react/core/index.js +1 -0
  23. package/cjs/dist/react/index.d.ts +3 -0
  24. package/cjs/dist/react/index.js +3 -0
  25. package/cjs/dist/services/common-types.d.ts +18 -0
  26. package/cjs/dist/services/common-types.js +10 -0
  27. package/cjs/dist/services/fulfillments-service.d.ts +13 -0
  28. package/cjs/dist/services/fulfillments-service.js +64 -0
  29. package/cjs/dist/services/index.d.ts +1 -0
  30. package/cjs/dist/services/index.js +1 -0
  31. package/cjs/dist/services/item-details-service.d.ts +2 -0
  32. package/cjs/dist/services/item-details-service.js +8 -1
  33. package/cjs/dist/services/olo-settings-service.d.ts +14 -8
  34. package/cjs/dist/services/olo-settings-service.js +24 -5
  35. package/cjs/dist/services/utils.d.ts +17 -0
  36. package/cjs/dist/services/utils.js +104 -0
  37. package/cjs/dist/types/fulfillments-types.d.ts +33 -0
  38. package/cjs/dist/types/fulfillments-types.js +7 -0
  39. package/cjs/dist/types/operation.d.ts +57 -0
  40. package/cjs/dist/types/operation.js +1 -0
  41. package/cjs/dist/utils/fulfillments-utils.d.ts +23 -0
  42. package/cjs/dist/utils/fulfillments-utils.js +144 -0
  43. package/dist/mappers/operation-mapper.d.ts +3 -0
  44. package/dist/mappers/operation-mapper.js +95 -0
  45. package/dist/react/ItemDetails.d.ts +4 -162
  46. package/dist/react/ItemDetails.js +6 -78
  47. package/dist/react/ModifierGroup.d.ts +57 -0
  48. package/dist/react/ModifierGroup.js +61 -0
  49. package/dist/react/OLO.d.ts +3 -2
  50. package/dist/react/OLOMenus.d.ts +20 -0
  51. package/dist/react/OLOMenus.js +22 -0
  52. package/dist/react/Settings.d.ts +160 -0
  53. package/dist/react/Settings.js +94 -0
  54. package/dist/react/core/ItemDetails.d.ts +1 -11
  55. package/dist/react/core/ItemDetails.js +4 -21
  56. package/dist/react/core/ModifierGroup.d.ts +42 -0
  57. package/dist/react/core/ModifierGroup.js +67 -0
  58. package/dist/react/core/OLO.js +16 -2
  59. package/dist/react/core/OLOMenus.d.ts +7 -0
  60. package/dist/react/core/OLOMenus.js +12 -0
  61. package/dist/react/core/Settings.d.ts +157 -0
  62. package/dist/react/core/Settings.js +192 -0
  63. package/dist/react/core/index.d.ts +1 -0
  64. package/dist/react/core/index.js +1 -0
  65. package/dist/react/index.d.ts +3 -0
  66. package/dist/react/index.js +3 -0
  67. package/dist/services/common-types.d.ts +18 -0
  68. package/dist/services/common-types.js +10 -0
  69. package/dist/services/fulfillments-service.d.ts +13 -0
  70. package/dist/services/fulfillments-service.js +64 -0
  71. package/dist/services/index.d.ts +1 -0
  72. package/dist/services/index.js +1 -0
  73. package/dist/services/item-details-service.d.ts +2 -0
  74. package/dist/services/item-details-service.js +8 -1
  75. package/dist/services/olo-settings-service.d.ts +14 -8
  76. package/dist/services/olo-settings-service.js +24 -5
  77. package/dist/services/utils.d.ts +17 -0
  78. package/dist/services/utils.js +104 -0
  79. package/dist/types/fulfillments-types.d.ts +33 -0
  80. package/dist/types/fulfillments-types.js +7 -0
  81. package/dist/types/operation.d.ts +57 -0
  82. package/dist/types/operation.js +1 -0
  83. package/dist/utils/fulfillments-utils.d.ts +23 -0
  84. package/dist/utils/fulfillments-utils.js +144 -0
  85. package/package.json +5 -6
@@ -0,0 +1,7 @@
1
+ export var DispatchType;
2
+ (function (DispatchType) {
3
+ /** Pickup fulfillment */
4
+ DispatchType["PICKUP"] = "PICKUP";
5
+ /** Delivery fulfillment */
6
+ DispatchType["DELIVERY"] = "DELIVERY";
7
+ })(DispatchType || (DispatchType = {}));
@@ -0,0 +1,57 @@
1
+ import { DispatchType } from './fulfillments-types.js';
2
+ export type MinMaxRange = {
3
+ min: number;
4
+ max: number;
5
+ };
6
+ export type AsapScheduling = {
7
+ maxInMinutes?: number;
8
+ rangeInMinutes?: MinMaxRange;
9
+ };
10
+ export type PreorderScheduling = {
11
+ timeWindowDuration: number;
12
+ timeInAdvance: MinMaxRange;
13
+ };
14
+ export type OperationType = 'PRE_ORDER' | 'ASAP';
15
+ type BaseOperation = {
16
+ id: string;
17
+ name: string;
18
+ };
19
+ export interface StreetAddress {
20
+ apt?: String;
21
+ formattedAddressLine?: String;
22
+ name?: String;
23
+ number?: String;
24
+ }
25
+ export interface Address {
26
+ addressLine?: String;
27
+ addressLine2?: String;
28
+ city?: String;
29
+ country?: String;
30
+ countryFullname?: String;
31
+ formattedAddress?: String;
32
+ hint?: String;
33
+ postalCode?: String;
34
+ streetAddress?: StreetAddress;
35
+ subdivision?: String;
36
+ subdivisionFullname?: String;
37
+ }
38
+ export type OSLocation = {
39
+ name: string;
40
+ address?: Address;
41
+ default?: boolean;
42
+ timeZone?: string;
43
+ };
44
+ export type Operation = BaseOperation & {
45
+ enabled: boolean;
46
+ fulfillmentIds: string[];
47
+ asapOptions?: AsapScheduling;
48
+ allowAsapFutureHandling?: boolean;
49
+ businessDaysAheadHandlingOptions?: number;
50
+ operationType: OperationType;
51
+ preOrderOptions?: PreorderScheduling;
52
+ defaultDispatchType?: DispatchType;
53
+ operationGroupId: string;
54
+ locationId: string;
55
+ locationDetails?: OSLocation;
56
+ };
57
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,23 @@
1
+ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
+ import { TimeSlot } from '../types/fulfillments-types.js';
3
+ export declare const createTimeSlotId: (startTime: Date, endTime: Date, maxTimeOptions?: number) => string;
4
+ export declare function hasSameByField<T>(field: keyof T, arr: T[]): boolean;
5
+ export declare function getMinValueObjects<T>(key: keyof T, arr: T[]): T[];
6
+ export declare function getMinTime(info: operationsSDK.FulfillmentInfo): number;
7
+ export declare function getFastestTimeOptionsByFulfillmentInfo(arr: operationsSDK.FulfillmentInfo[]): operationsSDK.FulfillmentInfo[];
8
+ export declare function getSlowestTimeOptionByFulfillmentInfo(arr: operationsSDK.FulfillmentInfo[]): operationsSDK.FulfillmentInfo;
9
+ export declare const createTimeRangeByFulfillmentInfo: (arr: operationsSDK.FulfillmentInfo[]) => {
10
+ maxTimeOptions: number | undefined;
11
+ durationRangeOptions?: undefined;
12
+ } | {
13
+ durationRangeOptions: {
14
+ minDuration: number | undefined;
15
+ maxDuration: number | undefined;
16
+ };
17
+ maxTimeOptions?: undefined;
18
+ };
19
+ export declare function hasSameTime(arr: operationsSDK.FulfillmentDetails[]): boolean;
20
+ export declare const resolveDifferentMinOrderPriceOptionByFulfillmentInfo: (fulfillmentInfo: operationsSDK.FulfillmentInfo[]) => operationsSDK.FulfillmentInfo | undefined;
21
+ export declare const resolveSameMinOrderPriceOptionByFulfillmentInfo: (fulfillmentInfo: operationsSDK.FulfillmentInfo[]) => operationsSDK.FulfillmentInfo;
22
+ export declare const resolveFulfillmentInfo: (fulfillmentInfo: operationsSDK.FulfillmentInfo[]) => operationsSDK.FulfillmentInfo | undefined;
23
+ export declare const processFulfillmentTimeSlotByOperationList: (operationTimeSlot: operationsSDK.TimeSlotForOperation) => [string, TimeSlot[] | undefined];
@@ -0,0 +1,144 @@
1
+ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
+ import { DispatchType } from '../types/fulfillments-types.js';
3
+ export const createTimeSlotId = (startTime, endTime, maxTimeOptions = 0) =>
4
+ // maxTimeOptions is used to avoid collisions when order pacing is enabled
5
+ `${startTime?.toUTCString()}-${endTime?.toUTCString()}-${maxTimeOptions}`;
6
+ export function hasSameByField(field, arr) {
7
+ const [first, ...rest] = arr;
8
+ return rest.every((item) => item[field] === first?.[field]);
9
+ }
10
+ export function getMinValueObjects(key, arr) {
11
+ return arr.slice(1).reduce((min, item) => {
12
+ if (Number(item[key]) < Number(min[0]?.[key])) {
13
+ return [item];
14
+ }
15
+ else if (Number(item[key]) === Number(min[0]?.[key])) {
16
+ return [...min, item];
17
+ }
18
+ return min;
19
+ }, (arr[0] ? [arr[0]] : []));
20
+ }
21
+ export function getMinTime(info) {
22
+ return info.durationRange
23
+ ? Number(info.durationRange.minDuration)
24
+ : Number(info.maxTime);
25
+ }
26
+ export function getFastestTimeOptionsByFulfillmentInfo(arr) {
27
+ const [first, ...rest] = arr;
28
+ if (!first) {
29
+ return [];
30
+ }
31
+ return rest.reduce((fastestOptions, current) => {
32
+ const currentTime = getMinTime(current);
33
+ const fastestTime = getMinTime(fastestOptions[0]);
34
+ if (currentTime < fastestTime) {
35
+ return [current];
36
+ }
37
+ else if (currentTime === fastestTime) {
38
+ return [...fastestOptions, current];
39
+ }
40
+ return fastestOptions;
41
+ }, [first]);
42
+ }
43
+ export function getSlowestTimeOptionByFulfillmentInfo(arr) {
44
+ return arr.reduce((max, item) => {
45
+ const { durationRange, maxTime: maxTimeOptions } = item;
46
+ let maxTime;
47
+ if (max.durationRange) {
48
+ maxTime = Number(max.durationRange?.maxDuration || 0);
49
+ }
50
+ else {
51
+ maxTime = Number(max.maxTime || 0);
52
+ }
53
+ if (durationRange) {
54
+ return Number(durationRange.maxDuration) > maxTime ? item : max;
55
+ }
56
+ else {
57
+ return Number(maxTimeOptions) > maxTime ? item : max;
58
+ }
59
+ }, {});
60
+ }
61
+ export const createTimeRangeByFulfillmentInfo = (arr) => {
62
+ const fastestOption = getFastestTimeOptionsByFulfillmentInfo(arr)[0];
63
+ const slowestOption = getSlowestTimeOptionByFulfillmentInfo(arr);
64
+ const minDuration = fastestOption?.durationRange?.minDuration ?? fastestOption?.maxTime;
65
+ const maxDuration = slowestOption.durationRange?.maxDuration ?? slowestOption.maxTime;
66
+ if (minDuration === maxDuration) {
67
+ return { maxTimeOptions: minDuration };
68
+ }
69
+ else {
70
+ return { durationRangeOptions: { minDuration, maxDuration } };
71
+ }
72
+ };
73
+ export function hasSameTime(arr) {
74
+ return (hasSameByField('fulfillmentTimeType', arr) &&
75
+ (arr[0]?.fulfillmentTimeType === operationsSDK.FulfillmentTimeType.MAX_TIME
76
+ ? hasSameByField('maxTimeOptions', arr)
77
+ : arr.every((details) => {
78
+ const { durationRangeOptions } = details;
79
+ return (durationRangeOptions?.maxDuration ===
80
+ arr[0]?.durationRangeOptions?.maxDuration &&
81
+ durationRangeOptions?.minDuration ===
82
+ arr[0]?.durationRangeOptions?.minDuration);
83
+ })));
84
+ }
85
+ export const resolveDifferentMinOrderPriceOptionByFulfillmentInfo = (fulfillmentInfo) => {
86
+ const hasSameFee = hasSameByField('fee', fulfillmentInfo);
87
+ if (hasSameFee && hasSameTime(fulfillmentInfo)) {
88
+ // if fee and time are the same, return the object with the min order price with the min free delivery price threshold
89
+ return getMinValueObjects('freeFulfillmentPriceThreshold', getMinValueObjects('minOrderPrice', fulfillmentInfo))[0];
90
+ }
91
+ else {
92
+ // if the fee is the same and time is different, return the fee
93
+ const fee = hasSameFee ? fulfillmentInfo[0]?.fee : undefined;
94
+ // if free delivery price threshold is the same, return free delivery price threshold
95
+ const freeFulfillmentPriceThreshold = hasSameByField('freeFulfillmentPriceThreshold', fulfillmentInfo)
96
+ ? fulfillmentInfo[0]?.freeFulfillmentPriceThreshold
97
+ : undefined;
98
+ // create a time range object from all the fulfillments
99
+ return {
100
+ fee,
101
+ ...createTimeRangeByFulfillmentInfo(fulfillmentInfo),
102
+ freeFulfillmentPriceThreshold,
103
+ };
104
+ }
105
+ };
106
+ export const resolveSameMinOrderPriceOptionByFulfillmentInfo = (fulfillmentInfo) => {
107
+ // filtering fulfillment details by order of precedent: fee, time, free delivery price threshold
108
+ const cheapestFulfillmentInfo = getMinValueObjects('fee', fulfillmentInfo);
109
+ const fastestFulfillmentInfo = getFastestTimeOptionsByFulfillmentInfo(cheapestFulfillmentInfo);
110
+ return getMinValueObjects('freeFulfillmentPriceThreshold', fastestFulfillmentInfo)[0];
111
+ };
112
+ export const resolveFulfillmentInfo = (fulfillmentInfo) => {
113
+ if (hasSameByField('minOrderPrice', fulfillmentInfo)) {
114
+ return resolveSameMinOrderPriceOptionByFulfillmentInfo(fulfillmentInfo);
115
+ }
116
+ else {
117
+ return resolveDifferentMinOrderPriceOptionByFulfillmentInfo(fulfillmentInfo);
118
+ }
119
+ };
120
+ export const processFulfillmentTimeSlotByOperationList = (operationTimeSlot) => {
121
+ return [
122
+ operationTimeSlot.operationId ?? '',
123
+ operationTimeSlot.timeslotsPerFulfillmentType?.map((fulfillmentTimeSlot) => {
124
+ const { timeSlot, fulfilmentType, fulfillmentInfo } = fulfillmentTimeSlot;
125
+ const { startTime, endTime, orderSchedulingType } = timeSlot ?? {};
126
+ const selectedFulfillmentInfo = resolveFulfillmentInfo(fulfillmentInfo);
127
+ const fulfillmentDetails = {
128
+ maxTimeOptions: selectedFulfillmentInfo?.maxTime,
129
+ durationRangeOptions: selectedFulfillmentInfo?.durationRange,
130
+ ...selectedFulfillmentInfo,
131
+ };
132
+ return {
133
+ id: createTimeSlotId(startTime, endTime),
134
+ startTime: startTime,
135
+ endTime: endTime,
136
+ dispatchType: fulfilmentType === 'DELIVERY'
137
+ ? DispatchType.DELIVERY
138
+ : DispatchType.PICKUP,
139
+ startsNow: orderSchedulingType === operationsSDK.OrderSchedulingType.ASAP,
140
+ fulfillmentDetails,
141
+ };
142
+ }),
143
+ ];
144
+ };
@@ -0,0 +1,3 @@
1
+ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
+ import { Operation } from '../types/operation.js';
3
+ export declare const OperationMapper: (operation: operationsSDK.Operation) => Operation;
@@ -0,0 +1,95 @@
1
+ import * as operationsSDK from '@wix/auto_sdk_restaurants_operations';
2
+ import { DispatchType } from '../types/fulfillments-types.js';
3
+ const TIME_UNIT_MULTIPLIER = {
4
+ MINUTES: 1,
5
+ UNKNOWN_TIME_UNIT: 0,
6
+ DAYS: 24 * 60,
7
+ HOURS: 60,
8
+ };
9
+ const getAsapOptionsFromOperation = (operation) => {
10
+ if (!operation.orderScheduling?.asapOptions) {
11
+ return;
12
+ }
13
+ const { timeRangeOptions, maxTimeOptions } = operation.orderScheduling.asapOptions.preparationTime || {};
14
+ if (maxTimeOptions &&
15
+ maxTimeOptions.duration !== null &&
16
+ maxTimeOptions.duration !== undefined &&
17
+ maxTimeOptions.timeUnit) {
18
+ return {
19
+ maxInMinutes: maxTimeOptions.duration * TIME_UNIT_MULTIPLIER[maxTimeOptions.timeUnit],
20
+ };
21
+ }
22
+ if (timeRangeOptions &&
23
+ timeRangeOptions.timeUnit &&
24
+ timeRangeOptions.maxDuration !== undefined &&
25
+ timeRangeOptions.maxDuration !== null &&
26
+ timeRangeOptions.minDuration !== undefined &&
27
+ timeRangeOptions.minDuration !== null) {
28
+ return {
29
+ rangeInMinutes: {
30
+ min: timeRangeOptions.minDuration *
31
+ TIME_UNIT_MULTIPLIER[timeRangeOptions.timeUnit],
32
+ max: timeRangeOptions.maxDuration *
33
+ TIME_UNIT_MULTIPLIER[timeRangeOptions.timeUnit],
34
+ },
35
+ };
36
+ }
37
+ };
38
+ function getPreOrderOptions(operation) {
39
+ if (!operation.orderScheduling?.preorderOptions) {
40
+ return;
41
+ }
42
+ const timeBoundedOptions = operation.orderScheduling?.preorderOptions?.method?.timeBoundedOptions;
43
+ if (!timeBoundedOptions) {
44
+ return;
45
+ }
46
+ const { maxTimeInAdvance, minTimeInAdvance } = timeBoundedOptions;
47
+ const max = TIME_UNIT_MULTIPLIER[maxTimeInAdvance?.timeUnit] *
48
+ maxTimeInAdvance?.duration;
49
+ const min = TIME_UNIT_MULTIPLIER[minTimeInAdvance?.timeUnit] *
50
+ minTimeInAdvance?.duration;
51
+ const timeWindowsOptions = operation.orderScheduling?.preorderOptions?.fulfillmentTimesDisplay
52
+ ?.timeWindowsOptions;
53
+ const timeWindowDuration = TIME_UNIT_MULTIPLIER[timeWindowsOptions.timeUnit] *
54
+ timeWindowsOptions.duration;
55
+ return {
56
+ timeInAdvance: { min, max },
57
+ timeWindowDuration,
58
+ };
59
+ }
60
+ function getOperationType(operation) {
61
+ switch (operation.orderScheduling?.type) {
62
+ case operationsSDK.SchedulingType.PREORDER:
63
+ return 'PRE_ORDER';
64
+ case operationsSDK.SchedulingType.ASAP:
65
+ default:
66
+ return 'ASAP';
67
+ }
68
+ }
69
+ export const OperationMapper = (operation) => {
70
+ const { asapFutureHandlingType, businessDaysAheadHandlingOptions } = operation.orderScheduling?.asapOptions || {};
71
+ const { daysCount } = businessDaysAheadHandlingOptions || {};
72
+ const allowAsapFutureHandling = asapFutureHandlingType ===
73
+ operationsSDK.AsapFutureHandlingType.BUSINESS_DAYS_AHEAD_HANDLING &&
74
+ Number(daysCount) >= 0;
75
+ return {
76
+ id: operation._id || '',
77
+ name: operation.name || '',
78
+ // @ts-expect-error - operation is not typed
79
+ enabled: !!operation.enabled,
80
+ fulfillmentIds: operation.fulfillmentIds || [],
81
+ asapOptions: getAsapOptionsFromOperation(operation),
82
+ preOrderOptions: getPreOrderOptions(operation),
83
+ operationType: getOperationType(operation),
84
+ allowAsapFutureHandling,
85
+ businessDaysAheadHandlingOptions: daysCount ?? undefined,
86
+ defaultDispatchType: operation.defaultFulfillmentType ===
87
+ operationsSDK.FulfillmentType.DELIVERY
88
+ ? DispatchType.DELIVERY
89
+ : DispatchType.PICKUP,
90
+ operationGroupId: operation.operationGroupId || '',
91
+ locationId: operation.businessLocationId || '',
92
+ // @ts-expect-error - operation is not typed
93
+ locationDetails: operation.businessLocationDetails,
94
+ };
95
+ };
@@ -1,9 +1,8 @@
1
1
  import React from 'react';
2
2
  import { Commerce } from '@wix/ecom/components';
3
- import { type LineItem } from '@wix/ecom/services';
4
3
  import { type AsChildChildren } from '@wix/headless-utils/react';
5
4
  import { ItemServiceConfig } from '../services/item-details-service.js';
6
- import { EnhancedModifier, EnhancedModifierGroup, EnhancedVariant } from '@wix/headless-restaurants-menus/services';
5
+ import { EnhancedVariant } from '@wix/headless-restaurants-menus/services';
7
6
  import { AvailabilityStatus, AvailabilityStatusMap } from '../services/common-types.js';
8
7
  /**
9
8
  * Root component for menu item display and interaction.
@@ -26,136 +25,6 @@ export interface RootProps {
26
25
  itemDetailsServiceConfig?: ItemServiceConfig;
27
26
  }
28
27
  export declare const Root: ({ children, itemDetailsServiceConfig }: RootProps) => import("react/jsx-runtime").JSX.Element;
29
- /**
30
- * Displays the item name with customizable rendering.
31
- *
32
- * @component
33
- * @example
34
- * ```tsx
35
- * <ItemDetails.Name />
36
- * <ItemDetails.Name asChild>
37
- * <h2 className="font-heading text-lg" />
38
- * </ItemDetails.Name>
39
- * ```
40
- */
41
- export interface ItemDetailsNameProps {
42
- asChild?: boolean;
43
- /** Custom render function when using asChild */
44
- children?: AsChildChildren<{
45
- name: string;
46
- }>;
47
- /** CSS classes to apply to the default element */
48
- className?: string;
49
- }
50
- export declare const Name: React.ForwardRefExoticComponent<ItemDetailsNameProps & React.RefAttributes<HTMLElement>>;
51
- /**
52
- * Displays the item price with customizable rendering.
53
- *
54
- * @component
55
- * @example
56
- * ```tsx
57
- * <ItemDetails.Price />
58
- * <ItemDetails.Price asChild>
59
- * <span className="font-semibold text-lg" />
60
- * </ItemDetails.Price>
61
- * ```
62
- */
63
- export interface ItemDetailsPriceProps {
64
- asChild?: boolean;
65
- /** CSS classes to apply to the default element */
66
- className?: string;
67
- }
68
- export declare const Price: React.ForwardRefExoticComponent<ItemDetailsPriceProps & React.RefAttributes<HTMLElement>>;
69
- /**
70
- * Displays the item description with customizable rendering.
71
- *
72
- * @component
73
- * @example
74
- * ```tsx
75
- * <ItemDetails.Description />
76
- * <ItemDetails.Description asChild>
77
- * <p className="text-sm" />
78
- * </ItemDetails.Description>
79
- * ```
80
- */
81
- export interface ItemDetailsDescriptionProps {
82
- asChild?: boolean;
83
- /** CSS classes to apply to the default element */
84
- className?: string;
85
- }
86
- export declare const Description: React.ForwardRefExoticComponent<ItemDetailsDescriptionProps & React.RefAttributes<HTMLElement>>;
87
- /**
88
- * Wrapper component for CoreItemDetails.ModifierComponent.
89
- * Renders a single modifier with checkbox functionality.
90
- *
91
- * @component
92
- * @example
93
- * ```tsx
94
- * <ItemDetails.Modifier>
95
- * {({ modifier, isSelected, onToggle }) => (
96
- * <div style={{ display: "flex", alignItems: "center" }}>
97
- * <CheckboxPrimitive.Root
98
- * className="CheckboxRoot"
99
- * checked={isSelected}
100
- * onCheckedChange={onToggle}
101
- * id={modifier._id}
102
- * >
103
- * <CheckboxPrimitive.Indicator className="CheckboxIndicator">
104
- * <CheckIcon />
105
- * </CheckboxPrimitive.Indicator>
106
- * </CheckboxPrimitive.Root>
107
- * <label className="Label" htmlFor={modifier._id}>
108
- * {modifier.name}
109
- * </label>
110
- * </div>
111
- * )}
112
- * </ItemDetails.Modifier>
113
- * ```
114
- */
115
- export interface ItemDetailsModifiersSingleSelectProps {
116
- children?: AsChildChildren<{
117
- selectedModifierIds: string[];
118
- onToggle: (modifierId: string) => void;
119
- modifierGroup: EnhancedModifierGroup;
120
- modifiers: EnhancedModifier[];
121
- }>;
122
- className?: string;
123
- asChild?: boolean;
124
- modifierNameClassName?: string;
125
- modifierPriceClassName?: string;
126
- }
127
- export interface ModifierCheckboxProps {
128
- selectedModifierIds: string[];
129
- onToggle: (modifierId: string) => void;
130
- className?: string;
131
- asChild?: boolean;
132
- modifierNameClassName?: string;
133
- modifierPriceClassName?: string;
134
- children?: AsChildChildren<{
135
- selectedModifierIds: string[];
136
- onToggle: (modifierId: string) => void;
137
- }>;
138
- }
139
- export declare const ModifierCheckbox: React.ForwardRefExoticComponent<ModifierCheckboxProps & React.RefAttributes<HTMLElement>>;
140
- export interface ModifierRadioProps {
141
- modifierNameClassName?: string;
142
- modifierPriceClassName?: string;
143
- }
144
- export declare const ModifierRadio: React.ForwardRefExoticComponent<ModifierRadioProps & React.RefAttributes<HTMLElement>>;
145
- export declare const ModifiersSingleSelect: React.ForwardRefExoticComponent<ItemDetailsModifiersSingleSelectProps & React.RefAttributes<HTMLElement>>;
146
- export interface ItemDetailsModifiersMultiSelectProps {
147
- children?: AsChildChildren<{
148
- selectedModifierIds: string[];
149
- onToggle: (modifierId: string) => void;
150
- modifierGroup: EnhancedModifierGroup;
151
- modifiers: EnhancedModifier[];
152
- }>;
153
- className?: string;
154
- asChild?: boolean;
155
- modifierNameClassName?: string;
156
- modifierPriceClassName?: string;
157
- }
158
- export declare const ModifiersMultiSelect: React.ForwardRefExoticComponent<ItemDetailsModifiersMultiSelectProps & React.RefAttributes<HTMLElement>>;
159
28
  /**
160
29
  * Wrapper component for CoreItemDetails.VariantsComponent.
161
30
  * Renders the variants for the item using Radix UI RadioGroup.
@@ -170,7 +39,9 @@ export declare const ModifiersMultiSelect: React.ForwardRefExoticComponent<ItemD
170
39
  */
171
40
  export interface ItemDetailsVariantsProps {
172
41
  children?: AsChildChildren<{
42
+ variant: EnhancedVariant;
173
43
  variants: EnhancedVariant[];
44
+ hasVariants: boolean;
174
45
  selectedVariantId?: string;
175
46
  onVariantChange?: (variantId: string) => void;
176
47
  }>;
@@ -178,37 +49,9 @@ export interface ItemDetailsVariantsProps {
178
49
  asChild?: boolean;
179
50
  variantNameClassName?: string;
180
51
  variantPriceClassName?: string;
52
+ emptyState?: React.ReactNode;
181
53
  }
182
54
  export declare const Variants: React.ForwardRefExoticComponent<ItemDetailsVariantsProps & React.RefAttributes<HTMLElement>>;
183
- export interface AddToCartActionProps {
184
- /** Whether to render as a child component */
185
- asChild?: boolean;
186
- /** Text label for the button */
187
- label: string;
188
- /** Custom render function when using asChild */
189
- lineItems: LineItem[];
190
- /** CSS classes to apply to the button */
191
- className?: string;
192
- /** Content to display when loading */
193
- loadingState?: string | React.ReactNode;
194
- children?: React.ReactNode;
195
- }
196
- /**
197
- * Add to Cart button for the menu item.
198
- * Triggers the action to add the selected item (and its modifiers/variants) to the cart.
199
- *
200
- * @component
201
- * @example
202
- * ```tsx
203
- * <ItemDetails>
204
- * <AddToCart
205
- * label="Add to Cart"
206
- * lineItems={[{ catalogReference: { ... }, quantity: 1 }]}
207
- * />
208
- * </ItemDetails>
209
- * ```
210
- */
211
- export declare const AddToCart: React.ForwardRefExoticComponent<AddToCartActionProps & React.RefAttributes<HTMLButtonElement>>;
212
55
  /**
213
56
  * Multi-line text input component for special requests or instructions.
214
57
  * Provides a textarea for customers to add custom notes or modifications.
@@ -256,7 +99,6 @@ export interface AddToCartButtonProps extends Omit<React.ComponentPropsWithoutRe
256
99
  children?: React.ReactNode;
257
100
  className?: string;
258
101
  label?: string;
259
- onClick?: () => void;
260
102
  }
261
103
  export interface ItemDetailsQuantityProps {
262
104
  children: React.ReactNode;
@@ -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 ||
@@ -89,29 +38,8 @@ export const Variants = React.forwardRef(({ children, className, asChild, varian
89
38
  } }));
90
39
  });
91
40
  Variants.displayName = 'ItemDetails.Variants';
92
- /**
93
- * Add to Cart button for the menu item.
94
- * Triggers the action to add the selected item (and its modifiers/variants) to the cart.
95
- *
96
- * @component
97
- * @example
98
- * ```tsx
99
- * <ItemDetails>
100
- * <AddToCart
101
- * label="Add to Cart"
102
- * lineItems={[{ catalogReference: { ... }, quantity: 1 }]}
103
- * />
104
- * </ItemDetails>
105
- * ```
106
- */
107
- export const AddToCart = React.forwardRef(({ lineItems, className, label, ...props }, ref) => {
108
- return (_jsx(Commerce.Actions.AddToCart, { ref: ref, asChild: false, label: label, className: className, lineItems: lineItems, children: props.children }));
109
- });
110
- AddToCart.displayName = 'AddToCart';
111
- export const AddToCartButton = ({ asChild = false, children, className, onClick, label = 'Add to cart', ...props }) => {
112
- return (_jsx(CoreItemDetails.LineItemComponent, { children: ({ lineItem }) => (_jsx(AsChildSlot, { asChild: asChild, className: className, customElement: children, customElementProps: {
113
- onClick,
114
- }, children: _jsx(Commerce.Actions.AddToCart, { asChild: false, label: label, className: className, lineItems: [lineItem], ...props, children: children }) })) }));
41
+ export const AddToCartButton = ({ asChild, children, className, label = 'Add to cart', ...props }) => {
42
+ return (_jsx(CoreItemDetails.LineItemComponent, { children: ({ lineItem }) => (_jsx(Commerce.Actions.AddToCart, { asChild: asChild, label: label, className: className, lineItems: [lineItem], ...props, children: children })) }));
115
43
  };
116
44
  export const Quantity = ({ children }) => {
117
45
  return (_jsx(CoreItemDetails.QuantityComponent, { children: ({ quantity, onValueChange, }) => (_jsx(QuantityComponent.Root, { onValueChange: onValueChange, initialValue: quantity, children: children })) }));