woocommerce/plugins/woocommerce-admin/packages/components/src/form
Sam Seay a2c4a6a306 A/B test creating a business features step for free extensions (https://github.com/woocommerce/woocommerce-admin/pull/5786)
This fixes woocommerce/woocommerce-admin#5287 

Major changes:

1. The `<Form>` component (which is a published component) gets a new optional prop (so its backward compatible), called `onChangeCallback`. This is called when any form value changes, allowing the controlling component to act on individual form changes. This was needed to utilise `<Form>` to revalidate and check if the user could access the next tab. This should not impact existing usages of the `<Form>`, but it could be good to test this.

2. Introduces a new flow for choosing business extensions that was specified in woocommerce/woocommerce-admin#5287 issue description. Please check the issue for reviewing the designs. The simplest way to implement this, ended up being keeping the existing flow intact and where necessary copy pasting code from those components into the new flow. This new flow is only shown if your segmentation matches the following: `Stores that selected the US as the country and Other or Food & Drinks as the industry
2021-01-07 11:08:57 +13:00
..
stories Migrate the devdocs examples to Storybook CSF stories (https://github.com/woocommerce/woocommerce-admin/pull/5271) 2020-10-15 14:55:55 +13:00
README.md Fetch component usage documentation from local README.md. 2019-09-06 11:52:18 -07:00
index.js A/B test creating a business features step for free extensions (https://github.com/woocommerce/woocommerce-admin/pull/5786) 2021-01-07 11:08:57 +13:00

README.md

Form

A form component to handle form state and provide input helper props.

Usage

const initialValues = { firstName: '' };

<Form
	onSubmitCallback={ ( values ) => {} }
	initialValues={ initialValues }
>
	{ ( {
		getInputProps,
		values,
		errors,
		handleSubmit,
	} ) => (
		<div>
			<TextControl
				label={ 'First Name' }
				{ ...getInputProps( 'firstName' ) }
			/>
			<Button
				isPrimary
				onClick={ handleSubmit }
				disabled={ Object.keys( errors ).length }
			>
				Submit
			</Button>
		</div>
	) }
</Form>

Props

Name Type Default Description
children * null A renderable component in which to pass this component's state and helpers. Generally a number of input or other form elements
errors Object {} Object of all initial errors to store in state
initialValues Object {} Object key:value pair list of all initial field values
onSubmitCallback Function noop Function to call when a form is submitted with valid fields
validate Function noop A function that is passed a list of all values and should return an errors object with error response
touched {}