@wix/headless-stores 0.0.29 → 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 +107 -16
- package/cjs/dist/react/ProductsList.js +101 -16
- 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 +107 -16
- package/dist/react/ProductsList.js +101 -16
- 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
|
@@ -18,6 +18,23 @@ export interface ProductDetailsRenderProps {
|
|
|
18
18
|
* Headless component for selected variant details display
|
|
19
19
|
*
|
|
20
20
|
* @component
|
|
21
|
+
* @example
|
|
22
|
+
* ```tsx
|
|
23
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
24
|
+
*
|
|
25
|
+
* function VariantDetails() {
|
|
26
|
+
* return (
|
|
27
|
+
* <SelectedVariant.Details>
|
|
28
|
+
* {({ sku, weight }) => (
|
|
29
|
+
* <div>
|
|
30
|
+
* {sku && <div>SKU: {sku}</div>}
|
|
31
|
+
* {weight && <div>Weight: {weight}</div>}
|
|
32
|
+
* </div>
|
|
33
|
+
* )}
|
|
34
|
+
* </SelectedVariant.Details>
|
|
35
|
+
* );
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
21
38
|
*/
|
|
22
39
|
export declare const Details: (props: ProductDetailsProps) => import("react").ReactNode;
|
|
23
40
|
/**
|
|
@@ -42,6 +59,28 @@ export interface PriceRenderProps {
|
|
|
42
59
|
* Headless component for product price display
|
|
43
60
|
*
|
|
44
61
|
* @component
|
|
62
|
+
* @example
|
|
63
|
+
* ```tsx
|
|
64
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
65
|
+
*
|
|
66
|
+
* function ProductPrice() {
|
|
67
|
+
* return (
|
|
68
|
+
* <SelectedVariant.Price>
|
|
69
|
+
* {({ price, compareAtPrice, currency }) => (
|
|
70
|
+
* <div className="price-display">
|
|
71
|
+
* <span className="current-price">{price}</span>
|
|
72
|
+
* {compareAtPrice && (
|
|
73
|
+
* <span className="compare-price">
|
|
74
|
+
* <s>{compareAtPrice}</s>
|
|
75
|
+
* </span>
|
|
76
|
+
* )}
|
|
77
|
+
* <span className="currency">{currency}</span>
|
|
78
|
+
* </div>
|
|
79
|
+
* )}
|
|
80
|
+
* </SelectedVariant.Price>
|
|
81
|
+
* );
|
|
82
|
+
* }
|
|
83
|
+
* ```
|
|
45
84
|
*/
|
|
46
85
|
export declare const Price: (props: PriceProps) => import("react").ReactNode;
|
|
47
86
|
/**
|
|
@@ -62,5 +101,25 @@ export interface SKURenderProps {
|
|
|
62
101
|
* Headless component for product SKU display
|
|
63
102
|
*
|
|
64
103
|
* @component
|
|
104
|
+
* @example
|
|
105
|
+
* ```tsx
|
|
106
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
107
|
+
*
|
|
108
|
+
* function ProductSKU() {
|
|
109
|
+
* return (
|
|
110
|
+
* <SelectedVariant.SKU>
|
|
111
|
+
* {({ sku }) => (
|
|
112
|
+
* <div>
|
|
113
|
+
* {sku && (
|
|
114
|
+
* <div className="product-sku">
|
|
115
|
+
* <strong>SKU:</strong> {sku}
|
|
116
|
+
* </div>
|
|
117
|
+
* )}
|
|
118
|
+
* </div>
|
|
119
|
+
* )}
|
|
120
|
+
* </SelectedVariant.SKU>
|
|
121
|
+
* );
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
65
124
|
*/
|
|
66
125
|
export declare const SKU: (props: SKUProps) => import("react").ReactNode;
|
|
@@ -4,6 +4,23 @@ import { SelectedVariantServiceDefinition } from "../services/selected-variant-s
|
|
|
4
4
|
* Headless component for selected variant details display
|
|
5
5
|
*
|
|
6
6
|
* @component
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
10
|
+
*
|
|
11
|
+
* function VariantDetails() {
|
|
12
|
+
* return (
|
|
13
|
+
* <SelectedVariant.Details>
|
|
14
|
+
* {({ sku, weight }) => (
|
|
15
|
+
* <div>
|
|
16
|
+
* {sku && <div>SKU: {sku}</div>}
|
|
17
|
+
* {weight && <div>Weight: {weight}</div>}
|
|
18
|
+
* </div>
|
|
19
|
+
* )}
|
|
20
|
+
* </SelectedVariant.Details>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
7
24
|
*/
|
|
8
25
|
export const Details = (props) => {
|
|
9
26
|
const selectedVariantService = useService(SelectedVariantServiceDefinition);
|
|
@@ -19,6 +36,28 @@ export const Details = (props) => {
|
|
|
19
36
|
* Headless component for product price display
|
|
20
37
|
*
|
|
21
38
|
* @component
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
42
|
+
*
|
|
43
|
+
* function ProductPrice() {
|
|
44
|
+
* return (
|
|
45
|
+
* <SelectedVariant.Price>
|
|
46
|
+
* {({ price, compareAtPrice, currency }) => (
|
|
47
|
+
* <div className="price-display">
|
|
48
|
+
* <span className="current-price">{price}</span>
|
|
49
|
+
* {compareAtPrice && (
|
|
50
|
+
* <span className="compare-price">
|
|
51
|
+
* <s>{compareAtPrice}</s>
|
|
52
|
+
* </span>
|
|
53
|
+
* )}
|
|
54
|
+
* <span className="currency">{currency}</span>
|
|
55
|
+
* </div>
|
|
56
|
+
* )}
|
|
57
|
+
* </SelectedVariant.Price>
|
|
58
|
+
* );
|
|
59
|
+
* }
|
|
60
|
+
* ```
|
|
22
61
|
*/
|
|
23
62
|
export const Price = (props) => {
|
|
24
63
|
const variantService = useService(SelectedVariantServiceDefinition);
|
|
@@ -35,6 +74,26 @@ export const Price = (props) => {
|
|
|
35
74
|
* Headless component for product SKU display
|
|
36
75
|
*
|
|
37
76
|
* @component
|
|
77
|
+
* @example
|
|
78
|
+
* ```tsx
|
|
79
|
+
* import { SelectedVariant } from '@wix/stores/components';
|
|
80
|
+
*
|
|
81
|
+
* function ProductSKU() {
|
|
82
|
+
* return (
|
|
83
|
+
* <SelectedVariant.SKU>
|
|
84
|
+
* {({ sku }) => (
|
|
85
|
+
* <div>
|
|
86
|
+
* {sku && (
|
|
87
|
+
* <div className="product-sku">
|
|
88
|
+
* <strong>SKU:</strong> {sku}
|
|
89
|
+
* </div>
|
|
90
|
+
* )}
|
|
91
|
+
* </div>
|
|
92
|
+
* )}
|
|
93
|
+
* </SelectedVariant.SKU>
|
|
94
|
+
* );
|
|
95
|
+
* }
|
|
96
|
+
* ```
|
|
38
97
|
*/
|
|
39
98
|
export const SKU = (props) => {
|
|
40
99
|
const selectedVariantService = useService(SelectedVariantServiceDefinition);
|
|
@@ -40,6 +40,43 @@ export interface RootRenderProps {
|
|
|
40
40
|
* Headless component for social sharing root
|
|
41
41
|
*
|
|
42
42
|
* @component
|
|
43
|
+
* @example
|
|
44
|
+
* ```tsx
|
|
45
|
+
* import { SocialSharing } from '@wix/stores/components';
|
|
46
|
+
*
|
|
47
|
+
* function ShareProduct() {
|
|
48
|
+
* const productUrl = 'https://example.com/product/123';
|
|
49
|
+
* const productTitle = 'Amazing Product';
|
|
50
|
+
*
|
|
51
|
+
* return (
|
|
52
|
+
* <SocialSharing.Root>
|
|
53
|
+
* {({ platforms, shareCount, shareFacebook, shareTwitter, copyLink, shareNative }) => (
|
|
54
|
+
* <div>
|
|
55
|
+
* <p>Share this product ({shareCount} shares)</p>
|
|
56
|
+
* <div className="share-buttons">
|
|
57
|
+
* <button onClick={() => shareFacebook(productUrl, productTitle)}>
|
|
58
|
+
* Share on Facebook
|
|
59
|
+
* </button>
|
|
60
|
+
* <button onClick={() => shareTwitter(productUrl, `Check out ${productTitle}!`)}>
|
|
61
|
+
* Share on Twitter
|
|
62
|
+
* </button>
|
|
63
|
+
* <button onClick={() => copyLink(productUrl)}>
|
|
64
|
+
* Copy Link
|
|
65
|
+
* </button>
|
|
66
|
+
* <button onClick={() => shareNative({
|
|
67
|
+
* title: productTitle,
|
|
68
|
+
* text: 'Check this out!',
|
|
69
|
+
* url: productUrl
|
|
70
|
+
* })}>
|
|
71
|
+
* Share
|
|
72
|
+
* </button>
|
|
73
|
+
* </div>
|
|
74
|
+
* </div>
|
|
75
|
+
* )}
|
|
76
|
+
* </SocialSharing.Root>
|
|
77
|
+
* );
|
|
78
|
+
* }
|
|
79
|
+
* ```
|
|
43
80
|
*/
|
|
44
81
|
export declare const Root: (props: RootProps) => React.ReactNode;
|
|
45
82
|
/**
|
|
@@ -66,6 +103,26 @@ export interface PlatformRenderProps {
|
|
|
66
103
|
* Headless component for individual social platform
|
|
67
104
|
*
|
|
68
105
|
* @component
|
|
106
|
+
* @example
|
|
107
|
+
* ```tsx
|
|
108
|
+
* import { SocialSharing } from '@wix/stores/components';
|
|
109
|
+
*
|
|
110
|
+
* function SocialButton({ platform, onClick }) {
|
|
111
|
+
* return (
|
|
112
|
+
* <SocialSharing.Platform platform={platform} onClick={onClick}>
|
|
113
|
+
* {({ platform, onSelect }) => (
|
|
114
|
+
* <button
|
|
115
|
+
* onClick={onSelect}
|
|
116
|
+
* className={`social-btn social-btn-${platform.name.toLowerCase()}`}
|
|
117
|
+
* >
|
|
118
|
+
* <span className="icon">{platform.icon}</span>
|
|
119
|
+
* Share on {platform.name}
|
|
120
|
+
* </button>
|
|
121
|
+
* )}
|
|
122
|
+
* </SocialSharing.Platform>
|
|
123
|
+
* );
|
|
124
|
+
* }
|
|
125
|
+
* ```
|
|
69
126
|
*/
|
|
70
127
|
export declare const Platform: (props: PlatformProps) => React.ReactNode;
|
|
71
128
|
/**
|
|
@@ -108,5 +165,30 @@ export interface PlatformsRenderProps {
|
|
|
108
165
|
* Headless component for social sharing platforms with logic
|
|
109
166
|
*
|
|
110
167
|
* @component
|
|
168
|
+
* @example
|
|
169
|
+
* ```tsx
|
|
170
|
+
* import { SocialSharing } from '@wix/stores/components';
|
|
171
|
+
*
|
|
172
|
+
* function SocialShareButtons() {
|
|
173
|
+
* return (
|
|
174
|
+
* <SocialSharing.Platforms
|
|
175
|
+
* url="https://example.com/product/123"
|
|
176
|
+
* title="Amazing Product"
|
|
177
|
+
* description="Check out this amazing product!"
|
|
178
|
+
* hashtags={['product', 'amazing']}
|
|
179
|
+
* >
|
|
180
|
+
* {({ platforms, shareFacebook, shareTwitter, shareLinkedIn, copyLink, shareNative }) => (
|
|
181
|
+
* <div className="social-platforms">
|
|
182
|
+
* <button onClick={shareFacebook}>Share on Facebook</button>
|
|
183
|
+
* <button onClick={shareTwitter}>Share on Twitter</button>
|
|
184
|
+
* <button onClick={shareLinkedIn}>Share on LinkedIn</button>
|
|
185
|
+
* <button onClick={() => copyLink()}>Copy Link</button>
|
|
186
|
+
* <button onClick={() => shareNative()}>Share</button>
|
|
187
|
+
* </div>
|
|
188
|
+
* )}
|
|
189
|
+
* </SocialSharing.Platforms>
|
|
190
|
+
* );
|
|
191
|
+
* }
|
|
192
|
+
* ```
|
|
111
193
|
*/
|
|
112
194
|
export declare const Platforms: (props: PlatformsProps) => React.ReactNode;
|
|
@@ -6,6 +6,43 @@ import { SignalsServiceDefinition } from "@wix/services-definitions/core-service
|
|
|
6
6
|
* Headless component for social sharing root
|
|
7
7
|
*
|
|
8
8
|
* @component
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* import { SocialSharing } from '@wix/stores/components';
|
|
12
|
+
*
|
|
13
|
+
* function ShareProduct() {
|
|
14
|
+
* const productUrl = 'https://example.com/product/123';
|
|
15
|
+
* const productTitle = 'Amazing Product';
|
|
16
|
+
*
|
|
17
|
+
* return (
|
|
18
|
+
* <SocialSharing.Root>
|
|
19
|
+
* {({ platforms, shareCount, shareFacebook, shareTwitter, copyLink, shareNative }) => (
|
|
20
|
+
* <div>
|
|
21
|
+
* <p>Share this product ({shareCount} shares)</p>
|
|
22
|
+
* <div className="share-buttons">
|
|
23
|
+
* <button onClick={() => shareFacebook(productUrl, productTitle)}>
|
|
24
|
+
* Share on Facebook
|
|
25
|
+
* </button>
|
|
26
|
+
* <button onClick={() => shareTwitter(productUrl, `Check out ${productTitle}!`)}>
|
|
27
|
+
* Share on Twitter
|
|
28
|
+
* </button>
|
|
29
|
+
* <button onClick={() => copyLink(productUrl)}>
|
|
30
|
+
* Copy Link
|
|
31
|
+
* </button>
|
|
32
|
+
* <button onClick={() => shareNative({
|
|
33
|
+
* title: productTitle,
|
|
34
|
+
* text: 'Check this out!',
|
|
35
|
+
* url: productUrl
|
|
36
|
+
* })}>
|
|
37
|
+
* Share
|
|
38
|
+
* </button>
|
|
39
|
+
* </div>
|
|
40
|
+
* </div>
|
|
41
|
+
* )}
|
|
42
|
+
* </SocialSharing.Root>
|
|
43
|
+
* );
|
|
44
|
+
* }
|
|
45
|
+
* ```
|
|
9
46
|
*/
|
|
10
47
|
export const Root = (props) => {
|
|
11
48
|
const service = useService(SocialSharingServiceDefinition);
|
|
@@ -44,6 +81,26 @@ export const Root = (props) => {
|
|
|
44
81
|
* Headless component for individual social platform
|
|
45
82
|
*
|
|
46
83
|
* @component
|
|
84
|
+
* @example
|
|
85
|
+
* ```tsx
|
|
86
|
+
* import { SocialSharing } from '@wix/stores/components';
|
|
87
|
+
*
|
|
88
|
+
* function SocialButton({ platform, onClick }) {
|
|
89
|
+
* return (
|
|
90
|
+
* <SocialSharing.Platform platform={platform} onClick={onClick}>
|
|
91
|
+
* {({ platform, onSelect }) => (
|
|
92
|
+
* <button
|
|
93
|
+
* onClick={onSelect}
|
|
94
|
+
* className={`social-btn social-btn-${platform.name.toLowerCase()}`}
|
|
95
|
+
* >
|
|
96
|
+
* <span className="icon">{platform.icon}</span>
|
|
97
|
+
* Share on {platform.name}
|
|
98
|
+
* </button>
|
|
99
|
+
* )}
|
|
100
|
+
* </SocialSharing.Platform>
|
|
101
|
+
* );
|
|
102
|
+
* }
|
|
103
|
+
* ```
|
|
47
104
|
*/
|
|
48
105
|
export const Platform = (props) => {
|
|
49
106
|
const { platform, onClick } = props;
|
|
@@ -56,6 +113,31 @@ export const Platform = (props) => {
|
|
|
56
113
|
* Headless component for social sharing platforms with logic
|
|
57
114
|
*
|
|
58
115
|
* @component
|
|
116
|
+
* @example
|
|
117
|
+
* ```tsx
|
|
118
|
+
* import { SocialSharing } from '@wix/stores/components';
|
|
119
|
+
*
|
|
120
|
+
* function SocialShareButtons() {
|
|
121
|
+
* return (
|
|
122
|
+
* <SocialSharing.Platforms
|
|
123
|
+
* url="https://example.com/product/123"
|
|
124
|
+
* title="Amazing Product"
|
|
125
|
+
* description="Check out this amazing product!"
|
|
126
|
+
* hashtags={['product', 'amazing']}
|
|
127
|
+
* >
|
|
128
|
+
* {({ platforms, shareFacebook, shareTwitter, shareLinkedIn, copyLink, shareNative }) => (
|
|
129
|
+
* <div className="social-platforms">
|
|
130
|
+
* <button onClick={shareFacebook}>Share on Facebook</button>
|
|
131
|
+
* <button onClick={shareTwitter}>Share on Twitter</button>
|
|
132
|
+
* <button onClick={shareLinkedIn}>Share on LinkedIn</button>
|
|
133
|
+
* <button onClick={() => copyLink()}>Copy Link</button>
|
|
134
|
+
* <button onClick={() => shareNative()}>Share</button>
|
|
135
|
+
* </div>
|
|
136
|
+
* )}
|
|
137
|
+
* </SocialSharing.Platforms>
|
|
138
|
+
* );
|
|
139
|
+
* }
|
|
140
|
+
* ```
|
|
59
141
|
*/
|
|
60
142
|
export const Platforms = (props) => {
|
|
61
143
|
const { url, title, description = "", hashtags = [] } = props;
|
package/dist/react/Sort.d.ts
CHANGED
|
@@ -11,5 +11,27 @@ export interface ControllerProps {
|
|
|
11
11
|
* Headless component for sorting products
|
|
12
12
|
*
|
|
13
13
|
* @component
|
|
14
|
+
* @example
|
|
15
|
+
* ```tsx
|
|
16
|
+
* import { Sort } from '@wix/stores/components';
|
|
17
|
+
*
|
|
18
|
+
* function ProductSortDropdown() {
|
|
19
|
+
* return (
|
|
20
|
+
* <Sort.Controller>
|
|
21
|
+
* {({ currentSort, setSortBy }) => (
|
|
22
|
+
* <select
|
|
23
|
+
* value={currentSort}
|
|
24
|
+
* onChange={(e) => setSortBy(e.target.value as Sort.SortBy)}
|
|
25
|
+
* >
|
|
26
|
+
* <option value="name_asc">Name (A-Z)</option>
|
|
27
|
+
* <option value="name_desc">Name (Z-A)</option>
|
|
28
|
+
* <option value="price_asc">Price (Low to High)</option>
|
|
29
|
+
* <option value="price_desc">Price (High to Low)</option>
|
|
30
|
+
* </select>
|
|
31
|
+
* )}
|
|
32
|
+
* </Sort.Controller>
|
|
33
|
+
* );
|
|
34
|
+
* }
|
|
35
|
+
* ```
|
|
14
36
|
*/
|
|
15
37
|
export declare function Controller({ children }: ControllerProps): import("react/jsx-runtime").JSX.Element;
|
package/dist/react/Sort.js
CHANGED
|
@@ -5,6 +5,28 @@ import { SortServiceDefinition, } from "../services/sort-service.js";
|
|
|
5
5
|
* Headless component for sorting products
|
|
6
6
|
*
|
|
7
7
|
* @component
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { Sort } from '@wix/stores/components';
|
|
11
|
+
*
|
|
12
|
+
* function ProductSortDropdown() {
|
|
13
|
+
* return (
|
|
14
|
+
* <Sort.Controller>
|
|
15
|
+
* {({ currentSort, setSortBy }) => (
|
|
16
|
+
* <select
|
|
17
|
+
* value={currentSort}
|
|
18
|
+
* onChange={(e) => setSortBy(e.target.value as Sort.SortBy)}
|
|
19
|
+
* >
|
|
20
|
+
* <option value="name_asc">Name (A-Z)</option>
|
|
21
|
+
* <option value="name_desc">Name (Z-A)</option>
|
|
22
|
+
* <option value="price_asc">Price (Low to High)</option>
|
|
23
|
+
* <option value="price_desc">Price (High to Low)</option>
|
|
24
|
+
* </select>
|
|
25
|
+
* )}
|
|
26
|
+
* </Sort.Controller>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
8
30
|
*/
|
|
9
31
|
export function Controller({ children }) {
|
|
10
32
|
const sortService = useService(SortServiceDefinition);
|
|
@@ -21,6 +21,93 @@ export declare const CategoryService: import("@wix/services-definitions").Servic
|
|
|
21
21
|
__config: {};
|
|
22
22
|
isServiceDefinition?: boolean;
|
|
23
23
|
} & CategoryServiceAPI, CategoryServiceConfig>;
|
|
24
|
+
/**
|
|
25
|
+
* Loads categories configuration from the Wix Categories API for SSR initialization.
|
|
26
|
+
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
27
|
+
* initial categories data that will be passed to the Category.Root component.
|
|
28
|
+
* Fetches all visible categories and sorts them with "all-products" category first.
|
|
29
|
+
*
|
|
30
|
+
* @returns Promise that resolves to an object containing categories array
|
|
31
|
+
*
|
|
32
|
+
* @example
|
|
33
|
+
* ```astro
|
|
34
|
+
* ---
|
|
35
|
+
* // Astro page example - pages/categories.astro
|
|
36
|
+
* import { loadCategoriesConfig } from '@wix/stores/services';
|
|
37
|
+
* import { Category } from '@wix/stores/components';
|
|
38
|
+
*
|
|
39
|
+
* // Load categories data during SSR
|
|
40
|
+
* const categoryConfig = await loadCategoriesConfig();
|
|
41
|
+
* ---
|
|
42
|
+
*
|
|
43
|
+
* <Category.Root categoryConfig={categoryConfig}>
|
|
44
|
+
* <Category.List>
|
|
45
|
+
* {({ categories, selectedCategory, setSelectedCategory }) => (
|
|
46
|
+
* <nav className="category-nav">
|
|
47
|
+
* <h2>Shop by Category</h2>
|
|
48
|
+
* {categories.map(category => (
|
|
49
|
+
* <button
|
|
50
|
+
* key={category.id}
|
|
51
|
+
* onClick={() => setSelectedCategory(category.id)}
|
|
52
|
+
* className={selectedCategory === category.id ? 'active' : ''}
|
|
53
|
+
* >
|
|
54
|
+
* {category.name}
|
|
55
|
+
* </button>
|
|
56
|
+
* ))}
|
|
57
|
+
* </nav>
|
|
58
|
+
* )}
|
|
59
|
+
* </Category.List>
|
|
60
|
+
* </Category.Root>
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```tsx
|
|
65
|
+
* // Next.js page example - pages/categories.tsx
|
|
66
|
+
* import { GetServerSideProps } from 'next';
|
|
67
|
+
* import { loadCategoriesConfig } from '@wix/stores/services';
|
|
68
|
+
* import { Category } from '@wix/stores/components';
|
|
69
|
+
*
|
|
70
|
+
* interface CategoryPageProps {
|
|
71
|
+
* categoryConfig: Awaited<ReturnType<typeof loadCategoriesConfig>>;
|
|
72
|
+
* }
|
|
73
|
+
*
|
|
74
|
+
* export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async () => {
|
|
75
|
+
* // Load categories data during SSR
|
|
76
|
+
* const categoryConfig = await loadCategoriesConfig();
|
|
77
|
+
*
|
|
78
|
+
* return {
|
|
79
|
+
* props: {
|
|
80
|
+
* categoryConfig,
|
|
81
|
+
* },
|
|
82
|
+
* };
|
|
83
|
+
* };
|
|
84
|
+
*
|
|
85
|
+
* export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
|
|
86
|
+
* return (
|
|
87
|
+
* <div>
|
|
88
|
+
* <h1>Product Categories</h1>
|
|
89
|
+
* <Category.Root categoryConfig={categoryConfig}>
|
|
90
|
+
* <Category.List>
|
|
91
|
+
* {({ categories, selectedCategory, setSelectedCategory }) => (
|
|
92
|
+
* <nav className="category-nav">
|
|
93
|
+
* {categories.map(category => (
|
|
94
|
+
* <button
|
|
95
|
+
* key={category.id}
|
|
96
|
+
* onClick={() => setSelectedCategory(category.id)}
|
|
97
|
+
* className={`category-btn ${selectedCategory === category.id ? 'active' : ''}`}
|
|
98
|
+
* >
|
|
99
|
+
* {category.name}
|
|
100
|
+
* </button>
|
|
101
|
+
* ))}
|
|
102
|
+
* </nav>
|
|
103
|
+
* )}
|
|
104
|
+
* </Category.List>
|
|
105
|
+
* </Category.Root>
|
|
106
|
+
* </div>
|
|
107
|
+
* );
|
|
108
|
+
* }
|
|
109
|
+
* ```
|
|
110
|
+
*/
|
|
24
111
|
export declare function loadCategoriesConfig(): Promise<{
|
|
25
112
|
categories: categories.Category[];
|
|
26
113
|
}>;
|
|
@@ -38,6 +38,93 @@ export const CategoryService = implementService.withConfig()(CategoryServiceDefi
|
|
|
38
38
|
loadCategories,
|
|
39
39
|
};
|
|
40
40
|
});
|
|
41
|
+
/**
|
|
42
|
+
* Loads categories configuration from the Wix Categories API for SSR initialization.
|
|
43
|
+
* This function is designed to be used during Server-Side Rendering (SSR) to preload
|
|
44
|
+
* initial categories data that will be passed to the Category.Root component.
|
|
45
|
+
* Fetches all visible categories and sorts them with "all-products" category first.
|
|
46
|
+
*
|
|
47
|
+
* @returns Promise that resolves to an object containing categories array
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```astro
|
|
51
|
+
* ---
|
|
52
|
+
* // Astro page example - pages/categories.astro
|
|
53
|
+
* import { loadCategoriesConfig } from '@wix/stores/services';
|
|
54
|
+
* import { Category } from '@wix/stores/components';
|
|
55
|
+
*
|
|
56
|
+
* // Load categories data during SSR
|
|
57
|
+
* const categoryConfig = await loadCategoriesConfig();
|
|
58
|
+
* ---
|
|
59
|
+
*
|
|
60
|
+
* <Category.Root categoryConfig={categoryConfig}>
|
|
61
|
+
* <Category.List>
|
|
62
|
+
* {({ categories, selectedCategory, setSelectedCategory }) => (
|
|
63
|
+
* <nav className="category-nav">
|
|
64
|
+
* <h2>Shop by Category</h2>
|
|
65
|
+
* {categories.map(category => (
|
|
66
|
+
* <button
|
|
67
|
+
* key={category.id}
|
|
68
|
+
* onClick={() => setSelectedCategory(category.id)}
|
|
69
|
+
* className={selectedCategory === category.id ? 'active' : ''}
|
|
70
|
+
* >
|
|
71
|
+
* {category.name}
|
|
72
|
+
* </button>
|
|
73
|
+
* ))}
|
|
74
|
+
* </nav>
|
|
75
|
+
* )}
|
|
76
|
+
* </Category.List>
|
|
77
|
+
* </Category.Root>
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```tsx
|
|
82
|
+
* // Next.js page example - pages/categories.tsx
|
|
83
|
+
* import { GetServerSideProps } from 'next';
|
|
84
|
+
* import { loadCategoriesConfig } from '@wix/stores/services';
|
|
85
|
+
* import { Category } from '@wix/stores/components';
|
|
86
|
+
*
|
|
87
|
+
* interface CategoryPageProps {
|
|
88
|
+
* categoryConfig: Awaited<ReturnType<typeof loadCategoriesConfig>>;
|
|
89
|
+
* }
|
|
90
|
+
*
|
|
91
|
+
* export const getServerSideProps: GetServerSideProps<CategoryPageProps> = async () => {
|
|
92
|
+
* // Load categories data during SSR
|
|
93
|
+
* const categoryConfig = await loadCategoriesConfig();
|
|
94
|
+
*
|
|
95
|
+
* return {
|
|
96
|
+
* props: {
|
|
97
|
+
* categoryConfig,
|
|
98
|
+
* },
|
|
99
|
+
* };
|
|
100
|
+
* };
|
|
101
|
+
*
|
|
102
|
+
* export default function CategoryPage({ categoryConfig }: CategoryPageProps) {
|
|
103
|
+
* return (
|
|
104
|
+
* <div>
|
|
105
|
+
* <h1>Product Categories</h1>
|
|
106
|
+
* <Category.Root categoryConfig={categoryConfig}>
|
|
107
|
+
* <Category.List>
|
|
108
|
+
* {({ categories, selectedCategory, setSelectedCategory }) => (
|
|
109
|
+
* <nav className="category-nav">
|
|
110
|
+
* {categories.map(category => (
|
|
111
|
+
* <button
|
|
112
|
+
* key={category.id}
|
|
113
|
+
* onClick={() => setSelectedCategory(category.id)}
|
|
114
|
+
* className={`category-btn ${selectedCategory === category.id ? 'active' : ''}`}
|
|
115
|
+
* >
|
|
116
|
+
* {category.name}
|
|
117
|
+
* </button>
|
|
118
|
+
* ))}
|
|
119
|
+
* </nav>
|
|
120
|
+
* )}
|
|
121
|
+
* </Category.List>
|
|
122
|
+
* </Category.Root>
|
|
123
|
+
* </div>
|
|
124
|
+
* );
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*/
|
|
41
128
|
export async function loadCategoriesConfig() {
|
|
42
129
|
try {
|
|
43
130
|
const categoriesResponse = await categories
|