@wix/headless-forms 0.0.1
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/Form.d.ts +632 -0
- package/cjs/dist/react/Form.js +652 -0
- package/cjs/dist/react/constants/calling-country-codes.d.ts +242 -0
- package/cjs/dist/react/constants/calling-country-codes.js +242 -0
- package/cjs/dist/react/core/Form.d.ts +215 -0
- package/cjs/dist/react/core/Form.js +196 -0
- package/cjs/dist/react/index.d.ts +2 -0
- package/cjs/dist/react/index.js +41 -0
- package/cjs/dist/react/types.d.ts +1251 -0
- package/cjs/dist/react/types.js +2 -0
- package/cjs/dist/services/form-service.d.ts +189 -0
- package/cjs/dist/services/form-service.js +141 -0
- package/cjs/dist/services/index.d.ts +1 -0
- package/cjs/dist/services/index.js +17 -0
- package/cjs/package.json +3 -0
- package/dist/react/Form.d.ts +632 -0
- package/dist/react/Form.js +613 -0
- package/dist/react/constants/calling-country-codes.d.ts +242 -0
- package/dist/react/constants/calling-country-codes.js +241 -0
- package/dist/react/core/Form.d.ts +215 -0
- package/dist/react/core/Form.js +189 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.js +2 -0
- package/dist/react/types.d.ts +1251 -0
- package/dist/react/types.js +1 -0
- package/dist/services/form-service.d.ts +189 -0
- package/dist/services/form-service.js +137 -0
- package/dist/services/index.d.ts +1 -0
- package/dist/services/index.js +1 -0
- package/package.json +49 -0
- package/react/package.json +4 -0
- package/services/package.json +4 -0
|
@@ -0,0 +1,632 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type FormServiceConfig } from '../services/form-service';
|
|
3
|
+
import { CheckboxGroupProps, CheckboxProps, PhoneInputProps, DateInputProps, DatePickerProps, DateTimeInputProps, DropdownProps, FileUploadProps, MultilineAddressProps, NumberInputProps, RadioGroupProps, RatingInputProps, RichTextProps, SignatureProps, SubmitButtonProps, TagsProps, TextAreaProps, TextInputProps, TimeInputProps, ProductListProps, FixedPaymentProps, PaymentInputProps, DonationProps, AppointmentProps, ImageChoiceProps } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Props for the Form root component following the documented API
|
|
6
|
+
*/
|
|
7
|
+
export interface RootProps {
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
/** Form service configuration */
|
|
10
|
+
formServiceConfig: FormServiceConfig;
|
|
11
|
+
/** Whether to render as a child component */
|
|
12
|
+
asChild?: boolean;
|
|
13
|
+
/** CSS classes to apply to the root element */
|
|
14
|
+
className?: string;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Root component that provides all necessary service contexts for a complete form experience.
|
|
18
|
+
* This component sets up the Form service and provides context to child components.
|
|
19
|
+
* Must be used as the top-level component for all form functionality.
|
|
20
|
+
*
|
|
21
|
+
* @component
|
|
22
|
+
* @param {RootProps} props - The component props
|
|
23
|
+
* @param {React.ReactNode} props.children - Child components that will have access to form context
|
|
24
|
+
* @param {FormServiceConfig} props.formServiceConfig - Form service configuration object
|
|
25
|
+
* @param {string} [props.className] - CSS classes to apply to the root element
|
|
26
|
+
* @example
|
|
27
|
+
* ```tsx
|
|
28
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
29
|
+
* import { loadFormServiceConfig } from '@wix/headless-forms/services';
|
|
30
|
+
*
|
|
31
|
+
* const FIELD_MAP = {
|
|
32
|
+
* TEXT_INPUT: TextInput,
|
|
33
|
+
* TEXT_AREA: TextArea,
|
|
34
|
+
* CHECKBOX: Checkbox,
|
|
35
|
+
* // ... other field components
|
|
36
|
+
* };
|
|
37
|
+
*
|
|
38
|
+
* // Pattern 1: Pre-loaded form data (SSR/SSG)
|
|
39
|
+
* function FormPage({ formServiceConfig }) {
|
|
40
|
+
* return (
|
|
41
|
+
* <Form.Root formServiceConfig={formServiceConfig}>
|
|
42
|
+
* <Form.Loading className="flex justify-center p-4" />
|
|
43
|
+
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
44
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
45
|
+
* <Form.Error className="text-destructive p-4 rounded-lg mb-4" />
|
|
46
|
+
* <Form.Submitted className="text-green-500 p-4 rounded-lg mb-4" />
|
|
47
|
+
* </Form.Root>
|
|
48
|
+
* );
|
|
49
|
+
* }
|
|
50
|
+
*
|
|
51
|
+
* // Pattern 2: Lazy loading with formId (Client-side)
|
|
52
|
+
* function DynamicFormPage({ formId }) {
|
|
53
|
+
* return (
|
|
54
|
+
* <Form.Root formServiceConfig={{ formId }}>
|
|
55
|
+
* <Form.Loading className="flex justify-center p-4" />
|
|
56
|
+
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
57
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
58
|
+
* <Form.Error className="text-destructive p-4 rounded-lg mb-4" />
|
|
59
|
+
* <Form.Submitted className="text-green-500 p-4 rounded-lg mb-4" />
|
|
60
|
+
* </Form.Root>
|
|
61
|
+
* );
|
|
62
|
+
* }
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
export declare const Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLDivElement>>;
|
|
66
|
+
/**
|
|
67
|
+
* Props for Form Loading component
|
|
68
|
+
*/
|
|
69
|
+
export interface LoadingProps {
|
|
70
|
+
/** Whether to render as a child component */
|
|
71
|
+
asChild?: boolean;
|
|
72
|
+
/** Content to display during loading state (can be a ReactNode) */
|
|
73
|
+
children?: React.ReactNode;
|
|
74
|
+
/** CSS classes to apply to the default element */
|
|
75
|
+
className?: string;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Component that renders content during loading state.
|
|
79
|
+
* Only displays its children when the form is currently loading.
|
|
80
|
+
*
|
|
81
|
+
* @component
|
|
82
|
+
* @param {LoadingProps} props - The component props
|
|
83
|
+
* @param {boolean} [props.asChild] - Whether to render as a child component
|
|
84
|
+
* @param {React.ReactNode} [props.children] - Content to display during loading state
|
|
85
|
+
* @param {string} [props.className] - CSS classes to apply to the default element
|
|
86
|
+
* @example
|
|
87
|
+
* ```tsx
|
|
88
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
89
|
+
*
|
|
90
|
+
* // Default usage with className
|
|
91
|
+
* function FormLoading() {
|
|
92
|
+
* return (
|
|
93
|
+
* <Form.Loading className="flex justify-center p-4" />
|
|
94
|
+
* );
|
|
95
|
+
* }
|
|
96
|
+
*
|
|
97
|
+
* // Custom content
|
|
98
|
+
* function CustomFormLoading() {
|
|
99
|
+
* return (
|
|
100
|
+
* <Form.Loading>
|
|
101
|
+
* <div className="flex justify-center items-center p-4">
|
|
102
|
+
* <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
|
103
|
+
* <span className="ml-2 text-foreground font-paragraph">Loading form...</span>
|
|
104
|
+
* </div>
|
|
105
|
+
* </Form.Loading>
|
|
106
|
+
* );
|
|
107
|
+
* }
|
|
108
|
+
*
|
|
109
|
+
* // With asChild for custom components
|
|
110
|
+
* function CustomFormLoadingAsChild() {
|
|
111
|
+
* return (
|
|
112
|
+
* <Form.Loading asChild>
|
|
113
|
+
* <div className="custom-loading-container">
|
|
114
|
+
* <div className="animate-spin rounded-full h-8 w-8 border-b-2 border-primary"></div>
|
|
115
|
+
* <span className="ml-2 text-foreground font-paragraph">Loading form...</span>
|
|
116
|
+
* </div>
|
|
117
|
+
* </Form.Loading>
|
|
118
|
+
* );
|
|
119
|
+
* }
|
|
120
|
+
* ```
|
|
121
|
+
*/
|
|
122
|
+
export declare const Loading: React.ForwardRefExoticComponent<LoadingProps & React.RefAttributes<HTMLElement>>;
|
|
123
|
+
/**
|
|
124
|
+
* Props for Form LoadingError component
|
|
125
|
+
*/
|
|
126
|
+
export interface LoadingErrorProps {
|
|
127
|
+
/** Whether to render as a child component */
|
|
128
|
+
asChild?: boolean;
|
|
129
|
+
/** Content to display during error state (can be a ReactNode) */
|
|
130
|
+
children?: React.ReactNode;
|
|
131
|
+
/** CSS classes to apply to the default element */
|
|
132
|
+
className?: string;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Component that renders content when there's an error loading the form.
|
|
136
|
+
* Only displays its children when an error has occurred.
|
|
137
|
+
*
|
|
138
|
+
* @component
|
|
139
|
+
* @param {LoadingErrorProps} props - The component props
|
|
140
|
+
* @param {boolean} [props.asChild] - Whether to render as a child component
|
|
141
|
+
* @param {React.ReactNode} [props.children] - Content to display during error state
|
|
142
|
+
* @param {string} [props.className] - CSS classes to apply to the default element
|
|
143
|
+
* @example
|
|
144
|
+
* ```tsx
|
|
145
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
146
|
+
*
|
|
147
|
+
* // Default usage with className
|
|
148
|
+
* function FormLoadingError() {
|
|
149
|
+
* return (
|
|
150
|
+
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
151
|
+
* );
|
|
152
|
+
* }
|
|
153
|
+
*
|
|
154
|
+
* // Custom content
|
|
155
|
+
* function CustomLoadingError() {
|
|
156
|
+
* return (
|
|
157
|
+
* <Form.LoadingError>
|
|
158
|
+
* <div className="bg-destructive/10 border border-destructive text-destructive px-4 py-3 rounded mb-4">
|
|
159
|
+
* <h3 className="font-heading text-lg">Error loading form</h3>
|
|
160
|
+
* <p className="font-paragraph">Something went wrong. Please try again.</p>
|
|
161
|
+
* </div>
|
|
162
|
+
* </Form.LoadingError>
|
|
163
|
+
* );
|
|
164
|
+
* }
|
|
165
|
+
*
|
|
166
|
+
* // With asChild for custom components
|
|
167
|
+
* function CustomLoadingErrorAsChild() {
|
|
168
|
+
* return (
|
|
169
|
+
* <Form.LoadingError asChild>
|
|
170
|
+
* {React.forwardRef<HTMLDivElement, { error: string | null; hasError: boolean }>(
|
|
171
|
+
* ({ error }, ref) => (
|
|
172
|
+
* <div ref={ref} className="custom-error-container">
|
|
173
|
+
* <h3 className="font-heading">Error Loading Form</h3>
|
|
174
|
+
* <p className="font-paragraph">{error}</p>
|
|
175
|
+
* </div>
|
|
176
|
+
* )
|
|
177
|
+
* )}
|
|
178
|
+
* </Form.LoadingError>
|
|
179
|
+
* );
|
|
180
|
+
* }
|
|
181
|
+
* ```
|
|
182
|
+
*/
|
|
183
|
+
export declare const LoadingError: React.ForwardRefExoticComponent<LoadingErrorProps & React.RefAttributes<HTMLElement>>;
|
|
184
|
+
/**
|
|
185
|
+
* Props for Form Error component
|
|
186
|
+
*/
|
|
187
|
+
export interface ErrorProps {
|
|
188
|
+
/** Whether to render as a child component */
|
|
189
|
+
asChild?: boolean;
|
|
190
|
+
/** Content to display during submit error state (can be a ReactNode) */
|
|
191
|
+
children?: React.ReactNode;
|
|
192
|
+
/** CSS classes to apply to the default element */
|
|
193
|
+
className?: string;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Component that renders content when there's an error during form submission.
|
|
197
|
+
* Only displays its children when a submission error has occurred.
|
|
198
|
+
*
|
|
199
|
+
* @component
|
|
200
|
+
* @param {ErrorProps} props - The component props
|
|
201
|
+
* @param {boolean} [props.asChild] - Whether to render as a child component
|
|
202
|
+
* @param {React.ReactNode} [props.children] - Content to display during submit error state
|
|
203
|
+
* @param {string} [props.className] - CSS classes to apply to the default element
|
|
204
|
+
* @example
|
|
205
|
+
* ```tsx
|
|
206
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
207
|
+
*
|
|
208
|
+
* // Default usage with className
|
|
209
|
+
* function FormError() {
|
|
210
|
+
* return <Form.Error className="text-destructive p-4 rounded-lg mb-4" />;
|
|
211
|
+
* }
|
|
212
|
+
*
|
|
213
|
+
* // Custom content
|
|
214
|
+
* function CustomFormError() {
|
|
215
|
+
* return (
|
|
216
|
+
* <Form.Error>
|
|
217
|
+
* <div className="bg-destructive/10 border border-destructive text-destructive p-4 rounded-lg mb-4">
|
|
218
|
+
* <h3 className="font-heading text-lg">Submission Failed</h3>
|
|
219
|
+
* <p className="font-paragraph">Please check your input and try again.</p>
|
|
220
|
+
* </div>
|
|
221
|
+
* </Form.Error>
|
|
222
|
+
* );
|
|
223
|
+
* }
|
|
224
|
+
*
|
|
225
|
+
* // With asChild for custom components
|
|
226
|
+
* function CustomFormErrorAsChild() {
|
|
227
|
+
* return (
|
|
228
|
+
* <Form.Error asChild>
|
|
229
|
+
* {React.forwardRef<HTMLDivElement, { error: string | null; hasError: boolean }>(
|
|
230
|
+
* ({ error }, ref) => (
|
|
231
|
+
* <div ref={ref} className="custom-error-container">
|
|
232
|
+
* <h3 className="font-heading">Submission Failed</h3>
|
|
233
|
+
* <p className="font-paragraph">{error}</p>
|
|
234
|
+
* </div>
|
|
235
|
+
* )
|
|
236
|
+
* )}
|
|
237
|
+
* </Form.Error>
|
|
238
|
+
* );
|
|
239
|
+
* }
|
|
240
|
+
* ```
|
|
241
|
+
*/
|
|
242
|
+
export declare const Error: React.ForwardRefExoticComponent<ErrorProps & React.RefAttributes<HTMLElement>>;
|
|
243
|
+
/**
|
|
244
|
+
* Props for Form Submitted component
|
|
245
|
+
*/
|
|
246
|
+
export interface SubmittedProps {
|
|
247
|
+
/** Whether to render as a child component */
|
|
248
|
+
asChild?: boolean;
|
|
249
|
+
/** Content to display after successful submission (can be a ReactNode) */
|
|
250
|
+
children?: React.ReactNode;
|
|
251
|
+
/** CSS classes to apply to the default element */
|
|
252
|
+
className?: string;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Component that renders content after successful form submission.
|
|
256
|
+
* Only displays its children when the form has been successfully submitted.
|
|
257
|
+
*
|
|
258
|
+
* @component
|
|
259
|
+
* @param {SubmittedProps} props - The component props
|
|
260
|
+
* @param {boolean} [props.asChild] - Whether to render as a child component
|
|
261
|
+
* @param {React.ReactNode} [props.children] - Content to display after successful submission
|
|
262
|
+
* @param {string} [props.className] - CSS classes to apply to the default element
|
|
263
|
+
* @example
|
|
264
|
+
* ```tsx
|
|
265
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
266
|
+
*
|
|
267
|
+
* // Default usage with className
|
|
268
|
+
* function FormSubmitted() {
|
|
269
|
+
* return <Form.Submitted className="text-green-500 p-4 rounded-lg mb-4" />;
|
|
270
|
+
* }
|
|
271
|
+
*
|
|
272
|
+
* // Custom content
|
|
273
|
+
* function CustomFormSubmitted() {
|
|
274
|
+
* return (
|
|
275
|
+
* <Form.Submitted>
|
|
276
|
+
* <div className="bg-green-50 border border-green-200 text-green-800 p-6 rounded-lg mb-4">
|
|
277
|
+
* <h2 className="font-heading text-xl mb-2">Thank You!</h2>
|
|
278
|
+
* <p className="font-paragraph">Your form has been submitted successfully.</p>
|
|
279
|
+
* </div>
|
|
280
|
+
* </Form.Submitted>
|
|
281
|
+
* );
|
|
282
|
+
* }
|
|
283
|
+
*
|
|
284
|
+
* // With asChild for custom components
|
|
285
|
+
* function CustomFormSubmittedAsChild() {
|
|
286
|
+
* return (
|
|
287
|
+
* <Form.Submitted asChild>
|
|
288
|
+
* {React.forwardRef<HTMLDivElement, { isSubmitted: boolean; message: string }>(
|
|
289
|
+
* ({ message }, ref) => (
|
|
290
|
+
* <div ref={ref} className="custom-success-container">
|
|
291
|
+
* <h2 className="font-heading">Thank You!</h2>
|
|
292
|
+
* <p className="font-paragraph">{message}</p>
|
|
293
|
+
* </div>
|
|
294
|
+
* )
|
|
295
|
+
* )}
|
|
296
|
+
* </Form.Submitted>
|
|
297
|
+
* );
|
|
298
|
+
* }
|
|
299
|
+
* ```
|
|
300
|
+
*/
|
|
301
|
+
export declare const Submitted: React.ForwardRefExoticComponent<SubmittedProps & React.RefAttributes<HTMLElement>>;
|
|
302
|
+
/**
|
|
303
|
+
* Mapping of form field types to their corresponding React components.
|
|
304
|
+
*
|
|
305
|
+
* Each key represents a field type identifier that matches the field types defined
|
|
306
|
+
* in the form configuration, and each value is a React component that will receive
|
|
307
|
+
* the field's props and render the appropriate UI element.
|
|
308
|
+
*
|
|
309
|
+
* The field components must accept the corresponding props interface for their field type.
|
|
310
|
+
* For example, TEXT_INPUT components should accept TextInputProps, CHECKBOX components
|
|
311
|
+
* should accept CheckboxProps, etc.
|
|
312
|
+
*
|
|
313
|
+
* @interface FieldMap
|
|
314
|
+
* @property {React.ComponentType<TextInputProps>} TEXT_INPUT - Component for single-line text input fields
|
|
315
|
+
* @property {React.ComponentType<TextAreaProps>} TEXT_AREA - Component for multi-line text input fields
|
|
316
|
+
* @property {React.ComponentType<PhoneInputProps>} PHONE_INPUT - Component for phone number input fields
|
|
317
|
+
* @property {React.ComponentType<MultilineAddressProps>} MULTILINE_ADDRESS - Component for complex address input fields
|
|
318
|
+
* @property {React.ComponentType<DateInputProps>} DATE_INPUT - Component for date input fields (day/month/year)
|
|
319
|
+
* @property {React.ComponentType<DatePickerProps>} DATE_PICKER - Component for calendar-based date selection
|
|
320
|
+
* @property {React.ComponentType<DateTimeInputProps>} DATE_TIME_INPUT - Component for combined date and time input
|
|
321
|
+
* @property {React.ComponentType<FileUploadProps>} FILE_UPLOAD - Component for file upload fields
|
|
322
|
+
* @property {React.ComponentType<NumberInputProps>} NUMBER_INPUT - Component for numerical input fields
|
|
323
|
+
* @property {React.ComponentType<CheckboxProps>} CHECKBOX - Component for boolean checkbox fields
|
|
324
|
+
* @property {React.ComponentType<SignatureProps>} SIGNATURE - Component for digital signature capture
|
|
325
|
+
* @property {React.ComponentType<RatingInputProps>} RATING_INPUT - Component for 1-5 star rating input
|
|
326
|
+
* @property {React.ComponentType<RadioGroupProps>} RADIO_GROUP - Component for single selection from multiple options
|
|
327
|
+
* @property {React.ComponentType<CheckboxGroupProps>} CHECKBOX_GROUP - Component for multiple selection from multiple options
|
|
328
|
+
* @property {React.ComponentType<DropdownProps>} DROPDOWN - Component for dropdown selection fields
|
|
329
|
+
* @property {React.ComponentType<TagsProps>} TAGS - Component for tag-based selection fields
|
|
330
|
+
* @property {React.ComponentType<TimeInputProps>} TIME_INPUT - Component for time-only input fields
|
|
331
|
+
* @property {React.ComponentType<RichTextProps>} TEXT - Component for rich text display fields
|
|
332
|
+
* @property {React.ComponentType<SubmitButtonProps>} SUBMIT_BUTTON - Component for form submission button
|
|
333
|
+
* @property {React.ComponentType<ProductListProps>} PRODUCT_LIST - Component for product selection fields
|
|
334
|
+
* @property {React.ComponentType<FixedPaymentProps>} FIXED_PAYMENT - Component for fixed payment amount display
|
|
335
|
+
* @property {React.ComponentType<PaymentInputProps>} PAYMENT_INPUT - Component for custom payment amount input
|
|
336
|
+
* @property {React.ComponentType<DonationProps>} DONATION - Component for donation amount selection
|
|
337
|
+
* @property {React.ComponentType<AppointmentProps>} APPOINTMENT - Component for appointment scheduling
|
|
338
|
+
* @property {React.ComponentType<ImageChoiceProps>} IMAGE_CHOICE - Component for image-based selection
|
|
339
|
+
*
|
|
340
|
+
* @example
|
|
341
|
+
* ```tsx
|
|
342
|
+
* const FIELD_MAP: FieldMap = {
|
|
343
|
+
* TEXT_INPUT: TextInput,
|
|
344
|
+
* TEXT_AREA: TextArea,
|
|
345
|
+
* PHONE_INPUT: PhoneInput,
|
|
346
|
+
* MULTILINE_ADDRESS: MultilineAddress,
|
|
347
|
+
* DATE_INPUT: DateInput,
|
|
348
|
+
* DATE_PICKER: DatePicker,
|
|
349
|
+
* DATE_TIME_INPUT: DateTimeInput,
|
|
350
|
+
* FILE_UPLOAD: FileUpload,
|
|
351
|
+
* NUMBER_INPUT: NumberInput,
|
|
352
|
+
* CHECKBOX: Checkbox,
|
|
353
|
+
* SIGNATURE: Signature,
|
|
354
|
+
* RATING_INPUT: RatingInput,
|
|
355
|
+
* RADIO_GROUP: RadioGroup,
|
|
356
|
+
* CHECKBOX_GROUP: CheckboxGroup,
|
|
357
|
+
* DROPDOWN: Dropdown,
|
|
358
|
+
* TAGS: Tags,
|
|
359
|
+
* TIME_INPUT: TimeInput,
|
|
360
|
+
* TEXT: RichText,
|
|
361
|
+
* SUBMIT_BUTTON: SubmitButton,
|
|
362
|
+
* PRODUCT_LIST: ProductList,
|
|
363
|
+
* FIXED_PAYMENT: FixedPayment,
|
|
364
|
+
* PAYMENT_INPUT: PaymentInput,
|
|
365
|
+
* DONATION: Donation,
|
|
366
|
+
* APPOINTMENT: Appointment,
|
|
367
|
+
* IMAGE_CHOICE: ImageChoice,
|
|
368
|
+
* };
|
|
369
|
+
* ```
|
|
370
|
+
*/
|
|
371
|
+
interface FieldMap {
|
|
372
|
+
TEXT_INPUT: React.ComponentType<TextInputProps>;
|
|
373
|
+
TEXT_AREA: React.ComponentType<TextAreaProps>;
|
|
374
|
+
PHONE_INPUT: React.ComponentType<PhoneInputProps>;
|
|
375
|
+
MULTILINE_ADDRESS: React.ComponentType<MultilineAddressProps>;
|
|
376
|
+
DATE_INPUT: React.ComponentType<DateInputProps>;
|
|
377
|
+
DATE_PICKER: React.ComponentType<DatePickerProps>;
|
|
378
|
+
DATE_TIME_INPUT: React.ComponentType<DateTimeInputProps>;
|
|
379
|
+
FILE_UPLOAD: React.ComponentType<FileUploadProps>;
|
|
380
|
+
NUMBER_INPUT: React.ComponentType<NumberInputProps>;
|
|
381
|
+
CHECKBOX: React.ComponentType<CheckboxProps>;
|
|
382
|
+
SIGNATURE: React.ComponentType<SignatureProps>;
|
|
383
|
+
RATING_INPUT: React.ComponentType<RatingInputProps>;
|
|
384
|
+
RADIO_GROUP: React.ComponentType<RadioGroupProps>;
|
|
385
|
+
CHECKBOX_GROUP: React.ComponentType<CheckboxGroupProps>;
|
|
386
|
+
DROPDOWN: React.ComponentType<DropdownProps>;
|
|
387
|
+
TAGS: React.ComponentType<TagsProps>;
|
|
388
|
+
TIME_INPUT: React.ComponentType<TimeInputProps>;
|
|
389
|
+
TEXT: React.ComponentType<RichTextProps>;
|
|
390
|
+
SUBMIT_BUTTON: React.ComponentType<SubmitButtonProps>;
|
|
391
|
+
PRODUCT_LIST: React.ComponentType<ProductListProps>;
|
|
392
|
+
FIXED_PAYMENT: React.ComponentType<FixedPaymentProps>;
|
|
393
|
+
PAYMENT_INPUT: React.ComponentType<PaymentInputProps>;
|
|
394
|
+
DONATION: React.ComponentType<DonationProps>;
|
|
395
|
+
APPOINTMENT: React.ComponentType<AppointmentProps>;
|
|
396
|
+
IMAGE_CHOICE: React.ComponentType<ImageChoiceProps>;
|
|
397
|
+
}
|
|
398
|
+
/**
|
|
399
|
+
* Props for the Form Fields component.
|
|
400
|
+
*
|
|
401
|
+
* @interface FieldsProps
|
|
402
|
+
* @property {FieldMap} fieldMap - A mapping of field types to their corresponding React components
|
|
403
|
+
* @example
|
|
404
|
+
* ```tsx
|
|
405
|
+
* const FIELD_MAP = {
|
|
406
|
+
* TEXT_INPUT: TextInput,
|
|
407
|
+
* TEXT_AREA: TextArea,
|
|
408
|
+
* NUMBER_INPUT: NumberInput,
|
|
409
|
+
* CHECKBOX: Checkbox,
|
|
410
|
+
* RADIO_GROUP: RadioGroup,
|
|
411
|
+
* CHECKBOX_GROUP: CheckboxGroup,
|
|
412
|
+
* DROPDOWN: Dropdown,
|
|
413
|
+
* // ... remaining field components
|
|
414
|
+
* };
|
|
415
|
+
*
|
|
416
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
417
|
+
* ```
|
|
418
|
+
*/
|
|
419
|
+
export interface FieldsProps {
|
|
420
|
+
fieldMap: FieldMap;
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Fields component for rendering a form with custom field renderers.
|
|
424
|
+
* This component handles the rendering of form fields based on the provided fieldMap.
|
|
425
|
+
* Must be used within Form.Root to access form context.
|
|
426
|
+
*
|
|
427
|
+
* @component
|
|
428
|
+
* @param {FieldsProps} props - Component props
|
|
429
|
+
* @param {FieldMap} props.fieldMap - A mapping of field types to their corresponding React components
|
|
430
|
+
* @example
|
|
431
|
+
* ```tsx
|
|
432
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
433
|
+
* import { TextInput, TextArea, Checkbox } from './field-components';
|
|
434
|
+
*
|
|
435
|
+
* const FIELD_MAP = {
|
|
436
|
+
* TEXT_INPUT: TextInput,
|
|
437
|
+
* TEXT_AREA: TextArea,
|
|
438
|
+
* CHECKBOX: Checkbox,
|
|
439
|
+
* NUMBER_INPUT: NumberInput,
|
|
440
|
+
* // ... remaining field components
|
|
441
|
+
* };
|
|
442
|
+
*
|
|
443
|
+
* function ContactForm({ formServiceConfig }) {
|
|
444
|
+
* return (
|
|
445
|
+
* <Form.Root formServiceConfig={formServiceConfig}>
|
|
446
|
+
* <Form.Loading className="flex justify-center p-4" />
|
|
447
|
+
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
448
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
449
|
+
* </Form.Root>
|
|
450
|
+
* );
|
|
451
|
+
* }
|
|
452
|
+
* ```
|
|
453
|
+
*/
|
|
454
|
+
/**
|
|
455
|
+
* Fields component for rendering a form with custom field renderers.
|
|
456
|
+
* It maps each field type from the form configuration to its corresponding React component
|
|
457
|
+
* and renders them in the order and layout defined by the form structure.
|
|
458
|
+
*
|
|
459
|
+
* The component automatically handles:
|
|
460
|
+
* - Field validation and error display
|
|
461
|
+
* - Form state management
|
|
462
|
+
* - Field value updates
|
|
463
|
+
*
|
|
464
|
+
* Must be used within Form.Root to access form context.
|
|
465
|
+
*
|
|
466
|
+
* @component
|
|
467
|
+
* @param {FieldsProps} props - The component props
|
|
468
|
+
* @param {FieldMap} props.fieldMap - A mapping of field types to their corresponding React components. Each key represents a field type (e.g., 'TEXT_INPUT', 'CHECKBOX') and the value is the React component that should render that field type.
|
|
469
|
+
*
|
|
470
|
+
* @example
|
|
471
|
+
* ```tsx
|
|
472
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
473
|
+
* import { loadFormServiceConfig } from '@wix/headless-forms/services';
|
|
474
|
+
* import {
|
|
475
|
+
* TextInput,
|
|
476
|
+
* TextArea,
|
|
477
|
+
* PhoneInput,
|
|
478
|
+
* MultilineAddress,
|
|
479
|
+
* DateInput,
|
|
480
|
+
* DatePicker,
|
|
481
|
+
* DateTimeInput,
|
|
482
|
+
* FileUpload,
|
|
483
|
+
* NumberInput,
|
|
484
|
+
* Checkbox,
|
|
485
|
+
* Signature,
|
|
486
|
+
* RatingInput,
|
|
487
|
+
* RadioGroup,
|
|
488
|
+
* CheckboxGroup,
|
|
489
|
+
* Dropdown,
|
|
490
|
+
* Tags,
|
|
491
|
+
* TimeInput,
|
|
492
|
+
* RichText,
|
|
493
|
+
* SubmitButton,
|
|
494
|
+
* ProductList,
|
|
495
|
+
* FixedPayment,
|
|
496
|
+
* PaymentInput,
|
|
497
|
+
* Donation,
|
|
498
|
+
* Appointment,
|
|
499
|
+
* ImageChoice
|
|
500
|
+
* } from './components';
|
|
501
|
+
*
|
|
502
|
+
* // Define your field mapping - this tells the Fields component which React component to use for each field type
|
|
503
|
+
* const FIELD_MAP = {
|
|
504
|
+
* TEXT_INPUT: TextInput,
|
|
505
|
+
* TEXT_AREA: TextArea,
|
|
506
|
+
* PHONE_INPUT: PhoneInput,
|
|
507
|
+
* MULTILINE_ADDRESS: MultilineAddress,
|
|
508
|
+
* DATE_INPUT: DateInput,
|
|
509
|
+
* DATE_PICKER: DatePicker,
|
|
510
|
+
* DATE_TIME_INPUT: DateTimeInput,
|
|
511
|
+
* FILE_UPLOAD: FileUpload,
|
|
512
|
+
* NUMBER_INPUT: NumberInput,
|
|
513
|
+
* CHECKBOX: Checkbox,
|
|
514
|
+
* SIGNATURE: Signature,
|
|
515
|
+
* RATING_INPUT: RatingInput,
|
|
516
|
+
* RADIO_GROUP: RadioGroup,
|
|
517
|
+
* CHECKBOX_GROUP: CheckboxGroup,
|
|
518
|
+
* DROPDOWN: Dropdown,
|
|
519
|
+
* TAGS: Tags,
|
|
520
|
+
* TIME_INPUT: TimeInput,
|
|
521
|
+
* TEXT: RichText,
|
|
522
|
+
* SUBMIT_BUTTON: SubmitButton,
|
|
523
|
+
* PRODUCT_LIST: ProductList,
|
|
524
|
+
* FIXED_PAYMENT: FixedPayment,
|
|
525
|
+
* PAYMENT_INPUT: PaymentInput,
|
|
526
|
+
* DONATION: Donation,
|
|
527
|
+
* APPOINTMENT: Appointment,
|
|
528
|
+
* IMAGE_CHOICE: ImageChoice,
|
|
529
|
+
* };
|
|
530
|
+
*
|
|
531
|
+
* function ContactForm({ formServiceConfig }) {
|
|
532
|
+
* return (
|
|
533
|
+
* <Form.Root formServiceConfig={formServiceConfig}>
|
|
534
|
+
* <Form.Loading className="flex justify-center p-4" />
|
|
535
|
+
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
536
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
537
|
+
* <Form.Error className="text-destructive p-4 rounded-lg mb-4" />
|
|
538
|
+
* <Form.Submitted className="text-green-500 p-4 rounded-lg mb-4" />
|
|
539
|
+
* </Form.Root>
|
|
540
|
+
* );
|
|
541
|
+
* }
|
|
542
|
+
* ```
|
|
543
|
+
*
|
|
544
|
+
* @example
|
|
545
|
+
* ```tsx
|
|
546
|
+
* // Advanced usage with custom field components
|
|
547
|
+
* const CustomTextField = ({ value, onChange, label, error, ...props }) => (
|
|
548
|
+
* <div className="form-field">
|
|
549
|
+
* <label className="text-foreground font-paragraph">{label}</label>
|
|
550
|
+
* <input
|
|
551
|
+
* value={value || ''}
|
|
552
|
+
* onChange={(e) => onChange(e.target.value)}
|
|
553
|
+
* className="bg-background border-foreground text-foreground"
|
|
554
|
+
* {...props}
|
|
555
|
+
* />
|
|
556
|
+
* {error && <span className="text-destructive">{error}</span>}
|
|
557
|
+
* </div>
|
|
558
|
+
* );
|
|
559
|
+
*
|
|
560
|
+
* const FIELD_MAP = {
|
|
561
|
+
* TEXT_INPUT: CustomTextField,
|
|
562
|
+
* // ... other field components
|
|
563
|
+
* };
|
|
564
|
+
* ```
|
|
565
|
+
*/
|
|
566
|
+
export declare const Fields: React.ForwardRefExoticComponent<FieldsProps & React.RefAttributes<HTMLElement>>;
|
|
567
|
+
/**
|
|
568
|
+
* Main Form namespace containing all form components following the compound component pattern.
|
|
569
|
+
* Provides a headless, flexible way to render and manage forms with custom field components.
|
|
570
|
+
*
|
|
571
|
+
* @namespace Form
|
|
572
|
+
* @property {typeof Root} Root - Form root component that provides service context to all child components
|
|
573
|
+
* @property {typeof Loading} Loading - Form loading state component that displays content during form loading
|
|
574
|
+
* @property {typeof LoadingError} LoadingError - Form loading error state component for handling form loading errors
|
|
575
|
+
* @property {typeof Error} Error - Form submit error state component for handling form submission errors
|
|
576
|
+
* @property {typeof Submitted} Submitted - Form submitted state component for displaying success messages
|
|
577
|
+
* @property {typeof Fields} Fields - Form fields component for rendering form fields with custom field renderers
|
|
578
|
+
* @example
|
|
579
|
+
* ```tsx
|
|
580
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
581
|
+
* import { loadFormServiceConfig } from '@wix/headless-forms/services';
|
|
582
|
+
* import { TextInput, TextArea, Checkbox } from './field-components';
|
|
583
|
+
*
|
|
584
|
+
* const FIELD_MAP = {
|
|
585
|
+
* TEXT_INPUT: TextInput,
|
|
586
|
+
* TEXT_AREA: TextArea,
|
|
587
|
+
* CHECKBOX: Checkbox,
|
|
588
|
+
* // ... other field components
|
|
589
|
+
* };
|
|
590
|
+
*
|
|
591
|
+
* // Pattern 1: Pre-loaded form data (SSR/SSG)
|
|
592
|
+
* function MyForm({ formServiceConfig }) {
|
|
593
|
+
* return (
|
|
594
|
+
* <Form.Root formServiceConfig={formServiceConfig}>
|
|
595
|
+
* <Form.Loading className="flex justify-center p-4" />
|
|
596
|
+
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
597
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
598
|
+
* <Form.Error className="text-destructive p-4 rounded-lg mb-4" />
|
|
599
|
+
* <Form.Submitted className="text-green-500 p-4 rounded-lg mb-4" />
|
|
600
|
+
* </Form.Root>
|
|
601
|
+
* );
|
|
602
|
+
* }
|
|
603
|
+
*
|
|
604
|
+
* // Pattern 2: Lazy loading with formId (Client-side)
|
|
605
|
+
* function DynamicForm({ formId }) {
|
|
606
|
+
* return (
|
|
607
|
+
* <Form.Root formServiceConfig={{ formId }}>
|
|
608
|
+
* <Form.Loading className="flex justify-center p-4" />
|
|
609
|
+
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
610
|
+
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
611
|
+
* <Form.Error className="text-destructive p-4 rounded-lg mb-4" />
|
|
612
|
+
* <Form.Submitted className="text-green-500 p-4 rounded-lg mb-4" />
|
|
613
|
+
* </Form.Root>
|
|
614
|
+
* );
|
|
615
|
+
* }
|
|
616
|
+
* ```
|
|
617
|
+
*/
|
|
618
|
+
export declare const Form: {
|
|
619
|
+
/** Form root component that provides service context */
|
|
620
|
+
readonly Root: React.ForwardRefExoticComponent<RootProps & React.RefAttributes<HTMLDivElement>>;
|
|
621
|
+
/** Form loading state component */
|
|
622
|
+
readonly Loading: React.ForwardRefExoticComponent<LoadingProps & React.RefAttributes<HTMLElement>>;
|
|
623
|
+
/** Form loading error state component */
|
|
624
|
+
readonly LoadingError: React.ForwardRefExoticComponent<LoadingErrorProps & React.RefAttributes<HTMLElement>>;
|
|
625
|
+
/** Form error state component */
|
|
626
|
+
readonly Error: React.ForwardRefExoticComponent<ErrorProps & React.RefAttributes<HTMLElement>>;
|
|
627
|
+
/** Form submitted state component */
|
|
628
|
+
readonly Submitted: React.ForwardRefExoticComponent<SubmittedProps & React.RefAttributes<HTMLElement>>;
|
|
629
|
+
/** Form fields component for rendering form fields */
|
|
630
|
+
readonly Fields: React.ForwardRefExoticComponent<FieldsProps & React.RefAttributes<HTMLElement>>;
|
|
631
|
+
};
|
|
632
|
+
export {};
|