@wix/headless-stores 0.0.30 → 0.0.31
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/Category.d.ts +30 -0
- package/cjs/dist/react/Category.js +30 -0
- package/cjs/dist/react/Collection.d.ts +145 -0
- package/cjs/dist/react/Collection.js +145 -0
- package/cjs/dist/react/FilteredCollection.d.ts +134 -0
- package/cjs/dist/react/FilteredCollection.js +134 -0
- package/cjs/dist/react/Product.d.ts +43 -18
- package/cjs/dist/react/Product.js +43 -18
- package/cjs/dist/react/ProductActions.d.ts +30 -0
- package/cjs/dist/react/ProductActions.js +30 -0
- package/cjs/dist/react/ProductModifiers.d.ts +172 -0
- package/cjs/dist/react/ProductModifiers.js +172 -0
- package/cjs/dist/react/ProductVariantSelector.d.ts +118 -0
- package/cjs/dist/react/ProductVariantSelector.js +118 -0
- package/cjs/dist/react/ProductsList.d.ts +101 -0
- package/cjs/dist/react/ProductsList.js +101 -0
- package/cjs/dist/react/RelatedProducts.d.ts +55 -0
- package/cjs/dist/react/RelatedProducts.js +55 -0
- package/cjs/dist/react/SelectedVariant.d.ts +59 -0
- package/cjs/dist/react/SelectedVariant.js +59 -0
- package/cjs/dist/react/SocialSharing.d.ts +82 -0
- package/cjs/dist/react/SocialSharing.js +82 -0
- package/cjs/dist/react/Sort.d.ts +22 -0
- package/cjs/dist/react/Sort.js +22 -0
- package/cjs/dist/services/category-service.d.ts +87 -0
- package/cjs/dist/services/category-service.js +87 -0
- package/cjs/dist/services/collection-service.d.ts +89 -0
- package/cjs/dist/services/collection-service.js +89 -0
- package/cjs/dist/services/product-service.d.ts +76 -0
- package/cjs/dist/services/product-service.js +76 -0
- package/cjs/dist/services/products-list-service.d.ts +93 -0
- package/cjs/dist/services/products-list-service.js +93 -0
- package/cjs/dist/services/related-products-service.d.ts +75 -0
- package/cjs/dist/services/related-products-service.js +75 -0
- package/dist/react/Category.d.ts +30 -0
- package/dist/react/Category.js +30 -0
- package/dist/react/Collection.d.ts +145 -0
- package/dist/react/Collection.js +145 -0
- package/dist/react/FilteredCollection.d.ts +134 -0
- package/dist/react/FilteredCollection.js +134 -0
- package/dist/react/Product.d.ts +43 -18
- package/dist/react/Product.js +43 -18
- package/dist/react/ProductActions.d.ts +30 -0
- package/dist/react/ProductActions.js +30 -0
- package/dist/react/ProductModifiers.d.ts +172 -0
- package/dist/react/ProductModifiers.js +172 -0
- package/dist/react/ProductVariantSelector.d.ts +118 -0
- package/dist/react/ProductVariantSelector.js +118 -0
- package/dist/react/ProductsList.d.ts +101 -0
- package/dist/react/ProductsList.js +101 -0
- package/dist/react/RelatedProducts.d.ts +55 -0
- package/dist/react/RelatedProducts.js +55 -0
- package/dist/react/SelectedVariant.d.ts +59 -0
- package/dist/react/SelectedVariant.js +59 -0
- package/dist/react/SocialSharing.d.ts +82 -0
- package/dist/react/SocialSharing.js +82 -0
- package/dist/react/Sort.d.ts +22 -0
- package/dist/react/Sort.js +22 -0
- package/dist/services/category-service.d.ts +87 -0
- package/dist/services/category-service.js +87 -0
- package/dist/services/collection-service.d.ts +89 -0
- package/dist/services/collection-service.js +89 -0
- package/dist/services/product-service.d.ts +76 -0
- package/dist/services/product-service.js +76 -0
- package/dist/services/products-list-service.d.ts +93 -0
- package/dist/services/products-list-service.js +93 -0
- package/dist/services/related-products-service.d.ts +75 -0
- package/dist/services/related-products-service.js +75 -0
- package/package.json +1 -1
|
@@ -2,6 +2,99 @@ import { defineService, implementService } from "@wix/services-definitions";
|
|
|
2
2
|
import { SignalsServiceDefinition, } from "@wix/services-definitions/core-services/signals";
|
|
3
3
|
import { productsV3 } from "@wix/stores";
|
|
4
4
|
;
|
|
5
|
+
/**
|
|
6
|
+
* Loads products list service configuration from the Wix Products API for SSR initialization.
|
|
7
|
+
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
8
|
+
* products based on search criteria that will be used to configure the ProductsListService.
|
|
9
|
+
*
|
|
10
|
+
* @param searchOptions Search options for filtering and querying products
|
|
11
|
+
* @returns Promise that resolves to ProductsListServiceConfig with products, metadata, and aggregations
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```astro
|
|
15
|
+
* ---
|
|
16
|
+
* // Astro page example - pages/search.astro
|
|
17
|
+
* import { loadProductsListServiceConfig } from '@wix/stores/services';
|
|
18
|
+
* import { ProductsList } from '@wix/stores/components';
|
|
19
|
+
*
|
|
20
|
+
* // Get search query from URL params
|
|
21
|
+
* const searchQuery = Astro.url.searchParams.get('q') || '';
|
|
22
|
+
* const category = Astro.url.searchParams.get('category');
|
|
23
|
+
*
|
|
24
|
+
* // Build search options
|
|
25
|
+
* const searchOptions = {
|
|
26
|
+
* query: { search: searchQuery },
|
|
27
|
+
* filter: category ? { categories: [category] } : undefined,
|
|
28
|
+
* paging: { limit: 12 }
|
|
29
|
+
* };
|
|
30
|
+
*
|
|
31
|
+
* // Load products during SSR
|
|
32
|
+
* const productsListConfig = await loadProductsListServiceConfig(searchOptions);
|
|
33
|
+
* ---
|
|
34
|
+
*
|
|
35
|
+
* <ProductsList.Root productsListConfig={productsListConfig}>
|
|
36
|
+
* <ProductsList.ItemContent>
|
|
37
|
+
* {({ product }) => (
|
|
38
|
+
* <div class="product-item">
|
|
39
|
+
* <h3>{product.name}</h3>
|
|
40
|
+
* </div>
|
|
41
|
+
* )}
|
|
42
|
+
* </ProductsList.ItemContent>
|
|
43
|
+
* </ProductsList.Root>
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* ```tsx
|
|
48
|
+
* // Next.js page example - pages/search.tsx
|
|
49
|
+
* import { GetServerSideProps } from 'next';
|
|
50
|
+
* import { loadProductsListServiceConfig } from '@wix/stores/services';
|
|
51
|
+
* import { ProductsList } from '@wix/stores/components';
|
|
52
|
+
*
|
|
53
|
+
* interface SearchPageProps {
|
|
54
|
+
* productsListConfig: Awaited<ReturnType<typeof loadProductsListServiceConfig>>;
|
|
55
|
+
* searchQuery: string;
|
|
56
|
+
* }
|
|
57
|
+
*
|
|
58
|
+
* export const getServerSideProps: GetServerSideProps<SearchPageProps> = async ({ query }) => {
|
|
59
|
+
* const searchQuery = (query.q as string) || '';
|
|
60
|
+
* const category = query.category as string;
|
|
61
|
+
*
|
|
62
|
+
* // Build search options
|
|
63
|
+
* const searchOptions = {
|
|
64
|
+
* query: { search: searchQuery },
|
|
65
|
+
* filter: category ? { categories: [category] } : undefined,
|
|
66
|
+
* paging: { limit: 12 }
|
|
67
|
+
* };
|
|
68
|
+
*
|
|
69
|
+
* // Load products during SSR
|
|
70
|
+
* const productsListConfig = await loadProductsListServiceConfig(searchOptions);
|
|
71
|
+
*
|
|
72
|
+
* return {
|
|
73
|
+
* props: {
|
|
74
|
+
* productsListConfig,
|
|
75
|
+
* searchQuery,
|
|
76
|
+
* },
|
|
77
|
+
* };
|
|
78
|
+
* };
|
|
79
|
+
*
|
|
80
|
+
* export default function SearchPage({ productsListConfig, searchQuery }: SearchPageProps) {
|
|
81
|
+
* return (
|
|
82
|
+
* <div>
|
|
83
|
+
* <h1>Search Results for "{searchQuery}"</h1>
|
|
84
|
+
* <ProductsList.Root productsListConfig={productsListConfig}>
|
|
85
|
+
* <ProductsList.ItemContent>
|
|
86
|
+
* {({ product }) => (
|
|
87
|
+
* <div className="product-item">
|
|
88
|
+
* <h3>{product.name}</h3>
|
|
89
|
+
* </div>
|
|
90
|
+
* )}
|
|
91
|
+
* </ProductsList.ItemContent>
|
|
92
|
+
* </ProductsList.Root>
|
|
93
|
+
* </div>
|
|
94
|
+
* );
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
97
|
+
*/
|
|
5
98
|
export async function loadProductsListServiceConfig(searchOptions) {
|
|
6
99
|
const result = await productsV3.searchProducts(searchOptions);
|
|
7
100
|
return {
|
|
@@ -22,4 +22,79 @@ export declare const RelatedProductsService: import("@wix/services-definitions")
|
|
|
22
22
|
__config: {};
|
|
23
23
|
isServiceDefinition?: boolean;
|
|
24
24
|
} & RelatedProductsServiceAPI, RelatedProductsServiceConfig>;
|
|
25
|
+
/**
|
|
26
|
+
* Loads related products service configuration for SSR initialization.
|
|
27
|
+
* This function is designed to be used during Server-Side Rendering (SSR) to create
|
|
28
|
+
* configuration that tells the RelatedProductsService which product to load related products for.
|
|
29
|
+
* Unlike other loaders, this creates configuration rather than fetching data during SSR.
|
|
30
|
+
*
|
|
31
|
+
* @param productId The ID of the product to find related products for
|
|
32
|
+
* @param limit Optional number of related products to load (default: 4)
|
|
33
|
+
* @returns Promise that resolves to RelatedProductsServiceConfig
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```astro
|
|
37
|
+
* ---
|
|
38
|
+
* // Astro page example - pages/product/[slug].astro
|
|
39
|
+
* import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
|
|
40
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
41
|
+
*
|
|
42
|
+
* // Create related products config for a specific product
|
|
43
|
+
* const relatedProductsConfig = await loadRelatedProductsServiceConfig(
|
|
44
|
+
* 'product-id-123',
|
|
45
|
+
* 6
|
|
46
|
+
* );
|
|
47
|
+
* ---
|
|
48
|
+
*
|
|
49
|
+
* <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
|
|
50
|
+
* <RelatedProducts.List>
|
|
51
|
+
* {({ products, isLoading }) => (
|
|
52
|
+
* <div>
|
|
53
|
+
* {isLoading ? 'Loading...' : `${products.length} related products`}
|
|
54
|
+
* </div>
|
|
55
|
+
* )}
|
|
56
|
+
* </RelatedProducts.List>
|
|
57
|
+
* </RelatedProducts.Root>
|
|
58
|
+
* ```
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```tsx
|
|
62
|
+
* // Next.js page example - pages/product/[slug].tsx
|
|
63
|
+
* import { GetServerSideProps } from 'next';
|
|
64
|
+
* import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
|
|
65
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
66
|
+
*
|
|
67
|
+
* interface ProductPageProps {
|
|
68
|
+
* relatedProductsConfig: Awaited<ReturnType<typeof loadRelatedProductsServiceConfig>>;
|
|
69
|
+
* }
|
|
70
|
+
*
|
|
71
|
+
* export const getServerSideProps: GetServerSideProps<ProductPageProps> = async () => {
|
|
72
|
+
* // Create related products config for a specific product
|
|
73
|
+
* const relatedProductsConfig = await loadRelatedProductsServiceConfig(
|
|
74
|
+
* 'product-id-123',
|
|
75
|
+
* 6
|
|
76
|
+
* );
|
|
77
|
+
*
|
|
78
|
+
* return {
|
|
79
|
+
* props: {
|
|
80
|
+
* relatedProductsConfig,
|
|
81
|
+
* },
|
|
82
|
+
* };
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* export default function ProductPage({ relatedProductsConfig }: ProductPageProps) {
|
|
86
|
+
* return (
|
|
87
|
+
* <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
|
|
88
|
+
* <RelatedProducts.List>
|
|
89
|
+
* {({ products, isLoading }) => (
|
|
90
|
+
* <div>
|
|
91
|
+
* {isLoading ? 'Loading...' : `${products.length} related products`}
|
|
92
|
+
* </div>
|
|
93
|
+
* )}
|
|
94
|
+
* </RelatedProducts.List>
|
|
95
|
+
* </RelatedProducts.Root>
|
|
96
|
+
* );
|
|
97
|
+
* }
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
25
100
|
export declare function loadRelatedProductsServiceConfig(productId: string, limit?: number): Promise<RelatedProductsServiceConfig>;
|
|
@@ -44,6 +44,81 @@ export const RelatedProductsService = implementService.withConfig()(RelatedProdu
|
|
|
44
44
|
refreshRelatedProducts,
|
|
45
45
|
};
|
|
46
46
|
});
|
|
47
|
+
/**
|
|
48
|
+
* Loads related products service configuration for SSR initialization.
|
|
49
|
+
* This function is designed to be used during Server-Side Rendering (SSR) to create
|
|
50
|
+
* configuration that tells the RelatedProductsService which product to load related products for.
|
|
51
|
+
* Unlike other loaders, this creates configuration rather than fetching data during SSR.
|
|
52
|
+
*
|
|
53
|
+
* @param productId The ID of the product to find related products for
|
|
54
|
+
* @param limit Optional number of related products to load (default: 4)
|
|
55
|
+
* @returns Promise that resolves to RelatedProductsServiceConfig
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```astro
|
|
59
|
+
* ---
|
|
60
|
+
* // Astro page example - pages/product/[slug].astro
|
|
61
|
+
* import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
|
|
62
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
63
|
+
*
|
|
64
|
+
* // Create related products config for a specific product
|
|
65
|
+
* const relatedProductsConfig = await loadRelatedProductsServiceConfig(
|
|
66
|
+
* 'product-id-123',
|
|
67
|
+
* 6
|
|
68
|
+
* );
|
|
69
|
+
* ---
|
|
70
|
+
*
|
|
71
|
+
* <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
|
|
72
|
+
* <RelatedProducts.List>
|
|
73
|
+
* {({ products, isLoading }) => (
|
|
74
|
+
* <div>
|
|
75
|
+
* {isLoading ? 'Loading...' : `${products.length} related products`}
|
|
76
|
+
* </div>
|
|
77
|
+
* )}
|
|
78
|
+
* </RelatedProducts.List>
|
|
79
|
+
* </RelatedProducts.Root>
|
|
80
|
+
* ```
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```tsx
|
|
84
|
+
* // Next.js page example - pages/product/[slug].tsx
|
|
85
|
+
* import { GetServerSideProps } from 'next';
|
|
86
|
+
* import { loadRelatedProductsServiceConfig } from '@wix/stores/services';
|
|
87
|
+
* import { RelatedProducts } from '@wix/stores/components';
|
|
88
|
+
*
|
|
89
|
+
* interface ProductPageProps {
|
|
90
|
+
* relatedProductsConfig: Awaited<ReturnType<typeof loadRelatedProductsServiceConfig>>;
|
|
91
|
+
* }
|
|
92
|
+
*
|
|
93
|
+
* export const getServerSideProps: GetServerSideProps<ProductPageProps> = async () => {
|
|
94
|
+
* // Create related products config for a specific product
|
|
95
|
+
* const relatedProductsConfig = await loadRelatedProductsServiceConfig(
|
|
96
|
+
* 'product-id-123',
|
|
97
|
+
* 6
|
|
98
|
+
* );
|
|
99
|
+
*
|
|
100
|
+
* return {
|
|
101
|
+
* props: {
|
|
102
|
+
* relatedProductsConfig,
|
|
103
|
+
* },
|
|
104
|
+
* };
|
|
105
|
+
* };
|
|
106
|
+
*
|
|
107
|
+
* export default function ProductPage({ relatedProductsConfig }: ProductPageProps) {
|
|
108
|
+
* return (
|
|
109
|
+
* <RelatedProducts.Root relatedProductsConfig={relatedProductsConfig}>
|
|
110
|
+
* <RelatedProducts.List>
|
|
111
|
+
* {({ products, isLoading }) => (
|
|
112
|
+
* <div>
|
|
113
|
+
* {isLoading ? 'Loading...' : `${products.length} related products`}
|
|
114
|
+
* </div>
|
|
115
|
+
* )}
|
|
116
|
+
* </RelatedProducts.List>
|
|
117
|
+
* </RelatedProducts.Root>
|
|
118
|
+
* );
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
47
122
|
export async function loadRelatedProductsServiceConfig(productId, limit = 4) {
|
|
48
123
|
return {
|
|
49
124
|
productId,
|
package/dist/react/Category.d.ts
CHANGED
|
@@ -11,5 +11,35 @@ export interface CategoryListProps {
|
|
|
11
11
|
* Headless component for displaying a list of categories
|
|
12
12
|
*
|
|
13
13
|
* @component
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { Category } from '@wix/stores/components';
|
|
17
|
+
*
|
|
18
|
+
* function CategoryNavigation() {
|
|
19
|
+
* return (
|
|
20
|
+
* <Category.List>
|
|
21
|
+
* {({ categories, selectedCategory, setSelectedCategory }) => (
|
|
22
|
+
* <nav>
|
|
23
|
+
* <button
|
|
24
|
+
* onClick={() => setSelectedCategory(null)}
|
|
25
|
+
* className={selectedCategory === null ? 'active' : ''}
|
|
26
|
+
* >
|
|
27
|
+
* All Categories
|
|
28
|
+
* </button>
|
|
29
|
+
* {categories.map(category => (
|
|
30
|
+
* <button
|
|
31
|
+
* key={category.id}
|
|
32
|
+
* onClick={() => setSelectedCategory(category.id)}
|
|
33
|
+
* className={selectedCategory === category.id ? 'active' : ''}
|
|
34
|
+
* >
|
|
35
|
+
* {category.name}
|
|
36
|
+
* </button>
|
|
37
|
+
* ))}
|
|
38
|
+
* </nav>
|
|
39
|
+
* )}
|
|
40
|
+
* </Category.List>
|
|
41
|
+
* );
|
|
42
|
+
* }
|
|
43
|
+
* ```
|
|
14
44
|
*/
|
|
15
45
|
export declare const List: React.FC<CategoryListProps>;
|
package/dist/react/Category.js
CHANGED
|
@@ -5,6 +5,36 @@ import { CategoryServiceDefinition } from "../services/category-service.js";
|
|
|
5
5
|
* Headless component for displaying a list of categories
|
|
6
6
|
*
|
|
7
7
|
* @component
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { Category } from '@wix/stores/components';
|
|
11
|
+
*
|
|
12
|
+
* function CategoryNavigation() {
|
|
13
|
+
* return (
|
|
14
|
+
* <Category.List>
|
|
15
|
+
* {({ categories, selectedCategory, setSelectedCategory }) => (
|
|
16
|
+
* <nav>
|
|
17
|
+
* <button
|
|
18
|
+
* onClick={() => setSelectedCategory(null)}
|
|
19
|
+
* className={selectedCategory === null ? 'active' : ''}
|
|
20
|
+
* >
|
|
21
|
+
* All Categories
|
|
22
|
+
* </button>
|
|
23
|
+
* {categories.map(category => (
|
|
24
|
+
* <button
|
|
25
|
+
* key={category.id}
|
|
26
|
+
* onClick={() => setSelectedCategory(category.id)}
|
|
27
|
+
* className={selectedCategory === category.id ? 'active' : ''}
|
|
28
|
+
* >
|
|
29
|
+
* {category.name}
|
|
30
|
+
* </button>
|
|
31
|
+
* ))}
|
|
32
|
+
* </nav>
|
|
33
|
+
* )}
|
|
34
|
+
* </Category.List>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
8
38
|
*/
|
|
9
39
|
export const List = ({ children }) => {
|
|
10
40
|
const service = useService(CategoryServiceDefinition);
|
|
@@ -27,6 +27,37 @@ export interface GridRenderProps {
|
|
|
27
27
|
* Headless component for product grid
|
|
28
28
|
*
|
|
29
29
|
* @component
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* import { Collection } from '@wix/stores/components';
|
|
33
|
+
*
|
|
34
|
+
* function ProductGrid() {
|
|
35
|
+
* return (
|
|
36
|
+
* <Collection.Grid>
|
|
37
|
+
* {({ products, isLoading, error, isEmpty, totalProducts, hasProducts }) => (
|
|
38
|
+
* <div>
|
|
39
|
+
* {isLoading && <div>Loading products...</div>}
|
|
40
|
+
* {error && <div>Error: {error}</div>}
|
|
41
|
+
* {isEmpty && <div>No products found</div>}
|
|
42
|
+
* {hasProducts && (
|
|
43
|
+
* <div>
|
|
44
|
+
* <p>Showing {products.length} of {totalProducts} products</p>
|
|
45
|
+
* <div className="product-grid">
|
|
46
|
+
* {products.map(product => (
|
|
47
|
+
* <div key={product.id} className="product-card">
|
|
48
|
+
* <h3>{product.name}</h3>
|
|
49
|
+
* <p>{product.price?.price} {product.price?.currency}</p>
|
|
50
|
+
* </div>
|
|
51
|
+
* ))}
|
|
52
|
+
* </div>
|
|
53
|
+
* </div>
|
|
54
|
+
* )}
|
|
55
|
+
* </div>
|
|
56
|
+
* )}
|
|
57
|
+
* </Collection.Grid>
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
30
61
|
*/
|
|
31
62
|
export declare const Grid: (props: GridProps) => import("react").ReactNode;
|
|
32
63
|
/**
|
|
@@ -63,6 +94,32 @@ export interface ItemRenderProps {
|
|
|
63
94
|
* Headless component for individual product item
|
|
64
95
|
*
|
|
65
96
|
* @component
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* import { Collection } from '@wix/stores/components';
|
|
100
|
+
*
|
|
101
|
+
* function ProductCard({ product }) {
|
|
102
|
+
* return (
|
|
103
|
+
* <Collection.Item product={product}>
|
|
104
|
+
* {({ id, title, slug, image, price, compareAtPrice, description, available }) => (
|
|
105
|
+
* <div className={`product-card ${!available ? 'unavailable' : ''}`}>
|
|
106
|
+
* {image && <img src={image} alt={title} />}
|
|
107
|
+
* <h3>{title}</h3>
|
|
108
|
+
* <p>{description}</p>
|
|
109
|
+
* <div className="pricing">
|
|
110
|
+
* <span className="price">{price}</span>
|
|
111
|
+
* {compareAtPrice && (
|
|
112
|
+
* <span className="compare-price"><s>{compareAtPrice}</s></span>
|
|
113
|
+
* )}
|
|
114
|
+
* </div>
|
|
115
|
+
* {!available && <div className="badge">Out of Stock</div>}
|
|
116
|
+
* <a href={`/products/${slug}`}>View Product</a>
|
|
117
|
+
* </div>
|
|
118
|
+
* )}
|
|
119
|
+
* </Collection.Item>
|
|
120
|
+
* );
|
|
121
|
+
* }
|
|
122
|
+
* ```
|
|
66
123
|
*/
|
|
67
124
|
export declare const Item: (props: ItemProps) => import("react").ReactNode;
|
|
68
125
|
/**
|
|
@@ -94,6 +151,37 @@ export interface LoadMoreRenderProps {
|
|
|
94
151
|
* Note: V3 API uses simplified loading without traditional pagination
|
|
95
152
|
*
|
|
96
153
|
* @component
|
|
154
|
+
* @example
|
|
155
|
+
* ```tsx
|
|
156
|
+
* import { Collection } from '@wix/stores/components';
|
|
157
|
+
*
|
|
158
|
+
* function LoadMoreButton() {
|
|
159
|
+
* return (
|
|
160
|
+
* <Collection.LoadMore>
|
|
161
|
+
* {({ loadMore, refresh, isLoading, hasProducts, totalProducts, hasMoreProducts }) => (
|
|
162
|
+
* <div className="load-more-section">
|
|
163
|
+
* {hasProducts && (
|
|
164
|
+
* <div>
|
|
165
|
+
* <p>Loaded {totalProducts} products</p>
|
|
166
|
+
* <div className="actions">
|
|
167
|
+
* {hasMoreProducts && (
|
|
168
|
+
* <button
|
|
169
|
+
* onClick={loadMore}
|
|
170
|
+
* disabled={isLoading}
|
|
171
|
+
* >
|
|
172
|
+
* {isLoading ? 'Loading...' : 'Load More Products'}
|
|
173
|
+
* </button>
|
|
174
|
+
* )}
|
|
175
|
+
* <button onClick={refresh}>Refresh Collection</button>
|
|
176
|
+
* </div>
|
|
177
|
+
* </div>
|
|
178
|
+
* )}
|
|
179
|
+
* </div>
|
|
180
|
+
* )}
|
|
181
|
+
* </Collection.LoadMore>
|
|
182
|
+
* );
|
|
183
|
+
* }
|
|
184
|
+
* ```
|
|
97
185
|
*/
|
|
98
186
|
export declare const LoadMore: (props: LoadMoreProps) => import("react").ReactNode;
|
|
99
187
|
/**
|
|
@@ -118,6 +206,28 @@ export interface HeaderRenderProps {
|
|
|
118
206
|
* Headless component for collection header with product count
|
|
119
207
|
*
|
|
120
208
|
* @component
|
|
209
|
+
* @example
|
|
210
|
+
* ```tsx
|
|
211
|
+
* import { Collection } from '@wix/stores/components';
|
|
212
|
+
*
|
|
213
|
+
* function CollectionHeader() {
|
|
214
|
+
* return (
|
|
215
|
+
* <Collection.Header>
|
|
216
|
+
* {({ totalProducts, isLoading, hasProducts }) => (
|
|
217
|
+
* <div className="collection-header">
|
|
218
|
+
* {isLoading && <div>Loading collection...</div>}
|
|
219
|
+
* {hasProducts && !isLoading && (
|
|
220
|
+
* <h2>Products ({totalProducts} items)</h2>
|
|
221
|
+
* )}
|
|
222
|
+
* {!hasProducts && !isLoading && (
|
|
223
|
+
* <h2>No products found</h2>
|
|
224
|
+
* )}
|
|
225
|
+
* </div>
|
|
226
|
+
* )}
|
|
227
|
+
* </Collection.Header>
|
|
228
|
+
* );
|
|
229
|
+
* }
|
|
230
|
+
* ```
|
|
121
231
|
*/
|
|
122
232
|
export declare const Header: (props: HeaderProps) => import("react").ReactNode;
|
|
123
233
|
/**
|
|
@@ -145,5 +255,40 @@ export interface ActionsRenderProps {
|
|
|
145
255
|
* Replaces traditional pagination for V3 API
|
|
146
256
|
*
|
|
147
257
|
* @component
|
|
258
|
+
* @example
|
|
259
|
+
* ```tsx
|
|
260
|
+
* import { Collection } from '@wix/stores/components';
|
|
261
|
+
*
|
|
262
|
+
* function CollectionActions() {
|
|
263
|
+
* return (
|
|
264
|
+
* <Collection.Actions>
|
|
265
|
+
* {({ refresh, loadMore, isLoading, error }) => (
|
|
266
|
+
* <div className="collection-actions">
|
|
267
|
+
* {error && (
|
|
268
|
+
* <div className="error">
|
|
269
|
+
* Error: {error}
|
|
270
|
+
* <button onClick={refresh}>Retry</button>
|
|
271
|
+
* </div>
|
|
272
|
+
* )}
|
|
273
|
+
* <div className="action-buttons">
|
|
274
|
+
* <button
|
|
275
|
+
* onClick={refresh}
|
|
276
|
+
* disabled={isLoading}
|
|
277
|
+
* >
|
|
278
|
+
* {isLoading ? 'Refreshing...' : 'Refresh'}
|
|
279
|
+
* </button>
|
|
280
|
+
* <button
|
|
281
|
+
* onClick={loadMore}
|
|
282
|
+
* disabled={isLoading}
|
|
283
|
+
* >
|
|
284
|
+
* Load More
|
|
285
|
+
* </button>
|
|
286
|
+
* </div>
|
|
287
|
+
* </div>
|
|
288
|
+
* )}
|
|
289
|
+
* </Collection.Actions>
|
|
290
|
+
* );
|
|
291
|
+
* }
|
|
292
|
+
* ```
|
|
148
293
|
*/
|
|
149
294
|
export declare const Actions: (props: ActionsProps) => import("react").ReactNode;
|
package/dist/react/Collection.js
CHANGED
|
@@ -5,6 +5,37 @@ import { InventoryAvailabilityStatus, } from "@wix/auto_sdk_stores_products-v-3"
|
|
|
5
5
|
* Headless component for product grid
|
|
6
6
|
*
|
|
7
7
|
* @component
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { Collection } from '@wix/stores/components';
|
|
11
|
+
*
|
|
12
|
+
* function ProductGrid() {
|
|
13
|
+
* return (
|
|
14
|
+
* <Collection.Grid>
|
|
15
|
+
* {({ products, isLoading, error, isEmpty, totalProducts, hasProducts }) => (
|
|
16
|
+
* <div>
|
|
17
|
+
* {isLoading && <div>Loading products...</div>}
|
|
18
|
+
* {error && <div>Error: {error}</div>}
|
|
19
|
+
* {isEmpty && <div>No products found</div>}
|
|
20
|
+
* {hasProducts && (
|
|
21
|
+
* <div>
|
|
22
|
+
* <p>Showing {products.length} of {totalProducts} products</p>
|
|
23
|
+
* <div className="product-grid">
|
|
24
|
+
* {products.map(product => (
|
|
25
|
+
* <div key={product.id} className="product-card">
|
|
26
|
+
* <h3>{product.name}</h3>
|
|
27
|
+
* <p>{product.price?.price} {product.price?.currency}</p>
|
|
28
|
+
* </div>
|
|
29
|
+
* ))}
|
|
30
|
+
* </div>
|
|
31
|
+
* </div>
|
|
32
|
+
* )}
|
|
33
|
+
* </div>
|
|
34
|
+
* )}
|
|
35
|
+
* </Collection.Grid>
|
|
36
|
+
* );
|
|
37
|
+
* }
|
|
38
|
+
* ```
|
|
8
39
|
*/
|
|
9
40
|
export const Grid = (props) => {
|
|
10
41
|
const service = useService(CollectionServiceDefinition);
|
|
@@ -52,6 +83,32 @@ export const Grid = (props) => {
|
|
|
52
83
|
* Headless component for individual product item
|
|
53
84
|
*
|
|
54
85
|
* @component
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* import { Collection } from '@wix/stores/components';
|
|
89
|
+
*
|
|
90
|
+
* function ProductCard({ product }) {
|
|
91
|
+
* return (
|
|
92
|
+
* <Collection.Item product={product}>
|
|
93
|
+
* {({ id, title, slug, image, price, compareAtPrice, description, available }) => (
|
|
94
|
+
* <div className={`product-card ${!available ? 'unavailable' : ''}`}>
|
|
95
|
+
* {image && <img src={image} alt={title} />}
|
|
96
|
+
* <h3>{title}</h3>
|
|
97
|
+
* <p>{description}</p>
|
|
98
|
+
* <div className="pricing">
|
|
99
|
+
* <span className="price">{price}</span>
|
|
100
|
+
* {compareAtPrice && (
|
|
101
|
+
* <span className="compare-price"><s>{compareAtPrice}</s></span>
|
|
102
|
+
* )}
|
|
103
|
+
* </div>
|
|
104
|
+
* {!available && <div className="badge">Out of Stock</div>}
|
|
105
|
+
* <a href={`/products/${slug}`}>View Product</a>
|
|
106
|
+
* </div>
|
|
107
|
+
* )}
|
|
108
|
+
* </Collection.Item>
|
|
109
|
+
* );
|
|
110
|
+
* }
|
|
111
|
+
* ```
|
|
55
112
|
*/
|
|
56
113
|
export const Item = (props) => {
|
|
57
114
|
const { product } = props;
|
|
@@ -84,6 +141,37 @@ export const Item = (props) => {
|
|
|
84
141
|
* Note: V3 API uses simplified loading without traditional pagination
|
|
85
142
|
*
|
|
86
143
|
* @component
|
|
144
|
+
* @example
|
|
145
|
+
* ```tsx
|
|
146
|
+
* import { Collection } from '@wix/stores/components';
|
|
147
|
+
*
|
|
148
|
+
* function LoadMoreButton() {
|
|
149
|
+
* return (
|
|
150
|
+
* <Collection.LoadMore>
|
|
151
|
+
* {({ loadMore, refresh, isLoading, hasProducts, totalProducts, hasMoreProducts }) => (
|
|
152
|
+
* <div className="load-more-section">
|
|
153
|
+
* {hasProducts && (
|
|
154
|
+
* <div>
|
|
155
|
+
* <p>Loaded {totalProducts} products</p>
|
|
156
|
+
* <div className="actions">
|
|
157
|
+
* {hasMoreProducts && (
|
|
158
|
+
* <button
|
|
159
|
+
* onClick={loadMore}
|
|
160
|
+
* disabled={isLoading}
|
|
161
|
+
* >
|
|
162
|
+
* {isLoading ? 'Loading...' : 'Load More Products'}
|
|
163
|
+
* </button>
|
|
164
|
+
* )}
|
|
165
|
+
* <button onClick={refresh}>Refresh Collection</button>
|
|
166
|
+
* </div>
|
|
167
|
+
* </div>
|
|
168
|
+
* )}
|
|
169
|
+
* </div>
|
|
170
|
+
* )}
|
|
171
|
+
* </Collection.LoadMore>
|
|
172
|
+
* );
|
|
173
|
+
* }
|
|
174
|
+
* ```
|
|
87
175
|
*/
|
|
88
176
|
export const LoadMore = (props) => {
|
|
89
177
|
const service = useService(CollectionServiceDefinition);
|
|
@@ -129,6 +217,28 @@ export const LoadMore = (props) => {
|
|
|
129
217
|
* Headless component for collection header with product count
|
|
130
218
|
*
|
|
131
219
|
* @component
|
|
220
|
+
* @example
|
|
221
|
+
* ```tsx
|
|
222
|
+
* import { Collection } from '@wix/stores/components';
|
|
223
|
+
*
|
|
224
|
+
* function CollectionHeader() {
|
|
225
|
+
* return (
|
|
226
|
+
* <Collection.Header>
|
|
227
|
+
* {({ totalProducts, isLoading, hasProducts }) => (
|
|
228
|
+
* <div className="collection-header">
|
|
229
|
+
* {isLoading && <div>Loading collection...</div>}
|
|
230
|
+
* {hasProducts && !isLoading && (
|
|
231
|
+
* <h2>Products ({totalProducts} items)</h2>
|
|
232
|
+
* )}
|
|
233
|
+
* {!hasProducts && !isLoading && (
|
|
234
|
+
* <h2>No products found</h2>
|
|
235
|
+
* )}
|
|
236
|
+
* </div>
|
|
237
|
+
* )}
|
|
238
|
+
* </Collection.Header>
|
|
239
|
+
* );
|
|
240
|
+
* }
|
|
241
|
+
* ```
|
|
132
242
|
*/
|
|
133
243
|
export const Header = (props) => {
|
|
134
244
|
const service = useService(CollectionServiceDefinition);
|
|
@@ -165,6 +275,41 @@ export const Header = (props) => {
|
|
|
165
275
|
* Replaces traditional pagination for V3 API
|
|
166
276
|
*
|
|
167
277
|
* @component
|
|
278
|
+
* @example
|
|
279
|
+
* ```tsx
|
|
280
|
+
* import { Collection } from '@wix/stores/components';
|
|
281
|
+
*
|
|
282
|
+
* function CollectionActions() {
|
|
283
|
+
* return (
|
|
284
|
+
* <Collection.Actions>
|
|
285
|
+
* {({ refresh, loadMore, isLoading, error }) => (
|
|
286
|
+
* <div className="collection-actions">
|
|
287
|
+
* {error && (
|
|
288
|
+
* <div className="error">
|
|
289
|
+
* Error: {error}
|
|
290
|
+
* <button onClick={refresh}>Retry</button>
|
|
291
|
+
* </div>
|
|
292
|
+
* )}
|
|
293
|
+
* <div className="action-buttons">
|
|
294
|
+
* <button
|
|
295
|
+
* onClick={refresh}
|
|
296
|
+
* disabled={isLoading}
|
|
297
|
+
* >
|
|
298
|
+
* {isLoading ? 'Refreshing...' : 'Refresh'}
|
|
299
|
+
* </button>
|
|
300
|
+
* <button
|
|
301
|
+
* onClick={loadMore}
|
|
302
|
+
* disabled={isLoading}
|
|
303
|
+
* >
|
|
304
|
+
* Load More
|
|
305
|
+
* </button>
|
|
306
|
+
* </div>
|
|
307
|
+
* </div>
|
|
308
|
+
* )}
|
|
309
|
+
* </Collection.Actions>
|
|
310
|
+
* );
|
|
311
|
+
* }
|
|
312
|
+
* ```
|
|
168
313
|
*/
|
|
169
314
|
export const Actions = (props) => {
|
|
170
315
|
const service = useService(CollectionServiceDefinition);
|