@wix/headless-forms 0.0.8 → 0.0.10
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 +2 -2
- package/cjs/dist/react/Form.js +8 -9
- package/cjs/dist/react/core/Form.d.ts +10 -4
- package/cjs/dist/react/core/Form.js +20 -11
- package/cjs/dist/react/types.d.ts +3 -1251
- package/cjs/dist/services/form-service.d.ts +25 -3
- package/cjs/dist/services/form-service.js +55 -2
- package/dist/react/Form.d.ts +2 -2
- package/dist/react/Form.js +3 -4
- package/dist/react/core/Form.d.ts +10 -4
- package/dist/react/core/Form.js +20 -11
- package/dist/react/types.d.ts +3 -1251
- package/dist/services/form-service.d.ts +25 -3
- package/dist/services/form-service.js +56 -3
- package/package.json +3 -3
package/cjs/dist/react/Form.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { type
|
|
3
|
-
import {
|
|
2
|
+
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
|
+
import { type FormServiceConfig } from '../services/form-service.js';
|
|
4
4
|
/**
|
|
5
5
|
* Props for the Form root component following the documented API
|
|
6
6
|
*/
|
package/cjs/dist/react/Form.js
CHANGED
|
@@ -38,7 +38,7 @@ const jsx_runtime_1 = require("react/jsx-runtime");
|
|
|
38
38
|
const react_1 = __importStar(require("react"));
|
|
39
39
|
const react_2 = require("@wix/headless-utils/react");
|
|
40
40
|
const form_public_1 = require("@wix/form-public");
|
|
41
|
-
const
|
|
41
|
+
const Form_js_1 = require("./core/Form.js");
|
|
42
42
|
var TestIds;
|
|
43
43
|
(function (TestIds) {
|
|
44
44
|
TestIds["formRoot"] = "form-root";
|
|
@@ -100,7 +100,7 @@ var TestIds;
|
|
|
100
100
|
*/
|
|
101
101
|
exports.Root = react_1.default.forwardRef((props, ref) => {
|
|
102
102
|
const { children, formServiceConfig, asChild, ...otherProps } = props;
|
|
103
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
103
|
+
return ((0, jsx_runtime_1.jsx)(Form_js_1.Root, { formServiceConfig: formServiceConfig, children: (0, jsx_runtime_1.jsx)(RootContent, { asChild: asChild, ref: ref, ...otherProps, children: children }) }));
|
|
104
104
|
});
|
|
105
105
|
/**
|
|
106
106
|
* Internal component to handle the Root content with service access.
|
|
@@ -164,7 +164,7 @@ const RootContent = react_1.default.forwardRef((props, ref) => {
|
|
|
164
164
|
*/
|
|
165
165
|
exports.Loading = react_1.default.forwardRef((props, ref) => {
|
|
166
166
|
const { asChild, children, className, ...otherProps } = props;
|
|
167
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
167
|
+
return ((0, jsx_runtime_1.jsx)(Form_js_1.Loading, { children: ({ isLoading }) => {
|
|
168
168
|
if (!isLoading)
|
|
169
169
|
return null;
|
|
170
170
|
return ((0, jsx_runtime_1.jsx)(react_2.AsChildSlot, { "data-testid": TestIds.formLoading, ref: ref, asChild: asChild, className: className, customElement: children, content: "Loading form...", ...otherProps, children: (0, jsx_runtime_1.jsx)("div", { children: "Loading form..." }) }));
|
|
@@ -221,7 +221,7 @@ exports.Loading = react_1.default.forwardRef((props, ref) => {
|
|
|
221
221
|
*/
|
|
222
222
|
exports.LoadingError = react_1.default.forwardRef((props, ref) => {
|
|
223
223
|
const { asChild, children, className, ...otherProps } = props;
|
|
224
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
224
|
+
return ((0, jsx_runtime_1.jsx)(Form_js_1.LoadingError, { children: ({ error, hasError }) => {
|
|
225
225
|
if (!hasError)
|
|
226
226
|
return null;
|
|
227
227
|
const errorData = { error, hasError };
|
|
@@ -277,7 +277,7 @@ exports.LoadingError = react_1.default.forwardRef((props, ref) => {
|
|
|
277
277
|
*/
|
|
278
278
|
exports.Error = react_1.default.forwardRef((props, ref) => {
|
|
279
279
|
const { asChild, children, className, ...otherProps } = props;
|
|
280
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
280
|
+
return ((0, jsx_runtime_1.jsx)(Form_js_1.Error, { children: ({ error, hasError }) => {
|
|
281
281
|
if (!hasError)
|
|
282
282
|
return null;
|
|
283
283
|
const errorData = { error, hasError };
|
|
@@ -333,7 +333,7 @@ exports.Error = react_1.default.forwardRef((props, ref) => {
|
|
|
333
333
|
*/
|
|
334
334
|
exports.Submitted = react_1.default.forwardRef((props, ref) => {
|
|
335
335
|
const { asChild, children, className, ...otherProps } = props;
|
|
336
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
336
|
+
return ((0, jsx_runtime_1.jsx)(Form_js_1.Submitted, { children: ({ isSubmitted, message }) => {
|
|
337
337
|
if (!isSubmitted)
|
|
338
338
|
return null;
|
|
339
339
|
const submittedData = { isSubmitted, message };
|
|
@@ -493,10 +493,9 @@ exports.Fields = react_1.default.forwardRef((props, ref) => {
|
|
|
493
493
|
const handleFormValidate = (0, react_1.useCallback)((errors) => {
|
|
494
494
|
setFormErrors(errors);
|
|
495
495
|
}, []);
|
|
496
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
497
|
-
console.log('Fields form', form);
|
|
496
|
+
return ((0, jsx_runtime_1.jsx)(Form_js_1.Fields, { children: ({ form, submitForm }) => {
|
|
498
497
|
if (!form)
|
|
499
498
|
return null;
|
|
500
|
-
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, children: (0, jsx_runtime_1.jsx)(form_public_1.Form, { form: form, values: formValues, onChange: handleFormChange, errors: formErrors, onValidate: handleFormValidate, fields: props.fieldMap }) }));
|
|
499
|
+
return ((0, jsx_runtime_1.jsx)("div", { ref: ref, children: (0, jsx_runtime_1.jsx)(form_public_1.Form, { form: form, values: formValues, onChange: handleFormChange, errors: formErrors, onValidate: handleFormValidate, fields: props.fieldMap, submitForm: () => submitForm(formValues) }) }));
|
|
501
500
|
} }));
|
|
502
501
|
});
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { forms } from '@wix/forms';
|
|
2
2
|
import { FormServiceConfig } from '../../services/form-service.js';
|
|
3
|
+
import { FormValues } from '../types.js';
|
|
3
4
|
/**
|
|
4
5
|
* Props for Root headless component
|
|
5
6
|
*/
|
|
@@ -223,6 +224,7 @@ export declare function Submitted(props: FormSubmittedProps): import("react").Re
|
|
|
223
224
|
*/
|
|
224
225
|
interface FieldsRenderProps {
|
|
225
226
|
form: forms.Form | null;
|
|
227
|
+
submitForm: (formValues: FormValues) => Promise<void>;
|
|
226
228
|
}
|
|
227
229
|
/**
|
|
228
230
|
* Props for Fields headless component
|
|
@@ -231,12 +233,13 @@ interface FieldsProps {
|
|
|
231
233
|
children: (props: FieldsRenderProps) => React.ReactNode;
|
|
232
234
|
}
|
|
233
235
|
/**
|
|
234
|
-
* Fields component that provides form data to its children.
|
|
235
|
-
* This component accesses the form data
|
|
236
|
+
* Fields component that provides form data and actions to its children.
|
|
237
|
+
* This component accesses the form data and submitForm action from the service
|
|
238
|
+
* and passes them to children via render props.
|
|
236
239
|
*
|
|
237
240
|
* @component
|
|
238
241
|
* @param {FieldsProps} props - Component props
|
|
239
|
-
* @param {FieldsProps['children']} props.children - Render prop function that receives form data
|
|
242
|
+
* @param {FieldsProps['children']} props.children - Render prop function that receives form data and actions
|
|
240
243
|
* @example
|
|
241
244
|
* ```tsx
|
|
242
245
|
* import { Form } from '@wix/headless-forms/react';
|
|
@@ -244,11 +247,14 @@ interface FieldsProps {
|
|
|
244
247
|
* function FormFields() {
|
|
245
248
|
* return (
|
|
246
249
|
* <Form.Fields>
|
|
247
|
-
* {({ form }) => (
|
|
250
|
+
* {({ form, submitForm }) => (
|
|
248
251
|
* form ? (
|
|
249
252
|
* <div>
|
|
250
253
|
* <h2>{form.name}</h2>
|
|
251
254
|
* <p>{form.description}</p>
|
|
255
|
+
* <button onClick={() => submitForm({ field1: 'value' })}>
|
|
256
|
+
* Submit
|
|
257
|
+
* </button>
|
|
252
258
|
* </div>
|
|
253
259
|
* ) : null
|
|
254
260
|
* )}
|
|
@@ -149,9 +149,10 @@ function LoadingError(props) {
|
|
|
149
149
|
* ```
|
|
150
150
|
*/
|
|
151
151
|
function Error(props) {
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
152
|
+
const { submitResponseSignal } = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
153
|
+
const submitResponse = submitResponseSignal.get();
|
|
154
|
+
const error = submitResponse.type === 'error' ? submitResponse.message : null;
|
|
155
|
+
const hasError = submitResponse.type === 'error';
|
|
155
156
|
return props.children({
|
|
156
157
|
error,
|
|
157
158
|
hasError,
|
|
@@ -184,21 +185,25 @@ function Error(props) {
|
|
|
184
185
|
* ```
|
|
185
186
|
*/
|
|
186
187
|
function Submitted(props) {
|
|
187
|
-
|
|
188
|
-
const
|
|
189
|
-
const
|
|
188
|
+
const { submitResponseSignal } = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
189
|
+
const submitResponse = submitResponseSignal.get();
|
|
190
|
+
const isSubmitted = submitResponse.type === 'success';
|
|
191
|
+
const message = submitResponse.type === 'success'
|
|
192
|
+
? submitResponse.message || DEFAULT_SUCCESS_MESSAGE
|
|
193
|
+
: DEFAULT_SUCCESS_MESSAGE;
|
|
190
194
|
return props.children({
|
|
191
195
|
isSubmitted,
|
|
192
196
|
message,
|
|
193
197
|
});
|
|
194
198
|
}
|
|
195
199
|
/**
|
|
196
|
-
* Fields component that provides form data to its children.
|
|
197
|
-
* This component accesses the form data
|
|
200
|
+
* Fields component that provides form data and actions to its children.
|
|
201
|
+
* This component accesses the form data and submitForm action from the service
|
|
202
|
+
* and passes them to children via render props.
|
|
198
203
|
*
|
|
199
204
|
* @component
|
|
200
205
|
* @param {FieldsProps} props - Component props
|
|
201
|
-
* @param {FieldsProps['children']} props.children - Render prop function that receives form data
|
|
206
|
+
* @param {FieldsProps['children']} props.children - Render prop function that receives form data and actions
|
|
202
207
|
* @example
|
|
203
208
|
* ```tsx
|
|
204
209
|
* import { Form } from '@wix/headless-forms/react';
|
|
@@ -206,11 +211,14 @@ function Submitted(props) {
|
|
|
206
211
|
* function FormFields() {
|
|
207
212
|
* return (
|
|
208
213
|
* <Form.Fields>
|
|
209
|
-
* {({ form }) => (
|
|
214
|
+
* {({ form, submitForm }) => (
|
|
210
215
|
* form ? (
|
|
211
216
|
* <div>
|
|
212
217
|
* <h2>{form.name}</h2>
|
|
213
218
|
* <p>{form.description}</p>
|
|
219
|
+
* <button onClick={() => submitForm({ field1: 'value' })}>
|
|
220
|
+
* Submit
|
|
221
|
+
* </button>
|
|
214
222
|
* </div>
|
|
215
223
|
* ) : null
|
|
216
224
|
* )}
|
|
@@ -220,9 +228,10 @@ function Submitted(props) {
|
|
|
220
228
|
* ```
|
|
221
229
|
*/
|
|
222
230
|
function Fields(props) {
|
|
223
|
-
const { formSignal } = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
231
|
+
const { formSignal, submitForm } = (0, services_manager_react_1.useService)(form_service_js_1.FormServiceDefinition);
|
|
224
232
|
const form = formSignal.get();
|
|
225
233
|
return props.children({
|
|
226
234
|
form,
|
|
235
|
+
submitForm,
|
|
227
236
|
});
|
|
228
237
|
}
|