@wix/headless-stores 0.0.52 → 0.0.53
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/astro/actions/custom-checkout.d.ts +1 -1
- package/cjs/dist/astro/actions/custom-checkout.js +2 -2
- package/cjs/dist/astro/actions/index.d.ts +1 -1
- package/cjs/dist/astro/actions/index.js +1 -1
- package/cjs/dist/enums/index.d.ts +2 -2
- package/cjs/dist/enums/index.js +2 -2
- package/cjs/dist/react/Category.d.ts +168 -67
- package/cjs/dist/react/Category.js +166 -50
- package/cjs/dist/react/CategoryList.d.ts +56 -138
- package/cjs/dist/react/CategoryList.js +44 -129
- package/cjs/dist/react/Choice.d.ts +193 -0
- package/cjs/dist/react/Choice.js +259 -0
- package/cjs/dist/react/Option.d.ts +224 -0
- package/cjs/dist/react/Option.js +388 -0
- package/cjs/dist/react/Product.d.ts +339 -96
- package/cjs/dist/react/Product.js +507 -94
- package/cjs/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
- package/cjs/dist/react/core/Category.d.ts +98 -0
- package/cjs/dist/react/core/Category.js +81 -0
- package/cjs/dist/react/core/CategoryList.d.ts +185 -0
- package/cjs/dist/react/core/CategoryList.js +174 -0
- package/{dist/react → cjs/dist/react/core}/PayNow.js +2 -2
- package/cjs/dist/react/core/Product.d.ts +148 -0
- package/cjs/dist/react/core/Product.js +126 -0
- package/cjs/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
- package/cjs/dist/react/{ProductList.js → core/ProductList.js} +10 -10
- package/{dist/react → cjs/dist/react/core}/ProductListFilters.d.ts +3 -3
- package/{dist/react → cjs/dist/react/core}/ProductListFilters.js +7 -7
- package/cjs/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
- package/{dist/react → cjs/dist/react/core}/ProductListSort.d.ts +1 -1
- package/cjs/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
- package/{dist/react → cjs/dist/react/core}/ProductModifiers.d.ts +1 -1
- package/{dist/react → cjs/dist/react/core}/ProductModifiers.js +13 -13
- package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.d.ts +2 -2
- package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.js +7 -10
- package/{dist/react → cjs/dist/react/core}/SelectedVariant.d.ts +2 -2
- package/{dist/react → cjs/dist/react/core}/SelectedVariant.js +43 -15
- package/cjs/dist/react/index.d.ts +15 -10
- package/cjs/dist/react/index.js +15 -10
- package/cjs/dist/react/types.d.ts +8 -0
- package/cjs/dist/react/types.js +9 -0
- package/cjs/dist/server-actions/custom-checkout-action.js +14 -10
- package/cjs/dist/server-actions/index.d.ts +1 -1
- package/cjs/dist/server-actions/index.js +1 -1
- package/cjs/dist/services/buy-now-service.d.ts +1 -1
- package/cjs/dist/services/buy-now-service.js +6 -6
- package/cjs/dist/services/categories-list-service.d.ts +4 -4
- package/cjs/dist/services/categories-list-service.js +10 -10
- package/cjs/dist/services/category-service.d.ts +18 -22
- package/cjs/dist/services/category-service.js +12 -10
- package/cjs/dist/services/index.d.ts +7 -7
- package/cjs/dist/services/index.js +7 -7
- package/cjs/dist/services/pay-now-service.d.ts +1 -1
- package/cjs/dist/services/pay-now-service.js +4 -4
- package/cjs/dist/services/product-modifiers-service.d.ts +3 -3
- package/cjs/dist/services/product-modifiers-service.js +7 -7
- package/cjs/dist/services/product-service.d.ts +4 -4
- package/cjs/dist/services/product-service.js +18 -18
- package/cjs/dist/services/products-list-search-service.d.ts +5 -5
- package/cjs/dist/services/products-list-search-service.js +117 -117
- package/cjs/dist/services/products-list-service.d.ts +4 -4
- package/cjs/dist/services/products-list-service.js +12 -12
- package/cjs/dist/services/selected-variant-service.d.ts +6 -2
- package/cjs/dist/services/selected-variant-service.js +86 -83
- package/cjs/dist/utils/index.d.ts +1 -0
- package/cjs/dist/utils/index.js +5 -4
- package/cjs/dist/utils/renderAsChild.d.ts +96 -0
- package/cjs/dist/utils/renderAsChild.js +66 -0
- package/cjs/dist/utils/renderChildren.d.ts +41 -0
- package/cjs/dist/utils/renderChildren.js +44 -0
- package/cjs/dist/utils/url-params.js +3 -3
- package/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/dist/astro/actions/custom-checkout.js +2 -2
- package/dist/astro/actions/index.d.ts +1 -1
- package/dist/astro/actions/index.js +1 -1
- package/dist/enums/index.d.ts +2 -2
- package/dist/enums/index.js +2 -2
- package/dist/react/Category.d.ts +168 -67
- package/dist/react/Category.js +166 -50
- package/dist/react/CategoryList.d.ts +56 -138
- package/dist/react/CategoryList.js +44 -129
- package/dist/react/Choice.d.ts +193 -0
- package/dist/react/Choice.js +259 -0
- package/dist/react/Option.d.ts +224 -0
- package/dist/react/Option.js +388 -0
- package/dist/react/Product.d.ts +339 -96
- package/dist/react/Product.js +507 -94
- package/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
- package/dist/react/core/Category.d.ts +98 -0
- package/dist/react/core/Category.js +81 -0
- package/dist/react/core/CategoryList.d.ts +185 -0
- package/dist/react/core/CategoryList.js +174 -0
- package/{cjs/dist/react → dist/react/core}/PayNow.js +2 -2
- package/dist/react/core/Product.d.ts +148 -0
- package/dist/react/core/Product.js +126 -0
- package/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
- package/dist/react/{ProductList.js → core/ProductList.js} +10 -10
- package/{cjs/dist/react → dist/react/core}/ProductListFilters.d.ts +3 -3
- package/{cjs/dist/react → dist/react/core}/ProductListFilters.js +7 -7
- package/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
- package/{cjs/dist/react → dist/react/core}/ProductListSort.d.ts +1 -1
- package/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
- package/{cjs/dist/react → dist/react/core}/ProductModifiers.d.ts +1 -1
- package/{cjs/dist/react → dist/react/core}/ProductModifiers.js +13 -13
- package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.d.ts +2 -2
- package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.js +7 -10
- package/{cjs/dist/react → dist/react/core}/SelectedVariant.d.ts +2 -2
- package/{cjs/dist/react → dist/react/core}/SelectedVariant.js +43 -15
- package/dist/react/index.d.ts +15 -10
- package/dist/react/index.js +15 -10
- package/dist/react/types.d.ts +8 -0
- package/dist/react/types.js +9 -0
- package/dist/server-actions/custom-checkout-action.js +14 -10
- package/dist/server-actions/index.d.ts +1 -1
- package/dist/server-actions/index.js +1 -1
- package/dist/services/buy-now-service.d.ts +1 -1
- package/dist/services/buy-now-service.js +6 -6
- package/dist/services/categories-list-service.d.ts +4 -4
- package/dist/services/categories-list-service.js +10 -10
- package/dist/services/category-service.d.ts +18 -22
- package/dist/services/category-service.js +12 -10
- package/dist/services/index.d.ts +7 -7
- package/dist/services/index.js +7 -7
- package/dist/services/pay-now-service.d.ts +1 -1
- package/dist/services/pay-now-service.js +4 -4
- package/dist/services/product-modifiers-service.d.ts +3 -3
- package/dist/services/product-modifiers-service.js +7 -7
- package/dist/services/product-service.d.ts +4 -4
- package/dist/services/product-service.js +18 -18
- package/dist/services/products-list-search-service.d.ts +5 -5
- package/dist/services/products-list-search-service.js +117 -117
- package/dist/services/products-list-service.d.ts +4 -4
- package/dist/services/products-list-service.js +12 -12
- package/dist/services/selected-variant-service.d.ts +6 -2
- package/dist/services/selected-variant-service.js +86 -83
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +5 -4
- package/dist/utils/renderAsChild.d.ts +96 -0
- package/dist/utils/renderAsChild.js +66 -0
- package/dist/utils/renderChildren.d.ts +41 -0
- package/dist/utils/renderChildren.js +44 -0
- package/dist/utils/url-params.js +3 -3
- package/package.json +7 -3
- /package/cjs/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
- /package/cjs/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
- /package/cjs/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
- /package/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
- /package/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
- /package/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
|
@@ -1,185 +1,103 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { type Category } from
|
|
3
|
-
|
|
4
|
-
children: React.ReactNode;
|
|
5
|
-
categoriesListConfig: CategoriesListServiceConfig;
|
|
6
|
-
}
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Category as CategoryType } from '../services/category-service.js';
|
|
3
|
+
import { type CategoriesListServiceConfig } from '../services/categories-list-service.js';
|
|
7
4
|
/**
|
|
8
|
-
*
|
|
9
|
-
* This component sets up the necessary services for managing categories list state.
|
|
10
|
-
*
|
|
11
|
-
* @order 1
|
|
12
|
-
* @component
|
|
13
|
-
* @example
|
|
14
|
-
* ```tsx
|
|
15
|
-
* import { CategoryList } from '@wix/stores/components';
|
|
16
|
-
*
|
|
17
|
-
* function CategoriesPage() {
|
|
18
|
-
* return (
|
|
19
|
-
* <CategoryList.Root categoriesListConfig={{ collectionId: 'my-collection' }}>
|
|
20
|
-
* <CategoryList.ItemContent>
|
|
21
|
-
* {({ category }) => (
|
|
22
|
-
* <div key={category._id}>
|
|
23
|
-
* <h2>{category.name}</h2>
|
|
24
|
-
* </div>
|
|
25
|
-
* )}
|
|
26
|
-
* </CategoryList.ItemContent>
|
|
27
|
-
* </CategoryList.Root>
|
|
28
|
-
* );
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
5
|
+
* Props for CategoryList.Root component
|
|
31
6
|
*/
|
|
32
|
-
export
|
|
7
|
+
export interface CategoryListRootProps {
|
|
8
|
+
/** Optional categories array to initialize the service with */
|
|
9
|
+
categories?: CategoryType[];
|
|
10
|
+
/** Configuration for the categories list service */
|
|
11
|
+
categoriesListConfig?: CategoriesListServiceConfig;
|
|
12
|
+
/** Child components */
|
|
13
|
+
children: React.ReactNode;
|
|
14
|
+
/** Optional empty state content to display when no categories are available */
|
|
15
|
+
emptyState?: React.ReactNode;
|
|
16
|
+
}
|
|
33
17
|
/**
|
|
34
|
-
* Props for
|
|
18
|
+
* Props for CategoryList.Loading component
|
|
35
19
|
*/
|
|
36
|
-
export interface
|
|
37
|
-
/**
|
|
38
|
-
children
|
|
20
|
+
export interface CategoryListLoadingProps {
|
|
21
|
+
/** Child content to display during loading */
|
|
22
|
+
children?: React.ReactNode;
|
|
23
|
+
/** Whether to render as a child component */
|
|
24
|
+
asChild?: boolean;
|
|
25
|
+
/** CSS classes to apply to the default element */
|
|
26
|
+
className?: string;
|
|
39
27
|
}
|
|
40
28
|
/**
|
|
41
|
-
*
|
|
29
|
+
* Props for CategoryList.CategoryRepeater component
|
|
42
30
|
*/
|
|
43
|
-
export interface
|
|
31
|
+
export interface CategoryListCategoryRepeaterProps {
|
|
32
|
+
/** Child components to repeat for each category */
|
|
33
|
+
children: React.ReactNode;
|
|
34
|
+
/** Maximum nesting depth for hierarchical categories */
|
|
35
|
+
maxDepth?: number;
|
|
36
|
+
/** Whether to render as a child component */
|
|
37
|
+
asChild?: boolean;
|
|
38
|
+
/** CSS classes to apply to the default element */
|
|
39
|
+
className?: string;
|
|
44
40
|
}
|
|
45
41
|
/**
|
|
46
|
-
*
|
|
47
|
-
*
|
|
42
|
+
* Root container that provides category list context to all child components.
|
|
43
|
+
* This component sets up the necessary services for managing categories list state.
|
|
48
44
|
*
|
|
45
|
+
* @order 1
|
|
49
46
|
* @component
|
|
50
47
|
* @example
|
|
51
48
|
* ```tsx
|
|
52
|
-
* import { CategoryList } from '@wix/stores/
|
|
49
|
+
* import { CategoryList } from '@wix/headless-stores/react';
|
|
53
50
|
*
|
|
54
|
-
* function
|
|
51
|
+
* function CategoriesPage() {
|
|
55
52
|
* return (
|
|
56
|
-
* <CategoryList.
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* )}
|
|
63
|
-
* </CategoryList.EmptyState>
|
|
53
|
+
* <CategoryList.Root categoriesListConfig={categoriesListConfig}>
|
|
54
|
+
* <CategoryList.Loading>Loading...</CategoryList.Loading>
|
|
55
|
+
* <CategoryList.CategoryRepeater>
|
|
56
|
+
* <Category.Label />
|
|
57
|
+
* </CategoryList.CategoryRepeater>
|
|
58
|
+
* </CategoryList.Root>
|
|
64
59
|
* );
|
|
65
60
|
* }
|
|
66
61
|
* ```
|
|
67
62
|
*/
|
|
68
|
-
export declare function
|
|
69
|
-
/**
|
|
70
|
-
* Props for Loading headless component
|
|
71
|
-
*/
|
|
72
|
-
export interface LoadingProps {
|
|
73
|
-
/** Content to display during loading (can be a render function or ReactNode) */
|
|
74
|
-
children: ((props: LoadingRenderProps) => React.ReactNode) | React.ReactNode;
|
|
75
|
-
}
|
|
63
|
+
export declare function Root(props: CategoryListRootProps): React.ReactNode;
|
|
76
64
|
/**
|
|
77
|
-
*
|
|
78
|
-
*/
|
|
79
|
-
export interface LoadingRenderProps {
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Component that renders content during loading state.
|
|
65
|
+
* Displays loading state while category data is being fetched.
|
|
83
66
|
* Only displays its children when the categories list is currently loading.
|
|
84
67
|
*
|
|
85
68
|
* @component
|
|
86
69
|
* @example
|
|
87
70
|
* ```tsx
|
|
88
|
-
* import { CategoryList } from '@wix/stores/
|
|
71
|
+
* import { CategoryList } from '@wix/headless-stores/react';
|
|
89
72
|
*
|
|
90
73
|
* function CategoriesLoading() {
|
|
91
74
|
* return (
|
|
92
75
|
* <CategoryList.Loading>
|
|
93
|
-
*
|
|
94
|
-
* <div className="loading-spinner">
|
|
95
|
-
* <div>Loading categories...</div>
|
|
96
|
-
* <div className="spinner"></div>
|
|
97
|
-
* </div>
|
|
98
|
-
* )}
|
|
76
|
+
* <div className="loading-spinner">Loading categories...</div>
|
|
99
77
|
* </CategoryList.Loading>
|
|
100
78
|
* );
|
|
101
79
|
* }
|
|
102
80
|
* ```
|
|
103
81
|
*/
|
|
104
|
-
export declare
|
|
105
|
-
/**
|
|
106
|
-
* Props for Error headless component
|
|
107
|
-
*/
|
|
108
|
-
export interface ErrorProps {
|
|
109
|
-
/** Content to display during error state (can be a render function or ReactNode) */
|
|
110
|
-
children: ((props: ErrorRenderProps) => React.ReactNode) | React.ReactNode;
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* Render props for Error component
|
|
114
|
-
*/
|
|
115
|
-
export interface ErrorRenderProps {
|
|
116
|
-
/** Error message */
|
|
117
|
-
error: string | null;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* Component that renders content when there's an error loading categories.
|
|
121
|
-
* Only displays its children when an error has occurred.
|
|
122
|
-
*
|
|
123
|
-
* @component
|
|
124
|
-
* @example
|
|
125
|
-
* ```tsx
|
|
126
|
-
* import { CategoryList } from '@wix/stores/components';
|
|
127
|
-
*
|
|
128
|
-
* function CategoriesError() {
|
|
129
|
-
* return (
|
|
130
|
-
* <CategoryList.Error>
|
|
131
|
-
* {({ error }) => (
|
|
132
|
-
* <div className="error-state">
|
|
133
|
-
* <h3>Error loading categories</h3>
|
|
134
|
-
* <p>{error}</p>
|
|
135
|
-
* <button onClick={() => window.location.reload()}>
|
|
136
|
-
* Try Again
|
|
137
|
-
* </button>
|
|
138
|
-
* </div>
|
|
139
|
-
* )}
|
|
140
|
-
* </CategoryList.Error>
|
|
141
|
-
* );
|
|
142
|
-
* }
|
|
143
|
-
* ```
|
|
144
|
-
*/
|
|
145
|
-
export declare function Error(props: ErrorProps): import("react").ReactNode;
|
|
146
|
-
/**
|
|
147
|
-
* Props for ItemContent headless component
|
|
148
|
-
*/
|
|
149
|
-
export interface ItemContentProps {
|
|
150
|
-
/** Content to display for each category (can be a render function receiving category data or ReactNode) */
|
|
151
|
-
children: ((props: ItemContentRenderProps) => React.ReactNode) | React.ReactNode;
|
|
152
|
-
}
|
|
153
|
-
/**
|
|
154
|
-
* Render props for ItemContent component
|
|
155
|
-
*/
|
|
156
|
-
export interface ItemContentRenderProps {
|
|
157
|
-
/** Category data */
|
|
158
|
-
category: Category;
|
|
159
|
-
}
|
|
82
|
+
export declare const Loading: React.ForwardRefExoticComponent<CategoryListLoadingProps & React.RefAttributes<HTMLDivElement>>;
|
|
160
83
|
/**
|
|
161
|
-
*
|
|
84
|
+
* Repeats for each category in the list, providing individual category context.
|
|
162
85
|
* Maps over all categories and provides each category through a service context.
|
|
163
|
-
* Only renders when categories are successfully loaded
|
|
86
|
+
* Only renders when categories are successfully loaded.
|
|
164
87
|
*
|
|
165
88
|
* @component
|
|
166
89
|
* @example
|
|
167
90
|
* ```tsx
|
|
168
|
-
* import { CategoryList } from '@wix/stores/
|
|
91
|
+
* import { CategoryList } from '@wix/headless-stores/react';
|
|
169
92
|
*
|
|
170
93
|
* function CategoriesGrid() {
|
|
171
94
|
* return (
|
|
172
|
-
* <CategoryList.
|
|
173
|
-
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
176
|
-
* <p>{category.description}</p>
|
|
177
|
-
* <a href={`/categories/${category.slug}`}>View Category</a>
|
|
178
|
-
* </div>
|
|
179
|
-
* )}
|
|
180
|
-
* </CategoryList.ItemContent>
|
|
95
|
+
* <CategoryList.CategoryRepeater maxDepth={3}>
|
|
96
|
+
* <Category.Label />
|
|
97
|
+
* <Category.ID />
|
|
98
|
+
* </CategoryList.CategoryRepeater>
|
|
181
99
|
* );
|
|
182
100
|
* }
|
|
183
101
|
* ```
|
|
184
102
|
*/
|
|
185
|
-
export declare
|
|
103
|
+
export declare const CategoryRepeater: React.ForwardRefExoticComponent<CategoryListCategoryRepeaterProps & React.RefAttributes<HTMLDivElement>>;
|
|
@@ -1,174 +1,89 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { Slot } from '@radix-ui/react-slot';
|
|
4
|
+
import * as CoreCategoryList from './core/CategoryList.js';
|
|
5
|
+
import * as Category from './Category.js';
|
|
6
|
+
var TestIds;
|
|
7
|
+
(function (TestIds) {
|
|
8
|
+
TestIds["categoryListRoot"] = "category-list";
|
|
9
|
+
TestIds["categoryRepeater"] = "category-repeater";
|
|
10
|
+
})(TestIds || (TestIds = {}));
|
|
6
11
|
/**
|
|
7
|
-
* Root
|
|
12
|
+
* Root container that provides category list context to all child components.
|
|
8
13
|
* This component sets up the necessary services for managing categories list state.
|
|
9
14
|
*
|
|
10
15
|
* @order 1
|
|
11
16
|
* @component
|
|
12
17
|
* @example
|
|
13
18
|
* ```tsx
|
|
14
|
-
* import { CategoryList } from '@wix/stores/
|
|
19
|
+
* import { CategoryList } from '@wix/headless-stores/react';
|
|
15
20
|
*
|
|
16
21
|
* function CategoriesPage() {
|
|
17
22
|
* return (
|
|
18
|
-
* <CategoryList.Root categoriesListConfig={
|
|
19
|
-
* <CategoryList.
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* </div>
|
|
24
|
-
* )}
|
|
25
|
-
* </CategoryList.ItemContent>
|
|
23
|
+
* <CategoryList.Root categoriesListConfig={categoriesListConfig}>
|
|
24
|
+
* <CategoryList.Loading>Loading...</CategoryList.Loading>
|
|
25
|
+
* <CategoryList.CategoryRepeater>
|
|
26
|
+
* <Category.Label />
|
|
27
|
+
* </CategoryList.CategoryRepeater>
|
|
26
28
|
* </CategoryList.Root>
|
|
27
29
|
* );
|
|
28
30
|
* }
|
|
29
31
|
* ```
|
|
30
32
|
*/
|
|
31
33
|
export function Root(props) {
|
|
32
|
-
|
|
34
|
+
const { categories, categoriesListConfig, children, emptyState } = props;
|
|
35
|
+
// Create service config, prioritizing categoriesListConfig, then categories prop
|
|
36
|
+
const serviceConfig = categoriesListConfig || (categories ? { categories } : { categories: [] });
|
|
37
|
+
return (_jsxs(CoreCategoryList.Root, { categoriesListConfig: serviceConfig, "data-testid": TestIds.categoryListRoot, children: [children, emptyState && (_jsx(CoreCategoryList.EmptyState, { children: emptyState }))] }));
|
|
33
38
|
}
|
|
34
39
|
/**
|
|
35
|
-
*
|
|
36
|
-
* Only displays its children when there are no categories, no loading state, and no errors.
|
|
37
|
-
*
|
|
38
|
-
* @component
|
|
39
|
-
* @example
|
|
40
|
-
* ```tsx
|
|
41
|
-
* import { CategoryList } from '@wix/stores/components';
|
|
42
|
-
*
|
|
43
|
-
* function EmptyCategoriesMessage() {
|
|
44
|
-
* return (
|
|
45
|
-
* <CategoryList.EmptyState>
|
|
46
|
-
* {() => (
|
|
47
|
-
* <div className="empty-state">
|
|
48
|
-
* <h3>No categories found</h3>
|
|
49
|
-
* <p>Categories will appear here once they are created</p>
|
|
50
|
-
* </div>
|
|
51
|
-
* )}
|
|
52
|
-
* </CategoryList.EmptyState>
|
|
53
|
-
* );
|
|
54
|
-
* }
|
|
55
|
-
* ```
|
|
56
|
-
*/
|
|
57
|
-
export function EmptyState(props) {
|
|
58
|
-
const { isLoading, error, categories } = useService(CategoriesListServiceDefinition);
|
|
59
|
-
const isLoadingValue = isLoading.get();
|
|
60
|
-
const errorValue = error.get();
|
|
61
|
-
const categoriesValue = categories.get();
|
|
62
|
-
if (!isLoadingValue && !errorValue && categoriesValue.length === 0) {
|
|
63
|
-
return typeof props.children === "function"
|
|
64
|
-
? props.children({})
|
|
65
|
-
: props.children;
|
|
66
|
-
}
|
|
67
|
-
return null;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Component that renders content during loading state.
|
|
40
|
+
* Displays loading state while category data is being fetched.
|
|
71
41
|
* Only displays its children when the categories list is currently loading.
|
|
72
42
|
*
|
|
73
43
|
* @component
|
|
74
44
|
* @example
|
|
75
45
|
* ```tsx
|
|
76
|
-
* import { CategoryList } from '@wix/stores/
|
|
46
|
+
* import { CategoryList } from '@wix/headless-stores/react';
|
|
77
47
|
*
|
|
78
48
|
* function CategoriesLoading() {
|
|
79
49
|
* return (
|
|
80
50
|
* <CategoryList.Loading>
|
|
81
|
-
*
|
|
82
|
-
* <div className="loading-spinner">
|
|
83
|
-
* <div>Loading categories...</div>
|
|
84
|
-
* <div className="spinner"></div>
|
|
85
|
-
* </div>
|
|
86
|
-
* )}
|
|
51
|
+
* <div className="loading-spinner">Loading categories...</div>
|
|
87
52
|
* </CategoryList.Loading>
|
|
88
53
|
* );
|
|
89
54
|
* }
|
|
90
55
|
* ```
|
|
91
56
|
*/
|
|
92
|
-
export
|
|
93
|
-
const {
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
? props.children({})
|
|
98
|
-
: props.children;
|
|
99
|
-
}
|
|
100
|
-
return null;
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Component that renders content when there's an error loading categories.
|
|
104
|
-
* Only displays its children when an error has occurred.
|
|
105
|
-
*
|
|
106
|
-
* @component
|
|
107
|
-
* @example
|
|
108
|
-
* ```tsx
|
|
109
|
-
* import { CategoryList } from '@wix/stores/components';
|
|
110
|
-
*
|
|
111
|
-
* function CategoriesError() {
|
|
112
|
-
* return (
|
|
113
|
-
* <CategoryList.Error>
|
|
114
|
-
* {({ error }) => (
|
|
115
|
-
* <div className="error-state">
|
|
116
|
-
* <h3>Error loading categories</h3>
|
|
117
|
-
* <p>{error}</p>
|
|
118
|
-
* <button onClick={() => window.location.reload()}>
|
|
119
|
-
* Try Again
|
|
120
|
-
* </button>
|
|
121
|
-
* </div>
|
|
122
|
-
* )}
|
|
123
|
-
* </CategoryList.Error>
|
|
124
|
-
* );
|
|
125
|
-
* }
|
|
126
|
-
* ```
|
|
127
|
-
*/
|
|
128
|
-
export function Error(props) {
|
|
129
|
-
const { error } = useService(CategoriesListServiceDefinition);
|
|
130
|
-
const errorValue = error.get();
|
|
131
|
-
if (errorValue) {
|
|
132
|
-
return typeof props.children === "function"
|
|
133
|
-
? props.children({ error: errorValue })
|
|
134
|
-
: props.children;
|
|
135
|
-
}
|
|
136
|
-
return null;
|
|
137
|
-
}
|
|
57
|
+
export const Loading = React.forwardRef((props, ref) => {
|
|
58
|
+
const { asChild, children, className } = props;
|
|
59
|
+
const Comp = asChild && children ? Slot : 'h1';
|
|
60
|
+
return (_jsx(CoreCategoryList.Loading, { children: _jsx(Comp, { className: className, ref: ref, children: "Loading..." }) }));
|
|
61
|
+
});
|
|
138
62
|
/**
|
|
139
|
-
*
|
|
63
|
+
* Repeats for each category in the list, providing individual category context.
|
|
140
64
|
* Maps over all categories and provides each category through a service context.
|
|
141
|
-
* Only renders when categories are successfully loaded
|
|
65
|
+
* Only renders when categories are successfully loaded.
|
|
142
66
|
*
|
|
143
67
|
* @component
|
|
144
68
|
* @example
|
|
145
69
|
* ```tsx
|
|
146
|
-
* import { CategoryList } from '@wix/stores/
|
|
70
|
+
* import { CategoryList } from '@wix/headless-stores/react';
|
|
147
71
|
*
|
|
148
72
|
* function CategoriesGrid() {
|
|
149
73
|
* return (
|
|
150
|
-
* <CategoryList.
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* <p>{category.description}</p>
|
|
155
|
-
* <a href={`/categories/${category.slug}`}>View Category</a>
|
|
156
|
-
* </div>
|
|
157
|
-
* )}
|
|
158
|
-
* </CategoryList.ItemContent>
|
|
74
|
+
* <CategoryList.CategoryRepeater maxDepth={3}>
|
|
75
|
+
* <Category.Label />
|
|
76
|
+
* <Category.ID />
|
|
77
|
+
* </CategoryList.CategoryRepeater>
|
|
159
78
|
* );
|
|
160
79
|
* }
|
|
161
80
|
* ```
|
|
162
81
|
*/
|
|
163
|
-
export
|
|
164
|
-
const {
|
|
165
|
-
const
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
category,
|
|
172
|
-
})
|
|
173
|
-
: props.children }, category._id)));
|
|
174
|
-
}
|
|
82
|
+
export const CategoryRepeater = React.forwardRef((props) => {
|
|
83
|
+
// const { children, asChild = false, className } = props;
|
|
84
|
+
const { children } = props;
|
|
85
|
+
// Note: maxDepth is not implemented yet as it depends on category hierarchy structure
|
|
86
|
+
return (_jsx(CoreCategoryList.ItemContent, { children: ({ category }) => {
|
|
87
|
+
return (_jsx(Category.Root, { categoryServiceConfig: { category }, children: children }, category._id));
|
|
88
|
+
} }));
|
|
89
|
+
});
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type AsChildProps } from '../utils/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Choice data interface
|
|
5
|
+
*/
|
|
6
|
+
export interface Choice {
|
|
7
|
+
colorCode?: string;
|
|
8
|
+
choiceId?: string | null;
|
|
9
|
+
linkedMedia?: any[];
|
|
10
|
+
type?: 'color' | 'text' | 'free-text';
|
|
11
|
+
key?: string;
|
|
12
|
+
name?: string | null;
|
|
13
|
+
addedPrice?: string | null;
|
|
14
|
+
minCharCount?: number;
|
|
15
|
+
maxCharCount?: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Context value interface for individual choice data and behavior
|
|
19
|
+
*/
|
|
20
|
+
export interface ChoiceContextValue {
|
|
21
|
+
/** The choice data object */
|
|
22
|
+
choice: Choice;
|
|
23
|
+
/** Whether this choice should render as text */
|
|
24
|
+
shouldRenderAsText: boolean;
|
|
25
|
+
/** Whether this choice should render as color swatch */
|
|
26
|
+
shouldRenderAsColor: boolean;
|
|
27
|
+
/** Whether this choice should render as free text input */
|
|
28
|
+
shouldRenderAsFreeText: boolean;
|
|
29
|
+
/** Display value for the choice */
|
|
30
|
+
value: string;
|
|
31
|
+
/** Whether this choice is currently selected */
|
|
32
|
+
isSelected: boolean;
|
|
33
|
+
/** Whether this choice is visible based on current selections */
|
|
34
|
+
isVisible: boolean;
|
|
35
|
+
/** Whether this choice is in stock */
|
|
36
|
+
isInStock: boolean;
|
|
37
|
+
/** Whether this choice is available for pre-order */
|
|
38
|
+
isPreOrderEnabled: boolean;
|
|
39
|
+
/** Function to select this choice */
|
|
40
|
+
select: () => void;
|
|
41
|
+
/** Callback for free text value changes */
|
|
42
|
+
onValueChange?: (value: string) => void;
|
|
43
|
+
}
|
|
44
|
+
export declare const ChoiceContext: React.Context<ChoiceContextValue | null>;
|
|
45
|
+
/**
|
|
46
|
+
* Hook to access ChoiceContext with proper error handling
|
|
47
|
+
* @throws {Error} When used outside of a Choice context provider
|
|
48
|
+
* @returns {ChoiceContextValue} The choice context value
|
|
49
|
+
*/
|
|
50
|
+
export declare function useChoiceContext(): ChoiceContextValue;
|
|
51
|
+
export interface RootProps {
|
|
52
|
+
children?: React.ReactNode;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Root component that consumes ChoiceContext provided by Option.ChoiceRepeater.
|
|
56
|
+
*
|
|
57
|
+
* @component
|
|
58
|
+
* @example
|
|
59
|
+
* ```tsx
|
|
60
|
+
* <Choice.Root>
|
|
61
|
+
* <Choice.Text />
|
|
62
|
+
* <Choice.Color />
|
|
63
|
+
* </Choice.Root>
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export declare const Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLDivElement>>;
|
|
67
|
+
/**
|
|
68
|
+
* Props for Choice Text component
|
|
69
|
+
*/
|
|
70
|
+
export interface TextProps extends AsChildProps<{
|
|
71
|
+
id: string;
|
|
72
|
+
value: string;
|
|
73
|
+
}> {
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Text-based choice button.
|
|
77
|
+
*
|
|
78
|
+
* @component
|
|
79
|
+
* @example
|
|
80
|
+
* ```tsx
|
|
81
|
+
* // Default usage
|
|
82
|
+
* <Choice.Text className="px-4 py-2 border rounded-lg" />
|
|
83
|
+
*
|
|
84
|
+
* // asChild with primitive
|
|
85
|
+
* <Choice.Text asChild>
|
|
86
|
+
* <button className="px-4 py-2 border rounded-lg" />
|
|
87
|
+
* </Choice.Text>
|
|
88
|
+
*
|
|
89
|
+
* // asChild with react component
|
|
90
|
+
* <Choice.Text asChild>
|
|
91
|
+
* {React.forwardRef(({id, value, ...props}, ref) => (
|
|
92
|
+
* <button ref={ref} {...props} className="px-4 py-2 border rounded-lg">
|
|
93
|
+
* {value}
|
|
94
|
+
* </button>
|
|
95
|
+
* ))}
|
|
96
|
+
* </Choice.Text>
|
|
97
|
+
* ```
|
|
98
|
+
*
|
|
99
|
+
* Data Attributes:
|
|
100
|
+
* - `data-testid="choice-text"` - Applied to choice buttons
|
|
101
|
+
* - `data-selected` - Is Choice selected
|
|
102
|
+
* - `disabled` - Is Choice disabled (not in stock)
|
|
103
|
+
*/
|
|
104
|
+
export declare const Text: React.ForwardRefExoticComponent<TextProps & React.RefAttributes<HTMLButtonElement>>;
|
|
105
|
+
/**
|
|
106
|
+
* Props for Choice Color component
|
|
107
|
+
*/
|
|
108
|
+
export interface ColorProps extends AsChildProps<{
|
|
109
|
+
colorCode: string;
|
|
110
|
+
name: string;
|
|
111
|
+
id: string;
|
|
112
|
+
}> {
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Color swatch choice.
|
|
116
|
+
*
|
|
117
|
+
* @component
|
|
118
|
+
* @example
|
|
119
|
+
* ```tsx
|
|
120
|
+
* // Default usage
|
|
121
|
+
* <Choice.Color className="w-10 h-10 rounded-full border-4" />
|
|
122
|
+
*
|
|
123
|
+
* // asChild with primitive
|
|
124
|
+
* <Choice.Color asChild>
|
|
125
|
+
* <button className="w-10 h-10 rounded-full border-4" />
|
|
126
|
+
* </Choice.Color>
|
|
127
|
+
*
|
|
128
|
+
* // asChild with react component
|
|
129
|
+
* <Choice.Color asChild>
|
|
130
|
+
* {React.forwardRef(({colorCode, name, id, ...props}, ref) => (
|
|
131
|
+
* <button
|
|
132
|
+
* ref={ref}
|
|
133
|
+
* {...props}
|
|
134
|
+
* className="w-10 h-10 rounded-full border-4"
|
|
135
|
+
* style={{ backgroundColor: colorCode }}
|
|
136
|
+
* title={name}
|
|
137
|
+
* />
|
|
138
|
+
* ))}
|
|
139
|
+
* </Choice.Color>
|
|
140
|
+
* ```
|
|
141
|
+
*
|
|
142
|
+
* Data Attributes:
|
|
143
|
+
* - `data-testid="choice-color"` - Applied to color swatches
|
|
144
|
+
* - `data-selected` - Is Choice selected
|
|
145
|
+
* - `disabled` - Is Choice disabled (not in stock)
|
|
146
|
+
*/
|
|
147
|
+
export declare const Color: React.ForwardRefExoticComponent<ColorProps & React.RefAttributes<HTMLButtonElement>>;
|
|
148
|
+
/**
|
|
149
|
+
* Props for Choice FreeText component
|
|
150
|
+
*/
|
|
151
|
+
export interface FreeTextProps extends AsChildProps<{
|
|
152
|
+
minCharCount?: number;
|
|
153
|
+
maxCharCount?: number;
|
|
154
|
+
defaultAddedPrice?: string | null;
|
|
155
|
+
title?: string;
|
|
156
|
+
value?: string;
|
|
157
|
+
onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
|
|
158
|
+
}>, Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'children'> {
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Provides a free text input for variant selection.
|
|
162
|
+
*
|
|
163
|
+
* @component
|
|
164
|
+
* @example
|
|
165
|
+
* ```tsx
|
|
166
|
+
* // Default usage
|
|
167
|
+
* <Choice.FreeText className="p-3 border rounded-lg" />
|
|
168
|
+
*
|
|
169
|
+
* // asChild with primitive
|
|
170
|
+
* <Choice.FreeText asChild>
|
|
171
|
+
* <textarea className="p-3 border rounded-lg" />
|
|
172
|
+
* </Choice.FreeText>
|
|
173
|
+
*
|
|
174
|
+
* // asChild with react component
|
|
175
|
+
* <Choice.FreeText asChild>
|
|
176
|
+
* {React.forwardRef(({value, onChange, title, ...props}, ref) => (
|
|
177
|
+
* <textarea
|
|
178
|
+
* ref={ref}
|
|
179
|
+
* {...props}
|
|
180
|
+
* className="p-3 border rounded-lg"
|
|
181
|
+
* value={value}
|
|
182
|
+
* onChange={onChange}
|
|
183
|
+
* placeholder={`Enter custom ${title}...`}
|
|
184
|
+
* />
|
|
185
|
+
* ))}
|
|
186
|
+
* </Choice.FreeText>
|
|
187
|
+
* ```
|
|
188
|
+
*
|
|
189
|
+
* Data Attributes:
|
|
190
|
+
* - `data-testid="choice-free-text"` - Applied to free text input
|
|
191
|
+
* - `data-selected` - Is Choice selected
|
|
192
|
+
*/
|
|
193
|
+
export declare const FreeText: React.ForwardRefExoticComponent<FreeTextProps & React.RefAttributes<HTMLTextAreaElement>>;
|