@wix/headless-stores 0.0.86 → 0.0.88
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.js +2 -2
- package/cjs/dist/react/Choice.js +6 -6
- package/cjs/dist/react/Option.js +4 -4
- package/cjs/dist/react/Product.js +12 -12
- package/cjs/dist/react/ProductList.js +8 -8
- package/cjs/dist/utils/index.d.ts +0 -1
- package/cjs/dist/utils/index.js +0 -1
- package/dist/react/Category.js +2 -2
- package/dist/react/Choice.js +6 -6
- package/dist/react/Option.js +4 -4
- package/dist/react/Product.js +12 -12
- package/dist/react/ProductList.js +8 -8
- package/dist/utils/index.d.ts +0 -1
- package/dist/utils/index.js +0 -1
- package/package.json +6 -4
- package/cjs/dist/utils/renderAsChild.d.ts +0 -96
- package/cjs/dist/utils/renderAsChild.js +0 -66
- package/cjs/dist/utils/renderChildren.d.ts +0 -42
- package/cjs/dist/utils/renderChildren.js +0 -47
- package/dist/utils/renderAsChild.d.ts +0 -96
- package/dist/utils/renderAsChild.js +0 -66
- package/dist/utils/renderChildren.d.ts +0 -42
- package/dist/utils/renderChildren.js +0 -47
|
@@ -81,7 +81,7 @@ export function Root(props) {
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
export const Trigger = React.forwardRef((props, ref) => {
|
|
84
|
-
const { asChild, children, onSelect, className } = props;
|
|
84
|
+
const { asChild, children, onSelect, className, ...otherProps } = props;
|
|
85
85
|
const { category, isSelected, setSelectedCategory } = useCategoryContext();
|
|
86
86
|
const handleSelect = () => {
|
|
87
87
|
// Use CategoryFilter's setSelectedCategory function
|
|
@@ -101,7 +101,7 @@ export const Trigger = React.forwardRef((props, ref) => {
|
|
|
101
101
|
category,
|
|
102
102
|
isSelected,
|
|
103
103
|
onSelect: handleSelect,
|
|
104
|
-
}, content: category.name, children: _jsx("button", { children: category.name }) }));
|
|
104
|
+
}, content: category.name, ...otherProps, children: _jsx("button", { children: category.name }) }));
|
|
105
105
|
});
|
|
106
106
|
/**
|
|
107
107
|
* Displays the category name or label.
|
package/cjs/dist/react/Choice.js
CHANGED
|
@@ -78,7 +78,7 @@ export const Root = React.forwardRef((props, ref) => {
|
|
|
78
78
|
* - `disabled` - Is Choice disabled (not in stock)
|
|
79
79
|
*/
|
|
80
80
|
export const Text = React.forwardRef((props, ref) => {
|
|
81
|
-
const { asChild, children, className } = props;
|
|
81
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
82
82
|
const choiceContext = React.useContext(ChoiceContext);
|
|
83
83
|
if (!choiceContext) {
|
|
84
84
|
return null; // Should be used within Option.ChoiceRepeater
|
|
@@ -91,7 +91,7 @@ export const Text = React.forwardRef((props, ref) => {
|
|
|
91
91
|
if (!isVisible)
|
|
92
92
|
return null;
|
|
93
93
|
const choiceId = choice?.choiceId || '';
|
|
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 }) }));
|
|
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, ...otherProps, children: _jsx("button", { children: value }) }));
|
|
95
95
|
});
|
|
96
96
|
/**
|
|
97
97
|
* Color swatch choice.
|
|
@@ -127,7 +127,7 @@ export const Text = React.forwardRef((props, ref) => {
|
|
|
127
127
|
* - `disabled` - Is Choice disabled (not in stock)
|
|
128
128
|
*/
|
|
129
129
|
export const Color = React.forwardRef((props, ref) => {
|
|
130
|
-
const { asChild, children, className } = props;
|
|
130
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
131
131
|
const choiceContext = React.useContext(ChoiceContext);
|
|
132
132
|
if (!choiceContext) {
|
|
133
133
|
return null; // Should be used within Option.ChoiceRepeater
|
|
@@ -144,7 +144,7 @@ export const Color = React.forwardRef((props, ref) => {
|
|
|
144
144
|
colorCode: colorCode || '',
|
|
145
145
|
name: value,
|
|
146
146
|
id: choiceId || '',
|
|
147
|
-
}, children: _jsx("button", { style: { backgroundColor: colorCode }, title: value }) }));
|
|
147
|
+
}, ...otherProps, children: _jsx("button", { style: { backgroundColor: colorCode }, title: value }) }));
|
|
148
148
|
});
|
|
149
149
|
/**
|
|
150
150
|
* Provides a free text input for variant selection.
|
|
@@ -180,7 +180,7 @@ export const Color = React.forwardRef((props, ref) => {
|
|
|
180
180
|
* - `data-selected` - Is Choice selected
|
|
181
181
|
*/
|
|
182
182
|
export const FreeText = React.forwardRef((props, ref) => {
|
|
183
|
-
const { asChild, children, className } = props;
|
|
183
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
184
184
|
const choiceContext = React.useContext(ChoiceContext);
|
|
185
185
|
if (!choiceContext) {
|
|
186
186
|
return null; // Should be used within Option.ChoiceRepeater
|
|
@@ -205,6 +205,6 @@ export const FreeText = React.forwardRef((props, ref) => {
|
|
|
205
205
|
defaultAddedPrice: choice?.addedPrice || undefined,
|
|
206
206
|
title: choice?.name || undefined,
|
|
207
207
|
onChange: handleChange,
|
|
208
|
-
}, children: _jsx("textarea", { placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, onChange: handleChange }) }));
|
|
208
|
+
}, ...otherProps, children: _jsx("textarea", { placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, onChange: handleChange }) }));
|
|
209
209
|
} }));
|
|
210
210
|
});
|
package/cjs/dist/react/Option.js
CHANGED
|
@@ -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, className } = props;
|
|
96
|
+
const { asChild, children, option, onValueChange, allowedTypes, className, ...otherProps } = 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,7 +113,7 @@ export const Root = React.forwardRef((props, ref) => {
|
|
|
113
113
|
allowedTypes,
|
|
114
114
|
mandatory: option?.mandatory || false,
|
|
115
115
|
};
|
|
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 }) }) }));
|
|
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 }, ...otherProps, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
|
|
117
117
|
});
|
|
118
118
|
// Create a context to pass option data down
|
|
119
119
|
export const OptionContext = React.createContext(null);
|
|
@@ -141,12 +141,12 @@ export const OptionContext = React.createContext(null);
|
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
143
|
export const Name = React.forwardRef((props, ref) => {
|
|
144
|
-
const { asChild, children, className } = props;
|
|
144
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
145
145
|
const optionData = React.useContext(OptionContext);
|
|
146
146
|
if (!optionData)
|
|
147
147
|
return null;
|
|
148
148
|
const name = optionData.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 }) }));
|
|
149
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionName, customElement: children, customElementProps: { name }, content: name, ...otherProps, children: _jsx("div", { children: name }) }));
|
|
150
150
|
});
|
|
151
151
|
/**
|
|
152
152
|
* Displays the mandatory indicator (asterisk) when the option is required.
|
|
@@ -117,9 +117,9 @@ export function Root(props) {
|
|
|
117
117
|
* ```
|
|
118
118
|
*/
|
|
119
119
|
export const Name = React.forwardRef((props, ref) => {
|
|
120
|
-
const { asChild, children, className } = props;
|
|
120
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
121
121
|
return (_jsx(CoreProduct.Name, { children: ({ name }) => {
|
|
122
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productName, customElement: children, customElementProps: { name }, content: name, children: _jsx("div", { children: name }) }));
|
|
122
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productName, customElement: children, customElementProps: { name }, content: name, ...otherProps, children: _jsx("div", { children: name }) }));
|
|
123
123
|
} }));
|
|
124
124
|
});
|
|
125
125
|
/**
|
|
@@ -146,7 +146,7 @@ export const Name = React.forwardRef((props, ref) => {
|
|
|
146
146
|
* ```
|
|
147
147
|
*/
|
|
148
148
|
export const Description = React.forwardRef((props, ref) => {
|
|
149
|
-
const { asChild, children, className, as = AsContent.Plain } = props;
|
|
149
|
+
const { asChild, children, className, as = AsContent.Plain, ...otherProps } = props;
|
|
150
150
|
return (_jsx(CoreProduct.Description, { children: ({ description: richDescription, plainDescription }) => {
|
|
151
151
|
// Determine which description to use based on the 'as' prop
|
|
152
152
|
let description;
|
|
@@ -171,7 +171,7 @@ export const Description = React.forwardRef((props, ref) => {
|
|
|
171
171
|
return (_jsx("div", { ref: ref, className: className, "data-testid": TestIds.productDescription, dangerouslySetInnerHTML: { __html: description } }));
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productDescription, customElement: children, customElementProps: { description }, content: description, children: _jsx("div", { children: description }) }));
|
|
174
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productDescription, customElement: children, customElementProps: { description }, content: description, ...otherProps, children: _jsx("div", { children: description }) }));
|
|
175
175
|
} }));
|
|
176
176
|
});
|
|
177
177
|
/**
|
|
@@ -199,12 +199,12 @@ export const Description = React.forwardRef((props, ref) => {
|
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
201
|
export const Price = React.forwardRef((props, ref) => {
|
|
202
|
-
const { asChild, children, className } = props;
|
|
202
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
203
203
|
return (_jsx(SelectedVariant.Price, { children: ({ price, compareAtPrice }) => {
|
|
204
204
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productPrice, "data-discounted": compareAtPrice !== null, customElement: children, customElementProps: {
|
|
205
205
|
price,
|
|
206
206
|
formattedPrice: price,
|
|
207
|
-
}, content: price, children: _jsx("span", { children: price }) }));
|
|
207
|
+
}, content: price, ...otherProps, children: _jsx("span", { children: price }) }));
|
|
208
208
|
} }));
|
|
209
209
|
});
|
|
210
210
|
/**
|
|
@@ -236,7 +236,7 @@ export const Price = React.forwardRef((props, ref) => {
|
|
|
236
236
|
* ```
|
|
237
237
|
*/
|
|
238
238
|
export const CompareAtPrice = React.forwardRef((props, ref) => {
|
|
239
|
-
const { asChild, children, className } = props;
|
|
239
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
240
240
|
const testId = TestIds.productCompareAtPrice;
|
|
241
241
|
return (_jsx(SelectedVariant.Price, { children: ({ compareAtPrice }) => {
|
|
242
242
|
// Don't render anything if there's no compare-at price
|
|
@@ -246,7 +246,7 @@ export const CompareAtPrice = React.forwardRef((props, ref) => {
|
|
|
246
246
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, "data-discounted": compareAtPrice !== null, customElement: children, customElementProps: {
|
|
247
247
|
price: compareAtPrice,
|
|
248
248
|
formattedPrice: compareAtPrice,
|
|
249
|
-
}, content: compareAtPrice, children: _jsx("span", { children: compareAtPrice }) }));
|
|
249
|
+
}, content: compareAtPrice, ...otherProps, children: _jsx("span", { children: compareAtPrice }) }));
|
|
250
250
|
} }));
|
|
251
251
|
});
|
|
252
252
|
/**
|
|
@@ -272,10 +272,10 @@ export const CompareAtPrice = React.forwardRef((props, ref) => {
|
|
|
272
272
|
* ```
|
|
273
273
|
*/
|
|
274
274
|
export const Slug = React.forwardRef((props, ref) => {
|
|
275
|
-
const { asChild, children, className } = props;
|
|
275
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
276
276
|
const testId = TestIds.productSlug;
|
|
277
277
|
return (_jsx(CoreProduct.Slug, { children: ({ slug }) => {
|
|
278
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, customElement: children, customElementProps: { slug }, content: slug, children: _jsx("span", { children: slug }) }));
|
|
278
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, customElement: children, customElementProps: { slug }, content: slug, ...otherProps, children: _jsx("span", { children: slug }) }));
|
|
279
279
|
} }));
|
|
280
280
|
});
|
|
281
281
|
/**
|
|
@@ -298,13 +298,13 @@ export const Slug = React.forwardRef((props, ref) => {
|
|
|
298
298
|
* ```
|
|
299
299
|
*/
|
|
300
300
|
export const Raw = React.forwardRef((props, ref) => {
|
|
301
|
-
const { asChild, children, className } = props;
|
|
301
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
302
302
|
return (_jsx(CoreProduct.Content, { children: ({ product }) => {
|
|
303
303
|
// Raw component should not render anything by default when not using asChild
|
|
304
304
|
if (!asChild || !children) {
|
|
305
305
|
return null;
|
|
306
306
|
}
|
|
307
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productRaw, customElement: children, customElementProps: { product } }));
|
|
307
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productRaw, customElement: children, customElementProps: { product }, ...otherProps }));
|
|
308
308
|
} }));
|
|
309
309
|
});
|
|
310
310
|
/**
|
|
@@ -212,11 +212,11 @@ export const LoadMoreTrigger = React.forwardRef((props, ref) => {
|
|
|
212
212
|
* ```
|
|
213
213
|
*/
|
|
214
214
|
export const TotalsDisplayed = React.forwardRef((props, ref) => {
|
|
215
|
-
const { asChild, children, className } = props;
|
|
215
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
216
216
|
const productsListService = useService(ProductsListServiceDefinition);
|
|
217
217
|
const products = productsListService.products.get();
|
|
218
218
|
const displayedProducts = products.length;
|
|
219
|
-
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 }) }));
|
|
219
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListTotalsDisplayed, "data-displayed": displayedProducts, customElement: children, customElementProps: { displayedProducts }, content: displayedProducts, ...otherProps, children: _jsx("span", { children: displayedProducts }) }));
|
|
220
220
|
});
|
|
221
221
|
/**
|
|
222
222
|
* Sort component for product lists that provides sorting functionality.
|
|
@@ -302,8 +302,8 @@ export const Sort = React.forwardRef(({ children, className, as, asChild }, ref)
|
|
|
302
302
|
* ```
|
|
303
303
|
*/
|
|
304
304
|
const FilterRoot = React.forwardRef((props, ref) => {
|
|
305
|
-
const { asChild, children, className } = props;
|
|
306
|
-
return (_jsx(CoreProductListFilters.FilterRoot, { asChild: asChild, className: className, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListFilter, customElement: children, children: _jsx("div", { children: children }) }) }));
|
|
305
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
306
|
+
return (_jsx(CoreProductListFilters.FilterRoot, { asChild: asChild, className: className, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListFilter, customElement: children, ...otherProps, children: _jsx("div", { children: children }) }) }));
|
|
307
307
|
});
|
|
308
308
|
FilterRoot.displayName = 'ProductList.Filter';
|
|
309
309
|
export const Filter = {
|
|
@@ -340,7 +340,7 @@ export const Filter = {
|
|
|
340
340
|
* ```
|
|
341
341
|
*/
|
|
342
342
|
export const FilterResetTrigger = React.forwardRef((props, ref) => {
|
|
343
|
-
const { asChild, children, className } = props;
|
|
343
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
344
344
|
const label = props.label || 'Reset All Filters';
|
|
345
345
|
return (_jsx(CoreProductListFilters.ResetTrigger, { children: ({ resetFilters, isFiltered }) => {
|
|
346
346
|
if (!isFiltered) {
|
|
@@ -349,7 +349,7 @@ export const FilterResetTrigger = React.forwardRef((props, ref) => {
|
|
|
349
349
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, onClick: resetFilters, disabled: !isFiltered, "data-testid": TestIds.productListFilterResetTrigger, "data-filtered": isFiltered ? 'true' : 'false', customElement: children, customElementProps: {
|
|
350
350
|
resetFilters,
|
|
351
351
|
isFiltered,
|
|
352
|
-
}, content: label, children: _jsx("button", { disabled: !isFiltered, children: label }) }));
|
|
352
|
+
}, content: label, ...otherProps, children: _jsx("button", { disabled: !isFiltered, children: label }) }));
|
|
353
353
|
} }));
|
|
354
354
|
});
|
|
355
355
|
FilterResetTrigger.displayName = 'ProductList.FilterResetTrigger';
|
|
@@ -379,14 +379,14 @@ FilterResetTrigger.displayName = 'ProductList.FilterResetTrigger';
|
|
|
379
379
|
* ```
|
|
380
380
|
*/
|
|
381
381
|
export const Error = React.forwardRef((props, ref) => {
|
|
382
|
-
const { asChild, children, className } = props;
|
|
382
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
383
383
|
return (_jsx(CoreProductList.Error, { children: ({ error }) => {
|
|
384
384
|
if (!error) {
|
|
385
385
|
return null;
|
|
386
386
|
}
|
|
387
387
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListError, "data-error": error, customElement: children, customElementProps: {
|
|
388
388
|
error,
|
|
389
|
-
}, content: error, children: _jsx("div", { className: "text-status-error text-sm sm:text-base", children: error }) }));
|
|
389
|
+
}, content: error, ...otherProps, children: _jsx("div", { className: "text-status-error text-sm sm:text-base", children: error }) }));
|
|
390
390
|
} }));
|
|
391
391
|
});
|
|
392
392
|
Error.displayName = 'ProductList.Error';
|
package/cjs/dist/utils/index.js
CHANGED
package/dist/react/Category.js
CHANGED
|
@@ -81,7 +81,7 @@ export function Root(props) {
|
|
|
81
81
|
* ```
|
|
82
82
|
*/
|
|
83
83
|
export const Trigger = React.forwardRef((props, ref) => {
|
|
84
|
-
const { asChild, children, onSelect, className } = props;
|
|
84
|
+
const { asChild, children, onSelect, className, ...otherProps } = props;
|
|
85
85
|
const { category, isSelected, setSelectedCategory } = useCategoryContext();
|
|
86
86
|
const handleSelect = () => {
|
|
87
87
|
// Use CategoryFilter's setSelectedCategory function
|
|
@@ -101,7 +101,7 @@ export const Trigger = React.forwardRef((props, ref) => {
|
|
|
101
101
|
category,
|
|
102
102
|
isSelected,
|
|
103
103
|
onSelect: handleSelect,
|
|
104
|
-
}, content: category.name, children: _jsx("button", { children: category.name }) }));
|
|
104
|
+
}, content: category.name, ...otherProps, children: _jsx("button", { children: category.name }) }));
|
|
105
105
|
});
|
|
106
106
|
/**
|
|
107
107
|
* Displays the category name or label.
|
package/dist/react/Choice.js
CHANGED
|
@@ -78,7 +78,7 @@ export const Root = React.forwardRef((props, ref) => {
|
|
|
78
78
|
* - `disabled` - Is Choice disabled (not in stock)
|
|
79
79
|
*/
|
|
80
80
|
export const Text = React.forwardRef((props, ref) => {
|
|
81
|
-
const { asChild, children, className } = props;
|
|
81
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
82
82
|
const choiceContext = React.useContext(ChoiceContext);
|
|
83
83
|
if (!choiceContext) {
|
|
84
84
|
return null; // Should be used within Option.ChoiceRepeater
|
|
@@ -91,7 +91,7 @@ export const Text = React.forwardRef((props, ref) => {
|
|
|
91
91
|
if (!isVisible)
|
|
92
92
|
return null;
|
|
93
93
|
const choiceId = choice?.choiceId || '';
|
|
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 }) }));
|
|
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, ...otherProps, children: _jsx("button", { children: value }) }));
|
|
95
95
|
});
|
|
96
96
|
/**
|
|
97
97
|
* Color swatch choice.
|
|
@@ -127,7 +127,7 @@ export const Text = React.forwardRef((props, ref) => {
|
|
|
127
127
|
* - `disabled` - Is Choice disabled (not in stock)
|
|
128
128
|
*/
|
|
129
129
|
export const Color = React.forwardRef((props, ref) => {
|
|
130
|
-
const { asChild, children, className } = props;
|
|
130
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
131
131
|
const choiceContext = React.useContext(ChoiceContext);
|
|
132
132
|
if (!choiceContext) {
|
|
133
133
|
return null; // Should be used within Option.ChoiceRepeater
|
|
@@ -144,7 +144,7 @@ export const Color = React.forwardRef((props, ref) => {
|
|
|
144
144
|
colorCode: colorCode || '',
|
|
145
145
|
name: value,
|
|
146
146
|
id: choiceId || '',
|
|
147
|
-
}, children: _jsx("button", { style: { backgroundColor: colorCode }, title: value }) }));
|
|
147
|
+
}, ...otherProps, children: _jsx("button", { style: { backgroundColor: colorCode }, title: value }) }));
|
|
148
148
|
});
|
|
149
149
|
/**
|
|
150
150
|
* Provides a free text input for variant selection.
|
|
@@ -180,7 +180,7 @@ export const Color = React.forwardRef((props, ref) => {
|
|
|
180
180
|
* - `data-selected` - Is Choice selected
|
|
181
181
|
*/
|
|
182
182
|
export const FreeText = React.forwardRef((props, ref) => {
|
|
183
|
-
const { asChild, children, className } = props;
|
|
183
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
184
184
|
const choiceContext = React.useContext(ChoiceContext);
|
|
185
185
|
if (!choiceContext) {
|
|
186
186
|
return null; // Should be used within Option.ChoiceRepeater
|
|
@@ -205,6 +205,6 @@ export const FreeText = React.forwardRef((props, ref) => {
|
|
|
205
205
|
defaultAddedPrice: choice?.addedPrice || undefined,
|
|
206
206
|
title: choice?.name || undefined,
|
|
207
207
|
onChange: handleChange,
|
|
208
|
-
}, children: _jsx("textarea", { placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, onChange: handleChange }) }));
|
|
208
|
+
}, ...otherProps, children: _jsx("textarea", { placeholder: placeholder, rows: 3, value: value, maxLength: maxChars, onChange: handleChange }) }));
|
|
209
209
|
} }));
|
|
210
210
|
});
|
package/dist/react/Option.js
CHANGED
|
@@ -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, className } = props;
|
|
96
|
+
const { asChild, children, option, onValueChange, allowedTypes, className, ...otherProps } = 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,7 +113,7 @@ export const Root = React.forwardRef((props, ref) => {
|
|
|
113
113
|
allowedTypes,
|
|
114
114
|
mandatory: option?.mandatory || false,
|
|
115
115
|
};
|
|
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 }) }) }));
|
|
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 }, ...otherProps, children: _jsx("div", { children: React.isValidElement(children) ? children : null }) }) }));
|
|
117
117
|
});
|
|
118
118
|
// Create a context to pass option data down
|
|
119
119
|
export const OptionContext = React.createContext(null);
|
|
@@ -141,12 +141,12 @@ export const OptionContext = React.createContext(null);
|
|
|
141
141
|
* ```
|
|
142
142
|
*/
|
|
143
143
|
export const Name = React.forwardRef((props, ref) => {
|
|
144
|
-
const { asChild, children, className } = props;
|
|
144
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
145
145
|
const optionData = React.useContext(OptionContext);
|
|
146
146
|
if (!optionData)
|
|
147
147
|
return null;
|
|
148
148
|
const name = optionData.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 }) }));
|
|
149
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.optionName, customElement: children, customElementProps: { name }, content: name, ...otherProps, children: _jsx("div", { children: name }) }));
|
|
150
150
|
});
|
|
151
151
|
/**
|
|
152
152
|
* Displays the mandatory indicator (asterisk) when the option is required.
|
package/dist/react/Product.js
CHANGED
|
@@ -117,9 +117,9 @@ export function Root(props) {
|
|
|
117
117
|
* ```
|
|
118
118
|
*/
|
|
119
119
|
export const Name = React.forwardRef((props, ref) => {
|
|
120
|
-
const { asChild, children, className } = props;
|
|
120
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
121
121
|
return (_jsx(CoreProduct.Name, { children: ({ name }) => {
|
|
122
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productName, customElement: children, customElementProps: { name }, content: name, children: _jsx("div", { children: name }) }));
|
|
122
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productName, customElement: children, customElementProps: { name }, content: name, ...otherProps, children: _jsx("div", { children: name }) }));
|
|
123
123
|
} }));
|
|
124
124
|
});
|
|
125
125
|
/**
|
|
@@ -146,7 +146,7 @@ export const Name = React.forwardRef((props, ref) => {
|
|
|
146
146
|
* ```
|
|
147
147
|
*/
|
|
148
148
|
export const Description = React.forwardRef((props, ref) => {
|
|
149
|
-
const { asChild, children, className, as = AsContent.Plain } = props;
|
|
149
|
+
const { asChild, children, className, as = AsContent.Plain, ...otherProps } = props;
|
|
150
150
|
return (_jsx(CoreProduct.Description, { children: ({ description: richDescription, plainDescription }) => {
|
|
151
151
|
// Determine which description to use based on the 'as' prop
|
|
152
152
|
let description;
|
|
@@ -171,7 +171,7 @@ export const Description = React.forwardRef((props, ref) => {
|
|
|
171
171
|
return (_jsx("div", { ref: ref, className: className, "data-testid": TestIds.productDescription, dangerouslySetInnerHTML: { __html: description } }));
|
|
172
172
|
}
|
|
173
173
|
}
|
|
174
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productDescription, customElement: children, customElementProps: { description }, content: description, children: _jsx("div", { children: description }) }));
|
|
174
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productDescription, customElement: children, customElementProps: { description }, content: description, ...otherProps, children: _jsx("div", { children: description }) }));
|
|
175
175
|
} }));
|
|
176
176
|
});
|
|
177
177
|
/**
|
|
@@ -199,12 +199,12 @@ export const Description = React.forwardRef((props, ref) => {
|
|
|
199
199
|
* ```
|
|
200
200
|
*/
|
|
201
201
|
export const Price = React.forwardRef((props, ref) => {
|
|
202
|
-
const { asChild, children, className } = props;
|
|
202
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
203
203
|
return (_jsx(SelectedVariant.Price, { children: ({ price, compareAtPrice }) => {
|
|
204
204
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productPrice, "data-discounted": compareAtPrice !== null, customElement: children, customElementProps: {
|
|
205
205
|
price,
|
|
206
206
|
formattedPrice: price,
|
|
207
|
-
}, content: price, children: _jsx("span", { children: price }) }));
|
|
207
|
+
}, content: price, ...otherProps, children: _jsx("span", { children: price }) }));
|
|
208
208
|
} }));
|
|
209
209
|
});
|
|
210
210
|
/**
|
|
@@ -236,7 +236,7 @@ export const Price = React.forwardRef((props, ref) => {
|
|
|
236
236
|
* ```
|
|
237
237
|
*/
|
|
238
238
|
export const CompareAtPrice = React.forwardRef((props, ref) => {
|
|
239
|
-
const { asChild, children, className } = props;
|
|
239
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
240
240
|
const testId = TestIds.productCompareAtPrice;
|
|
241
241
|
return (_jsx(SelectedVariant.Price, { children: ({ compareAtPrice }) => {
|
|
242
242
|
// Don't render anything if there's no compare-at price
|
|
@@ -246,7 +246,7 @@ export const CompareAtPrice = React.forwardRef((props, ref) => {
|
|
|
246
246
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, "data-discounted": compareAtPrice !== null, customElement: children, customElementProps: {
|
|
247
247
|
price: compareAtPrice,
|
|
248
248
|
formattedPrice: compareAtPrice,
|
|
249
|
-
}, content: compareAtPrice, children: _jsx("span", { children: compareAtPrice }) }));
|
|
249
|
+
}, content: compareAtPrice, ...otherProps, children: _jsx("span", { children: compareAtPrice }) }));
|
|
250
250
|
} }));
|
|
251
251
|
});
|
|
252
252
|
/**
|
|
@@ -272,10 +272,10 @@ export const CompareAtPrice = React.forwardRef((props, ref) => {
|
|
|
272
272
|
* ```
|
|
273
273
|
*/
|
|
274
274
|
export const Slug = React.forwardRef((props, ref) => {
|
|
275
|
-
const { asChild, children, className } = props;
|
|
275
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
276
276
|
const testId = TestIds.productSlug;
|
|
277
277
|
return (_jsx(CoreProduct.Slug, { children: ({ slug }) => {
|
|
278
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, customElement: children, customElementProps: { slug }, content: slug, children: _jsx("span", { children: slug }) }));
|
|
278
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": testId, customElement: children, customElementProps: { slug }, content: slug, ...otherProps, children: _jsx("span", { children: slug }) }));
|
|
279
279
|
} }));
|
|
280
280
|
});
|
|
281
281
|
/**
|
|
@@ -298,13 +298,13 @@ export const Slug = React.forwardRef((props, ref) => {
|
|
|
298
298
|
* ```
|
|
299
299
|
*/
|
|
300
300
|
export const Raw = React.forwardRef((props, ref) => {
|
|
301
|
-
const { asChild, children, className } = props;
|
|
301
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
302
302
|
return (_jsx(CoreProduct.Content, { children: ({ product }) => {
|
|
303
303
|
// Raw component should not render anything by default when not using asChild
|
|
304
304
|
if (!asChild || !children) {
|
|
305
305
|
return null;
|
|
306
306
|
}
|
|
307
|
-
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productRaw, customElement: children, customElementProps: { product } }));
|
|
307
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productRaw, customElement: children, customElementProps: { product }, ...otherProps }));
|
|
308
308
|
} }));
|
|
309
309
|
});
|
|
310
310
|
/**
|
|
@@ -212,11 +212,11 @@ export const LoadMoreTrigger = React.forwardRef((props, ref) => {
|
|
|
212
212
|
* ```
|
|
213
213
|
*/
|
|
214
214
|
export const TotalsDisplayed = React.forwardRef((props, ref) => {
|
|
215
|
-
const { asChild, children, className } = props;
|
|
215
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
216
216
|
const productsListService = useService(ProductsListServiceDefinition);
|
|
217
217
|
const products = productsListService.products.get();
|
|
218
218
|
const displayedProducts = products.length;
|
|
219
|
-
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 }) }));
|
|
219
|
+
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListTotalsDisplayed, "data-displayed": displayedProducts, customElement: children, customElementProps: { displayedProducts }, content: displayedProducts, ...otherProps, children: _jsx("span", { children: displayedProducts }) }));
|
|
220
220
|
});
|
|
221
221
|
/**
|
|
222
222
|
* Sort component for product lists that provides sorting functionality.
|
|
@@ -302,8 +302,8 @@ export const Sort = React.forwardRef(({ children, className, as, asChild }, ref)
|
|
|
302
302
|
* ```
|
|
303
303
|
*/
|
|
304
304
|
const FilterRoot = React.forwardRef((props, ref) => {
|
|
305
|
-
const { asChild, children, className } = props;
|
|
306
|
-
return (_jsx(CoreProductListFilters.FilterRoot, { asChild: asChild, className: className, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListFilter, customElement: children, children: _jsx("div", { children: children }) }) }));
|
|
305
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
306
|
+
return (_jsx(CoreProductListFilters.FilterRoot, { asChild: asChild, className: className, children: _jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListFilter, customElement: children, ...otherProps, children: _jsx("div", { children: children }) }) }));
|
|
307
307
|
});
|
|
308
308
|
FilterRoot.displayName = 'ProductList.Filter';
|
|
309
309
|
export const Filter = {
|
|
@@ -340,7 +340,7 @@ export const Filter = {
|
|
|
340
340
|
* ```
|
|
341
341
|
*/
|
|
342
342
|
export const FilterResetTrigger = React.forwardRef((props, ref) => {
|
|
343
|
-
const { asChild, children, className } = props;
|
|
343
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
344
344
|
const label = props.label || 'Reset All Filters';
|
|
345
345
|
return (_jsx(CoreProductListFilters.ResetTrigger, { children: ({ resetFilters, isFiltered }) => {
|
|
346
346
|
if (!isFiltered) {
|
|
@@ -349,7 +349,7 @@ export const FilterResetTrigger = React.forwardRef((props, ref) => {
|
|
|
349
349
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, onClick: resetFilters, disabled: !isFiltered, "data-testid": TestIds.productListFilterResetTrigger, "data-filtered": isFiltered ? 'true' : 'false', customElement: children, customElementProps: {
|
|
350
350
|
resetFilters,
|
|
351
351
|
isFiltered,
|
|
352
|
-
}, content: label, children: _jsx("button", { disabled: !isFiltered, children: label }) }));
|
|
352
|
+
}, content: label, ...otherProps, children: _jsx("button", { disabled: !isFiltered, children: label }) }));
|
|
353
353
|
} }));
|
|
354
354
|
});
|
|
355
355
|
FilterResetTrigger.displayName = 'ProductList.FilterResetTrigger';
|
|
@@ -379,14 +379,14 @@ FilterResetTrigger.displayName = 'ProductList.FilterResetTrigger';
|
|
|
379
379
|
* ```
|
|
380
380
|
*/
|
|
381
381
|
export const Error = React.forwardRef((props, ref) => {
|
|
382
|
-
const { asChild, children, className } = props;
|
|
382
|
+
const { asChild, children, className, ...otherProps } = props;
|
|
383
383
|
return (_jsx(CoreProductList.Error, { children: ({ error }) => {
|
|
384
384
|
if (!error) {
|
|
385
385
|
return null;
|
|
386
386
|
}
|
|
387
387
|
return (_jsx(AsChildSlot, { ref: ref, asChild: asChild, className: className, "data-testid": TestIds.productListError, "data-error": error, customElement: children, customElementProps: {
|
|
388
388
|
error,
|
|
389
|
-
}, content: error, children: _jsx("div", { className: "text-status-error text-sm sm:text-base", children: error }) }));
|
|
389
|
+
}, content: error, ...otherProps, children: _jsx("div", { className: "text-status-error text-sm sm:text-base", children: error }) }));
|
|
390
390
|
} }));
|
|
391
391
|
});
|
|
392
392
|
Error.displayName = 'ProductList.Error';
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wix/headless-stores",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.88",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prebuild": "cd ../media && yarn build && cd ../ecom && yarn build",
|
|
@@ -62,12 +62,14 @@
|
|
|
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-
|
|
66
|
-
"@wix/headless-
|
|
67
|
-
"@wix/headless-media": "0.0.11",
|
|
65
|
+
"@wix/headless-ecom": "0.0.29",
|
|
66
|
+
"@wix/headless-media": "0.0.12",
|
|
68
67
|
"@wix/headless-utils": "0.0.3",
|
|
69
68
|
"@wix/redirects": "^1.0.83",
|
|
70
69
|
"@wix/services-definitions": "^0.1.4",
|
|
71
70
|
"@wix/services-manager-react": "^0.1.26"
|
|
71
|
+
},
|
|
72
|
+
"peerDependencies": {
|
|
73
|
+
"@wix/headless-components": "0.0.12"
|
|
72
74
|
}
|
|
73
75
|
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Function signature for render function pattern
|
|
4
|
-
*/
|
|
5
|
-
export type AsChildRenderFunction<TProps = any> = (props: TProps, ref: React.Ref<HTMLElement>) => React.ReactNode;
|
|
6
|
-
/**
|
|
7
|
-
* Object with render method pattern
|
|
8
|
-
*/
|
|
9
|
-
export type AsChildRenderObject<TProps = any> = {
|
|
10
|
-
render: AsChildRenderFunction<TProps>;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Union type for all supported asChild patterns
|
|
14
|
-
*/
|
|
15
|
-
export type AsChildChildren<TProps = any> = React.ReactElement | AsChildRenderFunction<TProps> | AsChildRenderObject<TProps>;
|
|
16
|
-
/**
|
|
17
|
-
* Generic interface for components that support asChild pattern.
|
|
18
|
-
* This interface can be extended by specific components to add their own props.
|
|
19
|
-
*
|
|
20
|
-
* @template TData - The shape of the data object passed to asChild render functions
|
|
21
|
-
* @template TProps - Additional props specific to the component
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```tsx
|
|
25
|
-
* // For a component that provides name data
|
|
26
|
-
* interface NameProps extends AsChildProps<{ name: string }> {
|
|
27
|
-
* // className is already included from AsChildProps
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* // For a component that provides description data
|
|
31
|
-
* interface DescriptionProps extends AsChildProps<{ description: string }> {
|
|
32
|
-
* as?: "plain" | "html";
|
|
33
|
-
* // className is already included from AsChildProps
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export interface AsChildProps<TData extends Record<string, any> = Record<string, any>, TProps = {}> {
|
|
38
|
-
/** When true, renders as a child component instead of default element */
|
|
39
|
-
asChild?: boolean;
|
|
40
|
-
/** Custom render function or React element when using asChild */
|
|
41
|
-
children?: AsChildChildren<TData & TProps>;
|
|
42
|
-
/** CSS classes to apply to the default element */
|
|
43
|
-
className?: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Parameters for the renderAsChild utility function
|
|
47
|
-
*/
|
|
48
|
-
export interface RenderAsChildParams<TProps = any> {
|
|
49
|
-
/** The children to render (React element, function, or render object) */
|
|
50
|
-
children: AsChildChildren<TProps> | undefined;
|
|
51
|
-
/** Props to pass to render functions */
|
|
52
|
-
props: TProps;
|
|
53
|
-
/** Ref to forward to the rendered element */
|
|
54
|
-
ref: React.Ref<HTMLElement>;
|
|
55
|
-
/** Content to pass as children to React elements */
|
|
56
|
-
content?: React.ReactNode;
|
|
57
|
-
/** Additional attributes to merge into cloned React elements */
|
|
58
|
-
attributes?: Record<string, any>;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Utility function to handle asChild prop with different rendering patterns.
|
|
62
|
-
*
|
|
63
|
-
* Supports three rendering patterns:
|
|
64
|
-
* 1. **React Elements**: Clones the element and forwards the ref and attributes
|
|
65
|
-
* ```tsx
|
|
66
|
-
* <Component asChild><div>Content</div></Component>
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
70
|
-
* ```tsx
|
|
71
|
-
* <Component asChild>
|
|
72
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
73
|
-
* </Component>
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* 3. **Render Objects**: Calls the render method with props and ref
|
|
77
|
-
* ```tsx
|
|
78
|
-
* <Component asChild>
|
|
79
|
-
* {{ render: (props, ref) => <div ref={ref}>{props.content}</div> }}
|
|
80
|
-
* </Component>
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @param params - Configuration object with children, props, ref, content, and attributes
|
|
84
|
-
* @returns Rendered React node or null if no valid children provided
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```tsx
|
|
88
|
-
* const result = renderAsChild({
|
|
89
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
90
|
-
* props: { title: "Hello World" },
|
|
91
|
-
* ref: myRef,
|
|
92
|
-
* attributes: { "data-testid": "my-component" },
|
|
93
|
-
* });
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
export declare function renderAsChild<TProps = any>({ children, props, ref, content, attributes, }: RenderAsChildParams<TProps>): React.ReactNode | null;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Utility function to handle asChild prop with different rendering patterns.
|
|
4
|
-
*
|
|
5
|
-
* Supports three rendering patterns:
|
|
6
|
-
* 1. **React Elements**: Clones the element and forwards the ref and attributes
|
|
7
|
-
* ```tsx
|
|
8
|
-
* <Component asChild><div>Content</div></Component>
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
12
|
-
* ```tsx
|
|
13
|
-
* <Component asChild>
|
|
14
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
15
|
-
* </Component>
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* 3. **Render Objects**: Calls the render method with props and ref
|
|
19
|
-
* ```tsx
|
|
20
|
-
* <Component asChild>
|
|
21
|
-
* {{ render: (props, ref) => <div ref={ref}>{props.content}</div> }}
|
|
22
|
-
* </Component>
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @param params - Configuration object with children, props, ref, content, and attributes
|
|
26
|
-
* @returns Rendered React node or null if no valid children provided
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* const result = renderAsChild({
|
|
31
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
32
|
-
* props: { title: "Hello World" },
|
|
33
|
-
* ref: myRef,
|
|
34
|
-
* attributes: { "data-testid": "my-component" },
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export function renderAsChild({ children, props, ref, content, attributes, }) {
|
|
39
|
-
// Early return if no children provided
|
|
40
|
-
if (!children)
|
|
41
|
-
return null;
|
|
42
|
-
// Handle React element pattern
|
|
43
|
-
if (React.isValidElement(children)) {
|
|
44
|
-
return React.cloneElement(children, {
|
|
45
|
-
ref,
|
|
46
|
-
children: content,
|
|
47
|
-
...attributes,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
// Handle render function pattern
|
|
51
|
-
if (typeof children === 'function') {
|
|
52
|
-
return children({
|
|
53
|
-
...props,
|
|
54
|
-
...attributes,
|
|
55
|
-
}, ref);
|
|
56
|
-
}
|
|
57
|
-
// Handle render object pattern
|
|
58
|
-
if (children && typeof children === 'object' && 'render' in children) {
|
|
59
|
-
return children.render({
|
|
60
|
-
...props,
|
|
61
|
-
...attributes,
|
|
62
|
-
}, ref);
|
|
63
|
-
}
|
|
64
|
-
// Fallback for unknown patterns
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Parameters for the renderAsChild utility function
|
|
4
|
-
*/
|
|
5
|
-
export interface RenderChildrenParams<THTMLElement = HTMLElement, TProps = any> {
|
|
6
|
-
/** The children to render (React element, function, or render object) */
|
|
7
|
-
children: React.ReactNode | React.ForwardRefRenderFunction<THTMLElement, TProps> | undefined;
|
|
8
|
-
/** Props to pass to render functions */
|
|
9
|
-
props: TProps;
|
|
10
|
-
/** Ref to forward to the rendered element */
|
|
11
|
-
ref: React.Ref<THTMLElement>;
|
|
12
|
-
content?: string | null;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Utility function to handle children rendering.
|
|
16
|
-
*
|
|
17
|
-
* Supports three rendering patterns:
|
|
18
|
-
* 1. **React Elements**: Returns the element
|
|
19
|
-
* ```tsx
|
|
20
|
-
* <Component><div>Content</div></Component>
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
24
|
-
* ```tsx
|
|
25
|
-
* <Component>
|
|
26
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
27
|
-
* </Component>
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param params - Configuration object with children, props, and ref
|
|
31
|
-
* @returns Rendered React node or null if no valid children provided
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```tsx
|
|
35
|
-
* const result = renderChildren({
|
|
36
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
37
|
-
* props: { title: "Hello World" },
|
|
38
|
-
* ref: myRef,
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function renderChildren<THTMLElement = HTMLElement, TProps = any>({ children, props, ref, content, }: RenderChildrenParams<THTMLElement, TProps>): React.ReactNode | null;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Utility function to handle children rendering.
|
|
4
|
-
*
|
|
5
|
-
* Supports three rendering patterns:
|
|
6
|
-
* 1. **React Elements**: Returns the element
|
|
7
|
-
* ```tsx
|
|
8
|
-
* <Component><div>Content</div></Component>
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
12
|
-
* ```tsx
|
|
13
|
-
* <Component>
|
|
14
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
15
|
-
* </Component>
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @param params - Configuration object with children, props, and ref
|
|
19
|
-
* @returns Rendered React node or null if no valid children provided
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* const result = renderChildren({
|
|
24
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
25
|
-
* props: { title: "Hello World" },
|
|
26
|
-
* ref: myRef,
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function renderChildren({ children, props, ref, content, }) {
|
|
31
|
-
// Early return if no children provided
|
|
32
|
-
if (!children)
|
|
33
|
-
return null;
|
|
34
|
-
// Handle React element pattern
|
|
35
|
-
if (React.isValidElement(children)) {
|
|
36
|
-
return React.cloneElement(children, {
|
|
37
|
-
ref,
|
|
38
|
-
...(content ? { children: content } : {}),
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
// Handle render function pattern
|
|
42
|
-
if (typeof children === 'function') {
|
|
43
|
-
return children(props, ref);
|
|
44
|
-
}
|
|
45
|
-
// Fallback for unknown patterns
|
|
46
|
-
return null;
|
|
47
|
-
}
|
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Function signature for render function pattern
|
|
4
|
-
*/
|
|
5
|
-
export type AsChildRenderFunction<TProps = any> = (props: TProps, ref: React.Ref<HTMLElement>) => React.ReactNode;
|
|
6
|
-
/**
|
|
7
|
-
* Object with render method pattern
|
|
8
|
-
*/
|
|
9
|
-
export type AsChildRenderObject<TProps = any> = {
|
|
10
|
-
render: AsChildRenderFunction<TProps>;
|
|
11
|
-
};
|
|
12
|
-
/**
|
|
13
|
-
* Union type for all supported asChild patterns
|
|
14
|
-
*/
|
|
15
|
-
export type AsChildChildren<TProps = any> = React.ReactElement | AsChildRenderFunction<TProps> | AsChildRenderObject<TProps>;
|
|
16
|
-
/**
|
|
17
|
-
* Generic interface for components that support asChild pattern.
|
|
18
|
-
* This interface can be extended by specific components to add their own props.
|
|
19
|
-
*
|
|
20
|
-
* @template TData - The shape of the data object passed to asChild render functions
|
|
21
|
-
* @template TProps - Additional props specific to the component
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```tsx
|
|
25
|
-
* // For a component that provides name data
|
|
26
|
-
* interface NameProps extends AsChildProps<{ name: string }> {
|
|
27
|
-
* // className is already included from AsChildProps
|
|
28
|
-
* }
|
|
29
|
-
*
|
|
30
|
-
* // For a component that provides description data
|
|
31
|
-
* interface DescriptionProps extends AsChildProps<{ description: string }> {
|
|
32
|
-
* as?: "plain" | "html";
|
|
33
|
-
* // className is already included from AsChildProps
|
|
34
|
-
* }
|
|
35
|
-
* ```
|
|
36
|
-
*/
|
|
37
|
-
export interface AsChildProps<TData extends Record<string, any> = Record<string, any>, TProps = {}> {
|
|
38
|
-
/** When true, renders as a child component instead of default element */
|
|
39
|
-
asChild?: boolean;
|
|
40
|
-
/** Custom render function or React element when using asChild */
|
|
41
|
-
children?: AsChildChildren<TData & TProps>;
|
|
42
|
-
/** CSS classes to apply to the default element */
|
|
43
|
-
className?: string;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Parameters for the renderAsChild utility function
|
|
47
|
-
*/
|
|
48
|
-
export interface RenderAsChildParams<TProps = any> {
|
|
49
|
-
/** The children to render (React element, function, or render object) */
|
|
50
|
-
children: AsChildChildren<TProps> | undefined;
|
|
51
|
-
/** Props to pass to render functions */
|
|
52
|
-
props: TProps;
|
|
53
|
-
/** Ref to forward to the rendered element */
|
|
54
|
-
ref: React.Ref<HTMLElement>;
|
|
55
|
-
/** Content to pass as children to React elements */
|
|
56
|
-
content?: React.ReactNode;
|
|
57
|
-
/** Additional attributes to merge into cloned React elements */
|
|
58
|
-
attributes?: Record<string, any>;
|
|
59
|
-
}
|
|
60
|
-
/**
|
|
61
|
-
* Utility function to handle asChild prop with different rendering patterns.
|
|
62
|
-
*
|
|
63
|
-
* Supports three rendering patterns:
|
|
64
|
-
* 1. **React Elements**: Clones the element and forwards the ref and attributes
|
|
65
|
-
* ```tsx
|
|
66
|
-
* <Component asChild><div>Content</div></Component>
|
|
67
|
-
* ```
|
|
68
|
-
*
|
|
69
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
70
|
-
* ```tsx
|
|
71
|
-
* <Component asChild>
|
|
72
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
73
|
-
* </Component>
|
|
74
|
-
* ```
|
|
75
|
-
*
|
|
76
|
-
* 3. **Render Objects**: Calls the render method with props and ref
|
|
77
|
-
* ```tsx
|
|
78
|
-
* <Component asChild>
|
|
79
|
-
* {{ render: (props, ref) => <div ref={ref}>{props.content}</div> }}
|
|
80
|
-
* </Component>
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @param params - Configuration object with children, props, ref, content, and attributes
|
|
84
|
-
* @returns Rendered React node or null if no valid children provided
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* ```tsx
|
|
88
|
-
* const result = renderAsChild({
|
|
89
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
90
|
-
* props: { title: "Hello World" },
|
|
91
|
-
* ref: myRef,
|
|
92
|
-
* attributes: { "data-testid": "my-component" },
|
|
93
|
-
* });
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
export declare function renderAsChild<TProps = any>({ children, props, ref, content, attributes, }: RenderAsChildParams<TProps>): React.ReactNode | null;
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Utility function to handle asChild prop with different rendering patterns.
|
|
4
|
-
*
|
|
5
|
-
* Supports three rendering patterns:
|
|
6
|
-
* 1. **React Elements**: Clones the element and forwards the ref and attributes
|
|
7
|
-
* ```tsx
|
|
8
|
-
* <Component asChild><div>Content</div></Component>
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
12
|
-
* ```tsx
|
|
13
|
-
* <Component asChild>
|
|
14
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
15
|
-
* </Component>
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* 3. **Render Objects**: Calls the render method with props and ref
|
|
19
|
-
* ```tsx
|
|
20
|
-
* <Component asChild>
|
|
21
|
-
* {{ render: (props, ref) => <div ref={ref}>{props.content}</div> }}
|
|
22
|
-
* </Component>
|
|
23
|
-
* ```
|
|
24
|
-
*
|
|
25
|
-
* @param params - Configuration object with children, props, ref, content, and attributes
|
|
26
|
-
* @returns Rendered React node or null if no valid children provided
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```tsx
|
|
30
|
-
* const result = renderAsChild({
|
|
31
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
32
|
-
* props: { title: "Hello World" },
|
|
33
|
-
* ref: myRef,
|
|
34
|
-
* attributes: { "data-testid": "my-component" },
|
|
35
|
-
* });
|
|
36
|
-
* ```
|
|
37
|
-
*/
|
|
38
|
-
export function renderAsChild({ children, props, ref, content, attributes, }) {
|
|
39
|
-
// Early return if no children provided
|
|
40
|
-
if (!children)
|
|
41
|
-
return null;
|
|
42
|
-
// Handle React element pattern
|
|
43
|
-
if (React.isValidElement(children)) {
|
|
44
|
-
return React.cloneElement(children, {
|
|
45
|
-
ref,
|
|
46
|
-
children: content,
|
|
47
|
-
...attributes,
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
// Handle render function pattern
|
|
51
|
-
if (typeof children === 'function') {
|
|
52
|
-
return children({
|
|
53
|
-
...props,
|
|
54
|
-
...attributes,
|
|
55
|
-
}, ref);
|
|
56
|
-
}
|
|
57
|
-
// Handle render object pattern
|
|
58
|
-
if (children && typeof children === 'object' && 'render' in children) {
|
|
59
|
-
return children.render({
|
|
60
|
-
...props,
|
|
61
|
-
...attributes,
|
|
62
|
-
}, ref);
|
|
63
|
-
}
|
|
64
|
-
// Fallback for unknown patterns
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Parameters for the renderAsChild utility function
|
|
4
|
-
*/
|
|
5
|
-
export interface RenderChildrenParams<THTMLElement = HTMLElement, TProps = any> {
|
|
6
|
-
/** The children to render (React element, function, or render object) */
|
|
7
|
-
children: React.ReactNode | React.ForwardRefRenderFunction<THTMLElement, TProps> | undefined;
|
|
8
|
-
/** Props to pass to render functions */
|
|
9
|
-
props: TProps;
|
|
10
|
-
/** Ref to forward to the rendered element */
|
|
11
|
-
ref: React.Ref<THTMLElement>;
|
|
12
|
-
content?: string | null;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Utility function to handle children rendering.
|
|
16
|
-
*
|
|
17
|
-
* Supports three rendering patterns:
|
|
18
|
-
* 1. **React Elements**: Returns the element
|
|
19
|
-
* ```tsx
|
|
20
|
-
* <Component><div>Content</div></Component>
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
24
|
-
* ```tsx
|
|
25
|
-
* <Component>
|
|
26
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
27
|
-
* </Component>
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param params - Configuration object with children, props, and ref
|
|
31
|
-
* @returns Rendered React node or null if no valid children provided
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```tsx
|
|
35
|
-
* const result = renderChildren({
|
|
36
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
37
|
-
* props: { title: "Hello World" },
|
|
38
|
-
* ref: myRef,
|
|
39
|
-
* });
|
|
40
|
-
* ```
|
|
41
|
-
*/
|
|
42
|
-
export declare function renderChildren<THTMLElement = HTMLElement, TProps = any>({ children, props, ref, content, }: RenderChildrenParams<THTMLElement, TProps>): React.ReactNode | null;
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Utility function to handle children rendering.
|
|
4
|
-
*
|
|
5
|
-
* Supports three rendering patterns:
|
|
6
|
-
* 1. **React Elements**: Returns the element
|
|
7
|
-
* ```tsx
|
|
8
|
-
* <Component><div>Content</div></Component>
|
|
9
|
-
* ```
|
|
10
|
-
*
|
|
11
|
-
* 2. **Render Functions**: Calls the function with props and ref
|
|
12
|
-
* ```tsx
|
|
13
|
-
* <Component>
|
|
14
|
-
* {(props, ref) => <div ref={ref}>{props.content}</div>}
|
|
15
|
-
* </Component>
|
|
16
|
-
* ```
|
|
17
|
-
*
|
|
18
|
-
* @param params - Configuration object with children, props, and ref
|
|
19
|
-
* @returns Rendered React node or null if no valid children provided
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```tsx
|
|
23
|
-
* const result = renderChildren({
|
|
24
|
-
* children: (props, ref) => <h1 ref={ref}>{props.title}</h1>,
|
|
25
|
-
* props: { title: "Hello World" },
|
|
26
|
-
* ref: myRef,
|
|
27
|
-
* });
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
export function renderChildren({ children, props, ref, content, }) {
|
|
31
|
-
// Early return if no children provided
|
|
32
|
-
if (!children)
|
|
33
|
-
return null;
|
|
34
|
-
// Handle React element pattern
|
|
35
|
-
if (React.isValidElement(children)) {
|
|
36
|
-
return React.cloneElement(children, {
|
|
37
|
-
ref,
|
|
38
|
-
...(content ? { children: content } : {}),
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
// Handle render function pattern
|
|
42
|
-
if (typeof children === 'function') {
|
|
43
|
-
return children(props, ref);
|
|
44
|
-
}
|
|
45
|
-
// Fallback for unknown patterns
|
|
46
|
-
return null;
|
|
47
|
-
}
|