@wix/headless-stores 0.0.32 → 0.0.34
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/Product.d.ts +43 -1
- package/cjs/dist/react/Product.js +45 -2
- package/cjs/dist/react/ProductVariantSelector.d.ts +43 -0
- package/cjs/dist/react/ProductVariantSelector.js +45 -2
- package/cjs/dist/react/ProductsList.d.ts +5 -2
- package/cjs/dist/react/ProductsList.js +5 -3
- package/cjs/dist/react/RelatedProducts.d.ts +52 -0
- package/cjs/dist/react/RelatedProducts.js +54 -2
- package/cjs/dist/react/SelectedVariant.d.ts +38 -0
- package/cjs/dist/react/SelectedVariant.js +40 -2
- package/dist/react/Product.d.ts +43 -1
- package/dist/react/Product.js +45 -2
- package/dist/react/ProductVariantSelector.d.ts +43 -0
- package/dist/react/ProductVariantSelector.js +45 -2
- package/dist/react/ProductsList.d.ts +5 -2
- package/dist/react/ProductsList.js +5 -3
- package/dist/react/RelatedProducts.d.ts +52 -0
- package/dist/react/RelatedProducts.js +54 -2
- package/dist/react/SelectedVariant.d.ts +38 -0
- package/dist/react/SelectedVariant.js +40 -2
- package/package.json +1 -1
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ProductServiceConfig } from "../services/product-service.js";
|
|
2
|
+
import type { V3Product, ProductMedia } from "@wix/auto_sdk_stores_products-v-3";
|
|
3
|
+
import type { PropsWithChildren } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Root component that provides the Product service context to its children.
|
|
6
|
+
* This component sets up the necessary services for rendering and managing a single product's data.
|
|
7
|
+
*
|
|
8
|
+
* @order 1
|
|
9
|
+
* @component
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { Product } from '@wix/stores/components';
|
|
13
|
+
*
|
|
14
|
+
* function ProductPage() {
|
|
15
|
+
* return (
|
|
16
|
+
* <Product.Root productServiceConfig={{ product: myProduct }}>
|
|
17
|
+
* <div>
|
|
18
|
+
* <Product.Name>
|
|
19
|
+
* {({ name }) => (
|
|
20
|
+
* <h1
|
|
21
|
+
* className="text-4xl font-bold text-content-primary mb-4"
|
|
22
|
+
* data-testid="product-name"
|
|
23
|
+
* >
|
|
24
|
+
* {name}
|
|
25
|
+
* </h1>
|
|
26
|
+
* )}
|
|
27
|
+
* </Product.Name>
|
|
28
|
+
* </div>
|
|
29
|
+
* </Product.Root>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function Root(props: PropsWithChildren<{
|
|
35
|
+
productServiceConfig: ProductServiceConfig;
|
|
36
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
2
37
|
/**
|
|
3
38
|
* Props for ProductName headless component
|
|
4
39
|
*/
|
|
@@ -89,3 +124,10 @@ export interface ProductDescriptionRenderProps {
|
|
|
89
124
|
* ```
|
|
90
125
|
*/
|
|
91
126
|
export declare const Description: (props: ProductDescriptionProps) => import("react").ReactNode;
|
|
127
|
+
export interface ProductMediaProps {
|
|
128
|
+
children: (props: ProductMediaRenderProps) => React.ReactNode;
|
|
129
|
+
}
|
|
130
|
+
export interface ProductMediaRenderProps {
|
|
131
|
+
media: ProductMedia[];
|
|
132
|
+
}
|
|
133
|
+
export declare const Media: (props: ProductMediaProps) => import("react").ReactNode;
|
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
3
|
+
import { ProductServiceDefinition, ProductService, } from "../services/product-service.js";
|
|
4
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides the Product service context to its children.
|
|
7
|
+
* This component sets up the necessary services for rendering and managing a single product's data.
|
|
8
|
+
*
|
|
9
|
+
* @order 1
|
|
10
|
+
* @component
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { Product } from '@wix/stores/components';
|
|
14
|
+
*
|
|
15
|
+
* function ProductPage() {
|
|
16
|
+
* return (
|
|
17
|
+
* <Product.Root productServiceConfig={{ product: myProduct }}>
|
|
18
|
+
* <div>
|
|
19
|
+
* <Product.Name>
|
|
20
|
+
* {({ name }) => (
|
|
21
|
+
* <h1
|
|
22
|
+
* className="text-4xl font-bold text-content-primary mb-4"
|
|
23
|
+
* data-testid="product-name"
|
|
24
|
+
* >
|
|
25
|
+
* {name}
|
|
26
|
+
* </h1>
|
|
27
|
+
* )}
|
|
28
|
+
* </Product.Name>
|
|
29
|
+
* </div>
|
|
30
|
+
* </Product.Root>
|
|
31
|
+
* );
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function Root(props) {
|
|
36
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ProductServiceDefinition, ProductService, props.productServiceConfig), children: props.children }));
|
|
37
|
+
}
|
|
3
38
|
/**
|
|
4
39
|
* Headless component for product name display
|
|
5
40
|
*
|
|
@@ -67,3 +102,11 @@ export const Description = (props) => {
|
|
|
67
102
|
plainDescription: plainDescription,
|
|
68
103
|
});
|
|
69
104
|
};
|
|
105
|
+
export const Media = (props) => {
|
|
106
|
+
const service = useService(ProductServiceDefinition);
|
|
107
|
+
const product = service.product.get();
|
|
108
|
+
const media = product.media?.itemsInfo?.items ?? [];
|
|
109
|
+
return props.children({
|
|
110
|
+
media,
|
|
111
|
+
});
|
|
112
|
+
};
|
|
@@ -1,4 +1,47 @@
|
|
|
1
|
+
import { SelectedVariantServiceConfig } from "../services/selected-variant-service.js";
|
|
2
|
+
import type { PropsWithChildren } from "react";
|
|
1
3
|
import { type ConnectedOption, type ConnectedOptionChoice, InventoryAvailabilityStatus } from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
+
/**
|
|
5
|
+
* Root component that provides the ProductVariantSelector service context to its children.
|
|
6
|
+
* This component sets up the necessary services for rendering and managing product variant selection.
|
|
7
|
+
*
|
|
8
|
+
* @order 1
|
|
9
|
+
* @component
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { ProductVariantSelector } from '@wix/stores/components';
|
|
13
|
+
*
|
|
14
|
+
* function VariantSelector() {
|
|
15
|
+
* return (
|
|
16
|
+
* <ProductVariantSelector.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
17
|
+
* <div>
|
|
18
|
+
* <ProductVariantSelector.Options>
|
|
19
|
+
* {({ options, hasOptions, selectedChoices }) => (
|
|
20
|
+
* <div>
|
|
21
|
+
* {hasOptions && options.map(option => (
|
|
22
|
+
* <div key={option.id}>
|
|
23
|
+
* <label>{option.name}</label>
|
|
24
|
+
* <select value={selectedChoices[option.id] || ''}>
|
|
25
|
+
* {option.choices?.map(choice => (
|
|
26
|
+
* <option key={choice.id} value={choice.id}>
|
|
27
|
+
* {choice.description}
|
|
28
|
+
* </option>
|
|
29
|
+
* ))}
|
|
30
|
+
* </select>
|
|
31
|
+
* </div>
|
|
32
|
+
* ))}
|
|
33
|
+
* </div>
|
|
34
|
+
* )}
|
|
35
|
+
* </ProductVariantSelector.Options>
|
|
36
|
+
* </div>
|
|
37
|
+
* </ProductVariantSelector.Root>
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function Root(props: PropsWithChildren<{
|
|
43
|
+
selectedVariantServiceConfig?: SelectedVariantServiceConfig;
|
|
44
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
2
45
|
/**
|
|
3
46
|
* Props for Options headless component
|
|
4
47
|
*/
|
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
3
|
+
import { SelectedVariantServiceDefinition, SelectedVariantService, } from "../services/selected-variant-service.js";
|
|
4
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
3
5
|
import { InventoryAvailabilityStatus, } from "@wix/auto_sdk_stores_products-v-3";
|
|
6
|
+
/**
|
|
7
|
+
* Root component that provides the ProductVariantSelector service context to its children.
|
|
8
|
+
* This component sets up the necessary services for rendering and managing product variant selection.
|
|
9
|
+
*
|
|
10
|
+
* @order 1
|
|
11
|
+
* @component
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { ProductVariantSelector } from '@wix/stores/components';
|
|
15
|
+
*
|
|
16
|
+
* function VariantSelector() {
|
|
17
|
+
* return (
|
|
18
|
+
* <ProductVariantSelector.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
19
|
+
* <div>
|
|
20
|
+
* <ProductVariantSelector.Options>
|
|
21
|
+
* {({ options, hasOptions, selectedChoices }) => (
|
|
22
|
+
* <div>
|
|
23
|
+
* {hasOptions && options.map(option => (
|
|
24
|
+
* <div key={option.id}>
|
|
25
|
+
* <label>{option.name}</label>
|
|
26
|
+
* <select value={selectedChoices[option.id] || ''}>
|
|
27
|
+
* {option.choices?.map(choice => (
|
|
28
|
+
* <option key={choice.id} value={choice.id}>
|
|
29
|
+
* {choice.description}
|
|
30
|
+
* </option>
|
|
31
|
+
* ))}
|
|
32
|
+
* </select>
|
|
33
|
+
* </div>
|
|
34
|
+
* ))}
|
|
35
|
+
* </div>
|
|
36
|
+
* )}
|
|
37
|
+
* </ProductVariantSelector.Options>
|
|
38
|
+
* </div>
|
|
39
|
+
* </ProductVariantSelector.Root>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function Root(props) {
|
|
45
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(SelectedVariantServiceDefinition, SelectedVariantService, props.selectedVariantServiceConfig), children: props.children }));
|
|
46
|
+
}
|
|
4
47
|
/**
|
|
5
48
|
* Headless component for all product options
|
|
6
49
|
*
|
|
@@ -10,6 +10,7 @@ export interface RootProps {
|
|
|
10
10
|
* Root component that provides the ProductsList service context to its children.
|
|
11
11
|
* This component sets up the necessary services for managing products list state.
|
|
12
12
|
*
|
|
13
|
+
* @order 1
|
|
13
14
|
* @component
|
|
14
15
|
* @example
|
|
15
16
|
* ```tsx
|
|
@@ -19,8 +20,10 @@ export interface RootProps {
|
|
|
19
20
|
* return (
|
|
20
21
|
* <ProductsList.Root
|
|
21
22
|
* productsListConfig={{
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* products: myProducts,
|
|
24
|
+
* searchOptions: { query: { search: 'searchTerm' } },
|
|
25
|
+
* pagingMetadata: { count: 10, hasNext: true },
|
|
26
|
+
* aggregations: {}
|
|
24
27
|
* }}
|
|
25
28
|
* >
|
|
26
29
|
* <ProductsList.Grid>
|
|
@@ -7,6 +7,7 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
|
|
|
7
7
|
* Root component that provides the ProductsList service context to its children.
|
|
8
8
|
* This component sets up the necessary services for managing products list state.
|
|
9
9
|
*
|
|
10
|
+
* @order 1
|
|
10
11
|
* @component
|
|
11
12
|
* @example
|
|
12
13
|
* ```tsx
|
|
@@ -16,8 +17,10 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
|
|
|
16
17
|
* return (
|
|
17
18
|
* <ProductsList.Root
|
|
18
19
|
* productsListConfig={{
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* products: myProducts,
|
|
21
|
+
* searchOptions: { query: { search: 'searchTerm' } },
|
|
22
|
+
* pagingMetadata: { count: 10, hasNext: true },
|
|
23
|
+
* aggregations: {}
|
|
21
24
|
* }}
|
|
22
25
|
* >
|
|
23
26
|
* <ProductsList.Grid>
|
|
@@ -108,7 +111,6 @@ export function Loading(props) {
|
|
|
108
111
|
}
|
|
109
112
|
return null;
|
|
110
113
|
}
|
|
111
|
-
;
|
|
112
114
|
/**
|
|
113
115
|
* Component that renders content when there's an error loading products.
|
|
114
116
|
* Only displays its children when an error has occurred.
|
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { RelatedProductsServiceConfig } from "../services/related-products-service.js";
|
|
3
|
+
import type { PropsWithChildren } from "react";
|
|
2
4
|
import { type V3Product } from "@wix/auto_sdk_stores_products-v-3";
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides the RelatedProducts service context to its children.
|
|
7
|
+
* This component sets up the necessary services for rendering and managing related products functionality.
|
|
8
|
+
*
|
|
9
|
+
* @order 1
|
|
10
|
+
* @component
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
14
|
+
*
|
|
15
|
+
* function RecommendedSection({ currentProductId }) {
|
|
16
|
+
* return (
|
|
17
|
+
* <RelatedProducts.Root relatedProductsServiceConfig={{ productId: currentProductId }}>
|
|
18
|
+
* <div>
|
|
19
|
+
* <h3>You might also like</h3>
|
|
20
|
+
* <RelatedProducts.List>
|
|
21
|
+
* {({ products, isLoading, error, hasProducts, refresh }) => (
|
|
22
|
+
* <div>
|
|
23
|
+
* {isLoading && <div>Loading related products...</div>}
|
|
24
|
+
* {error && <div>Error: {error}</div>}
|
|
25
|
+
* {hasProducts && (
|
|
26
|
+
* <div className="products-grid">
|
|
27
|
+
* {products.map(product => (
|
|
28
|
+
* <RelatedProducts.Item key={product.id} product={product}>
|
|
29
|
+
* {({ title, image, price, available, description, onQuickAdd }) => (
|
|
30
|
+
* <div className={`related-product ${!available ? 'unavailable' : ''}`}>
|
|
31
|
+
* {image && <img src={image} alt={title} />}
|
|
32
|
+
* <h4>{title}</h4>
|
|
33
|
+
* <div className="price">{price}</div>
|
|
34
|
+
* <button onClick={onQuickAdd} disabled={!available}>
|
|
35
|
+
* Quick Add
|
|
36
|
+
* </button>
|
|
37
|
+
* </div>
|
|
38
|
+
* )}
|
|
39
|
+
* </RelatedProducts.Item>
|
|
40
|
+
* ))}
|
|
41
|
+
* </div>
|
|
42
|
+
* )}
|
|
43
|
+
* </div>
|
|
44
|
+
* )}
|
|
45
|
+
* </RelatedProducts.List>
|
|
46
|
+
* </div>
|
|
47
|
+
* </RelatedProducts.Root>
|
|
48
|
+
* );
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function Root(props: PropsWithChildren<{
|
|
53
|
+
relatedProductsServiceConfig: RelatedProductsServiceConfig;
|
|
54
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
3
55
|
/**
|
|
4
56
|
* Props for List headless component
|
|
5
57
|
*/
|
|
@@ -1,8 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import React from "react";
|
|
2
|
-
import { useService } from "@wix/services-manager-react";
|
|
3
|
-
import { RelatedProductsServiceDefinition } from "../services/related-products-service.js";
|
|
3
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
4
|
+
import { RelatedProductsServiceDefinition, RelatedProductsService, } from "../services/related-products-service.js";
|
|
5
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
4
6
|
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
5
7
|
import { InventoryAvailabilityStatus, } from "@wix/auto_sdk_stores_products-v-3";
|
|
8
|
+
/**
|
|
9
|
+
* Root component that provides the RelatedProducts service context to its children.
|
|
10
|
+
* This component sets up the necessary services for rendering and managing related products functionality.
|
|
11
|
+
*
|
|
12
|
+
* @order 1
|
|
13
|
+
* @component
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
17
|
+
*
|
|
18
|
+
* function RecommendedSection({ currentProductId }) {
|
|
19
|
+
* return (
|
|
20
|
+
* <RelatedProducts.Root relatedProductsServiceConfig={{ productId: currentProductId }}>
|
|
21
|
+
* <div>
|
|
22
|
+
* <h3>You might also like</h3>
|
|
23
|
+
* <RelatedProducts.List>
|
|
24
|
+
* {({ products, isLoading, error, hasProducts, refresh }) => (
|
|
25
|
+
* <div>
|
|
26
|
+
* {isLoading && <div>Loading related products...</div>}
|
|
27
|
+
* {error && <div>Error: {error}</div>}
|
|
28
|
+
* {hasProducts && (
|
|
29
|
+
* <div className="products-grid">
|
|
30
|
+
* {products.map(product => (
|
|
31
|
+
* <RelatedProducts.Item key={product.id} product={product}>
|
|
32
|
+
* {({ title, image, price, available, description, onQuickAdd }) => (
|
|
33
|
+
* <div className={`related-product ${!available ? 'unavailable' : ''}`}>
|
|
34
|
+
* {image && <img src={image} alt={title} />}
|
|
35
|
+
* <h4>{title}</h4>
|
|
36
|
+
* <div className="price">{price}</div>
|
|
37
|
+
* <button onClick={onQuickAdd} disabled={!available}>
|
|
38
|
+
* Quick Add
|
|
39
|
+
* </button>
|
|
40
|
+
* </div>
|
|
41
|
+
* )}
|
|
42
|
+
* </RelatedProducts.Item>
|
|
43
|
+
* ))}
|
|
44
|
+
* </div>
|
|
45
|
+
* )}
|
|
46
|
+
* </div>
|
|
47
|
+
* )}
|
|
48
|
+
* </RelatedProducts.List>
|
|
49
|
+
* </div>
|
|
50
|
+
* </RelatedProducts.Root>
|
|
51
|
+
* );
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function Root(props) {
|
|
56
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(RelatedProductsServiceDefinition, RelatedProductsService, props.relatedProductsServiceConfig), children: props.children }));
|
|
57
|
+
}
|
|
6
58
|
/**
|
|
7
59
|
* Headless component for displaying related products list
|
|
8
60
|
*
|
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
import { SelectedVariantServiceConfig } from "../services/selected-variant-service.js";
|
|
2
|
+
import type { PropsWithChildren } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Root component that provides the SelectedVariant service context to its children.
|
|
5
|
+
* This component sets up the necessary services for rendering and managing selected variant data.
|
|
6
|
+
*
|
|
7
|
+
* @order 1
|
|
8
|
+
* @component
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
12
|
+
*
|
|
13
|
+
* function ProductVariantDisplay() {
|
|
14
|
+
* return (
|
|
15
|
+
* <SelectedVariant.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
16
|
+
* <div>
|
|
17
|
+
* <SelectedVariant.Price>
|
|
18
|
+
* {({ price, compareAtPrice, currency }) => (
|
|
19
|
+
* <div className="price-display">
|
|
20
|
+
* <span className="current-price">{price}</span>
|
|
21
|
+
* {compareAtPrice && (
|
|
22
|
+
* <span className="compare-price">
|
|
23
|
+
* <s>{compareAtPrice}</s>
|
|
24
|
+
* </span>
|
|
25
|
+
* )}
|
|
26
|
+
* <span className="currency">{currency}</span>
|
|
27
|
+
* </div>
|
|
28
|
+
* )}
|
|
29
|
+
* </SelectedVariant.Price>
|
|
30
|
+
* </div>
|
|
31
|
+
* </SelectedVariant.Root>
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function Root(props: PropsWithChildren<{
|
|
37
|
+
selectedVariantServiceConfig?: SelectedVariantServiceConfig;
|
|
38
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
1
39
|
/**
|
|
2
40
|
* Props for ProductDetails headless component
|
|
3
41
|
*/
|
|
@@ -1,5 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
3
|
+
import { SelectedVariantServiceDefinition, SelectedVariantService, } from "../services/selected-variant-service.js";
|
|
4
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides the SelectedVariant service context to its children.
|
|
7
|
+
* This component sets up the necessary services for rendering and managing selected variant data.
|
|
8
|
+
*
|
|
9
|
+
* @order 1
|
|
10
|
+
* @component
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
14
|
+
*
|
|
15
|
+
* function ProductVariantDisplay() {
|
|
16
|
+
* return (
|
|
17
|
+
* <SelectedVariant.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
18
|
+
* <div>
|
|
19
|
+
* <SelectedVariant.Price>
|
|
20
|
+
* {({ price, compareAtPrice, currency }) => (
|
|
21
|
+
* <div className="price-display">
|
|
22
|
+
* <span className="current-price">{price}</span>
|
|
23
|
+
* {compareAtPrice && (
|
|
24
|
+
* <span className="compare-price">
|
|
25
|
+
* <s>{compareAtPrice}</s>
|
|
26
|
+
* </span>
|
|
27
|
+
* )}
|
|
28
|
+
* <span className="currency">{currency}</span>
|
|
29
|
+
* </div>
|
|
30
|
+
* )}
|
|
31
|
+
* </SelectedVariant.Price>
|
|
32
|
+
* </div>
|
|
33
|
+
* </SelectedVariant.Root>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function Root(props) {
|
|
39
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(SelectedVariantServiceDefinition, SelectedVariantService, props.selectedVariantServiceConfig), children: props.children }));
|
|
40
|
+
}
|
|
3
41
|
/**
|
|
4
42
|
* Headless component for selected variant details display
|
|
5
43
|
*
|
package/dist/react/Product.d.ts
CHANGED
|
@@ -1,4 +1,39 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { ProductServiceConfig } from "../services/product-service.js";
|
|
2
|
+
import type { V3Product, ProductMedia } from "@wix/auto_sdk_stores_products-v-3";
|
|
3
|
+
import type { PropsWithChildren } from "react";
|
|
4
|
+
/**
|
|
5
|
+
* Root component that provides the Product service context to its children.
|
|
6
|
+
* This component sets up the necessary services for rendering and managing a single product's data.
|
|
7
|
+
*
|
|
8
|
+
* @order 1
|
|
9
|
+
* @component
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { Product } from '@wix/stores/components';
|
|
13
|
+
*
|
|
14
|
+
* function ProductPage() {
|
|
15
|
+
* return (
|
|
16
|
+
* <Product.Root productServiceConfig={{ product: myProduct }}>
|
|
17
|
+
* <div>
|
|
18
|
+
* <Product.Name>
|
|
19
|
+
* {({ name }) => (
|
|
20
|
+
* <h1
|
|
21
|
+
* className="text-4xl font-bold text-content-primary mb-4"
|
|
22
|
+
* data-testid="product-name"
|
|
23
|
+
* >
|
|
24
|
+
* {name}
|
|
25
|
+
* </h1>
|
|
26
|
+
* )}
|
|
27
|
+
* </Product.Name>
|
|
28
|
+
* </div>
|
|
29
|
+
* </Product.Root>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export declare function Root(props: PropsWithChildren<{
|
|
35
|
+
productServiceConfig: ProductServiceConfig;
|
|
36
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
2
37
|
/**
|
|
3
38
|
* Props for ProductName headless component
|
|
4
39
|
*/
|
|
@@ -89,3 +124,10 @@ export interface ProductDescriptionRenderProps {
|
|
|
89
124
|
* ```
|
|
90
125
|
*/
|
|
91
126
|
export declare const Description: (props: ProductDescriptionProps) => import("react").ReactNode;
|
|
127
|
+
export interface ProductMediaProps {
|
|
128
|
+
children: (props: ProductMediaRenderProps) => React.ReactNode;
|
|
129
|
+
}
|
|
130
|
+
export interface ProductMediaRenderProps {
|
|
131
|
+
media: ProductMedia[];
|
|
132
|
+
}
|
|
133
|
+
export declare const Media: (props: ProductMediaProps) => import("react").ReactNode;
|
package/dist/react/Product.js
CHANGED
|
@@ -1,5 +1,40 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
3
|
+
import { ProductServiceDefinition, ProductService, } from "../services/product-service.js";
|
|
4
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides the Product service context to its children.
|
|
7
|
+
* This component sets up the necessary services for rendering and managing a single product's data.
|
|
8
|
+
*
|
|
9
|
+
* @order 1
|
|
10
|
+
* @component
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { Product } from '@wix/stores/components';
|
|
14
|
+
*
|
|
15
|
+
* function ProductPage() {
|
|
16
|
+
* return (
|
|
17
|
+
* <Product.Root productServiceConfig={{ product: myProduct }}>
|
|
18
|
+
* <div>
|
|
19
|
+
* <Product.Name>
|
|
20
|
+
* {({ name }) => (
|
|
21
|
+
* <h1
|
|
22
|
+
* className="text-4xl font-bold text-content-primary mb-4"
|
|
23
|
+
* data-testid="product-name"
|
|
24
|
+
* >
|
|
25
|
+
* {name}
|
|
26
|
+
* </h1>
|
|
27
|
+
* )}
|
|
28
|
+
* </Product.Name>
|
|
29
|
+
* </div>
|
|
30
|
+
* </Product.Root>
|
|
31
|
+
* );
|
|
32
|
+
* }
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export function Root(props) {
|
|
36
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ProductServiceDefinition, ProductService, props.productServiceConfig), children: props.children }));
|
|
37
|
+
}
|
|
3
38
|
/**
|
|
4
39
|
* Headless component for product name display
|
|
5
40
|
*
|
|
@@ -67,3 +102,11 @@ export const Description = (props) => {
|
|
|
67
102
|
plainDescription: plainDescription,
|
|
68
103
|
});
|
|
69
104
|
};
|
|
105
|
+
export const Media = (props) => {
|
|
106
|
+
const service = useService(ProductServiceDefinition);
|
|
107
|
+
const product = service.product.get();
|
|
108
|
+
const media = product.media?.itemsInfo?.items ?? [];
|
|
109
|
+
return props.children({
|
|
110
|
+
media,
|
|
111
|
+
});
|
|
112
|
+
};
|
|
@@ -1,4 +1,47 @@
|
|
|
1
|
+
import { SelectedVariantServiceConfig } from "../services/selected-variant-service.js";
|
|
2
|
+
import type { PropsWithChildren } from "react";
|
|
1
3
|
import { type ConnectedOption, type ConnectedOptionChoice, InventoryAvailabilityStatus } from "@wix/auto_sdk_stores_products-v-3";
|
|
4
|
+
/**
|
|
5
|
+
* Root component that provides the ProductVariantSelector service context to its children.
|
|
6
|
+
* This component sets up the necessary services for rendering and managing product variant selection.
|
|
7
|
+
*
|
|
8
|
+
* @order 1
|
|
9
|
+
* @component
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* import { ProductVariantSelector } from '@wix/stores/components';
|
|
13
|
+
*
|
|
14
|
+
* function VariantSelector() {
|
|
15
|
+
* return (
|
|
16
|
+
* <ProductVariantSelector.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
17
|
+
* <div>
|
|
18
|
+
* <ProductVariantSelector.Options>
|
|
19
|
+
* {({ options, hasOptions, selectedChoices }) => (
|
|
20
|
+
* <div>
|
|
21
|
+
* {hasOptions && options.map(option => (
|
|
22
|
+
* <div key={option.id}>
|
|
23
|
+
* <label>{option.name}</label>
|
|
24
|
+
* <select value={selectedChoices[option.id] || ''}>
|
|
25
|
+
* {option.choices?.map(choice => (
|
|
26
|
+
* <option key={choice.id} value={choice.id}>
|
|
27
|
+
* {choice.description}
|
|
28
|
+
* </option>
|
|
29
|
+
* ))}
|
|
30
|
+
* </select>
|
|
31
|
+
* </div>
|
|
32
|
+
* ))}
|
|
33
|
+
* </div>
|
|
34
|
+
* )}
|
|
35
|
+
* </ProductVariantSelector.Options>
|
|
36
|
+
* </div>
|
|
37
|
+
* </ProductVariantSelector.Root>
|
|
38
|
+
* );
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
export declare function Root(props: PropsWithChildren<{
|
|
43
|
+
selectedVariantServiceConfig?: SelectedVariantServiceConfig;
|
|
44
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
2
45
|
/**
|
|
3
46
|
* Props for Options headless component
|
|
4
47
|
*/
|
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
3
|
+
import { SelectedVariantServiceDefinition, SelectedVariantService, } from "../services/selected-variant-service.js";
|
|
4
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
3
5
|
import { InventoryAvailabilityStatus, } from "@wix/auto_sdk_stores_products-v-3";
|
|
6
|
+
/**
|
|
7
|
+
* Root component that provides the ProductVariantSelector service context to its children.
|
|
8
|
+
* This component sets up the necessary services for rendering and managing product variant selection.
|
|
9
|
+
*
|
|
10
|
+
* @order 1
|
|
11
|
+
* @component
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { ProductVariantSelector } from '@wix/stores/components';
|
|
15
|
+
*
|
|
16
|
+
* function VariantSelector() {
|
|
17
|
+
* return (
|
|
18
|
+
* <ProductVariantSelector.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
19
|
+
* <div>
|
|
20
|
+
* <ProductVariantSelector.Options>
|
|
21
|
+
* {({ options, hasOptions, selectedChoices }) => (
|
|
22
|
+
* <div>
|
|
23
|
+
* {hasOptions && options.map(option => (
|
|
24
|
+
* <div key={option.id}>
|
|
25
|
+
* <label>{option.name}</label>
|
|
26
|
+
* <select value={selectedChoices[option.id] || ''}>
|
|
27
|
+
* {option.choices?.map(choice => (
|
|
28
|
+
* <option key={choice.id} value={choice.id}>
|
|
29
|
+
* {choice.description}
|
|
30
|
+
* </option>
|
|
31
|
+
* ))}
|
|
32
|
+
* </select>
|
|
33
|
+
* </div>
|
|
34
|
+
* ))}
|
|
35
|
+
* </div>
|
|
36
|
+
* )}
|
|
37
|
+
* </ProductVariantSelector.Options>
|
|
38
|
+
* </div>
|
|
39
|
+
* </ProductVariantSelector.Root>
|
|
40
|
+
* );
|
|
41
|
+
* }
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export function Root(props) {
|
|
45
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(SelectedVariantServiceDefinition, SelectedVariantService, props.selectedVariantServiceConfig), children: props.children }));
|
|
46
|
+
}
|
|
4
47
|
/**
|
|
5
48
|
* Headless component for all product options
|
|
6
49
|
*
|
|
@@ -10,6 +10,7 @@ export interface RootProps {
|
|
|
10
10
|
* Root component that provides the ProductsList service context to its children.
|
|
11
11
|
* This component sets up the necessary services for managing products list state.
|
|
12
12
|
*
|
|
13
|
+
* @order 1
|
|
13
14
|
* @component
|
|
14
15
|
* @example
|
|
15
16
|
* ```tsx
|
|
@@ -19,8 +20,10 @@ export interface RootProps {
|
|
|
19
20
|
* return (
|
|
20
21
|
* <ProductsList.Root
|
|
21
22
|
* productsListConfig={{
|
|
22
|
-
*
|
|
23
|
-
*
|
|
23
|
+
* products: myProducts,
|
|
24
|
+
* searchOptions: { query: { search: 'searchTerm' } },
|
|
25
|
+
* pagingMetadata: { count: 10, hasNext: true },
|
|
26
|
+
* aggregations: {}
|
|
24
27
|
* }}
|
|
25
28
|
* >
|
|
26
29
|
* <ProductsList.Grid>
|
|
@@ -7,6 +7,7 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
|
|
|
7
7
|
* Root component that provides the ProductsList service context to its children.
|
|
8
8
|
* This component sets up the necessary services for managing products list state.
|
|
9
9
|
*
|
|
10
|
+
* @order 1
|
|
10
11
|
* @component
|
|
11
12
|
* @example
|
|
12
13
|
* ```tsx
|
|
@@ -16,8 +17,10 @@ import { ProductService, ProductServiceDefinition, } from "@wix/headless-stores/
|
|
|
16
17
|
* return (
|
|
17
18
|
* <ProductsList.Root
|
|
18
19
|
* productsListConfig={{
|
|
19
|
-
*
|
|
20
|
-
*
|
|
20
|
+
* products: myProducts,
|
|
21
|
+
* searchOptions: { query: { search: 'searchTerm' } },
|
|
22
|
+
* pagingMetadata: { count: 10, hasNext: true },
|
|
23
|
+
* aggregations: {}
|
|
21
24
|
* }}
|
|
22
25
|
* >
|
|
23
26
|
* <ProductsList.Grid>
|
|
@@ -108,7 +111,6 @@ export function Loading(props) {
|
|
|
108
111
|
}
|
|
109
112
|
return null;
|
|
110
113
|
}
|
|
111
|
-
;
|
|
112
114
|
/**
|
|
113
115
|
* Component that renders content when there's an error loading products.
|
|
114
116
|
* Only displays its children when an error has occurred.
|
|
@@ -1,5 +1,57 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { RelatedProductsServiceConfig } from "../services/related-products-service.js";
|
|
3
|
+
import type { PropsWithChildren } from "react";
|
|
2
4
|
import { type V3Product } from "@wix/auto_sdk_stores_products-v-3";
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides the RelatedProducts service context to its children.
|
|
7
|
+
* This component sets up the necessary services for rendering and managing related products functionality.
|
|
8
|
+
*
|
|
9
|
+
* @order 1
|
|
10
|
+
* @component
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
14
|
+
*
|
|
15
|
+
* function RecommendedSection({ currentProductId }) {
|
|
16
|
+
* return (
|
|
17
|
+
* <RelatedProducts.Root relatedProductsServiceConfig={{ productId: currentProductId }}>
|
|
18
|
+
* <div>
|
|
19
|
+
* <h3>You might also like</h3>
|
|
20
|
+
* <RelatedProducts.List>
|
|
21
|
+
* {({ products, isLoading, error, hasProducts, refresh }) => (
|
|
22
|
+
* <div>
|
|
23
|
+
* {isLoading && <div>Loading related products...</div>}
|
|
24
|
+
* {error && <div>Error: {error}</div>}
|
|
25
|
+
* {hasProducts && (
|
|
26
|
+
* <div className="products-grid">
|
|
27
|
+
* {products.map(product => (
|
|
28
|
+
* <RelatedProducts.Item key={product.id} product={product}>
|
|
29
|
+
* {({ title, image, price, available, description, onQuickAdd }) => (
|
|
30
|
+
* <div className={`related-product ${!available ? 'unavailable' : ''}`}>
|
|
31
|
+
* {image && <img src={image} alt={title} />}
|
|
32
|
+
* <h4>{title}</h4>
|
|
33
|
+
* <div className="price">{price}</div>
|
|
34
|
+
* <button onClick={onQuickAdd} disabled={!available}>
|
|
35
|
+
* Quick Add
|
|
36
|
+
* </button>
|
|
37
|
+
* </div>
|
|
38
|
+
* )}
|
|
39
|
+
* </RelatedProducts.Item>
|
|
40
|
+
* ))}
|
|
41
|
+
* </div>
|
|
42
|
+
* )}
|
|
43
|
+
* </div>
|
|
44
|
+
* )}
|
|
45
|
+
* </RelatedProducts.List>
|
|
46
|
+
* </div>
|
|
47
|
+
* </RelatedProducts.Root>
|
|
48
|
+
* );
|
|
49
|
+
* }
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare function Root(props: PropsWithChildren<{
|
|
53
|
+
relatedProductsServiceConfig: RelatedProductsServiceConfig;
|
|
54
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
3
55
|
/**
|
|
4
56
|
* Props for List headless component
|
|
5
57
|
*/
|
|
@@ -1,8 +1,60 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
import React from "react";
|
|
2
|
-
import { useService } from "@wix/services-manager-react";
|
|
3
|
-
import { RelatedProductsServiceDefinition } from "../services/related-products-service.js";
|
|
3
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
4
|
+
import { RelatedProductsServiceDefinition, RelatedProductsService, } from "../services/related-products-service.js";
|
|
5
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
4
6
|
import { SignalsServiceDefinition } from "@wix/services-definitions/core-services/signals";
|
|
5
7
|
import { InventoryAvailabilityStatus, } from "@wix/auto_sdk_stores_products-v-3";
|
|
8
|
+
/**
|
|
9
|
+
* Root component that provides the RelatedProducts service context to its children.
|
|
10
|
+
* This component sets up the necessary services for rendering and managing related products functionality.
|
|
11
|
+
*
|
|
12
|
+
* @order 1
|
|
13
|
+
* @component
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
17
|
+
*
|
|
18
|
+
* function RecommendedSection({ currentProductId }) {
|
|
19
|
+
* return (
|
|
20
|
+
* <RelatedProducts.Root relatedProductsServiceConfig={{ productId: currentProductId }}>
|
|
21
|
+
* <div>
|
|
22
|
+
* <h3>You might also like</h3>
|
|
23
|
+
* <RelatedProducts.List>
|
|
24
|
+
* {({ products, isLoading, error, hasProducts, refresh }) => (
|
|
25
|
+
* <div>
|
|
26
|
+
* {isLoading && <div>Loading related products...</div>}
|
|
27
|
+
* {error && <div>Error: {error}</div>}
|
|
28
|
+
* {hasProducts && (
|
|
29
|
+
* <div className="products-grid">
|
|
30
|
+
* {products.map(product => (
|
|
31
|
+
* <RelatedProducts.Item key={product.id} product={product}>
|
|
32
|
+
* {({ title, image, price, available, description, onQuickAdd }) => (
|
|
33
|
+
* <div className={`related-product ${!available ? 'unavailable' : ''}`}>
|
|
34
|
+
* {image && <img src={image} alt={title} />}
|
|
35
|
+
* <h4>{title}</h4>
|
|
36
|
+
* <div className="price">{price}</div>
|
|
37
|
+
* <button onClick={onQuickAdd} disabled={!available}>
|
|
38
|
+
* Quick Add
|
|
39
|
+
* </button>
|
|
40
|
+
* </div>
|
|
41
|
+
* )}
|
|
42
|
+
* </RelatedProducts.Item>
|
|
43
|
+
* ))}
|
|
44
|
+
* </div>
|
|
45
|
+
* )}
|
|
46
|
+
* </div>
|
|
47
|
+
* )}
|
|
48
|
+
* </RelatedProducts.List>
|
|
49
|
+
* </div>
|
|
50
|
+
* </RelatedProducts.Root>
|
|
51
|
+
* );
|
|
52
|
+
* }
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
export function Root(props) {
|
|
56
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(RelatedProductsServiceDefinition, RelatedProductsService, props.relatedProductsServiceConfig), children: props.children }));
|
|
57
|
+
}
|
|
6
58
|
/**
|
|
7
59
|
* Headless component for displaying related products list
|
|
8
60
|
*
|
|
@@ -1,3 +1,41 @@
|
|
|
1
|
+
import { SelectedVariantServiceConfig } from "../services/selected-variant-service.js";
|
|
2
|
+
import type { PropsWithChildren } from "react";
|
|
3
|
+
/**
|
|
4
|
+
* Root component that provides the SelectedVariant service context to its children.
|
|
5
|
+
* This component sets up the necessary services for rendering and managing selected variant data.
|
|
6
|
+
*
|
|
7
|
+
* @order 1
|
|
8
|
+
* @component
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
12
|
+
*
|
|
13
|
+
* function ProductVariantDisplay() {
|
|
14
|
+
* return (
|
|
15
|
+
* <SelectedVariant.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
16
|
+
* <div>
|
|
17
|
+
* <SelectedVariant.Price>
|
|
18
|
+
* {({ price, compareAtPrice, currency }) => (
|
|
19
|
+
* <div className="price-display">
|
|
20
|
+
* <span className="current-price">{price}</span>
|
|
21
|
+
* {compareAtPrice && (
|
|
22
|
+
* <span className="compare-price">
|
|
23
|
+
* <s>{compareAtPrice}</s>
|
|
24
|
+
* </span>
|
|
25
|
+
* )}
|
|
26
|
+
* <span className="currency">{currency}</span>
|
|
27
|
+
* </div>
|
|
28
|
+
* )}
|
|
29
|
+
* </SelectedVariant.Price>
|
|
30
|
+
* </div>
|
|
31
|
+
* </SelectedVariant.Root>
|
|
32
|
+
* );
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
35
|
+
*/
|
|
36
|
+
export declare function Root(props: PropsWithChildren<{
|
|
37
|
+
selectedVariantServiceConfig?: SelectedVariantServiceConfig;
|
|
38
|
+
}>): import("react/jsx-runtime").JSX.Element;
|
|
1
39
|
/**
|
|
2
40
|
* Props for ProductDetails headless component
|
|
3
41
|
*/
|
|
@@ -1,5 +1,43 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
3
|
+
import { SelectedVariantServiceDefinition, SelectedVariantService, } from "../services/selected-variant-service.js";
|
|
4
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides the SelectedVariant service context to its children.
|
|
7
|
+
* This component sets up the necessary services for rendering and managing selected variant data.
|
|
8
|
+
*
|
|
9
|
+
* @order 1
|
|
10
|
+
* @component
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
14
|
+
*
|
|
15
|
+
* function ProductVariantDisplay() {
|
|
16
|
+
* return (
|
|
17
|
+
* <SelectedVariant.Root selectedVariantServiceConfig={{ fetchInventoryData: true }}>
|
|
18
|
+
* <div>
|
|
19
|
+
* <SelectedVariant.Price>
|
|
20
|
+
* {({ price, compareAtPrice, currency }) => (
|
|
21
|
+
* <div className="price-display">
|
|
22
|
+
* <span className="current-price">{price}</span>
|
|
23
|
+
* {compareAtPrice && (
|
|
24
|
+
* <span className="compare-price">
|
|
25
|
+
* <s>{compareAtPrice}</s>
|
|
26
|
+
* </span>
|
|
27
|
+
* )}
|
|
28
|
+
* <span className="currency">{currency}</span>
|
|
29
|
+
* </div>
|
|
30
|
+
* )}
|
|
31
|
+
* </SelectedVariant.Price>
|
|
32
|
+
* </div>
|
|
33
|
+
* </SelectedVariant.Root>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function Root(props) {
|
|
39
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(SelectedVariantServiceDefinition, SelectedVariantService, props.selectedVariantServiceConfig), children: props.children }));
|
|
40
|
+
}
|
|
3
41
|
/**
|
|
4
42
|
* Headless component for selected variant details display
|
|
5
43
|
*
|