@wix/headless-stores 0.0.52 → 0.0.53
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/cjs/dist/astro/actions/custom-checkout.js +2 -2
- package/cjs/dist/astro/actions/index.d.ts +1 -1
- package/cjs/dist/astro/actions/index.js +1 -1
- package/cjs/dist/enums/index.d.ts +2 -2
- package/cjs/dist/enums/index.js +2 -2
- package/cjs/dist/react/Category.d.ts +168 -67
- package/cjs/dist/react/Category.js +166 -50
- package/cjs/dist/react/CategoryList.d.ts +56 -138
- package/cjs/dist/react/CategoryList.js +44 -129
- package/cjs/dist/react/Choice.d.ts +193 -0
- package/cjs/dist/react/Choice.js +259 -0
- package/cjs/dist/react/Option.d.ts +224 -0
- package/cjs/dist/react/Option.js +388 -0
- package/cjs/dist/react/Product.d.ts +339 -96
- package/cjs/dist/react/Product.js +507 -94
- package/cjs/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
- package/cjs/dist/react/core/Category.d.ts +98 -0
- package/cjs/dist/react/core/Category.js +81 -0
- package/cjs/dist/react/core/CategoryList.d.ts +185 -0
- package/cjs/dist/react/core/CategoryList.js +174 -0
- package/{dist/react → cjs/dist/react/core}/PayNow.js +2 -2
- package/cjs/dist/react/core/Product.d.ts +148 -0
- package/cjs/dist/react/core/Product.js +126 -0
- package/cjs/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
- package/cjs/dist/react/{ProductList.js → core/ProductList.js} +10 -10
- package/{dist/react → cjs/dist/react/core}/ProductListFilters.d.ts +3 -3
- package/{dist/react → cjs/dist/react/core}/ProductListFilters.js +7 -7
- package/cjs/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
- package/{dist/react → cjs/dist/react/core}/ProductListSort.d.ts +1 -1
- package/cjs/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
- package/{dist/react → cjs/dist/react/core}/ProductModifiers.d.ts +1 -1
- package/{dist/react → cjs/dist/react/core}/ProductModifiers.js +13 -13
- package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.d.ts +2 -2
- package/{dist/react → cjs/dist/react/core}/ProductVariantSelector.js +7 -10
- package/{dist/react → cjs/dist/react/core}/SelectedVariant.d.ts +2 -2
- package/{dist/react → cjs/dist/react/core}/SelectedVariant.js +43 -15
- package/cjs/dist/react/index.d.ts +15 -10
- package/cjs/dist/react/index.js +15 -10
- package/cjs/dist/react/types.d.ts +8 -0
- package/cjs/dist/react/types.js +9 -0
- package/cjs/dist/server-actions/custom-checkout-action.js +14 -10
- package/cjs/dist/server-actions/index.d.ts +1 -1
- package/cjs/dist/server-actions/index.js +1 -1
- package/cjs/dist/services/buy-now-service.d.ts +1 -1
- package/cjs/dist/services/buy-now-service.js +6 -6
- package/cjs/dist/services/categories-list-service.d.ts +4 -4
- package/cjs/dist/services/categories-list-service.js +10 -10
- package/cjs/dist/services/category-service.d.ts +18 -22
- package/cjs/dist/services/category-service.js +12 -10
- package/cjs/dist/services/index.d.ts +7 -7
- package/cjs/dist/services/index.js +7 -7
- package/cjs/dist/services/pay-now-service.d.ts +1 -1
- package/cjs/dist/services/pay-now-service.js +4 -4
- package/cjs/dist/services/product-modifiers-service.d.ts +3 -3
- package/cjs/dist/services/product-modifiers-service.js +7 -7
- package/cjs/dist/services/product-service.d.ts +4 -4
- package/cjs/dist/services/product-service.js +18 -18
- package/cjs/dist/services/products-list-search-service.d.ts +5 -5
- package/cjs/dist/services/products-list-search-service.js +117 -117
- package/cjs/dist/services/products-list-service.d.ts +4 -4
- package/cjs/dist/services/products-list-service.js +12 -12
- package/cjs/dist/services/selected-variant-service.d.ts +6 -2
- package/cjs/dist/services/selected-variant-service.js +86 -83
- package/cjs/dist/utils/index.d.ts +1 -0
- package/cjs/dist/utils/index.js +5 -4
- package/cjs/dist/utils/renderAsChild.d.ts +96 -0
- package/cjs/dist/utils/renderAsChild.js +66 -0
- package/cjs/dist/utils/renderChildren.d.ts +41 -0
- package/cjs/dist/utils/renderChildren.js +44 -0
- package/cjs/dist/utils/url-params.js +3 -3
- package/dist/astro/actions/custom-checkout.d.ts +1 -1
- package/dist/astro/actions/custom-checkout.js +2 -2
- package/dist/astro/actions/index.d.ts +1 -1
- package/dist/astro/actions/index.js +1 -1
- package/dist/enums/index.d.ts +2 -2
- package/dist/enums/index.js +2 -2
- package/dist/react/Category.d.ts +168 -67
- package/dist/react/Category.js +166 -50
- package/dist/react/CategoryList.d.ts +56 -138
- package/dist/react/CategoryList.js +44 -129
- package/dist/react/Choice.d.ts +193 -0
- package/dist/react/Choice.js +259 -0
- package/dist/react/Option.d.ts +224 -0
- package/dist/react/Option.js +388 -0
- package/dist/react/Product.d.ts +339 -96
- package/dist/react/Product.js +507 -94
- package/dist/react/{BuyNow.js → core/BuyNow.js} +2 -2
- package/dist/react/core/Category.d.ts +98 -0
- package/dist/react/core/Category.js +81 -0
- package/dist/react/core/CategoryList.d.ts +185 -0
- package/dist/react/core/CategoryList.js +174 -0
- package/{cjs/dist/react → dist/react/core}/PayNow.js +2 -2
- package/dist/react/core/Product.d.ts +148 -0
- package/dist/react/core/Product.js +126 -0
- package/dist/react/{ProductList.d.ts → core/ProductList.d.ts} +3 -3
- package/dist/react/{ProductList.js → core/ProductList.js} +10 -10
- package/{cjs/dist/react → dist/react/core}/ProductListFilters.d.ts +3 -3
- package/{cjs/dist/react → dist/react/core}/ProductListFilters.js +7 -7
- package/dist/react/{ProductListPagination.js → core/ProductListPagination.js} +8 -8
- package/{cjs/dist/react → dist/react/core}/ProductListSort.d.ts +1 -1
- package/dist/react/{ProductListSort.js → core/ProductListSort.js} +3 -3
- package/{cjs/dist/react → dist/react/core}/ProductModifiers.d.ts +1 -1
- package/{cjs/dist/react → dist/react/core}/ProductModifiers.js +13 -13
- package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.d.ts +2 -2
- package/{cjs/dist/react → dist/react/core}/ProductVariantSelector.js +7 -10
- package/{cjs/dist/react → dist/react/core}/SelectedVariant.d.ts +2 -2
- package/{cjs/dist/react → dist/react/core}/SelectedVariant.js +43 -15
- package/dist/react/index.d.ts +15 -10
- package/dist/react/index.js +15 -10
- package/dist/react/types.d.ts +8 -0
- package/dist/react/types.js +9 -0
- package/dist/server-actions/custom-checkout-action.js +14 -10
- package/dist/server-actions/index.d.ts +1 -1
- package/dist/server-actions/index.js +1 -1
- package/dist/services/buy-now-service.d.ts +1 -1
- package/dist/services/buy-now-service.js +6 -6
- package/dist/services/categories-list-service.d.ts +4 -4
- package/dist/services/categories-list-service.js +10 -10
- package/dist/services/category-service.d.ts +18 -22
- package/dist/services/category-service.js +12 -10
- package/dist/services/index.d.ts +7 -7
- package/dist/services/index.js +7 -7
- package/dist/services/pay-now-service.d.ts +1 -1
- package/dist/services/pay-now-service.js +4 -4
- package/dist/services/product-modifiers-service.d.ts +3 -3
- package/dist/services/product-modifiers-service.js +7 -7
- package/dist/services/product-service.d.ts +4 -4
- package/dist/services/product-service.js +18 -18
- package/dist/services/products-list-search-service.d.ts +5 -5
- package/dist/services/products-list-search-service.js +117 -117
- package/dist/services/products-list-service.d.ts +4 -4
- package/dist/services/products-list-service.js +12 -12
- package/dist/services/selected-variant-service.d.ts +6 -2
- package/dist/services/selected-variant-service.js +86 -83
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +5 -4
- package/dist/utils/renderAsChild.d.ts +96 -0
- package/dist/utils/renderAsChild.js +66 -0
- package/dist/utils/renderChildren.d.ts +41 -0
- package/dist/utils/renderChildren.js +44 -0
- package/dist/utils/url-params.js +3 -3
- package/package.json +7 -3
- /package/cjs/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
- /package/cjs/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
- /package/cjs/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
- /package/dist/react/{BuyNow.d.ts → core/BuyNow.d.ts} +0 -0
- /package/dist/react/{PayNow.d.ts → core/PayNow.d.ts} +0 -0
- /package/dist/react/{ProductListPagination.d.ts → core/ProductListPagination.d.ts} +0 -0
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { renderAsChild } from '../utils/index.js';
|
|
4
|
+
import { FreeText as FreeTextPrimitive } from './core/ProductModifiers.js';
|
|
5
|
+
var TestIds;
|
|
6
|
+
(function (TestIds) {
|
|
7
|
+
TestIds["choiceRoot"] = "choice-root";
|
|
8
|
+
TestIds["choiceText"] = "choice-text";
|
|
9
|
+
TestIds["choiceColor"] = "choice-color";
|
|
10
|
+
TestIds["choiceFreetext"] = "choice-freetext";
|
|
11
|
+
})(TestIds || (TestIds = {}));
|
|
12
|
+
// Create a context for individual choices
|
|
13
|
+
export const ChoiceContext = React.createContext(null);
|
|
14
|
+
/**
|
|
15
|
+
* Hook to access ChoiceContext with proper error handling
|
|
16
|
+
* @throws {Error} When used outside of a Choice context provider
|
|
17
|
+
* @returns {ChoiceContextValue} The choice context value
|
|
18
|
+
*/
|
|
19
|
+
export function useChoiceContext() {
|
|
20
|
+
const context = React.useContext(ChoiceContext);
|
|
21
|
+
if (!context) {
|
|
22
|
+
throw new Error('useChoiceContext must be used within a Choice context provider (Option.ChoiceRepeater)');
|
|
23
|
+
}
|
|
24
|
+
return context;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Root component that consumes ChoiceContext provided by Option.ChoiceRepeater.
|
|
28
|
+
*
|
|
29
|
+
* @component
|
|
30
|
+
* @example
|
|
31
|
+
* ```tsx
|
|
32
|
+
* <Choice.Root>
|
|
33
|
+
* <Choice.Text />
|
|
34
|
+
* <Choice.Color />
|
|
35
|
+
* </Choice.Root>
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export const Root = React.forwardRef((props, ref) => {
|
|
39
|
+
const { children } = props;
|
|
40
|
+
const choiceContext = React.useContext(ChoiceContext);
|
|
41
|
+
if (!choiceContext) {
|
|
42
|
+
return null; // Should be used within Option.ChoiceRepeater
|
|
43
|
+
}
|
|
44
|
+
const { choice } = choiceContext;
|
|
45
|
+
const attributes = {
|
|
46
|
+
'data-testid': TestIds.choiceRoot,
|
|
47
|
+
'data-type': choice?.type,
|
|
48
|
+
};
|
|
49
|
+
return (_jsx("div", { ...attributes, ref: ref, children: children }));
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Text-based choice button.
|
|
53
|
+
*
|
|
54
|
+
* @component
|
|
55
|
+
* @example
|
|
56
|
+
* ```tsx
|
|
57
|
+
* // Default usage
|
|
58
|
+
* <Choice.Text className="px-4 py-2 border rounded-lg" />
|
|
59
|
+
*
|
|
60
|
+
* // asChild with primitive
|
|
61
|
+
* <Choice.Text asChild>
|
|
62
|
+
* <button className="px-4 py-2 border rounded-lg" />
|
|
63
|
+
* </Choice.Text>
|
|
64
|
+
*
|
|
65
|
+
* // asChild with react component
|
|
66
|
+
* <Choice.Text asChild>
|
|
67
|
+
* {React.forwardRef(({id, value, ...props}, ref) => (
|
|
68
|
+
* <button ref={ref} {...props} className="px-4 py-2 border rounded-lg">
|
|
69
|
+
* {value}
|
|
70
|
+
* </button>
|
|
71
|
+
* ))}
|
|
72
|
+
* </Choice.Text>
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* Data Attributes:
|
|
76
|
+
* - `data-testid="choice-text"` - Applied to choice buttons
|
|
77
|
+
* - `data-selected` - Is Choice selected
|
|
78
|
+
* - `disabled` - Is Choice disabled (not in stock)
|
|
79
|
+
*/
|
|
80
|
+
export const Text = React.forwardRef((props, ref) => {
|
|
81
|
+
const { asChild, children, className } = props;
|
|
82
|
+
const choiceContext = React.useContext(ChoiceContext);
|
|
83
|
+
if (!choiceContext) {
|
|
84
|
+
return null; // Should be used within Option.ChoiceRepeater
|
|
85
|
+
}
|
|
86
|
+
const { choice, shouldRenderAsText, value, isSelected, select, isVisible, isInStock, isPreOrderEnabled, } = choiceContext;
|
|
87
|
+
// Only render if this should be rendered as text
|
|
88
|
+
if (!shouldRenderAsText)
|
|
89
|
+
return null;
|
|
90
|
+
// Don't render if not visible (handled by ProductVariantSelector in Root)
|
|
91
|
+
if (!isVisible)
|
|
92
|
+
return null;
|
|
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 }));
|
|
112
|
+
});
|
|
113
|
+
/**
|
|
114
|
+
* Color swatch choice.
|
|
115
|
+
*
|
|
116
|
+
* @component
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* // Default usage
|
|
120
|
+
* <Choice.Color className="w-10 h-10 rounded-full border-4" />
|
|
121
|
+
*
|
|
122
|
+
* // asChild with primitive
|
|
123
|
+
* <Choice.Color asChild>
|
|
124
|
+
* <button className="w-10 h-10 rounded-full border-4" />
|
|
125
|
+
* </Choice.Color>
|
|
126
|
+
*
|
|
127
|
+
* // asChild with react component
|
|
128
|
+
* <Choice.Color asChild>
|
|
129
|
+
* {React.forwardRef(({colorCode, name, id, ...props}, ref) => (
|
|
130
|
+
* <button
|
|
131
|
+
* ref={ref}
|
|
132
|
+
* {...props}
|
|
133
|
+
* className="w-10 h-10 rounded-full border-4"
|
|
134
|
+
* style={{ backgroundColor: colorCode }}
|
|
135
|
+
* title={name}
|
|
136
|
+
* />
|
|
137
|
+
* ))}
|
|
138
|
+
* </Choice.Color>
|
|
139
|
+
* ```
|
|
140
|
+
*
|
|
141
|
+
* Data Attributes:
|
|
142
|
+
* - `data-testid="choice-color"` - Applied to color swatches
|
|
143
|
+
* - `data-selected` - Is Choice selected
|
|
144
|
+
* - `disabled` - Is Choice disabled (not in stock)
|
|
145
|
+
*/
|
|
146
|
+
export const Color = React.forwardRef((props, ref) => {
|
|
147
|
+
const { asChild, children, className } = props;
|
|
148
|
+
const choiceContext = React.useContext(ChoiceContext);
|
|
149
|
+
if (!choiceContext) {
|
|
150
|
+
return null; // Should be used within Option.ChoiceRepeater
|
|
151
|
+
}
|
|
152
|
+
const { choice, shouldRenderAsColor, value, isSelected, select, isVisible, isInStock, isPreOrderEnabled, } = choiceContext;
|
|
153
|
+
// Only render if this should be rendered as color
|
|
154
|
+
if (!shouldRenderAsColor)
|
|
155
|
+
return null;
|
|
156
|
+
// Don't render if not visible (handled by ProductVariantSelector in Root)
|
|
157
|
+
if (!isVisible)
|
|
158
|
+
return null;
|
|
159
|
+
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 }));
|
|
182
|
+
});
|
|
183
|
+
/**
|
|
184
|
+
* Provides a free text input for variant selection.
|
|
185
|
+
*
|
|
186
|
+
* @component
|
|
187
|
+
* @example
|
|
188
|
+
* ```tsx
|
|
189
|
+
* // Default usage
|
|
190
|
+
* <Choice.FreeText className="p-3 border rounded-lg" />
|
|
191
|
+
*
|
|
192
|
+
* // asChild with primitive
|
|
193
|
+
* <Choice.FreeText asChild>
|
|
194
|
+
* <textarea className="p-3 border rounded-lg" />
|
|
195
|
+
* </Choice.FreeText>
|
|
196
|
+
*
|
|
197
|
+
* // asChild with react component
|
|
198
|
+
* <Choice.FreeText asChild>
|
|
199
|
+
* {React.forwardRef(({value, onChange, title, ...props}, ref) => (
|
|
200
|
+
* <textarea
|
|
201
|
+
* ref={ref}
|
|
202
|
+
* {...props}
|
|
203
|
+
* className="p-3 border rounded-lg"
|
|
204
|
+
* value={value}
|
|
205
|
+
* onChange={onChange}
|
|
206
|
+
* placeholder={`Enter custom ${title}...`}
|
|
207
|
+
* />
|
|
208
|
+
* ))}
|
|
209
|
+
* </Choice.FreeText>
|
|
210
|
+
* ```
|
|
211
|
+
*
|
|
212
|
+
* Data Attributes:
|
|
213
|
+
* - `data-testid="choice-free-text"` - Applied to free text input
|
|
214
|
+
* - `data-selected` - Is Choice selected
|
|
215
|
+
*/
|
|
216
|
+
export const FreeText = React.forwardRef((props, ref) => {
|
|
217
|
+
const { asChild, children, className } = props;
|
|
218
|
+
const choiceContext = React.useContext(ChoiceContext);
|
|
219
|
+
if (!choiceContext) {
|
|
220
|
+
return null; // Should be used within Option.ChoiceRepeater
|
|
221
|
+
}
|
|
222
|
+
const { choice, shouldRenderAsFreeText, onValueChange, isVisible, isSelected, } = choiceContext;
|
|
223
|
+
// Only render if this should be rendered as free text
|
|
224
|
+
if (!shouldRenderAsFreeText)
|
|
225
|
+
return null;
|
|
226
|
+
// Don't render if not visible (handled by ProductVariantSelector in Root)
|
|
227
|
+
if (!isVisible)
|
|
228
|
+
return null;
|
|
229
|
+
const attributes = {
|
|
230
|
+
'data-testid': TestIds.choiceFreetext,
|
|
231
|
+
'data-selected': isSelected ? 'true' : 'false',
|
|
232
|
+
};
|
|
233
|
+
return (_jsx(FreeTextPrimitive, { modifier: choice, children: ({ value, setText, placeholder, maxChars }) => {
|
|
234
|
+
const handleChange = (e) => {
|
|
235
|
+
setText(e.target.value);
|
|
236
|
+
if (onValueChange) {
|
|
237
|
+
onValueChange(e.target.value);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
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 }));
|
|
258
|
+
} }));
|
|
259
|
+
});
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type AsChildProps } from '../utils/index.js';
|
|
3
|
+
export interface Option {
|
|
4
|
+
name: string;
|
|
5
|
+
choices?: any[];
|
|
6
|
+
hasChoices?: boolean;
|
|
7
|
+
type?: string;
|
|
8
|
+
mandatory?: boolean;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Root props with asChild support
|
|
12
|
+
*/
|
|
13
|
+
export interface RootProps extends AsChildProps<{
|
|
14
|
+
option: Option;
|
|
15
|
+
onValueChange?: (value: string) => void;
|
|
16
|
+
allowedTypes?: ('color' | 'text' | 'free-text')[];
|
|
17
|
+
}> {
|
|
18
|
+
option: Option;
|
|
19
|
+
onValueChange?: (value: string) => void;
|
|
20
|
+
allowedTypes?: ('color' | 'text' | 'free-text')[];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Root component that provides context for variant options.
|
|
24
|
+
* Automatically detects and sets the option type based on the option name and available choices.
|
|
25
|
+
*
|
|
26
|
+
* @component
|
|
27
|
+
*
|
|
28
|
+
* **Data Attributes**
|
|
29
|
+
*
|
|
30
|
+
* - `data-testid="option-root"` - Applied to option container (TestIds.optionRoot)
|
|
31
|
+
* - `data-type` - The type of the option: 'color' | 'text' | 'free-text'
|
|
32
|
+
* @example
|
|
33
|
+
* ```tsx
|
|
34
|
+
* // Color option (data-type="color")
|
|
35
|
+
* <Option.Root
|
|
36
|
+
* option={{ name: "Color" }}
|
|
37
|
+
* onValueChange={(value) => console.log('Selected:', value)}
|
|
38
|
+
* >
|
|
39
|
+
* <Option.Name />
|
|
40
|
+
* <Option.Choices>
|
|
41
|
+
* <Option.ChoiceRepeater>
|
|
42
|
+
* <Choice.Color />
|
|
43
|
+
* </Option.ChoiceRepeater>
|
|
44
|
+
* </Option.Choices>
|
|
45
|
+
* </Option.Root>
|
|
46
|
+
*
|
|
47
|
+
* // Text option (data-type="text")
|
|
48
|
+
* <Option.Root
|
|
49
|
+
* option={{ name: "Size" }}
|
|
50
|
+
* onValueChange={(value) => console.log('Selected:', value)}
|
|
51
|
+
* >
|
|
52
|
+
* <Option.Name />
|
|
53
|
+
* <Option.Choices>
|
|
54
|
+
* <Option.ChoiceRepeater>
|
|
55
|
+
* <Choice.Text />
|
|
56
|
+
* </Option.ChoiceRepeater>
|
|
57
|
+
* </Option.Choices>
|
|
58
|
+
* </Option.Root>
|
|
59
|
+
*
|
|
60
|
+
* // Free text option (data-type="free-text")
|
|
61
|
+
* <Option.Root
|
|
62
|
+
* option={{ name: "Custom Text" }}
|
|
63
|
+
* onValueChange={(value) => console.log('Entered:', value)}
|
|
64
|
+
* >
|
|
65
|
+
* <Option.Name />
|
|
66
|
+
* <Option.Choices>
|
|
67
|
+
* <Option.ChoiceRepeater>
|
|
68
|
+
* <Choice.FreeText />
|
|
69
|
+
* </Option.ChoiceRepeater>
|
|
70
|
+
* </Option.Choices>
|
|
71
|
+
* </Option.Root>
|
|
72
|
+
*
|
|
73
|
+
* // With allowed types filter
|
|
74
|
+
* <Option.Root
|
|
75
|
+
* option={{ name: "Size" }}
|
|
76
|
+
* allowedTypes={['text']}
|
|
77
|
+
* onValueChange={(value) => console.log('Selected size:', value)}
|
|
78
|
+
* >
|
|
79
|
+
* <Option.Name />
|
|
80
|
+
* <Option.Choices>
|
|
81
|
+
* <Option.ChoiceRepeater>
|
|
82
|
+
* <Choice.Text />
|
|
83
|
+
* </Option.ChoiceRepeater>
|
|
84
|
+
* </Option.Choices>
|
|
85
|
+
* </Option.Root>
|
|
86
|
+
*
|
|
87
|
+
* // asChild with react component
|
|
88
|
+
* <Option.Root
|
|
89
|
+
* asChild
|
|
90
|
+
* option={{ name: "Color" }}
|
|
91
|
+
* onValueChange={(value) => console.log('Selected:', value)}
|
|
92
|
+
* >
|
|
93
|
+
* {React.forwardRef(({option, onValueChange, allowedTypes, ...props}, ref) => (
|
|
94
|
+
* <section ref={ref} {...props} className="option-section">
|
|
95
|
+
* <h3>Option: {option.name}</h3>
|
|
96
|
+
* <p>Allowed types: {allowedTypes.join(', ')}</p>
|
|
97
|
+
* {props.children}
|
|
98
|
+
* </section>
|
|
99
|
+
* ))}
|
|
100
|
+
* </Option.Root>
|
|
101
|
+
* ```
|
|
102
|
+
*/
|
|
103
|
+
export declare const Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLElement>>;
|
|
104
|
+
export declare const OptionContext: React.Context<any>;
|
|
105
|
+
/**
|
|
106
|
+
* Props for Option Name component
|
|
107
|
+
*/
|
|
108
|
+
export interface NameProps extends AsChildProps<{
|
|
109
|
+
name: string;
|
|
110
|
+
}> {
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Displays the option name.
|
|
114
|
+
* Follows true Radix pattern - use separate components for each styleable element.
|
|
115
|
+
*
|
|
116
|
+
* @component
|
|
117
|
+
* @example
|
|
118
|
+
* ```tsx
|
|
119
|
+
* // True Radix pattern - separate components
|
|
120
|
+
* <div className="flex items-center gap-1">
|
|
121
|
+
* <Option.Name className="text-lg font-medium" />
|
|
122
|
+
* <Option.MandatoryIndicator className="text-red-500" />
|
|
123
|
+
* </div>
|
|
124
|
+
*
|
|
125
|
+
* // Custom rendering
|
|
126
|
+
* <Option.Name asChild>
|
|
127
|
+
* {React.forwardRef<HTMLElement, { name: string }>(({ name, ...props }, ref) => (
|
|
128
|
+
* <h4 ref={ref} {...props} className="text-lg font-medium text-content-primary">
|
|
129
|
+
* {name}
|
|
130
|
+
* </h4>
|
|
131
|
+
* ))}
|
|
132
|
+
* </Option.Name>
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export declare const Name: React.ForwardRefExoticComponent<NameProps & React.RefAttributes<HTMLElement>>;
|
|
136
|
+
/**
|
|
137
|
+
* Props for Option MandatoryIndicator component
|
|
138
|
+
*/
|
|
139
|
+
export interface MandatoryIndicatorProps extends AsChildProps<{
|
|
140
|
+
mandatory: boolean;
|
|
141
|
+
}> {
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Displays the mandatory indicator (asterisk) when the option is required.
|
|
145
|
+
* Follows true Radix pattern - separate component for each styleable element.
|
|
146
|
+
*
|
|
147
|
+
* @component
|
|
148
|
+
* @example
|
|
149
|
+
* ```tsx
|
|
150
|
+
* // Default usage - only renders if mandatory
|
|
151
|
+
* <Option.MandatoryIndicator className="text-red-500 ml-1" />
|
|
152
|
+
*
|
|
153
|
+
* // Custom rendering
|
|
154
|
+
* <Option.MandatoryIndicator asChild>
|
|
155
|
+
* {React.forwardRef<HTMLElement, { mandatory: boolean }>(({ mandatory, ...props }, ref) => (
|
|
156
|
+
* mandatory ? <span ref={ref} {...props} className="text-red-500">*</span> : null
|
|
157
|
+
* ))}
|
|
158
|
+
* </Option.MandatoryIndicator>
|
|
159
|
+
* ```
|
|
160
|
+
*/
|
|
161
|
+
export declare const MandatoryIndicator: React.ForwardRefExoticComponent<MandatoryIndicatorProps & React.RefAttributes<HTMLElement>>;
|
|
162
|
+
/**
|
|
163
|
+
* Props for Option Choices component
|
|
164
|
+
*/
|
|
165
|
+
export interface ChoicesProps {
|
|
166
|
+
children: React.ReactNode;
|
|
167
|
+
emptyState?: React.ReactNode;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Container for the list items with empty state support.
|
|
171
|
+
* Follows List Container Level pattern (inspired by Product.VariantOptions).
|
|
172
|
+
*
|
|
173
|
+
* @component
|
|
174
|
+
*
|
|
175
|
+
* **Data Attributes**
|
|
176
|
+
*
|
|
177
|
+
* - `data-testid="option-choices"` - Applied to choices container (TestIds.optionChoices)
|
|
178
|
+
* - `data-type` - The type of the option 'color' | 'text' | 'free-text'
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```tsx
|
|
182
|
+
* // Default usage with empty state
|
|
183
|
+
* <Option.Choices emptyState={<div>No choices available</div>}>
|
|
184
|
+
* <Option.ChoiceRepeater>
|
|
185
|
+
* <Choice.Text />
|
|
186
|
+
* <Choice.Color />
|
|
187
|
+
* </Option.ChoiceRepeater>
|
|
188
|
+
* </Option.Choices>
|
|
189
|
+
*
|
|
190
|
+
* // Simple container usage
|
|
191
|
+
* <Option.Choices emptyState={<div>No choices</div>}>
|
|
192
|
+
* <div className="choices-grid">
|
|
193
|
+
* <Option.ChoiceRepeater>
|
|
194
|
+
* <Choice.Text />
|
|
195
|
+
* </Option.ChoiceRepeater>
|
|
196
|
+
* </div>
|
|
197
|
+
* </Option.Choices>
|
|
198
|
+
* ```
|
|
199
|
+
*/
|
|
200
|
+
export declare const Choices: React.ForwardRefExoticComponent<ChoicesProps & React.RefAttributes<HTMLElement>>;
|
|
201
|
+
/**
|
|
202
|
+
* Props for Option ChoiceRepeater component
|
|
203
|
+
*/
|
|
204
|
+
export interface ChoiceRepeaterProps {
|
|
205
|
+
children: React.ReactNode;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Repeater component that renders Choice.Root for each choice.
|
|
209
|
+
* Inspired by Product.VariantOptionRepeater pattern.
|
|
210
|
+
*
|
|
211
|
+
* Now handles ProductVariantSelector.Choice logic and provides ChoiceContext.
|
|
212
|
+
*
|
|
213
|
+
* @component
|
|
214
|
+
*
|
|
215
|
+
* @example
|
|
216
|
+
* ```tsx
|
|
217
|
+
* <Option.ChoiceRepeater>
|
|
218
|
+
* <Choice.Text />
|
|
219
|
+
* <Choice.Color />
|
|
220
|
+
* <Choice.FreeText />
|
|
221
|
+
* </Option.ChoiceRepeater>
|
|
222
|
+
* ```
|
|
223
|
+
*/
|
|
224
|
+
export declare const ChoiceRepeater: React.ForwardRefExoticComponent<ChoiceRepeaterProps & React.RefAttributes<HTMLElement>>;
|