-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(form): remove final-form legacy props and hook (#3780)
* feat(form): remove final-form legacy props and hook
- Loading branch information
1 parent
7dee114
commit 64af9b3
Showing
95 changed files
with
795 additions
and
859 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
--- | ||
"@ultraviolet/form": major | ||
--- | ||
|
||
## Accept control prop | ||
|
||
Field can accept a `control` prop. When this prop is provided, the `name` prop must be present in the form and the `onChange` callback is typed. | ||
|
||
## Remove defaultValues | ||
|
||
You must use the `useForm` hook to provide initial values: | ||
|
||
```tsx | ||
// Old | ||
<Form defaultValues={{ foo: 'bar' }}> | ||
// ... | ||
</Form> | ||
|
||
// New | ||
const methods = useForm({ defaultValues: { foo: 'bar' }}) | ||
|
||
<Form methods={methods}> | ||
// ... | ||
</Form> | ||
``` | ||
|
||
## Remove function as child component | ||
|
||
Function as child component must be remove: | ||
|
||
```tsx | ||
// Old | ||
<Form> | ||
{({ isSubmitting }) => ( | ||
<Button disabled={isSubmitting}>Submit</Button> | ||
)} | ||
</Form> | ||
|
||
// New | ||
const methods = useForm() | ||
|
||
const { isSubmitting } = methods.formState | ||
|
||
<Form methods={methods}> | ||
<Button disabled={isSubmitting}>Submit</Button> | ||
</Form> | ||
``` | ||
|
||
## onRawSubmit renamed to onSubmit | ||
|
||
The `onRawSubmit` is renamed to `onSubmit`. | ||
|
||
The return of the function is now a string if an error occurred. | ||
|
||
```tsx | ||
// Old | ||
<Form onRawSubmit={(values) => { | ||
return { [FORM_ERROR]: 'ERROR' } | ||
}}> | ||
// ... | ||
</Form> | ||
|
||
// New | ||
<Form onSubmit={(values) => { | ||
return 'ERROR' | ||
}}> | ||
// ... | ||
</Form> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
packages/form/src/__stories__/migrations/MigrationFormV3.mdx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { Meta } from '@storybook/blocks' | ||
|
||
<Meta title="Migrations/Formv2 to Formv3" /> | ||
|
||
# Migrate Formv2 to Formv3 | ||
|
||
## Remove defaultValues | ||
|
||
You must use the `useForm` hook to provide initial values: | ||
|
||
```tsx | ||
// Old | ||
<Form defaultValues={{ foo: 'bar' }}> | ||
// ... | ||
</Form> | ||
|
||
// New | ||
const methods = useForm({ defaultValues: { foo: 'bar' }}) | ||
|
||
<Form methods={methods}> | ||
// ... | ||
</Form> | ||
``` | ||
|
||
## Remove function as child component | ||
|
||
Function as child component must be remove: | ||
|
||
```tsx | ||
// Old | ||
<Form> | ||
{({ isSubmitting }) => ( | ||
<Button disabled={isSubmitting}>Submit</Button> | ||
)} | ||
</Form> | ||
|
||
// New | ||
const methods = useForm() | ||
|
||
const { isSubmitting } = methods.formState | ||
|
||
<Form methods={methods}> | ||
<Button disabled={isSubmitting}>Submit</Button> | ||
</Form> | ||
``` | ||
|
||
## onRawSubmit renamed to onSubmit | ||
|
||
The `onRawSubmit` is renamed to `onSubmit`. | ||
|
||
The return of the function is now a string if an error occurred. | ||
|
||
```tsx | ||
// Old | ||
<Form onRawSubmit={(values) => { | ||
return { [FORM_ERROR]: 'ERROR' } | ||
}}> | ||
// ... | ||
</Form> | ||
|
||
// New | ||
<Form onSubmit={(values) => { | ||
return 'ERROR' | ||
}}> | ||
// ... | ||
</Form> | ||
``` |
15 changes: 10 additions & 5 deletions
15
packages/form/src/components/CheckboxField/__stories__/BooleanChecked.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import type { StoryFn } from '@storybook/react' | ||
import { CheckboxField } from '..' | ||
import { useForm } from '../../..' | ||
import type { FormErrors } from '../../../types' | ||
import { Form } from '../../Form' | ||
|
||
export const BooleanChecked: StoryFn<{ errors: FormErrors }> = ({ errors }) => ( | ||
<Form onRawSubmit={() => {}} errors={errors} initialValues={{ foo: true }}> | ||
<CheckboxField name="foo">Default Checked Boolean Item</CheckboxField> | ||
</Form> | ||
) | ||
export const BooleanChecked: StoryFn<{ errors: FormErrors }> = ({ errors }) => { | ||
const methods = useForm({ defaultValues: { foo: true } }) | ||
|
||
return ( | ||
<Form onSubmit={() => {}} errors={errors} methods={methods}> | ||
<CheckboxField name="foo">Default Checked Boolean Item</CheckboxField> | ||
</Form> | ||
) | ||
} |
17 changes: 11 additions & 6 deletions
17
packages/form/src/components/CheckboxField/__stories__/Checked.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,16 @@ | ||
import type { StoryFn } from '@storybook/react' | ||
import { CheckboxField } from '..' | ||
import { useForm } from '../../..' | ||
import type { FormErrors } from '../../../types' | ||
import { Form } from '../../Form' | ||
|
||
export const Checked: StoryFn<{ errors: FormErrors }> = ({ errors }) => ( | ||
<Form onRawSubmit={() => {}} errors={errors} initialValues={{ foo: true }}> | ||
<CheckboxField name="foo">Checked Item</CheckboxField> | ||
<CheckboxField name="bar">Not Checked Item</CheckboxField> | ||
</Form> | ||
) | ||
export const Checked: StoryFn<{ errors: FormErrors }> = ({ errors }) => { | ||
const methods = useForm({ defaultValues: { foo: true } }) | ||
|
||
return ( | ||
<Form onSubmit={() => {}} errors={errors} methods={methods}> | ||
<CheckboxField name="foo">Checked Item</CheckboxField> | ||
<CheckboxField name="bar">Not Checked Item</CheckboxField> | ||
</Form> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/form/src/components/CheckboxGroupField/__stories__/Direction.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.