@wix/headless-stores 0.0.72 → 0.0.74

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.
@@ -1,7 +1,10 @@
1
1
  import type { V3Product } from '@wix/auto_sdk_stores_products-v-3';
2
+ import { Sort as SortPrimitive } from '@wix/headless-components/react';
2
3
  import React from 'react';
3
4
  import type { ProductsListServiceConfig } from '../services/products-list-service.js';
5
+ import { productsV3 } from '@wix/stores';
4
6
  import { AsChildChildren } from '@wix/headless-utils/react';
7
+ export { Filter, CategoryFilter } from './core/ProductListFilters.js';
5
8
  /**
6
9
  * Props for the ProductList root component following the documented API
7
10
  */
@@ -165,3 +168,99 @@ export interface TotalsDisplayedProps {
165
168
  * ```
166
169
  */
167
170
  export declare const TotalsDisplayed: React.ForwardRefExoticComponent<TotalsDisplayedProps & React.RefAttributes<HTMLElement>>;
171
+ /**
172
+ * Props for the ProductList Sort component
173
+ */
174
+ export interface SortProps {
175
+ /**
176
+ * Render function that provides sort state and controls when using asChild pattern.
177
+ * Only called when asChild is true and children is provided.
178
+ *
179
+ * @param props.currentSort - Current sort configuration from Wix Stores API
180
+ * @param props.sortOptions - Available sort options with field names, order, and labels
181
+ * @param props.setSort - Function to update the sort configuration
182
+ *
183
+ * @example
184
+ * ```tsx
185
+ * <ProductList.Sort asChild>
186
+ * {({ currentSort, sortOptions, setSort }) => (
187
+ * <CustomSortSelect
188
+ * value={currentSort}
189
+ * options={sortOptions}
190
+ * onChange={setSort}
191
+ * />
192
+ * )}
193
+ * </ProductList.Sort>
194
+ * ```
195
+ */
196
+ children?: (props: {
197
+ currentSort: productsV3.V3ProductSearch['sort'];
198
+ sortOptions: SortPrimitive.SortOption[];
199
+ setSort: (sort: productsV3.V3ProductSearch['sort']) => void;
200
+ }) => React.ReactNode;
201
+ /**
202
+ * CSS classes to apply to the sort component.
203
+ * Only used when asChild is false (default rendering).
204
+ */
205
+ className?: string;
206
+ /**
207
+ * Render mode for the default sort component.
208
+ * - 'select': Renders as HTML select dropdown
209
+ * - 'list': Renders as clickable list of options
210
+ *
211
+ * @default 'select'
212
+ */
213
+ as?: 'select' | 'list';
214
+ /**
215
+ * When true, the component uses the asChild pattern and delegates
216
+ * rendering to the children render function. When false (default),
217
+ * renders the built-in Sort.Root component.
218
+ *
219
+ * @default false
220
+ */
221
+ asChild?: boolean;
222
+ }
223
+ /**
224
+ * Sort component for product lists that provides sorting functionality.
225
+ *
226
+ * This component integrates with the ProductList service to provide predefined sort options
227
+ * including name (A-Z, Z-A) and price (low to high, high to low). It supports both
228
+ * controlled rendering via the asChild pattern and default UI rendering.
229
+ *
230
+ * @component
231
+ * @example
232
+ * ```tsx
233
+ * // Default select dropdown
234
+ * <ProductList.Sort />
235
+ *
236
+ * // As list of clickable options
237
+ * <ProductList.Sort as="list" />
238
+ *
239
+ * // With custom styling
240
+ * <ProductList.Sort
241
+ * as="select"
242
+ * className="custom-sort-select"
243
+ * />
244
+ *
245
+ * // Custom implementation using asChild pattern
246
+ * <ProductList.Sort asChild>
247
+ * {({ currentSort, sortOptions, setSort }) => (
248
+ * <div className="custom-sort-container">
249
+ * {sortOptions.map((option) => (
250
+ * <button
251
+ * key={`${option.fieldName}-${option.order}`}
252
+ * onClick={() => setSort([{ fieldName: option.fieldName, order: option.order }])}
253
+ * className={isCurrentSort(option) ? 'active' : ''}
254
+ * >
255
+ * {option.label}
256
+ * </button>
257
+ * ))}
258
+ * </div>
259
+ * )}
260
+ * </ProductList.Sort>
261
+ * ```
262
+ *
263
+ * @see {@link ProductListSortPrimitive} for the underlying sort logic
264
+ * @see {@link SortPrimitive.Root} for the primitive sort component
265
+ */
266
+ export declare const Sort: React.ForwardRefExoticComponent<SortProps & React.RefAttributes<HTMLElement>>;
@@ -1,11 +1,14 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Sort as SortPrimitive } from '@wix/headless-components/react';
2
3
  import { useService } from '@wix/services-manager-react';
3
4
  import React from 'react';
4
5
  import { ProductsListServiceDefinition } from '../services/products-list-service.js';
5
6
  import * as CoreProductList from './core/ProductList.js';
6
7
  import * as CoreProductListPagination from './core/ProductListPagination.js';
8
+ import { ProductListSort as ProductListSortPrimitive } from './core/ProductListSort.js';
7
9
  import * as Product from './Product.js';
8
10
  import { AsChildSlot } from '@wix/headless-utils/react';
11
+ export { Filter, CategoryFilter } from './core/ProductListFilters.js';
9
12
  var TestIds;
10
13
  (function (TestIds) {
11
14
  TestIds["productListRoot"] = "product-list-root";
@@ -13,6 +16,7 @@ var TestIds;
13
16
  TestIds["productListItem"] = "product-list-item";
14
17
  TestIds["productListLoadMore"] = "product-list-load-more";
15
18
  TestIds["productListTotalsDisplayed"] = "product-list-totals-displayed";
19
+ TestIds["productListSort"] = "product-list-sort";
16
20
  })(TestIds || (TestIds = {}));
17
21
  /**
18
22
  * Root component that provides the ProductList service context for rendering product lists.
@@ -205,3 +209,56 @@ export const TotalsDisplayed = React.forwardRef((props, ref) => {
205
209
  const displayedProducts = products.length;
206
210
  return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListTotalsDisplayed, "data-displayed": displayedProducts, customElement: children, customElementProps: { displayedProducts }, content: displayedProducts, children: _jsx("span", { children: displayedProducts }) }));
207
211
  });
212
+ /**
213
+ * Sort component for product lists that provides sorting functionality.
214
+ *
215
+ * This component integrates with the ProductList service to provide predefined sort options
216
+ * including name (A-Z, Z-A) and price (low to high, high to low). It supports both
217
+ * controlled rendering via the asChild pattern and default UI rendering.
218
+ *
219
+ * @component
220
+ * @example
221
+ * ```tsx
222
+ * // Default select dropdown
223
+ * <ProductList.Sort />
224
+ *
225
+ * // As list of clickable options
226
+ * <ProductList.Sort as="list" />
227
+ *
228
+ * // With custom styling
229
+ * <ProductList.Sort
230
+ * as="select"
231
+ * className="custom-sort-select"
232
+ * />
233
+ *
234
+ * // Custom implementation using asChild pattern
235
+ * <ProductList.Sort asChild>
236
+ * {({ currentSort, sortOptions, setSort }) => (
237
+ * <div className="custom-sort-container">
238
+ * {sortOptions.map((option) => (
239
+ * <button
240
+ * key={`${option.fieldName}-${option.order}`}
241
+ * onClick={() => setSort([{ fieldName: option.fieldName, order: option.order }])}
242
+ * className={isCurrentSort(option) ? 'active' : ''}
243
+ * >
244
+ * {option.label}
245
+ * </button>
246
+ * ))}
247
+ * </div>
248
+ * )}
249
+ * </ProductList.Sort>
250
+ * ```
251
+ *
252
+ * @see {@link ProductListSortPrimitive} for the underlying sort logic
253
+ * @see {@link SortPrimitive.Root} for the primitive sort component
254
+ */
255
+ export const Sort = React.forwardRef(({ children, className, as, asChild }, ref) => {
256
+ return (_jsx(ProductListSortPrimitive, { children: ({ currentSort, sortOptions, setSort }) => {
257
+ if (asChild && children) {
258
+ return children({ currentSort, sortOptions, setSort });
259
+ }
260
+ return (_jsx(SortPrimitive.Root, { ref: ref, value: currentSort, onChange: (value) => {
261
+ setSort(value);
262
+ }, sortOptions: sortOptions, as: as, className: className, "data-testid": TestIds.productListSort }));
263
+ } }));
264
+ });
@@ -57,10 +57,82 @@ export interface CategoryFilterProps {
57
57
  children: ((props: CategoryFilterRenderProps) => ReactNode) | ReactNode;
58
58
  }
59
59
  export declare function CategoryFilter(props: CategoryFilterProps): ReactNode;
60
- interface FilterProps {
60
+ /**
61
+ * Props for the ProductList Filter component
62
+ */
63
+ export interface FilterProps {
64
+ /**
65
+ * Child components that will have access to filter functionality.
66
+ * Typically contains Filter primitive components like FilterOptions,
67
+ * FilterOptionRepeater, etc.
68
+ */
61
69
  children: ReactNode;
70
+ /**
71
+ * When true, the component will not render its own div wrapper but will
72
+ * delegate rendering to its child component. Useful for custom containers.
73
+ *
74
+ * @default false
75
+ */
62
76
  asChild?: boolean;
77
+ /**
78
+ * CSS classes to apply to the filter container.
79
+ * Only used when asChild is false (default).
80
+ */
63
81
  className?: string;
64
82
  }
83
+ /**
84
+ * Filter component that provides comprehensive filtering functionality for product lists.
85
+ *
86
+ * This component acts as a provider that integrates with the ProductList service to offer
87
+ * predefined filter options including:
88
+ * - **Price Range**: Min/max price filtering with currency formatting
89
+ * - **Product Options**: Dynamic filters for colors, sizes, and other product variants
90
+ * - **Inventory Status**: Filter by availability (In Stock, Out of Stock, Limited Stock)
91
+ *
92
+ * The component automatically extracts available filter options from the current product set
93
+ * and provides them to child Filter primitive components for rendering.
94
+ *
95
+ * @component
96
+ * @example
97
+ * ```tsx
98
+ * // Basic usage with styled filter components
99
+ * <ProductList.Filter>
100
+ * <Filter.FilterOptions>
101
+ * <Filter.FilterOptionRepeater>
102
+ * <Filter.FilterOption.Label />
103
+ * <Filter.FilterOption.MultiFilter />
104
+ * <Filter.FilterOption.RangeFilter />
105
+ * </Filter.FilterOptionRepeater>
106
+ * </Filter.FilterOptions>
107
+ * </ProductList.Filter>
108
+ *
109
+ * // With custom container using asChild
110
+ * <ProductList.Filter asChild>
111
+ * <aside className="filter-sidebar">
112
+ * <Filter.FilterOptions>
113
+ * <Filter.FilterOptionRepeater>
114
+ * <Filter.FilterOption.Label />
115
+ * <Filter.FilterOption.MultiFilter />
116
+ * </Filter.FilterOptionRepeater>
117
+ * </Filter.FilterOptions>
118
+ * </aside>
119
+ * </ProductList.Filter>
120
+ *
121
+ * // With reset functionality
122
+ * <ProductList.Filter className="filters-container">
123
+ * <Filter.Action.Clear label="Clear All" />
124
+ * <Filter.FilterOptions>
125
+ * <Filter.FilterOptionRepeater>
126
+ * <Filter.FilterOption.Label />
127
+ * <Filter.FilterOption.MultiFilter />
128
+ * <Filter.FilterOption.RangeFilter />
129
+ * </Filter.FilterOptionRepeater>
130
+ * </Filter.FilterOptions>
131
+ * </ProductList.Filter>
132
+ * ```
133
+ *
134
+ * @see {@link AllFilters} for the underlying filter data logic
135
+ * @see {@link FilterPrimitive.Root} for the primitive filter component
136
+ * @see {@link ResetTrigger} for filter reset functionality
137
+ */
65
138
  export declare const Filter: React.ForwardRefExoticComponent<FilterProps & React.RefAttributes<HTMLDivElement>>;
66
- export {};
@@ -178,9 +178,65 @@ function AllFilters(props) {
178
178
  ? props.children({ searchFilter: searchFilterData })
179
179
  : props.children;
180
180
  }
181
+ /**
182
+ * Filter component that provides comprehensive filtering functionality for product lists.
183
+ *
184
+ * This component acts as a provider that integrates with the ProductList service to offer
185
+ * predefined filter options including:
186
+ * - **Price Range**: Min/max price filtering with currency formatting
187
+ * - **Product Options**: Dynamic filters for colors, sizes, and other product variants
188
+ * - **Inventory Status**: Filter by availability (In Stock, Out of Stock, Limited Stock)
189
+ *
190
+ * The component automatically extracts available filter options from the current product set
191
+ * and provides them to child Filter primitive components for rendering.
192
+ *
193
+ * @component
194
+ * @example
195
+ * ```tsx
196
+ * // Basic usage with styled filter components
197
+ * <ProductList.Filter>
198
+ * <Filter.FilterOptions>
199
+ * <Filter.FilterOptionRepeater>
200
+ * <Filter.FilterOption.Label />
201
+ * <Filter.FilterOption.MultiFilter />
202
+ * <Filter.FilterOption.RangeFilter />
203
+ * </Filter.FilterOptionRepeater>
204
+ * </Filter.FilterOptions>
205
+ * </ProductList.Filter>
206
+ *
207
+ * // With custom container using asChild
208
+ * <ProductList.Filter asChild>
209
+ * <aside className="filter-sidebar">
210
+ * <Filter.FilterOptions>
211
+ * <Filter.FilterOptionRepeater>
212
+ * <Filter.FilterOption.Label />
213
+ * <Filter.FilterOption.MultiFilter />
214
+ * </Filter.FilterOptionRepeater>
215
+ * </Filter.FilterOptions>
216
+ * </aside>
217
+ * </ProductList.Filter>
218
+ *
219
+ * // With reset functionality
220
+ * <ProductList.Filter className="filters-container">
221
+ * <Filter.Action.Clear label="Clear All" />
222
+ * <Filter.FilterOptions>
223
+ * <Filter.FilterOptionRepeater>
224
+ * <Filter.FilterOption.Label />
225
+ * <Filter.FilterOption.MultiFilter />
226
+ * <Filter.FilterOption.RangeFilter />
227
+ * </Filter.FilterOptionRepeater>
228
+ * </Filter.FilterOptions>
229
+ * </ProductList.Filter>
230
+ * ```
231
+ *
232
+ * @see {@link AllFilters} for the underlying filter data logic
233
+ * @see {@link FilterPrimitive.Root} for the primitive filter component
234
+ * @see {@link ResetTrigger} for filter reset functionality
235
+ */
181
236
  export const Filter = React.forwardRef(({ children, className, asChild }, ref) => {
182
237
  const Comp = asChild ? Slot : 'div';
183
238
  return (_jsx(AllFilters, { children: ({ searchFilter }) => {
184
239
  return (_jsx(FilterPrimitive.Root, { value: searchFilter.filterValue, onChange: searchFilter.updateFilter, filterOptions: searchFilter.filterOptions, children: _jsx(Comp, { className: className, ref: ref, children: children }) }));
185
240
  } }));
186
241
  });
242
+ Filter.displayName = 'ProductList.Filter';
@@ -3,9 +3,7 @@ export * as CategoryCore from './core/Category.js';
3
3
  export * as ProductCore from './core/Product.js';
4
4
  export * as ProductModifiers from './core/ProductModifiers.js';
5
5
  export * as ProductListCore from './core/ProductList.js';
6
- export * as ProductListFilters from './core/ProductListFilters.js';
7
6
  export * as ProductListPagination from './core/ProductListPagination.js';
8
- export * as ProductListSort from './core/ProductListSort.js';
9
7
  export * as ProductVariantSelector from './core/ProductVariantSelector.js';
10
8
  export * as SelectedVariant from './core/SelectedVariant.js';
11
9
  export * as Product from './Product.js';
@@ -3,9 +3,7 @@ export * as CategoryCore from './core/Category.js';
3
3
  export * as ProductCore from './core/Product.js';
4
4
  export * as ProductModifiers from './core/ProductModifiers.js';
5
5
  export * as ProductListCore from './core/ProductList.js';
6
- export * as ProductListFilters from './core/ProductListFilters.js';
7
6
  export * as ProductListPagination from './core/ProductListPagination.js';
8
- export * as ProductListSort from './core/ProductListSort.js';
9
7
  export * as ProductVariantSelector from './core/ProductVariantSelector.js';
10
8
  export * as SelectedVariant from './core/SelectedVariant.js';
11
9
  export * as Product from './Product.js';
@@ -1,7 +1,10 @@
1
1
  import type { V3Product } from '@wix/auto_sdk_stores_products-v-3';
2
+ import { Sort as SortPrimitive } from '@wix/headless-components/react';
2
3
  import React from 'react';
3
4
  import type { ProductsListServiceConfig } from '../services/products-list-service.js';
5
+ import { productsV3 } from '@wix/stores';
4
6
  import { AsChildChildren } from '@wix/headless-utils/react';
7
+ export { Filter, CategoryFilter } from './core/ProductListFilters.js';
5
8
  /**
6
9
  * Props for the ProductList root component following the documented API
7
10
  */
@@ -165,3 +168,99 @@ export interface TotalsDisplayedProps {
165
168
  * ```
166
169
  */
167
170
  export declare const TotalsDisplayed: React.ForwardRefExoticComponent<TotalsDisplayedProps & React.RefAttributes<HTMLElement>>;
171
+ /**
172
+ * Props for the ProductList Sort component
173
+ */
174
+ export interface SortProps {
175
+ /**
176
+ * Render function that provides sort state and controls when using asChild pattern.
177
+ * Only called when asChild is true and children is provided.
178
+ *
179
+ * @param props.currentSort - Current sort configuration from Wix Stores API
180
+ * @param props.sortOptions - Available sort options with field names, order, and labels
181
+ * @param props.setSort - Function to update the sort configuration
182
+ *
183
+ * @example
184
+ * ```tsx
185
+ * <ProductList.Sort asChild>
186
+ * {({ currentSort, sortOptions, setSort }) => (
187
+ * <CustomSortSelect
188
+ * value={currentSort}
189
+ * options={sortOptions}
190
+ * onChange={setSort}
191
+ * />
192
+ * )}
193
+ * </ProductList.Sort>
194
+ * ```
195
+ */
196
+ children?: (props: {
197
+ currentSort: productsV3.V3ProductSearch['sort'];
198
+ sortOptions: SortPrimitive.SortOption[];
199
+ setSort: (sort: productsV3.V3ProductSearch['sort']) => void;
200
+ }) => React.ReactNode;
201
+ /**
202
+ * CSS classes to apply to the sort component.
203
+ * Only used when asChild is false (default rendering).
204
+ */
205
+ className?: string;
206
+ /**
207
+ * Render mode for the default sort component.
208
+ * - 'select': Renders as HTML select dropdown
209
+ * - 'list': Renders as clickable list of options
210
+ *
211
+ * @default 'select'
212
+ */
213
+ as?: 'select' | 'list';
214
+ /**
215
+ * When true, the component uses the asChild pattern and delegates
216
+ * rendering to the children render function. When false (default),
217
+ * renders the built-in Sort.Root component.
218
+ *
219
+ * @default false
220
+ */
221
+ asChild?: boolean;
222
+ }
223
+ /**
224
+ * Sort component for product lists that provides sorting functionality.
225
+ *
226
+ * This component integrates with the ProductList service to provide predefined sort options
227
+ * including name (A-Z, Z-A) and price (low to high, high to low). It supports both
228
+ * controlled rendering via the asChild pattern and default UI rendering.
229
+ *
230
+ * @component
231
+ * @example
232
+ * ```tsx
233
+ * // Default select dropdown
234
+ * <ProductList.Sort />
235
+ *
236
+ * // As list of clickable options
237
+ * <ProductList.Sort as="list" />
238
+ *
239
+ * // With custom styling
240
+ * <ProductList.Sort
241
+ * as="select"
242
+ * className="custom-sort-select"
243
+ * />
244
+ *
245
+ * // Custom implementation using asChild pattern
246
+ * <ProductList.Sort asChild>
247
+ * {({ currentSort, sortOptions, setSort }) => (
248
+ * <div className="custom-sort-container">
249
+ * {sortOptions.map((option) => (
250
+ * <button
251
+ * key={`${option.fieldName}-${option.order}`}
252
+ * onClick={() => setSort([{ fieldName: option.fieldName, order: option.order }])}
253
+ * className={isCurrentSort(option) ? 'active' : ''}
254
+ * >
255
+ * {option.label}
256
+ * </button>
257
+ * ))}
258
+ * </div>
259
+ * )}
260
+ * </ProductList.Sort>
261
+ * ```
262
+ *
263
+ * @see {@link ProductListSortPrimitive} for the underlying sort logic
264
+ * @see {@link SortPrimitive.Root} for the primitive sort component
265
+ */
266
+ export declare const Sort: React.ForwardRefExoticComponent<SortProps & React.RefAttributes<HTMLElement>>;
@@ -1,11 +1,14 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Sort as SortPrimitive } from '@wix/headless-components/react';
2
3
  import { useService } from '@wix/services-manager-react';
