@wix/headless-stores 0.0.36 → 0.0.38
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 +65 -59
- package/cjs/dist/react/Category.js +50 -83
- package/cjs/dist/react/CategoryList.d.ts +184 -0
- package/cjs/dist/react/CategoryList.js +174 -0
- package/cjs/dist/react/Product.d.ts +3 -3
- package/cjs/dist/react/Product.js +6 -6
- package/{dist/react/ProductsList.d.ts → cjs/dist/react/ProductList.d.ts} +71 -38
- package/cjs/dist/react/{ProductsList.js → ProductList.js} +30 -26
- package/cjs/dist/react/ProductListFilters.d.ts +244 -0
- package/cjs/dist/react/ProductListFilters.js +216 -0
- package/cjs/dist/react/ProductListPagination.d.ts +246 -0
- package/cjs/dist/react/ProductListPagination.js +207 -0
- package/cjs/dist/react/ProductListSort.d.ts +87 -0
- package/cjs/dist/react/ProductListSort.js +85 -0
- package/cjs/dist/react/ProductModifiers.d.ts +5 -5
- package/cjs/dist/react/ProductModifiers.js +10 -10
- package/cjs/dist/react/ProductVariantSelector.d.ts +5 -5
- package/cjs/dist/react/ProductVariantSelector.js +13 -10
- package/cjs/dist/react/SelectedVariant.d.ts +66 -3
- package/cjs/dist/react/SelectedVariant.js +106 -7
- package/cjs/dist/react/index.d.ts +6 -9
- package/cjs/dist/react/index.js +6 -9
- package/cjs/dist/services/buy-now-service.d.ts +208 -0
- package/cjs/dist/services/buy-now-service.js +132 -1
- package/cjs/dist/services/categories-list-service.d.ts +163 -0
- package/cjs/dist/services/categories-list-service.js +148 -0
- package/cjs/dist/services/category-service.d.ts +115 -70
- package/cjs/dist/services/category-service.js +101 -110
- package/cjs/dist/services/index.d.ts +6 -7
- package/cjs/dist/services/index.js +5 -16
- package/cjs/dist/services/pay-now-service.d.ts +146 -0
- package/cjs/dist/services/pay-now-service.js +112 -1
- package/cjs/dist/services/product-service.d.ts +71 -0
- package/cjs/dist/services/product-service.js +47 -0
- package/cjs/dist/services/products-list-filters-service.d.ts +292 -0
- package/cjs/dist/services/products-list-filters-service.js +446 -0
- package/cjs/dist/services/products-list-pagination-service.d.ts +186 -0
- package/cjs/dist/services/products-list-pagination-service.js +179 -0
- package/cjs/dist/services/products-list-service.d.ts +138 -52
- package/cjs/dist/services/products-list-service.js +185 -54
- package/cjs/dist/services/products-list-sort-service.d.ts +117 -0
- package/cjs/dist/services/products-list-sort-service.js +144 -0
- package/cjs/dist/utils/url-params.d.ts +68 -0
- package/cjs/dist/utils/url-params.js +72 -4
- package/dist/react/Category.d.ts +65 -59
- package/dist/react/Category.js +50 -83
- package/dist/react/CategoryList.d.ts +184 -0
- package/dist/react/CategoryList.js +174 -0
- package/dist/react/Product.d.ts +3 -3
- package/dist/react/Product.js +6 -6
- package/{cjs/dist/react/ProductsList.d.ts → dist/react/ProductList.d.ts} +71 -38
- package/dist/react/{ProductsList.js → ProductList.js} +30 -26
- package/dist/react/ProductListFilters.d.ts +244 -0
- package/dist/react/ProductListFilters.js +216 -0
- package/dist/react/ProductListPagination.d.ts +246 -0
- package/dist/react/ProductListPagination.js +207 -0
- package/dist/react/ProductListSort.d.ts +87 -0
- package/dist/react/ProductListSort.js +85 -0
- package/dist/react/ProductModifiers.d.ts +5 -5
- package/dist/react/ProductModifiers.js +10 -10
- package/dist/react/ProductVariantSelector.d.ts +5 -5
- package/dist/react/ProductVariantSelector.js +13 -10
- package/dist/react/SelectedVariant.d.ts +66 -3
- package/dist/react/SelectedVariant.js +106 -7
- package/dist/react/index.d.ts +6 -9
- package/dist/react/index.js +6 -9
- package/dist/services/buy-now-service.d.ts +208 -0
- package/dist/services/buy-now-service.js +132 -1
- package/dist/services/categories-list-service.d.ts +163 -0
- package/dist/services/categories-list-service.js +148 -0
- package/dist/services/category-service.d.ts +115 -70
- package/dist/services/category-service.js +101 -110
- package/dist/services/index.d.ts +6 -7
- package/dist/services/index.js +5 -16
- package/dist/services/pay-now-service.d.ts +146 -0
- package/dist/services/pay-now-service.js +112 -1
- package/dist/services/product-service.d.ts +71 -0
- package/dist/services/product-service.js +47 -0
- package/dist/services/products-list-filters-service.d.ts +292 -0
- package/dist/services/products-list-filters-service.js +446 -0
- package/dist/services/products-list-pagination-service.d.ts +186 -0
- package/dist/services/products-list-pagination-service.js +179 -0
- package/dist/services/products-list-service.d.ts +138 -52
- package/dist/services/products-list-service.js +185 -54
- package/dist/services/products-list-sort-service.d.ts +117 -0
- package/dist/services/products-list-sort-service.js +144 -0
- package/dist/utils/url-params.d.ts +68 -0
- package/dist/utils/url-params.js +72 -4
- package/package.json +3 -3
- package/cjs/dist/react/Collection.d.ts +0 -294
- package/cjs/dist/react/Collection.js +0 -345
- package/cjs/dist/react/FilteredCollection.d.ts +0 -299
- package/cjs/dist/react/FilteredCollection.js +0 -352
- package/cjs/dist/react/ProductActions.d.ts +0 -70
- package/cjs/dist/react/ProductActions.js +0 -104
- package/cjs/dist/react/RelatedProducts.d.ts +0 -169
- package/cjs/dist/react/RelatedProducts.js +0 -180
- package/cjs/dist/react/Sort.d.ts +0 -37
- package/cjs/dist/react/Sort.js +0 -36
- package/cjs/dist/services/catalog-service.d.ts +0 -36
- package/cjs/dist/services/catalog-service.js +0 -193
- package/cjs/dist/services/collection-service.d.ts +0 -124
- package/cjs/dist/services/collection-service.js +0 -628
- package/cjs/dist/services/filter-service.d.ts +0 -35
- package/cjs/dist/services/filter-service.js +0 -119
- package/cjs/dist/services/related-products-service.d.ts +0 -100
- package/cjs/dist/services/related-products-service.js +0 -127
- package/cjs/dist/services/sort-service.d.ts +0 -20
- package/cjs/dist/services/sort-service.js +0 -27
- package/dist/react/Collection.d.ts +0 -294
- package/dist/react/Collection.js +0 -345
- package/dist/react/FilteredCollection.d.ts +0 -299
- package/dist/react/FilteredCollection.js +0 -352
- package/dist/react/ProductActions.d.ts +0 -70
- package/dist/react/ProductActions.js +0 -104
- package/dist/react/RelatedProducts.d.ts +0 -169
- package/dist/react/RelatedProducts.js +0 -180
- package/dist/react/Sort.d.ts +0 -37
- package/dist/react/Sort.js +0 -36
- package/dist/services/catalog-service.d.ts +0 -36
- package/dist/services/catalog-service.js +0 -193
- package/dist/services/collection-service.d.ts +0 -124
- package/dist/services/collection-service.js +0 -628
- package/dist/services/filter-service.d.ts +0 -35
- package/dist/services/filter-service.js +0 -119
- package/dist/services/related-products-service.d.ts +0 -100
- package/dist/services/related-products-service.js +0 -127
- package/dist/services/sort-service.d.ts +0 -20
- package/dist/services/sort-service.js +0 -27
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
3
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
4
|
+
import { ProductsListFiltersService, ProductsListFiltersServiceDefinition, } from "../services/products-list-filters-service.js";
|
|
5
|
+
/**
|
|
6
|
+
* Root component that provides the ProductListFilters service context to its children.
|
|
7
|
+
* This component sets up the necessary services for managing products list filters.
|
|
8
|
+
*
|
|
9
|
+
* @order 1
|
|
10
|
+
* @component
|
|
11
|
+
* @example
|
|
12
|
+
* ```tsx
|
|
13
|
+
* import { ProductListFilters } from '@wix/stores/components';
|
|
14
|
+
*
|
|
15
|
+
* function FiltersSection() {
|
|
16
|
+
* return (
|
|
17
|
+
* <ProductListFilters.Root
|
|
18
|
+
* productsListFiltersConfig={{
|
|
19
|
+
* minPrice: 0,
|
|
20
|
+
* maxPrice: 1000
|
|
21
|
+
* }}
|
|
22
|
+
* >
|
|
23
|
+
* <ProductListFilters.MinPrice>
|
|
24
|
+
* {({ minPrice, setMinPrice }) => (
|
|
25
|
+
* <input
|
|
26
|
+
* type="number"
|
|
27
|
+
* value={minPrice}
|
|
28
|
+
* onChange={(e) => setMinPrice(Number(e.target.value))}
|
|
29
|
+
* placeholder="Min price"
|
|
30
|
+
* />
|
|
31
|
+
* )}
|
|
32
|
+
* </ProductListFilters.MinPrice>
|
|
33
|
+
* </ProductListFilters.Root>
|
|
34
|
+
* );
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function Root(props) {
|
|
39
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ProductsListFiltersServiceDefinition, ProductsListFiltersService, props.productsListFiltersConfig), children: props.children }));
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Headless component for managing inventory status filters
|
|
43
|
+
*
|
|
44
|
+
* @component
|
|
45
|
+
* @example
|
|
46
|
+
* ```tsx
|
|
47
|
+
* import { ProductListFilters } from '@wix/stores/components';
|
|
48
|
+
*
|
|
49
|
+
* function InventoryStatusFilter() {
|
|
50
|
+
* return (
|
|
51
|
+
* <ProductListFilters.InventoryStatus>
|
|
52
|
+
* {({ availableInventoryStatuses, selectedInventoryStatuses, toggleInventoryStatus }) => (
|
|
53
|
+
* <div>
|
|
54
|
+
* <h4>Inventory Status:</h4>
|
|
55
|
+
* {availableInventoryStatuses.map(status => (
|
|
56
|
+
* <label key={status}>
|
|
57
|
+
* <input
|
|
58
|
+
* type="checkbox"
|
|
59
|
+
* checked={selectedInventoryStatuses.includes(status)}
|
|
60
|
+
* onChange={() => toggleInventoryStatus(status)}
|
|
61
|
+
* />
|
|
62
|
+
* {status}
|
|
63
|
+
* </label>
|
|
64
|
+
* ))}
|
|
65
|
+
* </div>
|
|
66
|
+
* )}
|
|
67
|
+
* </ProductListFilters.InventoryStatus>
|
|
68
|
+
* );
|
|
69
|
+
* }
|
|
70
|
+
* ```
|
|
71
|
+
*/
|
|
72
|
+
export function InventoryStatus(props) {
|
|
73
|
+
const service = useService(ProductsListFiltersServiceDefinition);
|
|
74
|
+
const availableInventoryStatuses = service.availableInventoryStatuses.get();
|
|
75
|
+
const selectedInventoryStatuses = service.selectedInventoryStatuses.get();
|
|
76
|
+
const toggleInventoryStatus = service.toggleInventoryStatus;
|
|
77
|
+
return typeof props.children === "function"
|
|
78
|
+
? props.children({
|
|
79
|
+
availableInventoryStatuses,
|
|
80
|
+
selectedInventoryStatuses,
|
|
81
|
+
toggleInventoryStatus,
|
|
82
|
+
})
|
|
83
|
+
: props.children;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Headless component for resetting all filters
|
|
87
|
+
*
|
|
88
|
+
* @component
|
|
89
|
+
* @example
|
|
90
|
+
* ```tsx
|
|
91
|
+
* import { ProductListFilters } from '@wix/stores/components';
|
|
92
|
+
*
|
|
93
|
+
* function ResetFiltersButton() {
|
|
94
|
+
* return (
|
|
95
|
+
* <ProductListFilters.ResetTrigger>
|
|
96
|
+
* {({ resetFilters, isFiltered }) => (
|
|
97
|
+
* <button
|
|
98
|
+
* onClick={resetFilters}
|
|
99
|
+
* disabled={!isFiltered}
|
|
100
|
+
* className={isFiltered ? 'active' : 'disabled'}
|
|
101
|
+
* >
|
|
102
|
+
* {isFiltered ? 'Clear Filters' : 'No Filters Applied'}
|
|
103
|
+
* </button>
|
|
104
|
+
* )}
|
|
105
|
+
* </ProductListFilters.ResetTrigger>
|
|
106
|
+
* );
|
|
107
|
+
* }
|
|
108
|
+
* ```
|
|
109
|
+
*/
|
|
110
|
+
export function ResetTrigger(props) {
|
|
111
|
+
const service = useService(ProductsListFiltersServiceDefinition);
|
|
112
|
+
const resetFilters = service.reset;
|
|
113
|
+
const isFiltered = service.isFiltered.get();
|
|
114
|
+
return typeof props.children === "function"
|
|
115
|
+
? props.children({ resetFilters, isFiltered })
|
|
116
|
+
: props.children;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Headless component for managing price range filters (combined min/max)
|
|
120
|
+
*
|
|
121
|
+
* @component
|
|
122
|
+
* @example
|
|
123
|
+
* ```tsx
|
|
124
|
+
* import { ProductListFilters } from '@wix/stores/components';
|
|
125
|
+
*
|
|
126
|
+
* function PriceRangeFilter() {
|
|
127
|
+
* return (
|
|
128
|
+
* <ProductListFilters.PriceRange>
|
|
129
|
+
* {({ minPrice, maxPrice, setMinPrice, setMaxPrice }) => (
|
|
130
|
+
* <div className="price-range">
|
|
131
|
+
* <h4>Price Range:</h4>
|
|
132
|
+
* <div className="price-inputs">
|
|
133
|
+
* <input
|
|
134
|
+
* type="number"
|
|
135
|
+
* value={minPrice}
|
|
136
|
+
* onChange={(e) => setMinPrice(Number(e.target.value))}
|
|
137
|
+
* placeholder="Min"
|
|
138
|
+
* />
|
|
139
|
+
* <span>to</span>
|
|
140
|
+
* <input
|
|
141
|
+
* type="number"
|
|
142
|
+
* value={maxPrice}
|
|
143
|
+
* onChange={(e) => setMaxPrice(Number(e.target.value))}
|
|
144
|
+
* placeholder="Max"
|
|
145
|
+
* />
|
|
146
|
+
* </div>
|
|
147
|
+
* </div>
|
|
148
|
+
* )}
|
|
149
|
+
* </ProductListFilters.PriceRange>
|
|
150
|
+
* );
|
|
151
|
+
* }
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
export function PriceRange(props) {
|
|
155
|
+
const service = useService(ProductsListFiltersServiceDefinition);
|
|
156
|
+
const minPrice = service.minPrice.get();
|
|
157
|
+
const maxPrice = service.maxPrice.get();
|
|
158
|
+
const setMinPrice = service.setMinPrice;
|
|
159
|
+
const setMaxPrice = service.setMaxPrice;
|
|
160
|
+
return typeof props.children === "function"
|
|
161
|
+
? props.children({ minPrice, maxPrice, setMinPrice, setMaxPrice })
|
|
162
|
+
: props.children;
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* Headless component that renders content for each product option in the list.
|
|
166
|
+
* Maps over all available product options and provides each option through a render prop.
|
|
167
|
+
* Only renders when options are available (not loading, no error, and has options).
|
|
168
|
+
* This follows the same collection pattern as ProductList.ItemContent and CategoryList.ItemContent.
|
|
169
|
+
*
|
|
170
|
+
* @component
|
|
171
|
+
* @example
|
|
172
|
+
* ```tsx
|
|
173
|
+
* import { ProductListFilters } from '@wix/stores/components';
|
|
174
|
+
*
|
|
175
|
+
* function ProductOptionsFilter() {
|
|
176
|
+
* return (
|
|
177
|
+
* <ProductListFilters.ProductOptions>
|
|
178
|
+
* {({ option, selectedChoices, toggleChoice }) => (
|
|
179
|
+
* <div key={option.id}>
|
|
180
|
+
* <h4>{option.name}</h4>
|
|
181
|
+
* {option.choices.map(choice => (
|
|
182
|
+
* <label key={choice.id}>
|
|
183
|
+
* <input
|
|
184
|
+
* type="checkbox"
|
|
185
|
+
* checked={selectedChoices.includes(choice.id)}
|
|
186
|
+
* onChange={() => toggleChoice(choice.id)}
|
|
187
|
+
* />
|
|
188
|
+
* {choice.name}
|
|
189
|
+
* </label>
|
|
190
|
+
* ))}
|
|
191
|
+
* </div>
|
|
192
|
+
* )}
|
|
193
|
+
* </ProductListFilters.ProductOptions>
|
|
194
|
+
* );
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export function ProductOptions(props) {
|
|
199
|
+
const service = useService(ProductsListFiltersServiceDefinition);
|
|
200
|
+
const availableOptions = service.availableProductOptions.get();
|
|
201
|
+
const selectedProductOptions = service.selectedProductOptions.get();
|
|
202
|
+
// Don't render if no options are available
|
|
203
|
+
if (availableOptions.length === 0) {
|
|
204
|
+
return null;
|
|
205
|
+
}
|
|
206
|
+
// Map over options and create render prop for each
|
|
207
|
+
return (_jsx(_Fragment, { children: availableOptions.map((option) => {
|
|
208
|
+
const selectedChoices = selectedProductOptions[option.id] || [];
|
|
209
|
+
const toggleChoice = (choiceId) => {
|
|
210
|
+
service.toggleProductOption(option.id, choiceId);
|
|
211
|
+
};
|
|
212
|
+
return typeof props.children === "function"
|
|
213
|
+
? props.children({ option, selectedChoices, toggleChoice })
|
|
214
|
+
: props.children;
|
|
215
|
+
}) }));
|
|
216
|
+
}
|
|
@@ -0,0 +1,246 @@
|
|
|
1
|
+
import type { PropsWithChildren, ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* Root component that provides the ProductListPagination service context to its children.
|
|
4
|
+
* This component sets up the necessary services for managing products list pagination.
|
|
5
|
+
*
|
|
6
|
+
* @order 1
|
|
7
|
+
* @component
|
|
8
|
+
* @example
|
|
9
|
+
* ```tsx
|
|
10
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
11
|
+
*
|
|
12
|
+
* function PaginationSection() {
|
|
13
|
+
* return (
|
|
14
|
+
* <ProductListPagination.Root>
|
|
15
|
+
* <ProductListPagination.NextPageTrigger>
|
|
16
|
+
* {({ nextPage, hasNextPage }) => (
|
|
17
|
+
* <button
|
|
18
|
+
* onClick={nextPage}
|
|
19
|
+
* disabled={!hasNextPage}
|
|
20
|
+
* >
|
|
21
|
+
* Next Page
|
|
22
|
+
* </button>
|
|
23
|
+
* )}
|
|
24
|
+
* </ProductListPagination.NextPageTrigger>
|
|
25
|
+
* </ProductListPagination.Root>
|
|
26
|
+
* );
|
|
27
|
+
* }
|
|
28
|
+
* ```
|
|
29
|
+
*/
|
|
30
|
+
export declare function Root(props: PropsWithChildren): import("react/jsx-runtime").JSX.Element;
|
|
31
|
+
/**
|
|
32
|
+
* Props for PageSize headless component
|
|
33
|
+
*/
|
|
34
|
+
export interface PageSizeProps {
|
|
35
|
+
/** Content to display (can be a render function receiving page size controls or ReactNode) */
|
|
36
|
+
children: ((props: PageSizeRenderProps) => ReactNode) | ReactNode;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Render props for PageSize component
|
|
40
|
+
*/
|
|
41
|
+
export interface PageSizeRenderProps {
|
|
42
|
+
/** Current page size (items per page) */
|
|
43
|
+
currentLimit: number;
|
|
44
|
+
/** Function to update the page size */
|
|
45
|
+
setLimit: (limit: number) => void;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Headless component for managing page size (items per page)
|
|
49
|
+
*
|
|
50
|
+
* @component
|
|
51
|
+
* @example
|
|
52
|
+
* ```tsx
|
|
53
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
54
|
+
*
|
|
55
|
+
* function PageSizeSelector() {
|
|
56
|
+
* return (
|
|
57
|
+
* <ProductListPagination.PageSize>
|
|
58
|
+
* {({ currentLimit, setLimit }) => (
|
|
59
|
+
* <div>
|
|
60
|
+
* <label>Items per page:</label>
|
|
61
|
+
* <select
|
|
62
|
+
* value={currentLimit}
|
|
63
|
+
* onChange={(e) => setLimit(Number(e.target.value))}
|
|
64
|
+
* >
|
|
65
|
+
* <option value={10}>10</option>
|
|
66
|
+
* <option value={20}>20</option>
|
|
67
|
+
* <option value={50}>50</option>
|
|
68
|
+
* </select>
|
|
69
|
+
* </div>
|
|
70
|
+
* )}
|
|
71
|
+
* </ProductListPagination.PageSize>
|
|
72
|
+
* );
|
|
73
|
+
* }
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
export declare function PageSize(props: PageSizeProps): ReactNode;
|
|
77
|
+
/**
|
|
78
|
+
* Props for NextPageTrigger headless component
|
|
79
|
+
*/
|
|
80
|
+
export interface NextPageTriggerProps {
|
|
81
|
+
/** Content to display (can be a render function receiving next page controls or ReactNode) */
|
|
82
|
+
children: ((props: NextPageTriggerRenderProps) => ReactNode) | ReactNode;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Render props for NextPageTrigger component
|
|
86
|
+
*/
|
|
87
|
+
export interface NextPageTriggerRenderProps {
|
|
88
|
+
/** Function to navigate to the next page */
|
|
89
|
+
nextPage: () => void;
|
|
90
|
+
/** Whether there is a next page available */
|
|
91
|
+
hasNextPage: boolean;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Headless component for navigating to the next page
|
|
95
|
+
*
|
|
96
|
+
* @component
|
|
97
|
+
* @example
|
|
98
|
+
* ```tsx
|
|
99
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
100
|
+
*
|
|
101
|
+
* function NextPageButton() {
|
|
102
|
+
* return (
|
|
103
|
+
* <ProductListPagination.NextPageTrigger>
|
|
104
|
+
* {({ nextPage, hasNextPage }) => (
|
|
105
|
+
* <button
|
|
106
|
+
* onClick={nextPage}
|
|
107
|
+
* disabled={!hasNextPage}
|
|
108
|
+
* className={hasNextPage ? 'enabled' : 'disabled'}
|
|
109
|
+
* >
|
|
110
|
+
* Next →
|
|
111
|
+
* </button>
|
|
112
|
+
* )}
|
|
113
|
+
* </ProductListPagination.NextPageTrigger>
|
|
114
|
+
* );
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function NextPageTrigger(props: NextPageTriggerProps): ReactNode;
|
|
119
|
+
/**
|
|
120
|
+
* Props for PreviousPageTrigger headless component
|
|
121
|
+
*/
|
|
122
|
+
export interface PreviousPageTriggerProps {
|
|
123
|
+
/** Content to display (can be a render function receiving previous page controls or ReactNode) */
|
|
124
|
+
children: ((props: PreviousPageTriggerRenderProps) => ReactNode) | ReactNode;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Render props for PreviousPageTrigger component
|
|
128
|
+
*/
|
|
129
|
+
export interface PreviousPageTriggerRenderProps {
|
|
130
|
+
/** Function to navigate to the previous page */
|
|
131
|
+
prevPage: () => void;
|
|
132
|
+
/** Whether there is a previous page available */
|
|
133
|
+
hasPrevPage: boolean;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Headless component for navigating to the previous page
|
|
137
|
+
*
|
|
138
|
+
* @component
|
|
139
|
+
* @example
|
|
140
|
+
* ```tsx
|
|
141
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
142
|
+
*
|
|
143
|
+
* function PrevPageButton() {
|
|
144
|
+
* return (
|
|
145
|
+
* <ProductListPagination.PreviousPageTrigger>
|
|
146
|
+
* {({ prevPage, hasPrevPage }) => (
|
|
147
|
+
* <button
|
|
148
|
+
* onClick={prevPage}
|
|
149
|
+
* disabled={!hasPrevPage}
|
|
150
|
+
* className={hasPrevPage ? 'enabled' : 'disabled'}
|
|
151
|
+
* >
|
|
152
|
+
* ← Previous
|
|
153
|
+
* </button>
|
|
154
|
+
* )}
|
|
155
|
+
* </ProductListPagination.PreviousPageTrigger>
|
|
156
|
+
* );
|
|
157
|
+
* }
|
|
158
|
+
* ```
|
|
159
|
+
*/
|
|
160
|
+
export declare function PreviousPageTrigger(props: PreviousPageTriggerProps): ReactNode;
|
|
161
|
+
/**
|
|
162
|
+
* Props for FirstPageTrigger headless component
|
|
163
|
+
*/
|
|
164
|
+
export interface FirstPageTriggerProps {
|
|
165
|
+
/** Content to display (can be a render function receiving first page controls or ReactNode) */
|
|
166
|
+
children: ((props: FirstPageTriggerRenderProps) => ReactNode) | ReactNode;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Render props for FirstPageTrigger component
|
|
170
|
+
*/
|
|
171
|
+
export interface FirstPageTriggerRenderProps {
|
|
172
|
+
/** Function to navigate to the first page */
|
|
173
|
+
goToFirstPage: () => void;
|
|
174
|
+
/** Whether there is a previous page (indicating not on first page) */
|
|
175
|
+
hasPrevPage: boolean;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Headless component for navigating to the first page
|
|
179
|
+
*
|
|
180
|
+
* @component
|
|
181
|
+
* @example
|
|
182
|
+
* ```tsx
|
|
183
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
184
|
+
*
|
|
185
|
+
* function FirstPageButton() {
|
|
186
|
+
* return (
|
|
187
|
+
* <ProductListPagination.FirstPageTrigger>
|
|
188
|
+
* {({ goToFirstPage, hasPrevPage }) => (
|
|
189
|
+
* <button
|
|
190
|
+
* onClick={goToFirstPage}
|
|
191
|
+
* disabled={!hasPrevPage}
|
|
192
|
+
* title="Go to first page"
|
|
193
|
+
* >
|
|
194
|
+
* ⏮ First
|
|
195
|
+
* </button>
|
|
196
|
+
* )}
|
|
197
|
+
* </ProductListPagination.FirstPageTrigger>
|
|
198
|
+
* );
|
|
199
|
+
* }
|
|
200
|
+
* ```
|
|
201
|
+
*/
|
|
202
|
+
export declare function FirstPageTrigger(props: FirstPageTriggerProps): ReactNode;
|
|
203
|
+
/**
|
|
204
|
+
* Props for LoadMoreTrigger headless component
|
|
205
|
+
*/
|
|
206
|
+
export interface LoadMoreTriggerProps {
|
|
207
|
+
/** Content to display (can be a render function receiving load more controls or ReactNode) */
|
|
208
|
+
children: ((props: LoadMoreTriggerRenderProps) => ReactNode) | ReactNode;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Render props for LoadMoreTrigger component
|
|
212
|
+
*/
|
|
213
|
+
export interface LoadMoreTriggerRenderProps {
|
|
214
|
+
/** Function to load more products */
|
|
215
|
+
loadMore: (count: number) => void;
|
|
216
|
+
/** Whether there are more products to load */
|
|
217
|
+
hasMoreProducts: boolean;
|
|
218
|
+
/** Whether products are currently loading */
|
|
219
|
+
isLoading: boolean;
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Headless component for loading more products (infinite scroll pattern)
|
|
223
|
+
*
|
|
224
|
+
* @component
|
|
225
|
+
* @example
|
|
226
|
+
* ```tsx
|
|
227
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
228
|
+
*
|
|
229
|
+
* function LoadMoreButton() {
|
|
230
|
+
* return (
|
|
231
|
+
* <ProductListPagination.LoadMoreTrigger>
|
|
232
|
+
* {({ loadMore, hasMoreProducts, isLoading }) => (
|
|
233
|
+
* <button
|
|
234
|
+
* onClick={() => loadMore(10)}
|
|
235
|
+
* disabled={!hasMoreProducts || isLoading}
|
|
236
|
+
* className="load-more-btn"
|
|
237
|
+
* >
|
|
238
|
+
* {isLoading ? 'Loading...' : hasMoreProducts ? 'Load More' : 'No More Products'}
|
|
239
|
+
* </button>
|
|
240
|
+
* )}
|
|
241
|
+
* </ProductListPagination.LoadMoreTrigger>
|
|
242
|
+
* );
|
|
243
|
+
* }
|
|
244
|
+
* ```
|
|
245
|
+
*/
|
|
246
|
+
export declare function LoadMoreTrigger(props: LoadMoreTriggerProps): ReactNode;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createServicesMap } from "@wix/services-manager";
|
|
3
|
+
import { useService, WixServices } from "@wix/services-manager-react";
|
|
4
|
+
import { ProductsListPaginationService, ProductsListPaginationServiceDefinition, } from "../services/products-list-pagination-service.js";
|
|
5
|
+
import { ProductsListServiceDefinition } from "../services/products-list-service.js";
|
|
6
|
+
/**
|
|
7
|
+
* Root component that provides the ProductListPagination service context to its children.
|
|
8
|
+
* This component sets up the necessary services for managing products list pagination.
|
|
9
|
+
*
|
|
10
|
+
* @order 1
|
|
11
|
+
* @component
|
|
12
|
+
* @example
|
|
13
|
+
* ```tsx
|
|
14
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
15
|
+
*
|
|
16
|
+
* function PaginationSection() {
|
|
17
|
+
* return (
|
|
18
|
+
* <ProductListPagination.Root>
|
|
19
|
+
* <ProductListPagination.NextPageTrigger>
|
|
20
|
+
* {({ nextPage, hasNextPage }) => (
|
|
21
|
+
* <button
|
|
22
|
+
* onClick={nextPage}
|
|
23
|
+
* disabled={!hasNextPage}
|
|
24
|
+
* >
|
|
25
|
+
* Next Page
|
|
26
|
+
* </button>
|
|
27
|
+
* )}
|
|
28
|
+
* </ProductListPagination.NextPageTrigger>
|
|
29
|
+
* </ProductListPagination.Root>
|
|
30
|
+
* );
|
|
31
|
+
* }
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
export function Root(props) {
|
|
35
|
+
return (_jsx(WixServices, { servicesMap: createServicesMap().addService(ProductsListPaginationServiceDefinition, ProductsListPaginationService), children: props.children }));
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Headless component for managing page size (items per page)
|
|
39
|
+
*
|
|
40
|
+
* @component
|
|
41
|
+
* @example
|
|
42
|
+
* ```tsx
|
|
43
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
44
|
+
*
|
|
45
|
+
* function PageSizeSelector() {
|
|
46
|
+
* return (
|
|
47
|
+
* <ProductListPagination.PageSize>
|
|
48
|
+
* {({ currentLimit, setLimit }) => (
|
|
49
|
+
* <div>
|
|
50
|
+
* <label>Items per page:</label>
|
|
51
|
+
* <select
|
|
52
|
+
* value={currentLimit}
|
|
53
|
+
* onChange={(e) => setLimit(Number(e.target.value))}
|
|
54
|
+
* >
|
|
55
|
+
* <option value={10}>10</option>
|
|
56
|
+
* <option value={20}>20</option>
|
|
57
|
+
* <option value={50}>50</option>
|
|
58
|
+
* </select>
|
|
59
|
+
* </div>
|
|
60
|
+
* )}
|
|
61
|
+
* </ProductListPagination.PageSize>
|
|
62
|
+
* );
|
|
63
|
+
* }
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
export function PageSize(props) {
|
|
67
|
+
const service = useService(ProductsListPaginationServiceDefinition);
|
|
68
|
+
const currentLimit = service.currentLimit.get();
|
|
69
|
+
const setLimit = service.setLimit;
|
|
70
|
+
return typeof props.children === "function"
|
|
71
|
+
? props.children({ currentLimit, setLimit })
|
|
72
|
+
: props.children;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Headless component for navigating to the next page
|
|
76
|
+
*
|
|
77
|
+
* @component
|
|
78
|
+
* @example
|
|
79
|
+
* ```tsx
|
|
80
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
81
|
+
*
|
|
82
|
+
* function NextPageButton() {
|
|
83
|
+
* return (
|
|
84
|
+
* <ProductListPagination.NextPageTrigger>
|
|
85
|
+
* {({ nextPage, hasNextPage }) => (
|
|
86
|
+
* <button
|
|
87
|
+
* onClick={nextPage}
|
|
88
|
+
* disabled={!hasNextPage}
|
|
89
|
+
* className={hasNextPage ? 'enabled' : 'disabled'}
|
|
90
|
+
* >
|
|
91
|
+
* Next →
|
|
92
|
+
* </button>
|
|
93
|
+
* )}
|
|
94
|
+
* </ProductListPagination.NextPageTrigger>
|
|
95
|
+
* );
|
|
96
|
+
* }
|
|
97
|
+
* ```
|
|
98
|
+
*/
|
|
99
|
+
export function NextPageTrigger(props) {
|
|
100
|
+
const service = useService(ProductsListPaginationServiceDefinition);
|
|
101
|
+
const nextPage = service.nextPage;
|
|
102
|
+
const hasNextPage = service.hasNextPage.get();
|
|
103
|
+
return typeof props.children === "function"
|
|
104
|
+
? props.children({ nextPage, hasNextPage })
|
|
105
|
+
: props.children;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Headless component for navigating to the previous page
|
|
109
|
+
*
|
|
110
|
+
* @component
|
|
111
|
+
* @example
|
|
112
|
+
* ```tsx
|
|
113
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
114
|
+
*
|
|
115
|
+
* function PrevPageButton() {
|
|
116
|
+
* return (
|
|
117
|
+
* <ProductListPagination.PreviousPageTrigger>
|
|
118
|
+
* {({ prevPage, hasPrevPage }) => (
|
|
119
|
+
* <button
|
|
120
|
+
* onClick={prevPage}
|
|
121
|
+
* disabled={!hasPrevPage}
|
|
122
|
+
* className={hasPrevPage ? 'enabled' : 'disabled'}
|
|
123
|
+
* >
|
|
124
|
+
* ← Previous
|
|
125
|
+
* </button>
|
|
126
|
+
* )}
|
|
127
|
+
* </ProductListPagination.PreviousPageTrigger>
|
|
128
|
+
* );
|
|
129
|
+
* }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function PreviousPageTrigger(props) {
|
|
133
|
+
const service = useService(ProductsListPaginationServiceDefinition);
|
|
134
|
+
const prevPage = service.prevPage;
|
|
135
|
+
const hasPrevPage = service.hasPrevPage.get();
|
|
136
|
+
return typeof props.children === "function"
|
|
137
|
+
? props.children({ prevPage, hasPrevPage })
|
|
138
|
+
: props.children;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Headless component for navigating to the first page
|
|
142
|
+
*
|
|
143
|
+
* @component
|
|
144
|
+
* @example
|
|
145
|
+
* ```tsx
|
|
146
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
147
|
+
*
|
|
148
|
+
* function FirstPageButton() {
|
|
149
|
+
* return (
|
|
150
|
+
* <ProductListPagination.FirstPageTrigger>
|
|
151
|
+
* {({ goToFirstPage, hasPrevPage }) => (
|
|
152
|
+
* <button
|
|
153
|
+
* onClick={goToFirstPage}
|
|
154
|
+
* disabled={!hasPrevPage}
|
|
155
|
+
* title="Go to first page"
|
|
156
|
+
* >
|
|
157
|
+
* ⏮ First
|
|
158
|
+
* </button>
|
|
159
|
+
* )}
|
|
160
|
+
* </ProductListPagination.FirstPageTrigger>
|
|
161
|
+
* );
|
|
162
|
+
* }
|
|
163
|
+
* ```
|
|
164
|
+
*/
|
|
165
|
+
export function FirstPageTrigger(props) {
|
|
166
|
+
const service = useService(ProductsListPaginationServiceDefinition);
|
|
167
|
+
const goToFirstPage = service.goToFirstPage;
|
|
168
|
+
const hasPrevPage = service.hasPrevPage.get();
|
|
169
|
+
return typeof props.children === "function"
|
|
170
|
+
? props.children({ goToFirstPage, hasPrevPage })
|
|
171
|
+
: props.children;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Headless component for loading more products (infinite scroll pattern)
|
|
175
|
+
*
|
|
176
|
+
* @component
|
|
177
|
+
* @example
|
|
178
|
+
* ```tsx
|
|
179
|
+
* import { ProductListPagination } from '@wix/stores/components';
|
|
180
|
+
*
|
|
181
|
+
* function LoadMoreButton() {
|
|
182
|
+
* return (
|
|
183
|
+
* <ProductListPagination.LoadMoreTrigger>
|
|
184
|
+
* {({ loadMore, hasMoreProducts, isLoading }) => (
|
|
185
|
+
* <button
|
|
186
|
+
* onClick={() => loadMore(10)}
|
|
187
|
+
* disabled={!hasMoreProducts || isLoading}
|
|
188
|
+
* className="load-more-btn"
|
|
189
|
+
* >
|
|
190
|
+
* {isLoading ? 'Loading...' : hasMoreProducts ? 'Load More' : 'No More Products'}
|
|
191
|
+
* </button>
|
|
192
|
+
* )}
|
|
193
|
+
* </ProductListPagination.LoadMoreTrigger>
|
|
194
|
+
* );
|
|
195
|
+
* }
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
export function LoadMoreTrigger(props) {
|
|
199
|
+
const service = useService(ProductsListPaginationServiceDefinition);
|
|
200
|
+
const productsListService = useService(ProductsListServiceDefinition);
|
|
201
|
+
const loadMore = service.loadMore;
|
|
202
|
+
const hasMoreProducts = service.hasNextPage.get();
|
|
203
|
+
const isLoading = productsListService.isLoading.get();
|
|
204
|
+
return typeof props.children === "function"
|
|
205
|
+
? props.children({ loadMore, hasMoreProducts, isLoading })
|
|
206
|
+
: props.children;
|
|
207
|
+
}
|