@wix/headless-stores 0.0.62 → 0.0.64

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,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type AsChildProps } from '../utils/index.js';
2
+ import { AsChildChildren } from '@wix/headless-utils/react';
3
3
  /**
4
4
  * Choice data interface
5
5
  */
@@ -67,10 +67,16 @@ export declare const Root: React.ForwardRefExoticComponent<RootProps & React.Ref
67
67
  /**
68
68
  * Props for Choice Text component
69
69
  */
70
- export interface TextProps extends AsChildProps<{
71
- id: string;
72
- value: string;
73
- }> {
70
+ export interface TextProps {
71
+ /** Whether to render as a child component */
72
+ asChild?: boolean;
73
+ /** Custom render function when using asChild */
74
+ children?: AsChildChildren<{
75
+ id: string;
76
+ value: string;
77
+ }>;
78
+ /** CSS classes to apply to the default element */
79
+ className?: string;
74
80
  }
75
81
  /**
76
82
  * Text-based choice button.
@@ -105,11 +111,17 @@ export declare const Text: React.ForwardRefExoticComponent<TextProps & React.Ref
105
111
  /**
106
112
  * Props for Choice Color component
107
113
  */
108
- export interface ColorProps extends AsChildProps<{
109
- colorCode: string;
110
- name: string;
111
- id: string;
112
- }> {
114
+ export interface ColorProps {
115
+ /** Whether to render as a child component */
116
+ asChild?: boolean;
117
+ /** Custom render function when using asChild */
118
+ children?: AsChildChildren<{
119
+ colorCode: string;
120
+ name: string;
121
+ id: string;
122
+ }>;
123
+ /** CSS classes to apply to the default element */
124
+ className?: string;
113
125
  }
114
126
  /**
115
127
  * Color swatch choice.
@@ -148,14 +160,20 @@ export declare const Color: React.ForwardRefExoticComponent<ColorProps & React.R
148
160
  /**
149
161
  * Props for Choice FreeText component
150
162
  */
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'> {
163
+ export interface FreeTextProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'children'> {
164
+ /** Whether to render as a child component */
165
+ asChild?: boolean;
166
+ /** Custom render function when using asChild */
167
+ children?: AsChildChildren<{
168
+ minCharCount?: number;
169
+ maxCharCount?: number;
170
+ defaultAddedPrice?: string | null;
171
+ title?: string;
172
+ value?: string;
173
+ onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
174
+ }>;
175
+ /** CSS classes to apply to the default element */
176
+ className?: string;
159
177
  }
160
178
  /**
161
179
  * Provides a free text input for variant selection.
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { renderAsChild } from '../utils/index.js';
4
3
  import { FreeText as FreeTextPrimitive } from './core/ProductModifiers.js';
4
+ import { AsChildSlot } from '@wix/headless-utils/react';
5
5
  var TestIds;
6
6
  (function (TestIds) {
7
7
  TestIds["choiceRoot"] = "choice-root";
@@ -91,24 +91,7 @@ export const Text = React.forwardRef((props, ref) => {
91
91
  if (!isVisible)
92
92
  return null;
93
93
  const choiceId = choice?.choiceId || '';
94
- const attributes = {
95
- 'data-testid': TestIds.choiceText,
96
- 'data-selected': isSelected ? 'true' : 'false',
97
- disabled: !isInStock && !isPreOrderEnabled,
98
- onClick: select,
99
- };
100
- if (asChild) {
101
- const rendered = renderAsChild({
102
- children,
103
- props: { id: choiceId, value },
104
- ref,
105
- content: value,
106
- attributes,
107
- });
108
- if (rendered)
109
- return rendered;
110
- }
111
- return (_jsx("button", { className: className, ...attributes, ref: ref, children: value }));
94
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.choiceText, "data-selected": isSelected ? 'true' : 'false', disabled: !isInStock && !isPreOrderEnabled, onClick: select, customElement: children, customElementProps: { id: choiceId, value }, content: value, children: _jsx("button", { children: value }) }));
112
95
  });
113
96
  /**
114
97
  * Color swatch choice.
@@ -157,28 +140,11 @@ export const Color = React.forwardRef((props, ref) => {
157
140
  if (!isVisible)
158
141
  return null;
159
142
  const { colorCode, choiceId } = choice;
160
- const attributes = {
161
- 'data-testid': TestIds.choiceColor,
162
- 'data-selected': isSelected ? 'true' : 'false',
163
- disabled: !isInStock && !isPreOrderEnabled,
164
- onClick: select,
165
- };
166
- if (asChild) {
167
- const rendered = renderAsChild({
168
- children,
169
- props: {
170
- colorCode: colorCode || '',
171
- name: value,
172
- id: choiceId || '',
173
- },
174
- ref,
175
- content: null,
176
- attributes,
177
- });
178
- if (rendered)
179
- return rendered;
180
- }
181
- return (_jsx("button", { className: className, ...attributes, ref: ref, style: { backgroundColor: colorCode }, title: value }));
143
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.choiceColor, "data-selected": isSelected ? 'true' : 'false', disabled: !isInStock && !isPreOrderEnabled, onClick: select, customElement: children, customElementProps: {
144
+ colorCode: colorCode || '',
145
+ name: value,
146
+ id: choiceId || '',
147
+ }, children: _jsx("button", { style: { backgroundColor: colorCode }, title: value }) }));
182
148
  });
183
149
  /**
184
150
  * Provides a free text input for variant selection.
@@ -226,10 +192,6 @@ export const FreeText = React.forwardRef((props, ref) => {
226
192
  // Don't render if not visible (handled by ProductVariantSelector in Root)
227
193
  if (!isVisible)
228
194
  return null;
229
- const attributes = {
230
- 'data-testid': TestIds.choiceFreetext,
231
- 'data-selected': isSelected ? 'true' : 'false',
232
- };
233
195
  return (_jsx(FreeTextPrimitive, { modifier: choice, children: ({ value, setText, placeholder, maxChars }) => {
234
196
  const handleChange = (e) => {
235
197
  setText(e.target.value);
@@ -237,23 +199,12 @@ export const FreeText = React.forwardRef((props, ref) => {
237
199
  onValueChange(e.target.value);
238
200
  }
239
201
  };
240
- if (asChild) {
241
- const rendered = renderAsChild({
242
- children,
243
- props: {
244
- minCharCount: choice?.minCharCount,
245
- maxCharCount: choice?.maxCharCount,
246
- defaultAddedPrice: choice?.addedPrice || undefined,
247
- title: choice?.name || undefined,
248
- onChange: handleChange,
249
- },
250
- ref,
251
- content: null,
252
- attributes,
253
- });
254
- if (rendered)
255
- return rendered;
256
- }
257
- return (_jsx("textarea", { ref: ref, className: className, placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, ...attributes, onChange: handleChange }));
202
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.choiceFreetext, "data-selected": isSelected ? 'true' : 'false', customElement: children, customElementProps: {
203
+ minCharCount: choice?.minCharCount,
204
+ maxCharCount: choice?.maxCharCount,
205
+ defaultAddedPrice: choice?.addedPrice || undefined,
206
+ title: choice?.name || undefined,
207
+ onChange: handleChange,
208
+ }, children: _jsx("textarea", { placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, onChange: handleChange }) }));
258
209
  } }));
259
210
  });
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type AsChildProps } from '../utils/index.js';
2
+ import { AsChildChildren } from '@wix/headless-utils/react';
3
3
  export interface Option {
4
4
  name: string;
5
5
  choices?: any[];
@@ -10,11 +10,17 @@ export interface Option {
10
10
  /**
11
11
  * Root props with asChild support
12
12
  */
13
- export interface RootProps extends AsChildProps<{
14
- option: Option;
15
- onValueChange?: (value: string) => void;
16
- allowedTypes?: ('color' | 'text' | 'free-text')[];
17
- }> {
13
+ export interface RootProps {
14
+ /** Whether to render as a child component */
15
+ asChild?: boolean;
16
+ /** Custom render function when using asChild */
17
+ children?: AsChildChildren<{
18
+ option: Option;
19
+ onValueChange?: (value: string) => void;
20
+ allowedTypes?: ('color' | 'text' | 'free-text')[];
21
+ }>;
22
+ /** CSS classes to apply to the default element */
23
+ className?: string;
18
24
  option: Option;
19
25
  onValueChange?: (value: string) => void;
20
26
  allowedTypes?: ('color' | 'text' | 'free-text')[];
@@ -105,9 +111,15 @@ export declare const OptionContext: React.Context<any>;
105
111
  /**
106
112
  * Props for Option Name component
107
113
  */
108
- export interface NameProps extends AsChildProps<{
109
- name: string;
110
- }> {
114
+ export interface NameProps {
115
+ /** Whether to render as a child component */
116
+ asChild?: boolean;
117
+ /** Custom render function when using asChild */
118
+ children?: AsChildChildren<{
119
+ name: string;
120
+ }>;
121
+ /** CSS classes to apply to the default element */
122
+ className?: string;
111
123
  }
112
124
  /**
113
125
  * Displays the option name.
@@ -136,9 +148,15 @@ export declare const Name: React.ForwardRefExoticComponent<NameProps & React.Ref
136
148
  /**
137
149
  * Props for Option MandatoryIndicator component
138
150
  */
139
- export interface MandatoryIndicatorProps extends AsChildProps<{
140
- mandatory: boolean;
141
- }> {
151
+ export interface MandatoryIndicatorProps {
152
+ /** Whether to render as a child component */
153
+ asChild?: boolean;
154
+ /** Custom render function when using asChild */
155
+ children?: AsChildChildren<{
156
+ mandatory: boolean;
157
+ }>;
158
+ /** CSS classes to apply to the default element */
159
+ className?: string;
142
160
  }
143
161
  /**
144
162
  * Displays the mandatory indicator (asterisk) when the option is required.
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { renderAsChild } from '../utils/index.js';
4
3
  import * as Choice from './Choice.js';
5
4
  import * as ProductModifiersPrimitive from './core/ProductModifiers.js';
6
5
  import * as ProductVariantSelectorPrimitive from './core/ProductVariantSelector.js';
6
+ import { AsChildSlot } from '@wix/headless-utils/react';
7
7
  var TestIds;
8
8
  (function (TestIds) {
9
9
  TestIds["optionRoot"] = "option-root";
@@ -93,7 +93,7 @@ var TestIds;
93
93
  * ```
94
94
  */
95
95
  export const Root = React.forwardRef((props, ref) => {
96
- const { asChild, children, option, onValueChange, allowedTypes } = props;
96
+ const { asChild, children, option, onValueChange, allowedTypes, className } = props;
97
97
  // Determine the option type based on the option name and available choices
98
98
  const getOptionType = () => {
99
99
  if (option.type === 'FREE_TEXT') {
@@ -113,23 +113,7 @@ export const Root = React.forwardRef((props, ref) => {
113
113
  allowedTypes,
114
114
  mandatory: option?.mandatory || false,
115
115
  };
116
- const attributes = {
117
- 'data-testid': TestIds.optionRoot,
118
- 'data-type': optionType,
119
- };
120
- const content = (_jsx(OptionContext.Provider, { value: contextValue, children: typeof children === 'function' ? null : children }));
121
- if (asChild) {
122
- const rendered = renderAsChild({
123
- children,
124
- props: { option, onValueChange, allowedTypes },
125
- ref,
126
- content,
127
- attributes,
128
- });
129
- if (rendered)
130
- return rendered;
131
- }
132
- return (_jsx("div", { ...attributes, ref: ref, children: content }));
116
+ return (_jsx(OptionContext.Provider, { value: contextValue, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionRoot, "data-type": optionType, customElement: children, customElementProps: { option, onValueChange, allowedTypes }, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
133
117
  });
134
118
  // Create a context to pass option data down
135
119
  export const OptionContext = React.createContext(null);
@@ -162,21 +146,7 @@ export const Name = React.forwardRef((props, ref) => {
162
146
  if (!optionData)
163
147
  return null;
164
148
  const name = optionData.name || '';
165
- const attributes = {
166
- 'data-testid': TestIds.optionName,
167
- };
168
- if (asChild) {
169
- const rendered = renderAsChild({
170
- children,
171
- props: { name },
172
- ref,
173
- content: name,
174
- attributes,
175
- });
176
- if (rendered)
177
- return rendered;
178
- }
179
- return (_jsx("div", { className: className, ...attributes, ref: ref, children: name }));
149
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionName, customElement: children, customElementProps: { name }, content: name, children: _jsx("div", { children: name }) }));
180
150
  });
181
151
  /**
182
152
  * Displays the mandatory indicator (asterisk) when the option is required.
@@ -205,21 +175,7 @@ export const MandatoryIndicator = React.forwardRef((props, ref) => {
205
175
  // Don't render anything if not mandatory
206
176
  if (!mandatory)
207
177
  return null;
208
- const attributes = {
209
- 'data-testid': TestIds.optionMandatoryIndicator,
210
- };
211
- if (asChild) {
212
- const rendered = renderAsChild({
213
- children,
214
- props: { mandatory },
215
- ref,
216
- content: '*',
217
- attributes,
218
- });
219
- if (rendered)
220
- return rendered;
221
- }
222
- return (_jsx("span", { className: className, ...attributes, ref: ref, children: "*" }));
178
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionMandatoryIndicator, customElement: children, customElementProps: { mandatory }, content: '*', children: _jsx("span", { children: "*" }) }));
223
179
  });
224
180
  /**
225
181
  * Container for the list items with empty state support.
@@ -289,9 +289,9 @@ export interface RibbonProps {
289
289
  /** Whether to render as a child component */
290
290
  asChild?: boolean;
291
291
  /** Custom render function when using asChild */
292
- children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
292
+ children?: AsChildChildren<{
293
293
  ribbon: string | null;
294
- }> | React.ForwardRefExoticComponent<any>;
294
+ }>;
295
295
  /** CSS classes to apply to the default element */
296
296
  className?: string;
297
297
  }
@@ -327,10 +327,10 @@ export interface StockProps {
327
327
  /** Whether to render as a child component */
328
328
  asChild?: boolean;
329
329
  /** Custom render function when using asChild */
330
- children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
330
+ children?: AsChildChildren<{
331
331
  status: 'in-stock' | 'limited-stock' | 'out-of-stock';
332
332
  label: string;
333
- }> | React.ForwardRefExoticComponent<any>;
333
+ }>;
334
334
  /** CSS classes to apply to the default element */
335
335
  className?: string;
336
336
  /** Custom labels for different stock states */
@@ -52,6 +52,10 @@ function buildSearchFilterData(availableOptions, availableInventoryStatuses, ava
52
52
  ? name.toLowerCase()
53
53
  : name;
54
54
  },
55
+ valueBgColorFormatter: (value) => {
56
+ const choice = option.choices.find((c) => c.id === value);
57
+ return choice?.colorCode || null;
58
+ },
55
59
  })),
56
60
  // Inventory status - use actual search field name
57
61
  {
@@ -323,15 +323,7 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
323
323
  }
324
324
  try {
325
325
  isLoadingSignal.set(true);
326
- const affectiveSearchOptions = searchOptions.cursorPaging?.cursor
327
- ? {
328
- cursorPaging: {
329
- cursor: searchOptions.cursorPaging.cursor,
330
- limit: searchOptions.cursorPaging.limit,
331
- },
332
- }
333
- : searchOptions;
334
- const result = await fetchProducts(affectiveSearchOptions);
326
+ const result = await fetchProducts(searchOptions);
335
327
  productsSignal.set(result.products ?? []);
336
328
  pagingMetadataSignal.set(result.pagingMetadata);
337
329
  }
@@ -344,6 +336,29 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
344
336
  });
345
337
  }
346
338
  firstRun = false;
339
+ const loadMoreCursor = async (count) => {
340
+ const affectiveSearchOptions = {
341
+ cursorPaging: {
342
+ cursor: pagingMetadataSignal.get().cursors?.next,
343
+ limit: DEFAULT_QUERY_LIMIT || count,
344
+ },
345
+ };
346
+ try {
347
+ isLoadingSignal.set(true);
348
+ const result = await fetchProducts(affectiveSearchOptions);
349
+ productsSignal.set([
350
+ ...productsSignal.get(),
351
+ ...(result.products ?? []),
352
+ ]);
353
+ pagingMetadataSignal.set(result.pagingMetadata);
354
+ }
355
+ catch (error) {
356
+ errorSignal.set(error instanceof Error ? error.message : 'Unknown error');
357
+ }
358
+ finally {
359
+ isLoadingSignal.set(false);
360
+ }
361
+ };
347
362
  return {
348
363
  products: productsSignal,
349
364
  searchOptions: searchOptionsSignal,
@@ -391,14 +406,7 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
391
406
  isLoading: isLoadingSignal,
392
407
  error: errorSignal,
393
408
  loadMore: (count) => {
394
- const currentOptions = searchOptionsSignal.peek();
395
- searchOptionsSignal.set({
396
- ...currentOptions,
397
- cursorPaging: {
398
- cursor: pagingMetadataSignal.get().cursors?.next,
399
- limit: currentOptions.cursorPaging?.limit ?? 0 + count,
400
- },
401
- });
409
+ loadMoreCursor(count);
402
410
  },
403
411
  hasMoreProducts: signalsService.computed(() => pagingMetadataSignal.get().hasNext ?? false),
404
412
  };
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type AsChildProps } from '../utils/index.js';
2
+ import { AsChildChildren } from '@wix/headless-utils/react';
3
3
  /**
4
4
  * Choice data interface
5
5
  */
