@wix/headless-restaurants-olo 0.0.2 → 0.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/dist/react/ClickableItem.d.ts +9 -0
- package/cjs/dist/react/ClickableItem.js +14 -0
- package/cjs/dist/react/ItemDetails.d.ts +134 -2
- package/cjs/dist/react/ItemDetails.js +30 -15
- package/cjs/dist/react/OLO.d.ts +179 -0
- package/cjs/dist/react/OLO.js +134 -0
- package/cjs/dist/react/core/ClickableItem.d.ts +13 -0
- package/cjs/dist/react/core/ClickableItem.js +21 -0
- package/cjs/dist/react/core/ItemDetails.d.ts +1 -1
- package/cjs/dist/react/core/ItemDetails.js +14 -8
- package/cjs/dist/react/core/OLO.d.ts +92 -0
- package/cjs/dist/react/core/OLO.js +122 -0
- package/cjs/dist/react/core/index.d.ts +2 -0
- package/cjs/dist/react/core/index.js +2 -0
- package/cjs/dist/react/index.d.ts +3 -1
- package/cjs/dist/react/index.js +3 -1
- package/cjs/dist/services/item-details-service.d.ts +2 -2
- package/dist/react/ClickableItem.d.ts +9 -0
- package/dist/react/ClickableItem.js +14 -0
- package/dist/react/ItemDetails.d.ts +134 -2
- package/dist/react/ItemDetails.js +30 -15
- package/dist/react/OLO.d.ts +179 -0
- package/dist/react/OLO.js +134 -0
- package/dist/react/core/ClickableItem.d.ts +13 -0
- package/dist/react/core/ClickableItem.js +21 -0
- package/dist/react/core/ItemDetails.d.ts +1 -1
- package/dist/react/core/ItemDetails.js +14 -8
- package/dist/react/core/OLO.d.ts +92 -0
- package/dist/react/core/OLO.js +122 -0
- package/dist/react/core/index.d.ts +2 -0
- package/dist/react/core/index.js +2 -0
- package/dist/react/index.d.ts +3 -1
- package/dist/react/index.js +3 -1
- package/dist/services/item-details-service.d.ts +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { OLOSettingsServiceConfig } from '../../services/olo-settings-service.js';
|
|
3
|
+
import { ItemServiceConfig } from '../../services/item-details-service.js';
|
|
4
|
+
interface CoreOLORootProps {
|
|
5
|
+
/** The ID of the item to load */
|
|
6
|
+
itemId?: string;
|
|
7
|
+
/** Pre-loaded item service config (optional) */
|
|
8
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
9
|
+
/** Pre-loaded cart service config (optional) */
|
|
10
|
+
cartServiceConfig?: any;
|
|
11
|
+
/** Pre-loaded OLO settings service config (optional) */
|
|
12
|
+
oloSettingsServiceConfig?: OLOSettingsServiceConfig;
|
|
13
|
+
/** Children render prop that receives the services manager state */
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Core OLO Root component that sets up service management
|
|
18
|
+
* Provides ItemService and CurrentCartService to child components
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```tsx
|
|
22
|
+
* <CoreOLO.Root itemId="item-123">
|
|
23
|
+
* {({ servicesManager, isLoading, hasServices }) => (
|
|
24
|
+
* hasServices ? (
|
|
25
|
+
* <ServicesManagerProvider servicesManager={servicesManager}>
|
|
26
|
+
* <ItemDetailsComponents />
|
|
27
|
+
* </ServicesManagerProvider>
|
|
28
|
+
* ) : (
|
|
29
|
+
* <LoadingSpinner />
|
|
30
|
+
* )
|
|
31
|
+
* )}
|
|
32
|
+
* </CoreOLO.Root>
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export declare const Root: React.FC<CoreOLORootProps>;
|
|
36
|
+
interface CoreOLOProviderProps {
|
|
37
|
+
/** The ID of the item to load */
|
|
38
|
+
itemId?: string;
|
|
39
|
+
/** Pre-loaded item service config (optional) */
|
|
40
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
41
|
+
/** Pre-loaded cart service config (optional) */
|
|
42
|
+
cartServiceConfig?: any;
|
|
43
|
+
/** Pre-loaded OLO settings service config (optional) */
|
|
44
|
+
oloSettingsServiceConfig?: OLOSettingsServiceConfig;
|
|
45
|
+
/** Loading component to show while services are initializing */
|
|
46
|
+
loading?: React.ReactNode;
|
|
47
|
+
/** Error component to show if service initialization fails */
|
|
48
|
+
error?: (error: string) => React.ReactNode;
|
|
49
|
+
/** Children that will receive the services context */
|
|
50
|
+
children: React.ReactNode;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Convenience wrapper that combines Root with ServicesManagerProvider
|
|
54
|
+
* Automatically provides services context to children
|
|
55
|
+
*
|
|
56
|
+
* @example
|
|
57
|
+
* ```tsx
|
|
58
|
+
* <CoreOLO.Provider itemId="item-123">
|
|
59
|
+
* <ItemDetailsComponents />
|
|
60
|
+
* </CoreOLO.Provider>
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export declare const Provider: React.FC<CoreOLOProviderProps>;
|
|
64
|
+
interface CoreOLOItemDetailsProps {
|
|
65
|
+
/** The ID of the item to load */
|
|
66
|
+
itemId: string;
|
|
67
|
+
/** Pre-loaded configurations (optional) */
|
|
68
|
+
configs?: {
|
|
69
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
70
|
+
cartServiceConfig?: any;
|
|
71
|
+
};
|
|
72
|
+
/** Loading component */
|
|
73
|
+
loading?: React.ReactNode;
|
|
74
|
+
/** Error component */
|
|
75
|
+
error?: (error: string) => React.ReactNode;
|
|
76
|
+
/** Children that will have access to item services */
|
|
77
|
+
children: React.ReactNode;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Specialized wrapper for item details that ensures ItemService is available
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* <CoreOLO.ItemDetails itemId="item-123">
|
|
85
|
+
* <ItemDetailsPrimitive.Root>
|
|
86
|
+
* {({ item }) => <div>{item.name}</div>}
|
|
87
|
+
* </ItemDetailsPrimitive.Root>
|
|
88
|
+
* </CoreOLO.ItemDetails>
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export declare const ItemDetails: React.FC<CoreOLOItemDetailsProps>;
|
|
92
|
+
export {};
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
import { createServicesMap } from '@wix/services-manager';
|
|
4
|
+
import { WixServices } from '@wix/services-manager-react';
|
|
5
|
+
// import { ItemService, ItemServiceDefinition, loadItemServiceConfig } from '@/components/restaurants-olo/services/itemDetailsService';
|
|
6
|
+
import { OLOSettingsService, OLOSettingsServiceDefinition, } from '@wix/headless-restaurants-olo/services';
|
|
7
|
+
/**
|
|
8
|
+
* Core OLO Root component that sets up service management
|
|
9
|
+
* Provides ItemService and CurrentCartService to child components
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* <CoreOLO.Root itemId="item-123">
|
|
14
|
+
* {({ servicesManager, isLoading, hasServices }) => (
|
|
15
|
+
* hasServices ? (
|
|
16
|
+
* <ServicesManagerProvider servicesManager={servicesManager}>
|
|
17
|
+
* <ItemDetailsComponents />
|
|
18
|
+
* </ServicesManagerProvider>
|
|
19
|
+
* ) : (
|
|
20
|
+
* <LoadingSpinner />
|
|
21
|
+
* )
|
|
22
|
+
* )}
|
|
23
|
+
* </CoreOLO.Root>
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export const Root = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettingsServiceConfig, children, }) => {
|
|
27
|
+
// const [servicesManager, setServicesManager] = useState<ServicesManager | null>(null);
|
|
28
|
+
// const [isLoading, setIsLoading] = useState(true);
|
|
29
|
+
// const [error, setError] = useState<string | undefined>();
|
|
30
|
+
useEffect(() => {
|
|
31
|
+
// const initializeServices = async () => {
|
|
32
|
+
// setIsLoading(true);
|
|
33
|
+
// setError(undefined);
|
|
34
|
+
// try {
|
|
35
|
+
// // Load configurations if not provided
|
|
36
|
+
// const loadedConfigs = await Promise.all([
|
|
37
|
+
// cartServiceConfig || loadCurrentCartServiceConfig(),
|
|
38
|
+
// itemServiceConfig || (loadItemServiceConfig(itemId))
|
|
39
|
+
// ]);
|
|
40
|
+
// const [currentCartServiceConfig, itemServiceConfigResult] = loadedConfigs;
|
|
41
|
+
// // Handle item service config result (discriminated union)
|
|
42
|
+
// if (itemServiceConfigResult && 'type' in itemServiceConfigResult) {
|
|
43
|
+
// if (itemServiceConfigResult.type === 'notFound') {
|
|
44
|
+
// setError('Item not found');
|
|
45
|
+
// return;
|
|
46
|
+
// }
|
|
47
|
+
// // Use the config from the success result
|
|
48
|
+
// const finalItemServiceConfig = itemServiceConfigResult.config;
|
|
49
|
+
// // Create services manager with both services
|
|
50
|
+
// const manager = createServicesManager(
|
|
51
|
+
// createServicesMap()
|
|
52
|
+
// .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
|
|
53
|
+
// // .addService(ItemServiceDefinition, ItemService, finalItemServiceConfig)
|
|
54
|
+
// );
|
|
55
|
+
// setServicesManager(manager);
|
|
56
|
+
// } else if (itemServiceConfigResult) {
|
|
57
|
+
// // Direct config provided
|
|
58
|
+
// const manager = createServicesManager(
|
|
59
|
+
// createServicesMap()
|
|
60
|
+
// .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
|
|
61
|
+
// // .addService(ItemServiceDefinition, ItemService, itemServiceConfigResult)
|
|
62
|
+
// );
|
|
63
|
+
// setServicesManager(manager);
|
|
64
|
+
// } else {
|
|
65
|
+
// // Only cart service, no item service
|
|
66
|
+
// const manager = createServicesManager(
|
|
67
|
+
// createServicesMap()
|
|
68
|
+
// .addService(CurrentCartServiceDefinition, CurrentCartService, currentCartServiceConfig)
|
|
69
|
+
// );
|
|
70
|
+
// setServicesManager(manager);
|
|
71
|
+
// }
|
|
72
|
+
// } catch (err) {
|
|
73
|
+
// console.error('Failed to initialize services:', err);
|
|
74
|
+
// setError('Failed to initialize services');
|
|
75
|
+
// } finally {
|
|
76
|
+
// setIsLoading(false);
|
|
77
|
+
// }
|
|
78
|
+
// };
|
|
79
|
+
// initializeServices();
|
|
80
|
+
}, [itemId, itemServiceConfig, cartServiceConfig]);
|
|
81
|
+
// const hasServices = Boolean(servicesManager);
|
|
82
|
+
// return children({
|
|
83
|
+
// servicesManager,
|
|
84
|
+
// isLoading,
|
|
85
|
+
// error,
|
|
86
|
+
// hasServices
|
|
87
|
+
// });
|
|
88
|
+
console.log('oloSettingsServiceConfig', oloSettingsServiceConfig);
|
|
89
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(OLOSettingsServiceDefinition, OLOSettingsService, oloSettingsServiceConfig), children: children }));
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Convenience wrapper that combines Root with ServicesManagerProvider
|
|
93
|
+
* Automatically provides services context to children
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```tsx
|
|
97
|
+
* <CoreOLO.Provider itemId="item-123">
|
|
98
|
+
* <ItemDetailsComponents />
|
|
99
|
+
* </CoreOLO.Provider>
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
export const Provider = ({ itemId, itemServiceConfig, cartServiceConfig, oloSettingsServiceConfig,
|
|
103
|
+
// loading = <div>Loading services...</div>,
|
|
104
|
+
// error: errorComponent = (error: string) => <div>Error: {error}</div>,
|
|
105
|
+
children, }) => {
|
|
106
|
+
return (_jsx(Root, { itemId: itemId, itemServiceConfig: itemServiceConfig, cartServiceConfig: cartServiceConfig, oloSettingsServiceConfig: oloSettingsServiceConfig, children: children }));
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Specialized wrapper for item details that ensures ItemService is available
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```tsx
|
|
113
|
+
* <CoreOLO.ItemDetails itemId="item-123">
|
|
114
|
+
* <ItemDetailsPrimitive.Root>
|
|
115
|
+
* {({ item }) => <div>{item.name}</div>}
|
|
116
|
+
* </ItemDetailsPrimitive.Root>
|
|
117
|
+
* </CoreOLO.ItemDetails>
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export const ItemDetails = ({ itemId, configs, loading, error, children, }) => {
|
|
121
|
+
return (_jsx(Provider, { itemId: itemId, itemServiceConfig: configs?.itemServiceConfig, cartServiceConfig: configs?.cartServiceConfig, loading: loading, error: error, children: children }));
|
|
122
|
+
};
|
package/cjs/dist/react/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import { type LineItem } from '@wix/ecom/services';
|
|
|
9
9
|
*/
|
|
10
10
|
export interface ItemServiceAPI {
|
|
11
11
|
/** Reactive signal containing the current item data */
|
|
12
|
-
item
|
|
12
|
+
item?: Signal<items.Item | undefined>;
|
|
13
13
|
quantity: Signal<number>;
|
|
14
14
|
specialRequest: Signal<string>;
|
|
15
15
|
lineItem: Signal<LineItem>;
|
|
@@ -41,7 +41,7 @@ export declare const ItemServiceDefinition: string & {
|
|
|
41
41
|
*/
|
|
42
42
|
export interface ItemServiceConfig {
|
|
43
43
|
/** The initial item data to configure the service with */
|
|
44
|
-
item
|
|
44
|
+
item?: items.Item;
|
|
45
45
|
itemId?: string;
|
|
46
46
|
operationId?: string;
|
|
47
47
|
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
declare function ClickableItem({ onItemSelected, children, }: {
|
|
3
|
+
onItemSelected: (item: any) => void;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
6
|
+
export declare const Actions: {
|
|
7
|
+
Select: typeof ClickableItem;
|
|
8
|
+
};
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { CoreClickableItem } from './core/ClickableItem.js';
|
|
3
|
+
function ClickableItem({ onItemSelected, children, }) {
|
|
4
|
+
const selectItem = (item, callback) => {
|
|
5
|
+
callback();
|
|
6
|
+
onItemSelected(item);
|
|
7
|
+
};
|
|
8
|
+
return (_jsx(CoreClickableItem, { children: ({ item, itemSelected }) => (_jsx("div", { onClick: () => {
|
|
9
|
+
selectItem(item, itemSelected);
|
|
10
|
+
}, children: children })) }));
|
|
11
|
+
}
|
|
12
|
+
export const Actions = {
|
|
13
|
+
Select: ClickableItem,
|
|
14
|
+
};
|
|
@@ -21,7 +21,7 @@ import { ItemServiceConfig } from '../services/item-details-service.js';
|
|
|
21
21
|
export interface RootProps {
|
|
22
22
|
asChild?: boolean;
|
|
23
23
|
children: React.ReactNode;
|
|
24
|
-
itemDetailsServiceConfig
|
|
24
|
+
itemDetailsServiceConfig?: ItemServiceConfig;
|
|
25
25
|
}
|
|
26
26
|
export declare const Root: ({ children, itemDetailsServiceConfig }: RootProps) => import("react/jsx-runtime").JSX.Element;
|
|
27
27
|
/**
|
|
@@ -36,7 +36,6 @@ export declare const Root: ({ children, itemDetailsServiceConfig }: RootProps) =
|
|
|
36
36
|
* </ItemDetails.Name>
|
|
37
37
|
* ```
|
|
38
38
|
*/
|
|
39
|
-
export declare const Name: React.ForwardRefExoticComponent<ItemDetailsNameProps & React.RefAttributes<HTMLElement>>;
|
|
40
39
|
export interface ItemDetailsNameProps {
|
|
41
40
|
asChild?: boolean;
|
|
42
41
|
/** Custom render function when using asChild */
|
|
@@ -46,6 +45,139 @@ export interface ItemDetailsNameProps {
|
|
|
46
45
|
/** CSS classes to apply to the default element */
|
|
47
46
|
className?: string;
|
|
48
47
|
}
|
|
48
|
+
export declare const Name: React.ForwardRefExoticComponent<ItemDetailsNameProps & React.RefAttributes<HTMLElement>>;
|
|
49
|
+
/**
|
|
50
|
+
* Displays the item image with customizable rendering.
|
|
51
|
+
*
|
|
52
|
+
* @component
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* <ItemDetails.Image />
|
|
56
|
+
* <ItemDetails.Image asChild>
|
|
57
|
+
* <img className="rounded" />
|
|
58
|
+
* </ItemDetails.Image>
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
export interface ItemDetailsImageProps {
|
|
62
|
+
asChild?: boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Custom render function when using asChild.
|
|
65
|
+
* Receives an object with:
|
|
66
|
+
* - hasImage: boolean - whether the item has an image
|
|
67
|
+
* - image: string - the actual image element (WixMediaImage)
|
|
68
|
+
* - altText: string - the alt text for the image
|
|
69
|
+
*/
|
|
70
|
+
children?: (props: {
|
|
71
|
+
hasImage: boolean;
|
|
72
|
+
image?: string;
|
|
73
|
+
altText: string;
|
|
74
|
+
}) => React.ReactNode;
|
|
75
|
+
/** CSS classes to apply to the default element */
|
|
76
|
+
className?: string;
|
|
77
|
+
}
|
|
78
|
+
export declare const Image: React.ForwardRefExoticComponent<ItemDetailsImageProps & React.RefAttributes<HTMLElement>>;
|
|
79
|
+
/**
|
|
80
|
+
* Displays the item price with customizable rendering.
|
|
81
|
+
*
|
|
82
|
+
* @component
|
|
83
|
+
* @example
|
|
84
|
+
* ```tsx
|
|
85
|
+
* <ItemDetails.Price />
|
|
86
|
+
* <ItemDetails.Price asChild>
|
|
87
|
+
* <span className="font-semibold text-lg" />
|
|
88
|
+
* </ItemDetails.Price>
|
|
89
|
+
* ```
|
|
90
|
+
*/
|
|
91
|
+
export interface ItemDetailsPriceProps {
|
|
92
|
+
asChild?: boolean;
|
|
93
|
+
/** CSS classes to apply to the default element */
|
|
94
|
+
className?: string;
|
|
95
|
+
}
|
|
96
|
+
export declare const Price: React.ForwardRefExoticComponent<ItemDetailsPriceProps & React.RefAttributes<HTMLElement>>;
|
|
97
|
+
/**
|
|
98
|
+
* Displays the item description with customizable rendering.
|
|
99
|
+
*
|
|
100
|
+
* @component
|
|
101
|
+
* @example
|
|
102
|
+
* ```tsx
|
|
103
|
+
* <ItemDetails.Description />
|
|
104
|
+
* <ItemDetails.Description asChild>
|
|
105
|
+
* <p className="text-sm" />
|
|
106
|
+
* </ItemDetails.Description>
|
|
107
|
+
* ```
|
|
108
|
+
*/
|
|
109
|
+
export interface ItemDetailsDescriptionProps {
|
|
110
|
+
asChild?: boolean;
|
|
111
|
+
/** CSS classes to apply to the default element */
|
|
112
|
+
className?: string;
|
|
113
|
+
}
|
|
114
|
+
export declare const Description: React.ForwardRefExoticComponent<ItemDetailsDescriptionProps & React.RefAttributes<HTMLElement>>;
|
|
115
|
+
/**
|
|
116
|
+
* Wrapper component for Item.LabelsRepeater.
|
|
117
|
+
* Renders the labels for the item using the headless component.
|
|
118
|
+
*
|
|
119
|
+
* @component
|
|
120
|
+
* @example
|
|
121
|
+
* ```tsx
|
|
122
|
+
* <ItemDetails.Labels>
|
|
123
|
+
* {(label) => <span>{label.name}</span>}
|
|
124
|
+
* </ItemDetails.Labels>
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
export interface ItemDetailsLabelsProps {
|
|
128
|
+
children?: AsChildChildren<{
|
|
129
|
+
label: string;
|
|
130
|
+
}>;
|
|
131
|
+
className?: string;
|
|
132
|
+
asChild?: boolean;
|
|
133
|
+
iconClassName?: string;
|
|
134
|
+
nameClassName?: string;
|
|
135
|
+
}
|
|
136
|
+
export declare const Labels: React.ForwardRefExoticComponent<ItemDetailsLabelsProps & React.RefAttributes<HTMLElement>>;
|
|
137
|
+
/**
|
|
138
|
+
* Wrapper component for Item.ModifierGroupsRepeater.
|
|
139
|
+
* Renders the modifier groups for the item using the headless component.
|
|
140
|
+
*
|
|
141
|
+
* @component
|
|
142
|
+
* @example
|
|
143
|
+
* ```tsx
|
|
144
|
+
* <ItemDetails.ModifierGroups>
|
|
145
|
+
* {(modifierGroup) => <span>{modifierGroup.name}</span>}
|
|
146
|
+
* </ItemDetails.ModifierGroups>
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export interface ItemDetailsModifierGroupsProps {
|
|
150
|
+
children?: AsChildChildren<{
|
|
151
|
+
modifierGroup: any;
|
|
152
|
+
}>;
|
|
153
|
+
className?: string;
|
|
154
|
+
asChild?: boolean;
|
|
155
|
+
modifierNameClassName?: string;
|
|
156
|
+
modifierPriceClassName?: string;
|
|
157
|
+
}
|
|
158
|
+
export declare const ModifierGroups: React.ForwardRefExoticComponent<ItemDetailsModifierGroupsProps & React.RefAttributes<HTMLElement>>;
|
|
159
|
+
/**
|
|
160
|
+
* Wrapper component for Item.VariantsRepeater.
|
|
161
|
+
* Renders the variants for the item using the headless component.
|
|
162
|
+
*
|
|
163
|
+
* @component
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* <ItemDetails.Variants>
|
|
167
|
+
* {(variant) => <span>{variant.name}</span>}
|
|
168
|
+
* </ItemDetails.Variants>
|
|
169
|
+
* ```
|
|
170
|
+
*/
|
|
171
|
+
export interface ItemDetailsVariantsProps {
|
|
172
|
+
children?: AsChildChildren<{
|
|
173
|
+
variant: any;
|
|
174
|
+
}>;
|
|
175
|
+
className?: string;
|
|
176
|
+
asChild?: boolean;
|
|
177
|
+
variantNameClassName?: string;
|
|
178
|
+
variantPriceClassName?: string;
|
|
179
|
+
}
|
|
180
|
+
export declare const Variants: React.ForwardRefExoticComponent<ItemDetailsVariantsProps & React.RefAttributes<HTMLElement>>;
|
|
49
181
|
export interface AddToCartActionProps {
|
|
50
182
|
/** Whether to render as a child component */
|
|
51
183
|
asChild?: boolean;
|
|
@@ -3,7 +3,7 @@ import React from 'react';
|
|
|
3
3
|
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
|
-
import { Item } from '@wix/restaurants/components';
|
|
6
|
+
import { Item, Label, Modifier, ModifierGroup, Variant, } from '@wix/restaurants/components';
|
|
7
7
|
import * as CoreItemDetails from './core/ItemDetails.js';
|
|
8
8
|
var TestIds;
|
|
9
9
|
(function (TestIds) {
|
|
@@ -13,26 +13,41 @@ var TestIds;
|
|
|
13
13
|
TestIds["itemImage"] = "item-image";
|
|
14
14
|
TestIds["itemAddToCart"] = "item-add-to-cart";
|
|
15
15
|
TestIds["itemSpecialRequest"] = "item-special-request";
|
|
16
|
+
TestIds["itemLabels"] = "item-labels";
|
|
17
|
+
TestIds["itemModifierGroups"] = "item-modifier-groups";
|
|
18
|
+
TestIds["itemVariants"] = "item-variants";
|
|
16
19
|
})(TestIds || (TestIds = {}));
|
|
17
20
|
export const Root = ({ children, itemDetailsServiceConfig }) => {
|
|
18
21
|
return (_jsx(CoreItemDetails.Root, { itemDetailsServiceConfig: itemDetailsServiceConfig, children: ({ item }) => _jsx(Item.Root, { item: item, children: children }) }));
|
|
19
22
|
};
|
|
20
|
-
/**
|
|
21
|
-
* Displays the item name with customizable rendering.
|
|
22
|
-
*
|
|
23
|
-
* @component
|
|
24
|
-
* @example
|
|
25
|
-
* ```tsx
|
|
26
|
-
* <ItemDetails.Name />
|
|
27
|
-
* <ItemDetails.Name asChild>
|
|
28
|
-
* <h2 className="font-heading text-lg" />
|
|
29
|
-
* </ItemDetails.Name>
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
32
23
|
export const Name = React.forwardRef(({ asChild, children, className, ...rest }, ref) => {
|
|
33
24
|
return (_jsx(Item.Name, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.itemName, ...rest, children: children }));
|
|
34
25
|
});
|
|
35
26
|
Name.displayName = 'ItemDetails.Name';
|
|
27
|
+
export const Image = React.forwardRef(({ asChild, children, className, ...rest }) => {
|
|
28
|
+
return (_jsx(Item.Image, { asChild: asChild, className: className, "data-testid": TestIds.itemImage, ...rest, children: children }));
|
|
29
|
+
});
|
|
30
|
+
Image.displayName = 'ItemDetails.Image';
|
|
31
|
+
export const Price = React.forwardRef(({ asChild, className, ...rest }, ref) => {
|
|
32
|
+
return (_jsx(Item.Price, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.itemPrice, ...rest }));
|
|
33
|
+
});
|
|
34
|
+
Price.displayName = 'ItemDetails.Price';
|
|
35
|
+
export const Description = React.forwardRef(({ asChild, className, ...rest }, ref) => {
|
|
36
|
+
return (_jsx(Item.Description, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.itemDescription, ...rest }));
|
|
37
|
+
});
|
|
38
|
+
Description.displayName = 'ItemDetails.Description';
|
|
39
|
+
export const Labels = React.forwardRef(({ children, className, asChild, iconClassName, nameClassName, ...rest }) => {
|
|
40
|
+
return (_jsx(Item.LabelsRepeater, { ...rest, children: _jsxs(AsChildSlot, { asChild: asChild, testId: TestIds.itemLabels, className: className, customElement: children, children: [_jsx(Label.Icon, { className: iconClassName }), _jsx(Label.Name, { className: nameClassName })] }) }));
|
|
41
|
+
});
|
|
42
|
+
Labels.displayName = 'ItemDetails.Labels';
|
|
43
|
+
export const ModifierGroups = React.forwardRef(({ children, className, asChild, modifierNameClassName, modifierPriceClassName, ...rest }) => {
|
|
44
|
+
return (_jsx(Item.ModifierGroupsRepeater, { ...rest, children: _jsx(AsChildSlot, { asChild: asChild, testId: TestIds.itemModifierGroups, className: className, customElement: children, children: _jsxs(ModifierGroup.ModifiersRepeater, { children: [_jsx(Modifier.Name, { className: modifierNameClassName }), _jsx(Modifier.Price, { className: modifierPriceClassName })] }) }) }));
|
|
45
|
+
});
|
|
46
|
+
export const Variants = React.forwardRef(({ children, className, asChild, variantNameClassName, variantPriceClassName, ...rest }) => {
|
|
47
|
+
return (_jsx(Item.VariantsRepeater, { ...rest, children: _jsxs(AsChildSlot, { asChild: asChild, testId: TestIds.itemVariants, className: className, customElement: children, children: [_jsx(Variant.Name, { className: variantNameClassName }), _jsx(Variant.Price, { className: variantPriceClassName })] }) }));
|
|
48
|
+
});
|
|
49
|
+
Variants.displayName = 'ItemDetails.Variants';
|
|
50
|
+
ModifierGroups.displayName = 'ItemDetails.ModifierGroups';
|
|
36
51
|
/**
|
|
37
52
|
* Add to Cart button for the menu item.
|
|
38
53
|
* Triggers the action to add the selected item (and its modifiers/variants) to the cart.
|
|
@@ -57,8 +72,8 @@ export const AddToCartButton = ({ asChild = false, children, className, onClick,
|
|
|
57
72
|
onClick,
|
|
58
73
|
}, children: _jsx(Commerce.Actions.AddToCart, { asChild: false, label: label, className: className, lineItems: [lineItem], ...props, children: children }) })) }));
|
|
59
74
|
};
|
|
60
|
-
export const Quantity = ({ children }
|
|
61
|
-
return (_jsx(CoreItemDetails.QuantityComponent, { children: ({ quantity, onValueChange, }) => (_jsx(QuantityComponent.Root, {
|
|
75
|
+
export const Quantity = ({ children }) => {
|
|
76
|
+
return (_jsx(CoreItemDetails.QuantityComponent, { children: ({ quantity, onValueChange, }) => (_jsx(QuantityComponent.Root, { onValueChange: onValueChange, initialValue: quantity, children: children })) }));
|
|
62
77
|
};
|
|
63
78
|
Quantity.displayName = 'Quantity';
|
|
64
79
|
export const SpecialRequest = React.forwardRef(({ className, labelClassName, placeholder = 'Any special requests or dietary restrictions?', maxLength = 200, rows = 3, label = 'Special Requests', asChild, children, ...props }, ref) => {
|