@wix/headless-forms 0.0.7 → 0.0.9
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/README.md +1 -1
- package/cjs/dist/react/Form.d.ts +1 -1
- package/cjs/dist/react/Form.js +2 -3
- 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 +1 -1
- package/dist/react/Form.js +2 -3
- 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/README.md
CHANGED
|
@@ -42,5 +42,5 @@ All changes should be documented using `jsdoc` and updating `docs/api/FORM_INTER
|
|
|
42
42
|
- "Forms SDK Exports Components"
|
|
43
43
|
- "Forms SDK Exports Services"
|
|
44
44
|
- Release new app version
|
|
45
|
-
- Check if update has been commited to `auto-sdk-packages` repo
|
|
45
|
+
- Check if update has been commited to `auto-sdk-packages` repo (might take around 20mins)
|
|
46
46
|
|
package/cjs/dist/react/Form.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
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';
|
|
2
3
|
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
4
|
/**
|
|
5
5
|
* Props for the Form root component following the documented API
|
|
6
6
|
*/
|
package/cjs/dist/react/Form.js
CHANGED
|
@@ -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)(Form_1.Fields, { children: ({ form }) => {
|
|
497
|
-
console.log('Fields form', form);
|
|
496
|
+
return ((0, jsx_runtime_1.jsx)(Form_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
|
}
|