@@ -67,10 +67,16 @@ export declare const Root: React.ForwardRefExoticComponent<RootProps & React.Ref
67
67
  /**
68
68
  * Props for Choice Text component
69
69
  */
70
- export interface TextProps extends AsChildProps<{
71
- id: string;
72
- value: string;
73
- }> {
70
+ export interface TextProps {
71
+ /** Whether to render as a child component */
72
+ asChild?: boolean;
73
+ /** Custom render function when using asChild */
74
+ children?: AsChildChildren<{
75
+ id: string;
76
+ value: string;
77
+ }>;
78
+ /** CSS classes to apply to the default element */
79
+ className?: string;
74
80
  }
75
81
  /**
76
82
  * Text-based choice button.
@@ -105,11 +111,17 @@ export declare const Text: React.ForwardRefExoticComponent<TextProps & React.Ref
105
111
  /**
106
112
  * Props for Choice Color component
107
113
  */
108
- export interface ColorProps extends AsChildProps<{
109
- colorCode: string;
110
- name: string;
111
- id: string;
112
- }> {
114
+ export interface ColorProps {
115
+ /** Whether to render as a child component */
116
+ asChild?: boolean;
117
+ /** Custom render function when using asChild */
118
+ children?: AsChildChildren<{
119
+ colorCode: string;
120
+ name: string;
121
+ id: string;
122
+ }>;
123
+ /** CSS classes to apply to the default element */
124
+ className?: string;
113
125
  }
114
126
  /**
115
127
  * Color swatch choice.
@@ -148,14 +160,20 @@ export declare const Color: React.ForwardRefExoticComponent<ColorProps & React.R
148
160
  /**
149
161
  * Props for Choice FreeText component
150
162
  */
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'> {
163
+ export interface FreeTextProps extends Omit<React.TextareaHTMLAttributes<HTMLTextAreaElement>, 'children'> {
164
+ /** Whether to render as a child component */
165
+ asChild?: boolean;
166
+ /** Custom render function when using asChild */
167
+ children?: AsChildChildren<{
168
+ minCharCount?: number;
169
+ maxCharCount?: number;
170
+ defaultAddedPrice?: string | null;
171
+ title?: string;
172
+ value?: string;
173
+ onChange?: (e: React.ChangeEvent<HTMLTextAreaElement>) => void;
174
+ }>;
175
+ /** CSS classes to apply to the default element */
176
+ className?: string;
159
177
  }
160
178
  /**
161
179
  * Provides a free text input for variant selection.
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { renderAsChild } from '../utils/index.js';
4
3
  import { FreeText as FreeTextPrimitive } from './core/ProductModifiers.js';
4
+ import { AsChildSlot } from '@wix/headless-utils/react';
5
5
  var TestIds;
6
6
  (function (TestIds) {
7
7
  TestIds["choiceRoot"] = "choice-root";
@@ -91,24 +91,7 @@ export const Text = React.forwardRef((props, ref) => {
91
91
  if (!isVisible)
92
92
  return null;
93
93
  const choiceId = choice?.choiceId || '';
94
- const attributes = {
95
- 'data-testid': TestIds.choiceText,
96
- 'data-selected': isSelected ? 'true' : 'false',
97
- disabled: !isInStock && !isPreOrderEnabled,
98
- onClick: select,
99
- };
100
- if (asChild) {
101
- const rendered = renderAsChild({
102
- children,
103
- props: { id: choiceId, value },
104
- ref,
105
- content: value,
106
- attributes,
107
- });
108
- if (rendered)
109
- return rendered;
110
- }
111
- return (_jsx("button", { className: className, ...attributes, ref: ref, children: value }));
94
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.choiceText, "data-selected": isSelected ? 'true' : 'false', disabled: !isInStock && !isPreOrderEnabled, onClick: select, customElement: children, customElementProps: { id: choiceId, value }, content: value, children: _jsx("button", { children: value }) }));
112
95
  });
113
96
  /**
114
97
  * Color swatch choice.
@@ -157,28 +140,11 @@ export const Color = React.forwardRef((props, ref) => {
157
140
  if (!isVisible)
158
141
  return null;
159
142
  const { colorCode, choiceId } = choice;
160
- const attributes = {
161
- 'data-testid': TestIds.choiceColor,
162
- 'data-selected': isSelected ? 'true' : 'false',
163
- disabled: !isInStock && !isPreOrderEnabled,
164
- onClick: select,
165
- };
166
- if (asChild) {
167
- const rendered = renderAsChild({
168
- children,
169
- props: {
170
- colorCode: colorCode || '',
171
- name: value,
172
- id: choiceId || '',
173
- },
174
- ref,
175
- content: null,
176
- attributes,
177
- });
178
- if (rendered)
179
- return rendered;
180
- }
181
- return (_jsx("button", { className: className, ...attributes, ref: ref, style: { backgroundColor: colorCode }, title: value }));
143
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.choiceColor, "data-selected": isSelected ? 'true' : 'false', disabled: !isInStock && !isPreOrderEnabled, onClick: select, customElement: children, customElementProps: {
144
+ colorCode: colorCode || '',
145
+ name: value,
146
+ id: choiceId || '',
147
+ }, children: _jsx("button", { style: { backgroundColor: colorCode }, title: value }) }));
182
148
  });
183
149
  /**
184
150
  * Provides a free text input for variant selection.
@@ -226,10 +192,6 @@ export const FreeText = React.forwardRef((props, ref) => {
226
192
  // Don't render if not visible (handled by ProductVariantSelector in Root)
227
193
  if (!isVisible)
228
194
  return null;
229
- const attributes = {
230
- 'data-testid': TestIds.choiceFreetext,
231
- 'data-selected': isSelected ? 'true' : 'false',
232
- };
233
195
  return (_jsx(FreeTextPrimitive, { modifier: choice, children: ({ value, setText, placeholder, maxChars }) => {
234
196
  const handleChange = (e) => {
235
197
  setText(e.target.value);
@@ -237,23 +199,12 @@ export const FreeText = React.forwardRef((props, ref) => {
237
199
  onValueChange(e.target.value);
238
200
  }
239
201
  };
240
- if (asChild) {
241
- const rendered = renderAsChild({
242
- children,
243
- props: {
244
- minCharCount: choice?.minCharCount,
245
- maxCharCount: choice?.maxCharCount,
246
- defaultAddedPrice: choice?.addedPrice || undefined,
247
- title: choice?.name || undefined,
248
- onChange: handleChange,
249
- },
250
- ref,
251
- content: null,
252
- attributes,
253
- });
254
- if (rendered)
255
- return rendered;
256
- }
257
- return (_jsx("textarea", { ref: ref, className: className, placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, ...attributes, onChange: handleChange }));
202
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.choiceFreetext, "data-selected": isSelected ? 'true' : 'false', customElement: children, customElementProps: {
203
+ minCharCount: choice?.minCharCount,
204
+ maxCharCount: choice?.maxCharCount,
205
+ defaultAddedPrice: choice?.addedPrice || undefined,
206
+ title: choice?.name || undefined,
207
+ onChange: handleChange,
208
+ }, children: _jsx("textarea", { placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, onChange: handleChange }) }));
258
209
  } }));
259
210
  });
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- import { type AsChildProps } from '../utils/index.js';
2
+ import { AsChildChildren } from '@wix/headless-utils/react';
3
3
  export interface Option {
4
4
  name: string;
5
5
  choices?: any[];
@@ -10,11 +10,17 @@ export interface Option {
10
10
  /**
11
11
  * Root props with asChild support
12
12
  */
13
- export interface RootProps extends AsChildProps<{
14
- option: Option;
15
- onValueChange?: (value: string) => void;
16
- allowedTypes?: ('color' | 'text' | 'free-text')[];
17
- }> {
13
+ export interface RootProps {
14
+ /** Whether to render as a child component */
15
+ asChild?: boolean;
16
+ /** Custom render function when using asChild */
17
+ children?: AsChildChildren<{
18
+ option: Option;
19
+ onValueChange?: (value: string) => void;
20
+ allowedTypes?: ('color' | 'text' | 'free-text')[];
21
+ }>;
22
+ /** CSS classes to apply to the default element */
23
+ className?: string;
18
24
  option: Option;
19
25
  onValueChange?: (value: string) => void;
20
26
  allowedTypes?: ('color' | 'text' | 'free-text')[];
@@ -105,9 +111,15 @@ export declare const OptionContext: React.Context<any>;
105
111
  /**
106
112
  * Props for Option Name component
107
113
  */
108
- export interface NameProps extends AsChildProps<{
109
- name: string;
110
- }> {
114
+ export interface NameProps {
115
+ /** Whether to render as a child component */
116
+ asChild?: boolean;
117
+ /** Custom render function when using asChild */
118
+ children?: AsChildChildren<{
119
+ name: string;
120
+ }>;
121
+ /** CSS classes to apply to the default element */
122
+ className?: string;
111
123
  }
112
124
  /**
113
125
  * Displays the option name.
@@ -136,9 +148,15 @@ export declare const Name: React.ForwardRefExoticComponent<NameProps & React.Ref
136
148
  /**
137
149
  * Props for Option MandatoryIndicator component
138
150
  */
139
- export interface MandatoryIndicatorProps extends AsChildProps<{
140
- mandatory: boolean;
141
- }> {
151
+ export interface MandatoryIndicatorProps {
152
+ /** Whether to render as a child component */
153
+ asChild?: boolean;
154
+ /** Custom render function when using asChild */
155
+ children?: AsChildChildren<{
156
+ mandatory: boolean;
157
+ }>;
158
+ /** CSS classes to apply to the default element */
159
+ className?: string;
142
160
  }
143
161
  /**
144
162
  * Displays the mandatory indicator (asterisk) when the option is required.
@@ -1,9 +1,9 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import React from 'react';
3
- import { renderAsChild } from '../utils/index.js';
4
3
  import * as Choice from './Choice.js';
5
4
  import * as ProductModifiersPrimitive from './core/ProductModifiers.js';
6
5
  import * as ProductVariantSelectorPrimitive from './core/ProductVariantSelector.js';
6
+ import { AsChildSlot } from '@wix/headless-utils/react';
7
7
  var TestIds;
8
8
  (function (TestIds) {
9
9
  TestIds["optionRoot"] = "option-root";
@@ -93,7 +93,7 @@ var TestIds;
93
93
  * ```
94
94
  */
95
95
  export const Root = React.forwardRef((props, ref) => {
96
- const { asChild, children, option, onValueChange, allowedTypes } = props;
96
+ const { asChild, children, option, onValueChange, allowedTypes, className } = props;
97
97
  // Determine the option type based on the option name and available choices
98
98
  const getOptionType = () => {
99
99
  if (option.type === 'FREE_TEXT') {
@@ -113,23 +113,7 @@ export const Root = React.forwardRef((props, ref) => {
113
113
  allowedTypes,
114
114
  mandatory: option?.mandatory || false,
115
115
  };
116
- const attributes = {
117
- 'data-testid': TestIds.optionRoot,
118
- 'data-type': optionType,
119
- };
120
- const content = (_jsx(OptionContext.Provider, { value: contextValue, children: typeof children === 'function' ? null : children }));
121
- if (asChild) {
122
- const rendered = renderAsChild({
123
- children,
124
- props: { option, onValueChange, allowedTypes },
125
- ref,
126
- content,
127
- attributes,
128
- });
129
- if (rendered)
130
- return rendered;
131
- }
132
- return (_jsx("div", { ...attributes, ref: ref, children: content }));
116
+ return (_jsx(OptionContext.Provider, { value: contextValue, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionRoot, "data-type": optionType, customElement: children, customElementProps: { option, onValueChange, allowedTypes }, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
133
117
  });
134
118
  // Create a context to pass option data down
135
119
  export const OptionContext = React.createContext(null);
@@ -162,21 +146,7 @@ export const Name = React.forwardRef((props, ref) => {
162
146
  if (!optionData)
163
147
  return null;
164
148
  const name = optionData.name || '';
165
- const attributes = {
166
- 'data-testid': TestIds.optionName,
167
- };
168
- if (asChild) {
169
- const rendered = renderAsChild({
170
- children,
171
- props: { name },
172
- ref,
173
- content: name,
174
- attributes,
175
- });
176
- if (rendered)
177
- return rendered;
178
- }
179
- return (_jsx("div", { className: className, ...attributes, ref: ref, children: name }));
149
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionName, customElement: children, customElementProps: { name }, content: name, children: _jsx("div", { children: name }) }));
180
150
  });
181
151
  /**
182
152
  * Displays the mandatory indicator (asterisk) when the option is required.
@@ -205,21 +175,7 @@ export const MandatoryIndicator = React.forwardRef((props, ref) => {
205
175
  // Don't render anything if not mandatory
206
176
  if (!mandatory)
207
177
  return null;
208
- const attributes = {
209
- 'data-testid': TestIds.optionMandatoryIndicator,
210
- };
211
- if (asChild) {
212
- const rendered = renderAsChild({
213
- children,
214
- props: { mandatory },
215
- ref,
216
- content: '*',
217
- attributes,
218
- });
219
- if (rendered)
220
- return rendered;
221
- }
222
- return (_jsx("span", { className: className, ...attributes, ref: ref, children: "*" }));
178
+ return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionMandatoryIndicator, customElement: children, customElementProps: { mandatory }, content: '*', children: _jsx("span", { children: "*" }) }));
223
179
  });
224
180
  /**
225
181
  * Container for the list items with empty state support.
@@ -289,9 +289,9 @@ export interface RibbonProps {
289
289
  /** Whether to render as a child component */
290
290
  asChild?: boolean;
291
291
  /** Custom render function when using asChild */
292
- children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
292
+ children?: AsChildChildren<{
293
293
  ribbon: string | null;
294
- }> | React.ForwardRefExoticComponent<any>;
294
+ }>;
295
295
  /** CSS classes to apply to the default element */
296
296
  className?: string;
297
297
  }
@@ -327,10 +327,10 @@ export interface StockProps {
327
327
  /** Whether to render as a child component */
328
328
  asChild?: boolean;
329
329
  /** Custom render function when using asChild */
330
- children?: React.ReactNode | React.ForwardRefRenderFunction<HTMLElement, {
330
+ children?: AsChildChildren<{
331
331
  status: 'in-stock' | 'limited-stock' | 'out-of-stock';
332
332
  label: string;
333
- }> | React.ForwardRefExoticComponent<any>;
333
+ }>;
334
334
  /** CSS classes to apply to the default element */
335
335
  className?: string;
336
336
  /** Custom labels for different stock states */
@@ -52,6 +52,10 @@ function buildSearchFilterData(availableOptions, availableInventoryStatuses, ava
52
52
  ? name.toLowerCase()
53
53
  : name;
54
54
  },
55
+ valueBgColorFormatter: (value) => {
56
+ const choice = option.choices.find((c) => c.id === value);
57
+ return choice?.colorCode || null;
58
+ },
55
59
  })),
56
60
  // Inventory status - use actual search field name
57
61
  {
@@ -323,15 +323,7 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
323
323
  }
324
324
  try {
325
325
  isLoadingSignal.set(true);
326
- const affectiveSearchOptions = searchOptions.cursorPaging?.cursor
327
- ? {
328
- cursorPaging: {
329
- cursor: searchOptions.cursorPaging.cursor,
330
- limit: searchOptions.cursorPaging.limit,
331
- },
332
- }
333
- : searchOptions;
334
- const result = await fetchProducts(affectiveSearchOptions);
326
+ const result = await fetchProducts(searchOptions);
335
327
  productsSignal.set(result.products ?? []);
336
328
  pagingMetadataSignal.set(result.pagingMetadata);
337
329
  }
@@ -344,6 +336,29 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
344
336
  });
345
337
  }
346
338
  firstRun = false;
339
+ const loadMoreCursor = async (count) => {
340
+ const affectiveSearchOptions = {
341
+ cursorPaging: {
342
+ cursor: pagingMetadataSignal.get().cursors?.next,
343
+ limit: DEFAULT_QUERY_LIMIT || count,
344
+ },
345
+ };
346
+ try {
347
+ isLoadingSignal.set(true);
348
+ const result = await fetchProducts(affectiveSearchOptions);
349
+ productsSignal.set([
350
+ ...productsSignal.get(),
351
+ ...(result.products ?? []),
352
+ ]);
353
+ pagingMetadataSignal.set(result.pagingMetadata);
354
+ }
355
+ catch (error) {
356
+ errorSignal.set(error instanceof Error ? error.message : 'Unknown error');
357
+ }
358
+ finally {
359
+ isLoadingSignal.set(false);
360
+ }
361
+ };
347
362
  return {
348
363
  products: productsSignal,
349
364
  searchOptions: searchOptionsSignal,
@@ -391,14 +406,7 @@ export const ProductListService = implementService.withConfig()(ProductsListServ
391
406
  isLoading: isLoadingSignal,
392
407
  error: errorSignal,
393
408
  loadMore: (count) => {
394
- const currentOptions = searchOptionsSignal.peek();
395
- searchOptionsSignal.set({
396
- ...currentOptions,
397
- cursorPaging: {
398
- cursor: pagingMetadataSignal.get().cursors?.next,
399
- limit: currentOptions.cursorPaging?.limit ?? 0 + count,
400
- },
401
- });
409
+ loadMoreCursor(count);
402
410
  },
403
411
  hasMoreProducts: signalsService.computed(() => pagingMetadataSignal.get().hasNext ?? false),
404
412
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wix/headless-stores",
3
- "version": "0.0.62",
3
+ "version": "0.0.64",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
@@ -62,10 +62,10 @@
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.3",
66
- "@wix/headless-ecom": "0.0.17",
67
- "@wix/headless-media": "^0.0.11",
68
- "@wix/headless-utils": "^0.0.2",
65
+ "@wix/headless-components": "workspace:*",
66
+ "@wix/headless-ecom": "workspace:*",
67
+ "@wix/headless-media": "workspace:*",
68
+ "@wix/headless-utils": "workspace:*",
69
69
  "@wix/redirects": "^1.0.83",
70
70
  "@wix/services-definitions": "^0.1.4",
71
71
  "@wix/services-manager-react": "^0.1.26"