@wix/headless-restaurants-olo 0.0.2 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/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 +11 -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 +11 -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,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) => {
|
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ItemServiceConfig } from '../services/item-details-service.js';
|
|
3
|
+
interface OLORootProps {
|
|
4
|
+
/** The ID of the item to load */
|
|
5
|
+
itemId?: string;
|
|
6
|
+
/** Pre-loaded item service config (optional) */
|
|
7
|
+
itemServiceConfig?: any;
|
|
8
|
+
/** Pre-loaded OLO settings service config (optional) */
|
|
9
|
+
oloSettingsServiceConfig?: any;
|
|
10
|
+
/** Children render prop that receives the service state */
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Root headless component for OLO service management
|
|
15
|
+
* Wraps CoreOLO.Root and provides service state to children
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```tsx
|
|
19
|
+
* <OLO.Root itemId="item-123">
|
|
20
|
+
* {({ isLoading, hasServices, error, retry }) => (
|
|
21
|
+
* isLoading ? (
|
|
22
|
+
* <LoadingSpinner />
|
|
23
|
+
* ) : error ? (
|
|
24
|
+
* <ErrorMessage error={error} onRetry={retry} />
|
|
25
|
+
* ) : hasServices ? (
|
|
26
|
+
* <ItemDetailsComponents />
|
|
27
|
+
* ) : null
|
|
28
|
+
* )}
|
|
29
|
+
* </OLO.Root>
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare const Root: React.FC<OLORootProps>;
|
|
33
|
+
interface OLOProviderProps {
|
|
34
|
+
/** The ID of the item to load */
|
|
35
|
+
itemId?: string;
|
|
36
|
+
/** Pre-loaded configurations (optional) */
|
|
37
|
+
configs?: {
|
|
38
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
39
|
+
};
|
|
40
|
+
/** Loading component to show while services are initializing */
|
|
41
|
+
loading?: React.ReactNode;
|
|
42
|
+
/** Error component to show if service initialization fails */
|
|
43
|
+
error?: (props: {
|
|
44
|
+
error: string;
|
|
45
|
+
retry: () => void;
|
|
46
|
+
}) => React.ReactNode;
|
|
47
|
+
/** Children that will receive the services context */
|
|
48
|
+
children: React.ReactNode;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Convenience provider that handles loading and error states automatically
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* ```tsx
|
|
55
|
+
* <OLO.Provider
|
|
56
|
+
* itemId="item-123"
|
|
57
|
+
* loading={<Spinner />}
|
|
58
|
+
* error={({ error, retry }) => <ErrorBanner message={error} onRetry={retry} />}
|
|
59
|
+
* >
|
|
60
|
+
* <ItemDetailsComponents />
|
|
61
|
+
* </OLO.Provider>
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
export declare const Provider: React.FC<OLOProviderProps>;
|
|
65
|
+
interface OLOItemDetailsProps {
|
|
66
|
+
/** The ID of the item to load */
|
|
67
|
+
itemId: string;
|
|
68
|
+
/** Pre-loaded configurations (optional) */
|
|
69
|
+
configs?: {
|
|
70
|
+
itemServiceConfig?: ItemServiceConfig;
|
|
71
|
+
cartServiceConfig?: any;
|
|
72
|
+
};
|
|
73
|
+
/** Custom loading component */
|
|
74
|
+
loading?: React.ReactNode;
|
|
75
|
+
/** Custom error component */
|
|
76
|
+
error?: (props: {
|
|
77
|
+
error: string;
|
|
78
|
+
retry: () => void;
|
|
79
|
+
}) => React.ReactNode;
|
|
80
|
+
/** Custom not found component */
|
|
81
|
+
notFound?: React.ReactNode;
|
|
82
|
+
/** Children that will have access to item services */
|
|
83
|
+
children: React.ReactNode;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Specialized headless component for item details
|
|
87
|
+
* Includes item-specific error handling (like 404 not found)
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```tsx
|
|
91
|
+
* <OLO.ItemDetails
|
|
92
|
+
* itemId="item-123"
|
|
93
|
+
* notFound={<NotFoundPage />}
|
|
94
|
+
* >
|
|
95
|
+
* <ItemDetailsUI />
|
|
96
|
+
* </OLO.ItemDetails>
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export declare const ItemDetails: React.FC<OLOItemDetailsProps>;
|
|
100
|
+
interface OLOCartProps {
|
|
101
|
+
/** Pre-loaded cart service config (optional) */
|
|
102
|
+
cartServiceConfig?: any;
|
|
103
|
+
/** Loading component */
|
|
104
|
+
loading?: React.ReactNode;
|
|
105
|
+
/** Error component */
|
|
106
|
+
error?: (props: {
|
|
107
|
+
error: string;
|
|
108
|
+
retry: () => void;
|
|
109
|
+
}) => React.ReactNode;
|
|
110
|
+
/** Children that will have access to cart services */
|
|
111
|
+
children: React.ReactNode;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Headless component for cart-only functionality
|
|
115
|
+
* Doesn't load item services, only cart services
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* <OLO.Cart>
|
|
120
|
+
* <CartComponents />
|
|
121
|
+
* </OLO.Cart>
|
|
122
|
+
* ```
|
|
123
|
+
*/
|
|
124
|
+
export declare const Cart: React.FC<OLOCartProps>;
|
|
125
|
+
interface OLOServicesStatusProps {
|
|
126
|
+
/** The ID of the item to check */
|
|
127
|
+
itemId?: string;
|
|
128
|
+
/** Children render prop that receives service status */
|
|
129
|
+
children: React.ReactNode;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Headless component for checking service status
|
|
133
|
+
* Useful for debugging or conditional rendering
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```tsx
|
|
137
|
+
* <OLO.ServicesStatus itemId="item-123">
|
|
138
|
+
* {({ hasItemService, hasCartService, error }) => (
|
|
139
|
+
* <div>
|
|
140
|
+
* Item Service: {hasItemService ? '✅' : '❌'}
|
|
141
|
+
* Cart Service: {hasCartService ? '✅' : '❌'}
|
|
142
|
+
* {error && <div>Error: {error}</div>}
|
|
143
|
+
* </div>
|
|
144
|
+
* )}
|
|
145
|
+
* </OLO.ServicesStatus>
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
export declare const ServicesStatus: React.FC<OLOServicesStatusProps>;
|
|
149
|
+
/**
|
|
150
|
+
* Headless component for Menus service management.
|
|
151
|
+
* Wraps CoreOLO.Menus and provides render props for UI.
|
|
152
|
+
*
|
|
153
|
+
* @example
|
|
154
|
+
* ```tsx
|
|
155
|
+
* <OLO.Menus>
|
|
156
|
+
* {({ menus, isLoading, error }) => (
|
|
157
|
+
* isLoading ? (
|
|
158
|
+
* <div>Loading...</div>
|
|
159
|
+
* ) : error ? (
|
|
160
|
+
* <div className="text-destructive">{error}</div>
|
|
161
|
+
* ) : (
|
|
162
|
+
* <ul>
|
|
163
|
+
* {menus.map(menu => (
|
|
164
|
+
* <li key={menu.id} className="text-foreground font-paragraph">{menu.name}</li>
|
|
165
|
+
* ))}
|
|
166
|
+
* </ul>
|
|
167
|
+
* )
|
|
168
|
+
* )}
|
|
169
|
+
* </OLO.Menus>
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
interface OLOMenusProps {
|
|
173
|
+
/** Optional menu service config */
|
|
174
|
+
menuServiceConfig?: any;
|
|
175
|
+
/** Children render prop that receives menus state */
|
|
176
|
+
children?: React.ReactNode;
|
|
177
|
+
}
|
|
178
|
+
export declare const Menus: React.FC<OLOMenusProps>;
|
|
179
|
+
export {};
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { CoreOLO } from './core/index.js';
|
|
4
|
+
/**
|
|
5
|
+
* Root headless component for OLO service management
|
|
6
|
+
* Wraps CoreOLO.Root and provides service state to children
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* <OLO.Root itemId="item-123">
|
|
11
|
+
* {({ isLoading, hasServices, error, retry }) => (
|
|
12
|
+
* isLoading ? (
|
|
13
|
+
* <LoadingSpinner />
|
|
14
|
+
* ) : error ? (
|
|
15
|
+
* <ErrorMessage error={error} onRetry={retry} />
|
|
16
|
+
* ) : hasServices ? (
|
|
17
|
+
* <ItemDetailsComponents />
|
|
18
|
+
* ) : null
|
|
19
|
+
* )}
|
|
20
|
+
* </OLO.Root>
|
|
21
|
+
* ```
|
|
22
|
+
*/
|
|
23
|
+
export const Root = ({ itemId, oloSettingsServiceConfig, children, }) => {
|
|
24
|
+
const [retryKey] = React.useState(0);
|
|
25
|
+
// const retry = React.useCallback(() => {
|
|
26
|
+
// setRetryKey(prev => prev + 1);
|
|
27
|
+
// }, []);
|
|
28
|
+
return (_jsx(CoreOLO.Root, { itemId: itemId, oloSettingsServiceConfig: oloSettingsServiceConfig, children: children }, retryKey));
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Convenience provider that handles loading and error states automatically
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* <OLO.Provider
|
|
36
|
+
* itemId="item-123"
|
|
37
|
+
* loading={<Spinner />}
|
|
38
|
+
* error={({ error, retry }) => <ErrorBanner message={error} onRetry={retry} />}
|
|
39
|
+
* >
|
|
40
|
+
* <ItemDetailsComponents />
|
|
41
|
+
* </OLO.Provider>
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export const Provider = ({ itemId, configs,
|
|
45
|
+
// loading = (
|
|
46
|
+
// <div className="flex items-center justify-center p-8">
|
|
47
|
+
// <div className="text-secondary-foreground">Loading services...</div>
|
|
48
|
+
// </div>
|
|
49
|
+
// ),
|
|
50
|
+
// error: errorComponent = ({ error, retry }) => (
|
|
51
|
+
// <div className="flex flex-col items-center justify-center p-8 space-y-4">
|
|
52
|
+
// <div className="text-destructive">Error: {error}</div>
|
|
53
|
+
// <button
|
|
54
|
+
// onClick={retry}
|
|
55
|
+
// className="px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90"
|
|
56
|
+
// >
|
|
57
|
+
// Retry
|
|
58
|
+
// </button>
|
|
59
|
+
// </div>
|
|
60
|
+
// ),
|
|
61
|
+
children, }) => {
|
|
62
|
+
return (_jsx(Root, { itemId: itemId, itemServiceConfig: configs?.itemServiceConfig, children: children }));
|
|
63
|
+
};
|
|
64
|
+
/**
|
|
65
|
+
* Specialized headless component for item details
|
|
66
|
+
* Includes item-specific error handling (like 404 not found)
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```tsx
|
|
70
|
+
* <OLO.ItemDetails
|
|
71
|
+
* itemId="item-123"
|
|
72
|
+
* notFound={<NotFoundPage />}
|
|
73
|
+
* >
|
|
74
|
+
* <ItemDetailsUI />
|
|
75
|
+
* </OLO.ItemDetails>
|
|
76
|
+
* ```
|
|
77
|
+
*/
|
|
78
|
+
export const ItemDetails = ({ itemId, configs, loading, error, notFound = (_jsx("div", { className: "flex items-center justify-center p-8", children: _jsx("div", { className: "text-secondary-foreground", children: "Item not found" }) })), children, }) => {
|
|
79
|
+
return (_jsx(Provider, { itemId: itemId, configs: configs, loading: loading, error: ({ error: errorMessage, retry }) => {
|
|
80
|
+
// Handle item not found specifically
|
|
81
|
+
if (errorMessage === 'Item not found') {
|
|
82
|
+
return _jsx(_Fragment, { children: notFound });
|
|
83
|
+
}
|
|
84
|
+
// Use custom error component if provided
|
|
85
|
+
if (error) {
|
|
86
|
+
return _jsx(_Fragment, { children: error({ error: errorMessage, retry }) });
|
|
87
|
+
}
|
|
88
|
+
// Default error handling
|
|
89
|
+
return (_jsxs("div", { className: "flex flex-col items-center justify-center p-8 space-y-4", children: [_jsxs("div", { className: "text-destructive", children: ["Error: ", errorMessage] }), _jsx("button", { onClick: retry, className: "px-4 py-2 bg-primary text-primary-foreground rounded hover:bg-primary/90", children: "Retry" })] }));
|
|
90
|
+
}, children: children }));
|
|
91
|
+
};
|
|
92
|
+
/**
|
|
93
|
+
* Headless component for cart-only functionality
|
|
94
|
+
* Doesn't load item services, only cart services
|
|
95
|
+
*
|
|
96
|
+
* @example
|
|
97
|
+
* ```tsx
|
|
98
|
+
* <OLO.Cart>
|
|
99
|
+
* <CartComponents />
|
|
100
|
+
* </OLO.Cart>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export const Cart = ({ loading, error, children }) => {
|
|
104
|
+
return (_jsx(Provider, { loading: loading, error: error, children: children }));
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Headless component for checking service status
|
|
108
|
+
* Useful for debugging or conditional rendering
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```tsx
|
|
112
|
+
* <OLO.ServicesStatus itemId="item-123">
|
|
113
|
+
* {({ hasItemService, hasCartService, error }) => (
|
|
114
|
+
* <div>
|
|
115
|
+
* Item Service: {hasItemService ? '✅' : '❌'}
|
|
116
|
+
* Cart Service: {hasCartService ? '✅' : '❌'}
|
|
117
|
+
* {error && <div>Error: {error}</div>}
|
|
118
|
+
* </div>
|
|
119
|
+
* )}
|
|
120
|
+
* </OLO.ServicesStatus>
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
export const ServicesStatus = ({ itemId, children, }) => {
|
|
124
|
+
return (_jsx(Root, { itemId: itemId, children: children }));
|
|
125
|
+
};
|
|
126
|
+
export const Menus = ({
|
|
127
|
+
// menuServiceConfig,
|
|
128
|
+
children, }) => {
|
|
129
|
+
// const [retryKey, setRetryKey] = React.useState(0);
|
|
130
|
+
// const [menus, setMenus] = React.useState<any[]>([]);
|
|
131
|
+
// const [isLoading, setIsLoading] = React.useState(true);
|
|
132
|
+
// const [error, setError] = React.useState<string | undefined>(undefined);
|
|
133
|
+
return _jsx(_Fragment, { children: children });
|
|
134
|
+
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* CoreMenuItem
|
|
4
|
+
*
|
|
5
|
+
* A core menu item component that displays the item image, name, description, and price
|
|
6
|
+
* using the project's design system for colors and fonts.
|
|
7
|
+
*/
|
|
8
|
+
export declare function CoreClickableItem({ children, }: {
|
|
9
|
+
children: (props: {
|
|
10
|
+
item: any;
|
|
11
|
+
itemSelected: () => void;
|
|
12
|
+
}) => React.ReactNode;
|
|
13
|
+
}): React.ReactNode;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useItemContext, useMenuContext, useSectionContext, } from '@wix/restaurants/components';
|
|
2
|
+
import { useService } from '@wix/services-manager-react';
|
|
3
|
+
import { OLOSettingsServiceDefinition } from '@wix/headless-restaurants-olo/services';
|
|
4
|
+
// import { OLOSettingsServiceDefinition } from "../../services/OLOSettingsService";
|
|
5
|
+
/**
|
|
6
|
+
* CoreMenuItem
|
|
7
|
+
*
|
|
8
|
+
* A core menu item component that displays the item image, name, description, and price
|
|
9
|
+
* using the project's design system for colors and fonts.
|
|
10
|
+
*/
|
|
11
|
+
export function CoreClickableItem({ children, }) {
|
|
12
|
+
const { item } = useItemContext();
|
|
13
|
+
const { section } = useSectionContext();
|
|
14
|
+
const { menu } = useMenuContext();
|
|
15
|
+
const service = useService(OLOSettingsServiceDefinition);
|
|
16
|
+
const itemSelected = () => {
|
|
17
|
+
const selectedItem = { ...item, sectionId: section._id, menuId: menu._id };
|
|
18
|
+
service.selectedItem?.set(selectedItem);
|
|
19
|
+
};
|
|
20
|
+
return children({ item, itemSelected });
|
|
21
|
+
}
|
|
@@ -5,7 +5,7 @@ interface ItemDetailsRootProps {
|
|
|
5
5
|
children: (props: {
|
|
6
6
|
item: unknown;
|
|
7
7
|
}) => React.ReactNode;
|
|
8
|
-
itemDetailsServiceConfig
|
|
8
|
+
itemDetailsServiceConfig?: ItemServiceConfig;
|
|
9
9
|
}
|
|
10
10
|
export declare const Root: React.FC<ItemDetailsRootProps>;
|
|
11
11
|
interface ItemDetailsModifiersRepeaterProps {
|
|
@@ -4,18 +4,21 @@ 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
|
-
export const Root = ({ children }) => {
|
|
7
|
+
export const Root = ({ children, itemDetailsServiceConfig, }) => {
|
|
8
8
|
const service = useService(OLOSettingsServiceDefinition);
|
|
9
9
|
const selectedItem = service.selectedItem?.get();
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
let config = itemDetailsServiceConfig;
|
|
11
|
+
if (!config) {
|
|
12
|
+
config = loadItemServiceConfig({
|
|
13
|
+
item: selectedItem,
|
|
14
|
+
operationId: service.operation?.get()?._id ?? '',
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ItemServiceDefinition, ItemService, config), children: children({ item: selectedItem }) }));
|
|
15
18
|
};
|
|
16
19
|
export const ModifiersRepeater = ({ children, }) => {
|
|
17
20
|
const service = useService(ItemServiceDefinition);
|
|
18
|
-
const item = service.item
|
|
21
|
+
const item = service.item?.get();
|
|
19
22
|
// TODO: Check if modifiers exist on item type - might be in a different property
|
|
20
23
|
const modifiers = item?.modifiers || [];
|
|
21
24
|
const hasModifiers = modifiers.length > 0;
|
|
@@ -23,7 +26,7 @@ export const ModifiersRepeater = ({ children, }) => {
|
|
|
23
26
|
};
|
|
24
27
|
export const VariantsRepeater = ({ children, }) => {
|
|
25
28
|
const service = useService(ItemServiceDefinition);
|
|
26
|
-
const item = service.item
|
|
29
|
+
const item = service.item?.get();
|
|
27
30
|
// TODO: Check if variants exist on item type - might be in a different property
|
|
28
31
|
const variants = item?.variants || [];
|
|
29
32
|
const hasVariants = variants.length > 0;
|