3
4
  import React from 'react';
4
5
  import { ProductsListServiceDefinition } from '../services/products-list-service.js';
5
6
  import * as CoreProductList from './core/ProductList.js';
6
7
  import * as CoreProductListPagination from './core/ProductListPagination.js';
8
+ import { ProductListSort as ProductListSortPrimitive } from './core/ProductListSort.js';
7
9
  import * as Product from './Product.js';
8
10
  import { AsChildSlot } from '@wix/headless-utils/react';
11
+ export { Filter, CategoryFilter } from './core/ProductListFilters.js';
9
12
  var TestIds;
10
13
  (function (TestIds) {
11
14
  TestIds["productListRoot"] = "product-list-root";
@@ -13,6 +16,7 @@ var TestIds;
13
16
  TestIds["productListItem"] = "product-list-item";
14
17
  TestIds["productListLoadMore"] = "product-list-load-more";
15
18
  TestIds["productListTotalsDisplayed"] = "product-list-totals-displayed";
19
+ TestIds["productListSort"] = "product-list-sort";
16
20
  })(TestIds || (TestIds = {}));
17
21
  /**
18
22
  * Root component that provides the ProductList service context for rendering product lists.
@@ -205,3 +209,56 @@ export const TotalsDisplayed = React.forwardRef((props, ref) => {
205
209
  const displayedProducts = products.length;
206
210
  return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListTotalsDisplayed, "data-displayed": displayedProducts, customElement: children, customElementProps: { displayedProducts }, content: displayedProducts, children: _jsx("span", { children: displayedProducts }) }));
207
211
  });
212
+ /**
213
+ * Sort component for product lists that provides sorting functionality.
214
+ *
215
+ * This component integrates with the ProductList service to provide predefined sort options
216
+ * including name (A-Z, Z-A) and price (low to high, high to low). It supports both
217
+ * controlled rendering via the asChild pattern and default UI rendering.
218
+ *
219
+ * @component
220
+ * @example
221
+ * ```tsx
222
+ * // Default select dropdown
223
+ * <ProductList.Sort />
224
+ *
225
+ * // As list of clickable options
226
+ * <ProductList.Sort as="list" />
227
+ *
228
+ * // With custom styling
229
+ * <ProductList.Sort
230
+ * as="select"
231
+ * className="custom-sort-select"
232
+ * />
233
+ *
234
+ * // Custom implementation using asChild pattern
235
+ * <ProductList.Sort asChild>
236
+ * {({ currentSort, sortOptions, setSort }) => (
237
+ * <div className="custom-sort-container">
238
+ * {sortOptions.map((option) => (
239
+ * <button
240
+ * key={`${option.fieldName}-${option.order}`}
241
+ * onClick={() => setSort([{ fieldName: option.fieldName, order: option.order }])}
242
+ * className={isCurrentSort(option) ? 'active' : ''}
243
+ * >
244
+ * {option.label}
245
+ * </button>
246
+ * ))}
247
+ * </div>
248
+ * )}
249
+ * </ProductList.Sort>
250
+ * ```
251
+ *
252
+ * @see {@link ProductListSortPrimitive} for the underlying sort logic
253
+ * @see {@link SortPrimitive.Root} for the primitive sort component
254
+ */
255
+ export const Sort = React.forwardRef(({ children, className, as, asChild }, ref) => {
256
+ return (_jsx(ProductListSortPrimitive, { children: ({ currentSort, sortOptions, setSort }) => {
257
+ if (asChild && children) {
258
+ return children({ currentSort, sortOptions, setSort });
259
+ }
260
+ return (_jsx(SortPrimitive.Root, { ref: ref, value: currentSort, onChange: (value) => {
261
+ setSort(value);
262
+ }, sortOptions: sortOptions, as: as, className: className, "data-testid": TestIds.productListSort }));
263
+ } }));
264
+ });
@@ -57,10 +57,82 @@ export interface CategoryFilterProps {
57
57
  children: ((props: CategoryFilterRenderProps) => ReactNode) | ReactNode;
58
58
  }
