@wix/headless-forms 0.0.10 → 0.0.12
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 +235 -18
- package/cjs/dist/react/Form.js +251 -19
- package/cjs/dist/react/context/FieldContext.d.ts +12 -0
- package/cjs/dist/react/context/FieldContext.js +16 -0
- package/cjs/dist/react/context/FieldLayoutContext.d.ts +12 -0
- package/cjs/dist/react/context/FieldLayoutContext.js +21 -0
- package/cjs/dist/react/core/Form.d.ts +80 -5
- package/cjs/dist/react/core/Form.js +41 -0
- package/cjs/dist/react/utils.d.ts +13 -0
- package/cjs/dist/react/utils.js +20 -0
- package/cjs/dist/services/form-service.d.ts +2 -0
- package/cjs/dist/services/form-service.js +5 -2
- package/dist/react/Form.d.ts +235 -18
- package/dist/react/Form.js +252 -20
- package/dist/react/context/FieldContext.d.ts +12 -0
- package/dist/react/context/FieldContext.js +9 -0
- package/dist/react/context/FieldLayoutContext.d.ts +12 -0
- package/dist/react/context/FieldLayoutContext.js +13 -0
- package/dist/react/core/Form.d.ts +80 -5
- package/dist/react/core/Form.js +40 -0
- package/dist/react/utils.d.ts +13 -0
- package/dist/react/utils.js +17 -0
- package/dist/services/form-service.d.ts +2 -0
- package/dist/services/form-service.js +5 -2
- package/package.json +3 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FieldContext = void 0;
|
|
7
|
+
exports.useFieldContext = useFieldContext;
|
|
8
|
+
const react_1 = __importDefault(require("react"));
|
|
9
|
+
exports.FieldContext = react_1.default.createContext(null);
|
|
10
|
+
function useFieldContext() {
|
|
11
|
+
const context = react_1.default.useContext(exports.FieldContext);
|
|
12
|
+
if (!context) {
|
|
13
|
+
throw new Error('Field components must be used within a Form.Field component');
|
|
14
|
+
}
|
|
15
|
+
return context;
|
|
16
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { type Layout } from '../core/Form.js';
|
|
3
|
+
export interface FieldLayoutMap {
|
|
4
|
+
[fieldId: string]: Layout;
|
|
5
|
+
}
|
|
6
|
+
export declare const FieldLayoutContext: React.Context<FieldLayoutMap | null>;
|
|
7
|
+
export interface FieldLayoutProviderProps {
|
|
8
|
+
value: FieldLayoutMap;
|
|
9
|
+
children: React.ReactNode;
|
|
10
|
+
}
|
|
11
|
+
export declare const FieldLayoutProvider: React.FC<FieldLayoutProviderProps>;
|
|
12
|
+
export declare function useFieldLayout(fieldId: string): Layout | null;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.FieldLayoutProvider = exports.FieldLayoutContext = void 0;
|
|
7
|
+
exports.useFieldLayout = useFieldLayout;
|
|
8
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
9
|
+
const react_1 = __importDefault(require("react"));
|
|
10
|
+
exports.FieldLayoutContext = react_1.default.createContext(null);
|
|
11
|
+
const FieldLayoutProvider = ({ value, children, }) => {
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(exports.FieldLayoutContext.Provider, { value: value, children: children }));
|
|
13
|
+
};
|
|
14
|
+
exports.FieldLayoutProvider = FieldLayoutProvider;
|
|
15
|
+
function useFieldLayout(fieldId) {
|
|
16
|
+
const layoutMap = react_1.default.useContext(exports.FieldLayoutContext);
|
|
17
|
+
if (!layoutMap) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
return layoutMap[fieldId] || null;
|
|
21
|
+
}
|
|
@@ -135,14 +135,14 @@ export interface FormErrorRenderProps {
|
|
|
135
135
|
*/
|
|
136
136
|
export declare function LoadingError(props: FormErrorProps): import("react").ReactNode;
|
|
137
137
|
/**
|
|
138
|
-
* Props for Form Error headless component
|
|
138
|
+
* Props for Form Submit Error headless component
|
|
139
139
|
*/
|
|
140
140
|
export interface FormSubmitErrorProps {
|
|
141
141
|
/** Render prop function that receives submit error state data */
|
|
142
142
|
children: (props: FormSubmitErrorRenderProps) => React.ReactNode;
|
|
143
143
|
}
|
|
144
144
|
/**
|
|
145
|
-
* Render props for Form Error component
|
|
145
|
+
* Render props for Form Submit Error component
|
|
146
146
|
*/
|
|
147
147
|
export interface FormSubmitErrorRenderProps {
|
|
148
148
|
/** Submit error message */
|
|
@@ -222,14 +222,17 @@ export declare function Submitted(props: FormSubmittedProps): import("react").Re
|
|
|
222
222
|
/**
|
|
223
223
|
* Render props for Fields component
|
|
224
224
|
*/
|
|
225
|
-
interface FieldsRenderProps {
|
|
225
|
+
export interface FieldsRenderProps {
|
|
226
|
+
/** The form data, or null if not loaded */
|
|
226
227
|
form: forms.Form | null;
|
|
228
|
+
/** Function to submit the form with values */
|
|
227
229
|
submitForm: (formValues: FormValues) => Promise<void>;
|
|
228
230
|
}
|
|
229
231
|
/**
|
|
230
232
|
* Props for Fields headless component
|
|
231
233
|
*/
|
|
232
|
-
interface FieldsProps {
|
|
234
|
+
export interface FieldsProps {
|
|
235
|
+
/** Render prop function that receives form data and submit handler */
|
|
233
236
|
children: (props: FieldsRenderProps) => React.ReactNode;
|
|
234
237
|
}
|
|
235
238
|
/**
|
|
@@ -264,4 +267,76 @@ interface FieldsProps {
|
|
|
264
267
|
* ```
|
|
265
268
|
*/
|
|
266
269
|
export declare function Fields(props: FieldsProps): import("react").ReactNode;
|
|
267
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Form view interface containing field definitions
|
|
272
|
+
*/
|
|
273
|
+
export interface FormView {
|
|
274
|
+
fields: FieldDefinition[];
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Field layout configuration
|
|
278
|
+
*/
|
|
279
|
+
export interface Layout {
|
|
280
|
+
column: number;
|
|
281
|
+
row: number;
|
|
282
|
+
height: number;
|
|
283
|
+
width: number;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Field definition including layout information
|
|
287
|
+
*/
|
|
288
|
+
export interface FieldDefinition {
|
|
289
|
+
id: string;
|
|
290
|
+
layout: Layout;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Render props for Field component
|
|
294
|
+
*/
|
|
295
|
+
export interface FieldRenderProps {
|
|
296
|
+
/** The field ID */
|
|
297
|
+
id: string;
|
|
298
|
+
/** The field layout configuration */
|
|
299
|
+
layout: Layout;
|
|
300
|
+
/** Grid styles for container */
|
|
301
|
+
gridStyles: {
|
|
302
|
+
label: React.CSSProperties;
|
|
303
|
+
input: React.CSSProperties;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Props for Field headless component
|
|
308
|
+
*/
|
|
309
|
+
export interface FieldProps {
|
|
310
|
+
/** The unique identifier for this field */
|
|
311
|
+
id: string;
|
|
312
|
+
/** The field layout configuration */
|
|
313
|
+
layout: Layout;
|
|
314
|
+
/** Render prop function that receives field layout data */
|
|
315
|
+
children: (props: FieldRenderProps) => React.ReactNode;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
* Headless Field component that provides field layout data and grid styles.
|
|
319
|
+
* This component accesses field configuration and calculates grid positioning.
|
|
320
|
+
*
|
|
321
|
+
* @component
|
|
322
|
+
* @param {FieldProps} props - Component props
|
|
323
|
+
* @param {FieldProps['children']} props.children - Render prop function that receives field layout data
|
|
324
|
+
* @example
|
|
325
|
+
* ```tsx
|
|
326
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
327
|
+
*
|
|
328
|
+
* function CustomField({ id, layout }) {
|
|
329
|
+
* return (
|
|
330
|
+
* <Form.Field id={id} layout={layout}>
|
|
331
|
+
* {({ id, layout, gridStyles }) => (
|
|
332
|
+
* <div data-field-id={id}>
|
|
333
|
+
* <div style={gridStyles.label}>Label</div>
|
|
334
|
+
* <div style={gridStyles.input}>Input</div>
|
|
335
|
+
* </div>
|
|
336
|
+
* )}
|
|
337
|
+
* </Form.Field>
|
|
338
|
+
* );
|
|
339
|
+
* }
|
|
340
|
+
* ```
|
|
341
|
+
*/
|
|
342
|
+
export declare function Field(props: FieldProps): import("react").ReactNode;
|
|
@@ -6,10 +6,12 @@ exports.LoadingError = LoadingError;
|
|
|
6
6
|
exports.Error = Error;
|
|
7
7
|
exports.Submitted = Submitted;
|
|
8
8
|
exports.Fields = Fields;
|
|
9
|
+
exports.Field = Field;
|
|
9
10
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
10
11
|
const services_manager_react_1 = require("@wix/services-manager-react");
|
|
11
12
|
const services_manager_1 = require("@wix/services-manager");
|
|
12
13
|
const form_service_js_1 = require("../../services/form-service.js");
|
|
14
|
+
const utils_js_1 = require("../utils.js");
|
|
13
15
|
const DEFAULT_SUCCESS_MESSAGE = 'Your form has been submitted successfully.';
|
|
14
16
|
/**
|
|
15
17
|
* Root component that provides the Form service context to its children.
|
|
@@ -235,3 +237,42 @@ function Fields(props) {
|
|
|
235
237
|
submitForm,
|
|
236
238
|
});
|
|
237
239
|
}
|
|
240
|
+
/**
|
|
241
|
+
* Headless Field component that provides field layout data and grid styles.
|
|
242
|
+
* This component accesses field configuration and calculates grid positioning.
|
|
243
|
+
*
|
|
244
|
+
* @component
|
|
245
|
+
* @param {FieldProps} props - Component props
|
|
246
|
+
* @param {FieldProps['children']} props.children - Render prop function that receives field layout data
|
|
247
|
+
* @example
|
|
248
|
+
* ```tsx
|
|
249
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
250
|
+
*
|
|
251
|
+
* function CustomField({ id, layout }) {
|
|
252
|
+
* return (
|
|
253
|
+
* <Form.Field id={id} layout={layout}>
|
|
254
|
+
* {({ id, layout, gridStyles }) => (
|
|
255
|
+
* <div data-field-id={id}>
|
|
256
|
+
* <div style={gridStyles.label}>Label</div>
|
|
257
|
+
* <div style={gridStyles.input}>Input</div>
|
|
258
|
+
* </div>
|
|
259
|
+
* )}
|
|
260
|
+
* </Form.Field>
|
|
261
|
+
* );
|
|
262
|
+
* }
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
function Field(props) {
|
|
266
|
+
const { id, children, layout } = props;
|
|
267
|
+
const { formSignal } = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
268
|
+
const form = formSignal.get();
|
|
269
|
+
if (!form) {
|
|
270
|
+
return null;
|
|
271
|
+
}
|
|
272
|
+
const gridStyles = (0, utils_js_1.calculateGridStyles)(layout);
|
|
273
|
+
return children({
|
|
274
|
+
id,
|
|
275
|
+
layout,
|
|
276
|
+
gridStyles,
|
|
277
|
+
});
|
|
278
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Layout } from './core/Form';
|
|
2
|
+
export declare function calculateGridStyles(layout: Layout): {
|
|
3
|
+
label: {
|
|
4
|
+
gridRow: string;
|
|
5
|
+
gridColumn: string;
|
|
6
|
+
display: string;
|
|
7
|
+
alignItems: string;
|
|
8
|
+
};
|
|
9
|
+
input: {
|
|
10
|
+
gridRow: string;
|
|
11
|
+
gridColumn: string;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.calculateGridStyles = calculateGridStyles;
|
|
4
|
+
function calculateGridStyles(layout) {
|
|
5
|
+
const labelRow = 1;
|
|
6
|
+
const inputRow = 2;
|
|
7
|
+
const gridColumn = `${layout.column + 1} / span ${layout.width}`;
|
|
8
|
+
return {
|
|
9
|
+
label: {
|
|
10
|
+
gridRow: `${labelRow} / span 1`,
|
|
11
|
+
gridColumn,
|
|
12
|
+
display: 'flex',
|
|
13
|
+
alignItems: 'flex-end',
|
|
14
|
+
},
|
|
15
|
+
input: {
|
|
16
|
+
gridRow: `${inputRow} / span 1`,
|
|
17
|
+
gridColumn,
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -71,7 +71,10 @@ exports.FormService = services_definitions_1.implementService.withConfig()(expor
|
|
|
71
71
|
}
|
|
72
72
|
async function defaultSubmitHandler(formId, formValues) {
|
|
73
73
|
try {
|
|
74
|
-
await forms_1.submissions.createSubmission({
|
|
74
|
+
await forms_1.submissions.createSubmission({
|
|
75
|
+
formId,
|
|
76
|
+
submissions: formValues,
|
|
77
|
+
});
|
|
75
78
|
// TODO: add message
|
|
76
79
|
return { type: 'success' };
|
|
77
80
|
}
|
|
@@ -92,7 +95,7 @@ exports.FormService = services_definitions_1.implementService.withConfig()(expor
|
|
|
92
95
|
}
|
|
93
96
|
// @ts-expect-error
|
|
94
97
|
const formId = form._id ? form._id : form.id;
|
|
95
|
-
submitResponseSignal.set({ type: '
|
|
98
|
+
submitResponseSignal.set({ type: 'loading' });
|
|
96
99
|
try {
|
|
97
100
|
const handler = config.onSubmit || defaultSubmitHandler;
|
|
98
101
|
const response = await handler(formId, formValues);
|
package/dist/react/Form.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import { type FormError } from '@wix/form-public';
|
|
2
3
|
import { type CheckboxGroupProps, type CheckboxProps, type PhoneInputProps, type DateInputProps, type DatePickerProps, type DateTimeInputProps, type DropdownProps, type FileUploadProps, type MultilineAddressProps, type NumberInputProps, type RadioGroupProps, type RatingInputProps, type RichTextProps, type SignatureProps, type SubmitButtonProps, type TagsProps, type TextAreaProps, type TextInputProps, type TimeInputProps, type ProductListProps, type FixedPaymentProps, type PaymentInputProps, type DonationProps, type AppointmentProps, type ImageChoiceProps } from './types.js';
|
|
3
4
|
import { type FormServiceConfig } from '../services/form-service.js';
|
|
4
5
|
/**
|
|
@@ -303,6 +304,9 @@ export declare const Submitted: React.ForwardRefExoticComponent<SubmittedProps &
|
|
|
303
304
|
/**
|
|
304
305
|
* Mapping of form field types to their corresponding React components.
|
|
305
306
|
*
|
|
307
|
+
* ALL field components in this map MUST use Form.Field for proper
|
|
308
|
+
* grid layout positioning.
|
|
309
|
+
*
|
|
306
310
|
* Each key represents a field type identifier that matches the field types defined
|
|
307
311
|
* in the form configuration, and each value is a React component that will receive
|
|
308
312
|
* the field's props and render the appropriate UI element.
|
|
@@ -401,6 +405,8 @@ export interface FieldMap {
|
|
|
401
405
|
*
|
|
402
406
|
* @interface FieldsProps
|
|
403
407
|
* @property {FieldMap} fieldMap - A mapping of field types to their corresponding React components
|
|
408
|
+
* @property {string} rowGapClassname - CSS class name for gap between rows
|
|
409
|
+
* @property {string} columnGapClassname - CSS class name for gap between columns
|
|
404
410
|
* @example
|
|
405
411
|
* ```tsx
|
|
406
412
|
* const FIELD_MAP = {
|
|
@@ -414,11 +420,13 @@ export interface FieldMap {
|
|
|
414
420
|
* // ... remaining field components
|
|
415
421
|
* };
|
|
416
422
|
*
|
|
417
|
-
* <Form.Fields fieldMap={FIELD_MAP} />
|
|
423
|
+
* <Form.Fields fieldMap={FIELD_MAP} rowGapClassname="gap-y-4" columnGapClassname="gap-x-2" />
|
|
418
424
|
* ```
|
|
419
425
|
*/
|
|
420
426
|
interface FieldsProps {
|
|
421
427
|
fieldMap: FieldMap;
|
|
428
|
+
rowGapClassname: string;
|
|
429
|
+
columnGapClassname: string;
|
|
422
430
|
}
|
|
423
431
|
/**
|
|
424
432
|
* Fields component for rendering a form with custom field renderers.
|
|
@@ -428,6 +436,8 @@ interface FieldsProps {
|
|
|
428
436
|
* @component
|
|
429
437
|
* @param {FieldsProps} props - Component props
|
|
430
438
|
* @param {FieldMap} props.fieldMap - A mapping of field types to their corresponding React components
|
|
439
|
+
* @param {string} props.rowGapClassname - CSS class name for gap between rows
|
|
440
|
+
* @param {string} props.columnGapClassname - CSS class name for gap between columns
|
|
431
441
|
* @example
|
|
432
442
|
* ```tsx
|
|
433
443
|
* import { Form } from '@wix/headless-forms/react';
|
|
@@ -446,7 +456,11 @@ interface FieldsProps {
|
|
|
446
456
|
* <Form.Root formServiceConfig={formServiceConfig}>
|
|
447
457
|
* <Form.Loading className="flex justify-center p-4" />
|
|
448
458
|
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
449
|
-
* <Form.Fields
|
|
459
|
+
* <Form.Fields
|
|
460
|
+
* fieldMap={FIELD_MAP}
|
|
461
|
+
* rowGapClassname="gap-y-4"
|
|
462
|
+
* columnGapClassname="gap-x-2"
|
|
463
|
+
* />
|
|
450
464
|
* </Form.Root>
|
|
451
465
|
* );
|
|
452
466
|
* }
|
|
@@ -461,12 +475,15 @@ interface FieldsProps {
|
|
|
461
475
|
* - Field validation and error display
|
|
462
476
|
* - Form state management
|
|
463
477
|
* - Field value updates
|
|
478
|
+
* - Grid layout with configurable row and column gaps
|
|
464
479
|
*
|
|
465
480
|
* Must be used within Form.Root to access form context.
|
|
466
481
|
*
|
|
467
482
|
* @component
|
|
468
483
|
* @param {FieldsProps} props - The component props
|
|
469
484
|
* @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.
|
|
485
|
+
* @param {string} props.rowGapClassname - CSS class name for gap between form rows
|
|
486
|
+
* @param {string} props.columnGapClassname - CSS class name for gap between form columns
|
|
470
487
|
*
|
|
471
488
|
* @example
|
|
472
489
|
* ```tsx
|
|
@@ -534,7 +551,11 @@ interface FieldsProps {
|
|
|
534
551
|
* <Form.Root formServiceConfig={formServiceConfig}>
|
|
535
552
|
* <Form.Loading className="flex justify-center p-4" />
|
|
536
553
|
* <Form.LoadingError className="text-destructive px-4 py-3 rounded mb-4" />
|
|
537
|
-
* <Form.Fields
|
|
554
|
+
* <Form.Fields
|
|
555
|
+
* fieldMap={FIELD_MAP}
|
|
556
|
+
* rowGapClassname="gap-y-4"
|
|
557
|
+
* columnGapClassname="gap-x-2"
|
|
558
|
+
* />
|
|
538
559
|
* <Form.Error className="text-destructive p-4 rounded-lg mb-4" />
|
|
539
560
|
* <Form.Submitted className="text-green-500 p-4 rounded-lg mb-4" />
|
|
540
561
|
* </Form.Root>
|
|
@@ -544,25 +565,221 @@ interface FieldsProps {
|
|
|
544
565
|
*
|
|
545
566
|
* @example
|
|
546
567
|
* ```tsx
|
|
547
|
-
* //
|
|
548
|
-
*
|
|
549
|
-
*
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
*
|
|
553
|
-
*
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
*
|
|
558
|
-
*
|
|
559
|
-
*
|
|
568
|
+
* // Creating custom field components - ALL field components MUST use Form.Field
|
|
569
|
+
* // This example shows the REQUIRED structure for a TEXT_INPUT component
|
|
570
|
+
* import { Form, type TextInputProps } from '@wix/headless-forms/react';
|
|
571
|
+
*
|
|
572
|
+
* const TextInput = (props: TextInputProps) => {
|
|
573
|
+
* const { id, value, onChange, label, error, required, ...inputProps } = props;
|
|
574
|
+
*
|
|
575
|
+
* // Form.Field provides automatic grid layout positioning
|
|
576
|
+
* return (
|
|
577
|
+
* <Form.Field id={id}>
|
|
578
|
+
* <Form.Field.Label>
|
|
579
|
+
* <label className="text-foreground font-paragraph">
|
|
580
|
+
* {label}
|
|
581
|
+
* {required && <span className="text-destructive ml-1">*</span>}
|
|
582
|
+
* </label>
|
|
583
|
+
* </Form.Field.Label>
|
|
584
|
+
* <Form.Field.Input
|
|
585
|
+
* description={error && <span className="text-destructive text-sm">{error}</span>}
|
|
586
|
+
* >
|
|
587
|
+
* <input
|
|
588
|
+
* type="text"
|
|
589
|
+
* value={value || ''}
|
|
590
|
+
* onChange={(e) => onChange(e.target.value)}
|
|
591
|
+
* className="bg-background border-foreground text-foreground"
|
|
592
|
+
* aria-invalid={!!error}
|
|
593
|
+
* {...inputProps}
|
|
594
|
+
* />
|
|
595
|
+
* </Form.Field.Input>
|
|
596
|
+
* </Form.Field>
|
|
597
|
+
* );
|
|
598
|
+
* };
|
|
560
599
|
*
|
|
561
600
|
* const FIELD_MAP = {
|
|
562
|
-
* TEXT_INPUT:
|
|
563
|
-
* // ... other field components
|
|
601
|
+
* TEXT_INPUT: TextInput,
|
|
602
|
+
* // ... all other field components must also use Form.Field
|
|
564
603
|
* };
|
|
565
604
|
* ```
|
|
566
605
|
*/
|
|
567
606
|
export declare const Fields: React.ForwardRefExoticComponent<FieldsProps & React.RefAttributes<HTMLDivElement>>;
|
|
607
|
+
/**
|
|
608
|
+
* Props for Field container component
|
|
609
|
+
*/
|
|
610
|
+
export interface FieldProps {
|
|
611
|
+
/** The unique identifier for this field */
|
|
612
|
+
id: string;
|
|
613
|
+
/** Child components (Field.Label, Field.Input, etc.) */
|
|
614
|
+
children: React.ReactNode;
|
|
615
|
+
/** Whether to render as a child component */
|
|
616
|
+
asChild?: boolean;
|
|
617
|
+
/** CSS classes to apply to the root element */
|
|
618
|
+
className?: string;
|
|
619
|
+
}
|
|
620
|
+
/**
|
|
621
|
+
* Field component with sub-components
|
|
622
|
+
*/
|
|
623
|
+
interface FieldComponent extends React.ForwardRefExoticComponent<FieldProps & React.RefAttributes<HTMLDivElement>> {
|
|
624
|
+
Label: typeof FieldLabel;
|
|
625
|
+
InputWrapper: typeof FieldInputWrapper;
|
|
626
|
+
Input: typeof FieldInput;
|
|
627
|
+
Error: typeof FieldError;
|
|
628
|
+
}
|
|
629
|
+
/**
|
|
630
|
+
* Props for Field.Label component
|
|
631
|
+
*/
|
|
632
|
+
export interface FieldLabelProps {
|
|
633
|
+
/** Label content to display */
|
|
634
|
+
children: React.ReactNode;
|
|
635
|
+
/** Whether to render as a child component */
|
|
636
|
+
asChild?: boolean;
|
|
637
|
+
/** CSS classes to apply to the label element */
|
|
638
|
+
className?: string;
|
|
639
|
+
}
|
|
640
|
+
/**
|
|
641
|
+
* Props for Field.InputWrapper component
|
|
642
|
+
*/
|
|
643
|
+
export interface FieldInputWrapperProps {
|
|
644
|
+
/** Child components (typically Field.Input and Field.Error) */
|
|
645
|
+
children: React.ReactNode;
|
|
646
|
+
/** Whether to render as a child component */
|
|
647
|
+
asChild?: boolean;
|
|
648
|
+
/** CSS classes to apply to the wrapper element */
|
|
649
|
+
className?: string;
|
|
650
|
+
}
|
|
651
|
+
/**
|
|
652
|
+
* Props for Field.Input component
|
|
653
|
+
*/
|
|
654
|
+
export interface FieldInputProps {
|
|
655
|
+
/** Input element to render */
|
|
656
|
+
children: React.ReactNode;
|
|
657
|
+
/** Whether to render as a child component */
|
|
658
|
+
asChild?: boolean;
|
|
659
|
+
/** CSS classes to apply to the input element */
|
|
660
|
+
className?: string;
|
|
661
|
+
/** Description text to display below the input */
|
|
662
|
+
description?: React.ReactNode;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Render props for Field.Error component
|
|
666
|
+
*/
|
|
667
|
+
export interface FieldErrorRenderProps {
|
|
668
|
+
/** The error type */
|
|
669
|
+
type: FormError['errorType'];
|
|
670
|
+
/** The error message */
|
|
671
|
+
message: string;
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* Props for Field.Error component
|
|
675
|
+
*/
|
|
676
|
+
export interface FieldErrorProps {
|
|
677
|
+
/** Whether to render as a child component */
|
|
678
|
+
asChild?: boolean;
|
|
679
|
+
/** CSS classes to apply to the error element */
|
|
680
|
+
className?: string;
|
|
681
|
+
/** The error message */
|
|
682
|
+
errorMessage?: string;
|
|
683
|
+
/** Child components to render */
|
|
684
|
+
children?: React.ReactNode;
|
|
685
|
+
}
|
|
686
|
+
/**
|
|
687
|
+
* Label component for a form field with automatic grid positioning.
|
|
688
|
+
* Must be used within a Form.Field component.
|
|
689
|
+
* Renders in the label row of the field's grid layout.
|
|
690
|
+
*
|
|
691
|
+
* @component
|
|
692
|
+
* @example
|
|
693
|
+
* ```tsx
|
|
694
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
695
|
+
*
|
|
696
|
+
* <Form.Field id="email">
|
|
697
|
+
* <Form.Field.Label>
|
|
698
|
+
* <label className="text-foreground font-paragraph">Email Address</label>
|
|
699
|
+
* </Form.Field.Label>
|
|
700
|
+
* <Form.Field.InputWrapper>
|
|
701
|
+
* <Form.Field.Input>
|
|
702
|
+
* <input type="email" className="bg-background border-foreground text-foreground" />
|
|
703
|
+
* </Form.Field.Input>
|
|
704
|
+
* </Form.Field.InputWrapper>
|
|
705
|
+
* </Form.Field>
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
export declare const FieldLabel: React.ForwardRefExoticComponent<FieldLabelProps & React.RefAttributes<HTMLDivElement>>;
|
|
709
|
+
/**
|
|
710
|
+
* InputWrapper component that wraps input and error elements with grid positioning.
|
|
711
|
+
* Must be used within a Form.Field component.
|
|
712
|
+
* This wrapper applies the grid positioning styles to contain both the input and error.
|
|
713
|
+
*
|
|
714
|
+
* @component
|
|
715
|
+
* @example
|
|
716
|
+
* ```tsx
|
|
717
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
718
|
+
*
|
|
719
|
+
* <Form.Field id="email">
|
|
720
|
+
* <Form.Field.Label>
|
|
721
|
+
* <label className="text-foreground font-paragraph">Email Address</label>
|
|
722
|
+
* </Form.Field.Label>
|
|
723
|
+
* <Form.Field.InputWrapper>
|
|
724
|
+
* <Form.Field.Input>
|
|
725
|
+
* <input type="email" className="bg-background border-foreground text-foreground" />
|
|
726
|
+
* </Form.Field.Input>
|
|
727
|
+
* <Form.Field.Error>
|
|
728
|
+
* <span className="text-destructive text-sm font-paragraph">Please enter a valid email</span>
|
|
729
|
+
* </Form.Field.Error>
|
|
730
|
+
* </Form.Field.InputWrapper>
|
|
731
|
+
* </Form.Field>
|
|
732
|
+
* ```
|
|
733
|
+
*/
|
|
734
|
+
export declare const FieldInputWrapper: React.ForwardRefExoticComponent<FieldInputWrapperProps & React.RefAttributes<HTMLDivElement>>;
|
|
735
|
+
/**
|
|
736
|
+
* Input component for a form field.
|
|
737
|
+
* Must be used within a Form.Field.InputWrapper component.
|
|
738
|
+
* Renders the actual input element without grid positioning.
|
|
739
|
+
*
|
|
740
|
+
* @component
|
|
741
|
+
* @example
|
|
742
|
+
* ```tsx
|
|
743
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
744
|
+
*
|
|
745
|
+
* <Form.Field id="password">
|
|
746
|
+
* <Form.Field.Label>
|
|
747
|
+
* <label className="text-foreground font-paragraph">Password</label>
|
|
748
|
+
* </Form.Field.Label>
|
|
749
|
+
* <Form.Field.InputWrapper>
|
|
750
|
+
* <Form.Field.Input description={<span className="text-secondary-foreground">Min 8 characters</span>}>
|
|
751
|
+
* <input type="password" className="bg-background border-foreground text-foreground" />
|
|
752
|
+
* </Form.Field.Input>
|
|
753
|
+
* </Form.Field.InputWrapper>
|
|
754
|
+
* </Form.Field>
|
|
755
|
+
* ```
|
|
756
|
+
*/
|
|
757
|
+
export declare const FieldInput: React.ForwardRefExoticComponent<FieldInputProps & React.RefAttributes<HTMLDivElement>>;
|
|
758
|
+
/**
|
|
759
|
+
* Error component for displaying field-level validation errors.
|
|
760
|
+
* Must be used within a Form.Field.InputWrapper component.
|
|
761
|
+
* Only renders when there is an error for the current field.
|
|
762
|
+
*
|
|
763
|
+
* @component
|
|
764
|
+
* @example
|
|
765
|
+
* ```tsx
|
|
766
|
+
* import { Form } from '@wix/headless-forms/react';
|
|
767
|
+
*
|
|
768
|
+
* <Form.Field id="email">
|
|
769
|
+
* <Form.Field.Label>
|
|
770
|
+
* <label className="text-foreground font-paragraph">Email Address</label>
|
|
771
|
+
* </Form.Field.Label>
|
|
772
|
+
* <Form.Field.InputWrapper>
|
|
773
|
+
* <Form.Field.Input>
|
|
774
|
+
* <input type="email" className="bg-background border-foreground text-foreground" />
|
|
775
|
+
* </Form.Field.Input>
|
|
776
|
+
* <Form.Field.Error path="email">
|
|
777
|
+
* <span className="text-destructive text-sm font-paragraph">Please enter a valid email address</span>
|
|
778
|
+
* </Form.Field.Error>
|
|
779
|
+
* </Form.Field.InputWrapper>
|
|
780
|
+
* </Form.Field>
|
|
781
|
+
* ```
|
|
782
|
+
*/
|
|
783
|
+
export declare const FieldError: React.ForwardRefExoticComponent<FieldErrorProps & React.RefAttributes<HTMLDivElement>>;
|
|
784
|
+
export declare const Field: FieldComponent;
|
|
568
785
|
export {};
|