59
59
  export declare function CategoryFilter(props: CategoryFilterProps): ReactNode;
60
- interface FilterProps {
60
+ /**
61
+ * Props for the ProductList Filter component
62
+ */
63
+ export interface FilterProps {
64
+ /**
65
+ * Child components that will have access to filter functionality.
66
+ * Typically contains Filter primitive components like FilterOptions,
67
+ * FilterOptionRepeater, etc.
68
+ */
61
69
  children: ReactNode;
70
+ /**
71
+ * When true, the component will not render its own div wrapper but will
72
+ * delegate rendering to its child component. Useful for custom containers.
73
+ *
74
+ * @default false
75
+ */
62
76
  asChild?: boolean;
77
+ /**
78
+ * CSS classes to apply to the filter container.
79
+ * Only used when asChild is false (default).
80
+ */
63
81
  className?: string;
64
82
  }
83
+ /**
84
+ * Filter component that provides comprehensive filtering functionality for product lists.
85
+ *
86
+ * This component acts as a provider that integrates with the ProductList service to offer
87
+ * predefined filter options including:
88
+ * - **Price Range**: Min/max price filtering with currency formatting
89
+ * - **Product Options**: Dynamic filters for colors, sizes, and other product variants
90
+ * - **Inventory Status**: Filter by availability (In Stock, Out of Stock, Limited Stock)
91
+ *
92
+ * The component automatically extracts available filter options from the current product set
93
+ * and provides them to child Filter primitive components for rendering.
94
+ *
95
+ * @component
96
+ * @example
97
+ * ```tsx
98
+ * // Basic usage with styled filter components
99
+ * <ProductList.Filter>
100
+ * <Filter.FilterOptions>
101
+ * <Filter.FilterOptionRepeater>
102
+ * <Filter.FilterOption.Label />
103
+ * <Filter.FilterOption.MultiFilter />
104
+ * <Filter.FilterOption.RangeFilter />
105
+ * </Filter.FilterOptionRepeater>
106
+ * </Filter.FilterOptions>
107
+ * </ProductList.Filter>
108
+ *
109
+ * // With custom container using asChild
110
+ * <ProductList.Filter asChild>
111
+ * <aside className="filter-sidebar">
112
+ * <Filter.FilterOptions>
113
+ * <Filter.FilterOptionRepeater>
114
+ * <Filter.FilterOption.Label />
115
+ * <Filter.FilterOption.MultiFilter />
116
+ * </Filter.FilterOptionRepeater>
117
+ * </Filter.FilterOptions>
118
+ * </aside>
119
+ * </ProductList.Filter>
120
+ *
121
+ * // With reset functionality
122
+ * <ProductList.Filter className="filters-container">
123
+ * <Filter.Action.Clear label="Clear All" />
124
+ * <Filter.FilterOptions>
125
+ * <Filter.FilterOptionRepeater>
126
+ * <Filter.FilterOption.Label />
127
+ * <Filter.FilterOption.MultiFilter />
128
+ * <Filter.FilterOption.RangeFilter />
129
+ * </Filter.FilterOptionRepeater>
130
+ * </Filter.FilterOptions>
131
+ * </ProductList.Filter>
132
+ * ```
133
+ *
134
+ * @see {@link AllFilters} for the underlying filter data logic
135
+ * @see {@link FilterPrimitive.Root} for the primitive filter component
136
+ * @see {@link ResetTrigger} for filter reset functionality
137
+ */
65
138
  export declare const Filter: React.ForwardRefExoticComponent<FilterProps & React.RefAttributes<HTMLDivElement>>;
66
- export {};
@@ -178,9 +178,65 @@ function AllFilters(props) {
178
178
  ? props.children({ searchFilter: searchFilterData })
179
179
  : props.children;
180
180
  }
181
+ /**
182
+ * Filter component that provides comprehensive filtering functionality for product lists.
183
+ *
184
+ * This component acts as a provider that integrates with the ProductList service to offer
185
+ * predefined filter options including:
186
+ * - **Price Range**: Min/max price filtering with currency formatting
187
+ * - **Product Options**: Dynamic filters for colors, sizes, and other product variants
188
+ * - **Inventory Status**: Filter by availability (In Stock, Out of Stock, Limited Stock)
189
+ *
190
+ * The component automatically extracts available filter options from the current product set
191
+ * and provides them to child Filter primitive components for rendering.
192
+ *
193
+ * @component
194
+ * @example
195
+ * ```tsx
196
+ * // Basic usage with styled filter components
197
+ * <ProductList.Filter>
198
+ * <Filter.FilterOptions>
199
+ * <Filter.FilterOptionRepeater>
200
+ * <Filter.FilterOption.Label />
201
+ * <Filter.FilterOption.MultiFilter />
202
+ * <Filter.FilterOption.RangeFilter />
203
+ * </Filter.FilterOptionRepeater>
204
+ * </Filter.FilterOptions>
205
+ * </ProductList.Filter>
206
+ *
207
+ * // With custom container using asChild
208
+ * <ProductList.Filter asChild>
209
+ * <aside className="filter-sidebar">
210
+ * <Filter.FilterOptions>
211
+ * <Filter.FilterOptionRepeater>
212
+ * <Filter.FilterOption.Label />
213
+ * <Filter.FilterOption.MultiFilter />
214
+ * </Filter.FilterOptionRepeater>
215
+ * </Filter.FilterOptions>
216
+ * </aside>
217
+ * </ProductList.Filter>
218
+ *
219
+ * // With reset functionality
220
+ * <ProductList.Filter className="filters-container">
221
+ * <Filter.Action.Clear label="Clear All" />
222
+ * <Filter.FilterOptions>
223
+ * <Filter.FilterOptionRepeater>
224
+ * <Filter.FilterOption.Label />
225
+ * <Filter.FilterOption.MultiFilter />
226
+ * <Filter.FilterOption.RangeFilter />
227
+ * </Filter.FilterOptionRepeater>
228
+ * </Filter.FilterOptions>
229
+ * </ProductList.Filter>
230
+ * ```
231
+ *
232
+ * @see {@link AllFilters} for the underlying filter data logic
233
+ * @see {@link FilterPrimitive.Root} for the primitive filter component
234
+ * @see {@link ResetTrigger} for filter reset functionality
235
+ */
181
236
  export const Filter = React.forwardRef(({ children, className, asChild }, ref) => {
182
237
  const Comp = asChild ? Slot : 'div';
183
238
  return (_jsx(AllFilters, { children: ({ searchFilter }) => {
184
239
  return (_jsx(FilterPrimitive.Root, { value: searchFilter.filterValue, onChange: searchFilter.updateFilter, filterOptions: searchFilter.filterOptions, children: _jsx(Comp, { className: className, ref: ref, children: children }) }));
185
240
  } }));
186
241
  });
242
+ Filter.displayName = 'ProductList.Filter';
@@ -3,9 +3,7 @@ export * as CategoryCore from './core/Category.js';
3
3
  export * as ProductCore from './core/Product.js';
4
4
  export * as ProductModifiers from './core/ProductModifiers.js';
5
5
  export * as ProductListCore from './core/ProductList.js';
6
- export * as ProductListFilters from './core/ProductListFilters.js';
7
6
  export * as ProductListPagination from './core/ProductListPagination.js';
8
- export * as ProductListSort from './core/ProductListSort.js';
9
7
  export * as ProductVariantSelector from './core/ProductVariantSelector.js';
10
8
  export * as SelectedVariant from './core/SelectedVariant.js';
11
9
  export * as Product from './Product.js';
@@ -3,9 +3,7 @@ export * as CategoryCore from './core/Category.js';
3
3
  export * as ProductCore from './core/Product.js';
4
4
  export * as ProductModifiers from './core/ProductModifiers.js';
5
5
  export * as ProductListCore from './core/ProductList.js';
6
- export * as ProductListFilters from './core/ProductListFilters.js';
7
6
  export * as ProductListPagination from './core/ProductListPagination.js';
8
- export * as ProductListSort from './core/ProductListSort.js';
9
7
  export * as ProductVariantSelector from './core/ProductVariantSelector.js';
10
8
  export * as SelectedVariant from './core/SelectedVariant.js';
11
9
  export * as Product from './Product.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.72",
3
+ "version": "0.0.74",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
@@ -62,8 +62,8 @@
62
62
  "@wix/auto_sdk_stores_read-only-variants-v-3": "^1.0.23",
63
63
  "@wix/ecom": "^1.0.1278",
64
64
  "@wix/essentials": "^0.1.24",
65
- "@wix/headless-components": "0.0.7",
66
- "@wix/headless-ecom": "0.0.21",
65
+ "@wix/headless-components": "0.0.9",
66
+ "@wix/headless-ecom": "0.0.23",
67
67
  "@wix/headless-media": "0.0.11",
68
68
  "@wix/headless-utils": "0.0.3",
69
69
  "@wix/redirects": "^1.0.83",
@@ -1,14 +0,0 @@
1
- import { Sort as SortPrimitive } from '@wix/headless-components/react';
2
- import { productsV3 } from '@wix/stores';
3
- import React from 'react';
4
- export interface ProductListSortProps {
5
- children?: (props: {
6
- currentSort: productsV3.V3ProductSearch['sort'];
7
- sortOptions: SortPrimitive.SortOption[];
8
- setSort: (sort: productsV3.V3ProductSearch['sort']) => void;
9
- }) => React.ReactNode;
10
- className?: string;
11
- as?: 'select' | 'list';
12
- asChild?: boolean;
13
- }
14
- export declare const ProductListSort: React.ForwardRefExoticComponent<ProductListSortProps & React.RefAttributes<HTMLElement>>;
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Sort as SortPrimitive } from '@wix/headless-components/react';
3
- import { ProductListSort as ProductListSortPrimitive } from './core/ProductListSort.js';
4
- import React from 'react';
5
- export const ProductListSort = React.forwardRef(({ children, className, as, asChild }, ref) => {
6
- return (_jsx(ProductListSortPrimitive, { children: ({ currentSort, sortOptions, setSort }) => {
7
- if (asChild && children) {
8
- return children({ currentSort, sortOptions, setSort });
9
- }
10
- return (_jsx(SortPrimitive.Root, { ref: ref, value: currentSort, onChange: (value) => {
11
- setSort(value);
12
- }, sortOptions: sortOptions, as: as, className: className }));
13
- } }));
14
- });
@@ -1,56 +0,0 @@
1
- /**
2
- * Props passed to the render function of the BuyNow component
3
- */
4
- export interface BuyNowRenderProps {
5
- /** Whether the buy now operation is currently loading */
6
- isLoading: boolean;
7
- /** The name of the product being purchased */
8
- productName: string;
9
- /** Function to redirect the user to the checkout page */
10
- redirectToCheckout: () => void;
11
- /** The error message if the buy now operation fails */
12
- error: string | null;
13
- /** The price of the product being purchased */
14
- price: string;
15
- /** The currency of the product being purchased */
16
- currency: string;
17
- /** Whether the product is in stock */
18
- inStock: boolean;
19
- /** Whether the product is available for pre-order */
20
- preOrderAvailable: boolean;
21
- }
22
- /**
23
- * Props for the BuyNow component
24
- */
25
- export interface BuyNowProps {
26
- /** Render function that receives buy now state and actions */
27
- children: (props: BuyNowRenderProps) => React.ReactNode;
28
- }
29
- /**
30
- * A headless component that provides buy now functionality using the render props pattern.
31
- *
32
- * This component manages the state and actions for a "buy now" flow, allowing consumers
33
- * to render their own UI while accessing the underlying buy now functionality.
34
- * @example
35
- * ```tsx
36
- * <BuyNow>
37
- * {({ isLoading, productName, redirectToCheckout, error, price, currency, inStock, preOrderAvailable }) => (
38
- * <div>
39
- * <h2>{productName}</h2>
40
- * <p>{price} {currency}</p>
41
- * {error && <div className="error">{error}</div>}
42
- * {inStock && <div>In stock</div>}
43
- * {preOrderAvailable && <div>Pre-order available</div>}
44
- * <button
45
- * onClick={redirectToCheckout}
46
- * disabled={isLoading}
47
- * >
48
- * {isLoading ? 'Processing...' : 'Buy Now'}
49
- * </button>
50
- * </div>
51
- * )}
52
- * </BuyNow>
53
- * ```
54
- * @component
55
- */
56
- export declare function BuyNow(props: BuyNowProps): React.ReactNode;
@@ -1,42 +0,0 @@
1
- import { useService } from '@wix/services-manager-react';
2
- import { BuyNowServiceDefinition } from '../../services/buy-now-service.js';
3
- /**
4
- * A headless component that provides buy now functionality using the render props pattern.
5
- *
6
- * This component manages the state and actions for a "buy now" flow, allowing consumers
7
- * to render their own UI while accessing the underlying buy now functionality.
8
- * @example
9
- * ```tsx
10
- * <BuyNow>
11
- * {({ isLoading, productName, redirectToCheckout, error, price, currency, inStock, preOrderAvailable }) => (
12
- * <div>
13
- * <h2>{productName}</h2>
14
- * <p>{price} {currency}</p>
15
- * {error && <div className="error">{error}</div>}
16
- * {inStock && <div>In stock</div>}
17
- * {preOrderAvailable && <div>Pre-order available</div>}
18
- * <button
19
- * onClick={redirectToCheckout}
20
- * disabled={isLoading}
21
- * >
22
- * {isLoading ? 'Processing...' : 'Buy Now'}
23
- * </button>
24
- * </div>
25
- * )}
26
- * </BuyNow>
27
- * ```
28
- * @component
29
- */
30
- export function BuyNow(props) {
31
- const { redirectToCheckout, loadingSignal, productName, errorSignal, price, currency, inStockSignal, preOrderAvailableSignal, } = useService(BuyNowServiceDefinition);
32
- return props.children({
33
- isLoading: loadingSignal.get(),
34
- error: errorSignal.get(),
35
- productName: productName,
36
- redirectToCheckout,
37
- price,
38
- currency,
39
- inStock: inStockSignal.get(),
40
- preOrderAvailable: preOrderAvailableSignal.get(),
41
- });
42
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Props passed to the render function of the PayNow component
3
- */
4
- export interface PayNowRenderProps {
5
- /** Whether the buy now operation is currently loading */
6
- isLoading: boolean;
7
- /** Function to redirect the user to the checkout page */
8
- redirectToCheckout: () => void;
9
- /** The error message if the buy now operation fails */
10
- error: string | null;
11
- }
12
- /**
13
- * Props for the PayNow component
14
- */
15
- export interface PayNowProps {
16
- /** Render function that receives buy now state and actions */
17
- children: (props: PayNowRenderProps) => React.ReactNode;
18
- }
19
- /**
20
- * A headless component that provides pay now functionality using the render props pattern.
21
- *
22
- * This component manages the state and actions for a "pay now" flow, allowing consumers
23
- * to render their own UI while accessing the underlying payment functionality.
24
- * @example
25
- * ```tsx
26
- * <PayNow>
27
- * {({ isLoading, redirectToCheckout, error }) => (
28
- * <div>
29
- * {error && <div className="error">{error}</div>}
30
- * <button
31
- * onClick={redirectToCheckout}
32
- * disabled={isLoading}
33
- * >
34
- * {isLoading ? 'Processing...' : 'Pay Now'}
35
- * </button>
36
- * </div>
37
- * )}
38
- * </PayNow>
39
- * ```
40
- * @component
41
- */
42
- export declare function PayNow(props: PayNowProps): React.ReactNode;
@@ -1,33 +0,0 @@
1
- import { useService } from '@wix/services-manager-react';
2
- import { PayNowServiceDefinition } from '../../services/pay-now-service.js';
3
- /**
4
- * A headless component that provides pay now functionality using the render props pattern.
5
- *
6
- * This component manages the state and actions for a "pay now" flow, allowing consumers
7
- * to render their own UI while accessing the underlying payment functionality.
8
- * @example
9
- * ```tsx
10
- * <PayNow>
11
- * {({ isLoading, redirectToCheckout, error }) => (
12
- * <div>
13
- * {error && <div className="error">{error}</div>}
14
- * <button
15
- * onClick={redirectToCheckout}
16
- * disabled={isLoading}
17
- * >
18
- * {isLoading ? 'Processing...' : 'Pay Now'}
19
- * </button>
20
- * </div>
21
- * )}
22
- * </PayNow>
23
- * ```
24
- * @component
25
- */
26
- export function PayNow(props) {
27
- const { redirectToCheckout, loadingSignal, errorSignal } = useService(PayNowServiceDefinition);
28
- return props.children({
29
- isLoading: loadingSignal.get(),
30
- error: errorSignal.get(),
31
- redirectToCheckout,
32
- });
33
- }
@@ -1,14 +0,0 @@
1
- import { Sort as SortPrimitive } from '@wix/headless-components/react';
2
- import { productsV3 } from '@wix/stores';
3
- import React from 'react';
4
- export interface ProductListSortProps {
5
- children?: (props: {
6
- currentSort: productsV3.V3ProductSearch['sort'];
7
- sortOptions: SortPrimitive.SortOption[];
8
- setSort: (sort: productsV3.V3ProductSearch['sort']) => void;
9
- }) => React.ReactNode;
10
- className?: string;
11
- as?: 'select' | 'list';
12
- asChild?: boolean;
13
- }
14
- export declare const ProductListSort: React.ForwardRefExoticComponent<ProductListSortProps & React.RefAttributes<HTMLElement>>;
@@ -1,14 +0,0 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Sort as SortPrimitive } from '@wix/headless-components/react';
3
- import { ProductListSort as ProductListSortPrimitive } from './core/ProductListSort.js';
4
- import React from 'react';
5
- export const ProductListSort = React.forwardRef(({ children, className, as, asChild }, ref) => {
6
- return (_jsx(ProductListSortPrimitive, { children: ({ currentSort, sortOptions, setSort }) => {
7
- if (asChild && children) {
8
- return children({ currentSort, sortOptions, setSort });
9
- }
10
- return (_jsx(SortPrimitive.Root, { ref: ref, value: currentSort, onChange: (value) => {
11
- setSort(value);
12
- }, sortOptions: sortOptions, as: as, className: className }));
13
- } }));
14
- });
@@ -1,56 +0,0 @@
1
- /**
2
- * Props passed to the render function of the BuyNow component
3
- */
4
- export interface BuyNowRenderProps {
5
- /** Whether the buy now operation is currently loading */
6
- isLoading: boolean;
7
- /** The name of the product being purchased */
8
- productName: string;
9
- /** Function to redirect the user to the checkout page */
10
- redirectToCheckout: () => void;
11
- /** The error message if the buy now operation fails */
12
- error: string | null;
13
- /** The price of the product being purchased */
14
- price: string;
15
- /** The currency of the product being purchased */
16
- currency: string;
17
- /** Whether the product is in stock */
18
- inStock: boolean;
19
- /** Whether the product is available for pre-order */
20
- preOrderAvailable: boolean;
21
- }
22
- /**
23
- * Props for the BuyNow component
24
- */
25
- export interface BuyNowProps {
26
- /** Render function that receives buy now state and actions */
27
- children: (props: BuyNowRenderProps) => React.ReactNode;
28
- }
29
- /**
30
- * A headless component that provides buy now functionality using the render props pattern.
31
- *
32
- * This component manages the state and actions for a "buy now" flow, allowing consumers
33
- * to render their own UI while accessing the underlying buy now functionality.
34
- * @example
35
- * ```tsx
36
- * <BuyNow>
37
- * {({ isLoading, productName, redirectToCheckout, error, price, currency, inStock, preOrderAvailable }) => (
38
- * <div>
39
- * <h2>{productName}</h2>
40
- * <p>{price} {currency}</p>
41
- * {error && <div className="error">{error}</div>}
42
- * {inStock && <div>In stock</div>}
43
- * {preOrderAvailable && <div>Pre-order available</div>}
44
- * <button
45
- * onClick={redirectToCheckout}
46
- * disabled={isLoading}
47
- * >
48
- * {isLoading ? 'Processing...' : 'Buy Now'}
49
- * </button>
50
- * </div>
51
- * )}
52
- * </BuyNow>
53
- * ```
54
- * @component
55
- */
56
- export declare function BuyNow(props: BuyNowProps): React.ReactNode;
@@ -1,42 +0,0 @@
1
- import { useService } from '@wix/services-manager-react';
2
- import { BuyNowServiceDefinition } from '../../services/buy-now-service.js';
3
- /**
4
- * A headless component that provides buy now functionality using the render props pattern.
5
- *
6
- * This component manages the state and actions for a "buy now" flow, allowing consumers
7
- * to render their own UI while accessing the underlying buy now functionality.
8
- * @example
9
- * ```tsx
10
- * <BuyNow>
11
- * {({ isLoading, productName, redirectToCheckout, error, price, currency, inStock, preOrderAvailable }) => (
12
- * <div>
13
- * <h2>{productName}</h2>
14
- * <p>{price} {currency}</p>
15
- * {error && <div className="error">{error}</div>}
16
- * {inStock && <div>In stock</div>}
17
- * {preOrderAvailable && <div>Pre-order available</div>}
18
- * <button
19
- * onClick={redirectToCheckout}
20
- * disabled={isLoading}
21
- * >
22
- * {isLoading ? 'Processing...' : 'Buy Now'}
23
- * </button>
24
- * </div>
25
- * )}
26
- * </BuyNow>
27
- * ```
28
- * @component
29
- */
30
- export function BuyNow(props) {
31
- const { redirectToCheckout, loadingSignal, productName, errorSignal, price, currency, inStockSignal, preOrderAvailableSignal, } = useService(BuyNowServiceDefinition);
32
- return props.children({
33
- isLoading: loadingSignal.get(),
34
- error: errorSignal.get(),
35
- productName: productName,
36
- redirectToCheckout,
37
- price,
38
- currency,
39
- inStock: inStockSignal.get(),
40
- preOrderAvailable: preOrderAvailableSignal.get(),
41
- });
42
- }
@@ -1,42 +0,0 @@
1
- /**
2
- * Props passed to the render function of the PayNow component
3
- */
4
- export interface PayNowRenderProps {
5
- /** Whether the buy now operation is currently loading */
6
- isLoading: boolean;
7
- /** Function to redirect the user to the checkout page */
8
- redirectToCheckout: () => void;
9
- /** The error message if the buy now operation fails */
10
- error: string | null;
11
- }
12
- /**
13
- * Props for the PayNow component
14
- */
15
- export interface PayNowProps {
16
- /** Render function that receives buy now state and actions */
17
- children: (props: PayNowRenderProps) => React.ReactNode;
18
- }
19
- /**
20
- * A headless component that provides pay now functionality using the render props pattern.
21
- *
22
- * This component manages the state and actions for a "pay now" flow, allowing consumers
23
- * to render their own UI while accessing the underlying payment functionality.
24
- * @example
25
- * ```tsx
26
- * <PayNow>
27
- * {({ isLoading, redirectToCheckout, error }) => (
28
- * <div>
29
- * {error && <div className="error">{error}</div>}
30
- * <button
31
- * onClick={redirectToCheckout}
32
- * disabled={isLoading}
33
- * >
34
- * {isLoading ? 'Processing...' : 'Pay Now'}
35
- * </button>
36
- * </div>
37
- * )}
38
- * </PayNow>
39
- * ```
40
- * @component
41
- */
42
- export declare function PayNow(props: PayNowProps): React.ReactNode;
@@ -1,33 +0,0 @@
1
- import { useService } from '@wix/services-manager-react';
2
- import { PayNowServiceDefinition } from '../../services/pay-now-service.js';
3
- /**
4
- * A headless component that provides pay now functionality using the render props pattern.
5
- *
6
- * This component manages the state and actions for a "pay now" flow, allowing consumers
7
- * to render their own UI while accessing the underlying payment functionality.
8
- * @example
9
- * ```tsx
10
- * <PayNow>
11
- * {({ isLoading, redirectToCheckout, error }) => (
12
- * <div>
13
- * {error && <div className="error">{error}</div>}
14
- * <button
15
- * onClick={redirectToCheckout}
16
- * disabled={isLoading}
17
- * >
18
- * {isLoading ? 'Processing...' : 'Pay Now'}
19
- * </button>
20
- * </div>
21
- * )}
22
- * </PayNow>
23
- * ```
24
- * @component
25
- */
26
- export function PayNow(props) {
27
- const { redirectToCheckout, loadingSignal, errorSignal } = useService(PayNowServiceDefinition);
28
- return props.children({
29
- isLoading: loadingSignal.get(),
30
- error: errorSignal.get(),
31
- redirectToCheckout,
32
- });
33
- }