-
-
Notifications
You must be signed in to change notification settings - Fork 7.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mfrachet
committed
Sep 7, 2021
1 parent
0f3d6d7
commit f98a1a4
Showing
3 changed files
with
76 additions
and
1 deletion.
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
packages/core/helper-plugin/lib/src/components/Form/Form.stories.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,75 @@ | ||
<!--- EmptyStateLayout.stories.mdx ---> | ||
|
||
import { Meta, ArgsTable, Canvas, Story } from '@storybook/addon-docs'; | ||
import { Main, Row } from '@strapi/parts'; | ||
import { TextInput } from '@strapi/parts/TextInput'; | ||
import { Button } from '@strapi/parts/Button'; | ||
import { Box } from '@strapi/parts/Box'; | ||
import { Text } from '@strapi/parts/Text'; | ||
import { Formik } from 'formik'; | ||
import * as Yup from 'yup'; | ||
import Form from './'; | ||
|
||
<Meta title="components/Form" /> | ||
|
||
# Form | ||
|
||
This component is used to display a Formik form with additionnal error handling on fields | ||
|
||
## Per field error | ||
|
||
<Canvas> | ||
<Story name="Per field error"> | ||
<Main> | ||
<Formik initialValues={{ email: '' }} validationSchema={Yup.object().shape({ email: Yup.string().email('Invalid email').required('Required')})}> | ||
{({ handleSubmit, values, errors, handleChange }) => ( | ||
<Form onSubmit={handleSubmit}> | ||
<TextInput | ||
name="email" | ||
label="Email" | ||
hint="Enter a valid email" | ||
value={values.email} | ||
error={errors.email} | ||
value={values.displayName} | ||
onChange={handleChange} | ||
/> | ||
<Button type="submit">Submit</Button> | ||
</Form> | ||
)} | ||
</Formik> | ||
</Main> | ||
</Story> | ||
</Canvas> | ||
|
||
## Per form error | ||
|
||
Make sure to run this story in detached mode. The embeded iframe breaks the focus behaviour. | ||
|
||
<Canvas> | ||
<Story name="Per form error"> | ||
<Main> | ||
<Formik initialValues={{ email: '' }} validationSchema={Yup.object().shape({ email: Yup.string().email('Invalid email').required('Required')})} validateOnChange={false}> | ||
{({ handleSubmit, values, errors, handleChange }) => ( | ||
<Form onSubmit={handleSubmit} noValidate> | ||
{errors.email ? <Box padding={3} hasRadius background="danger100" color="danger600" tabIndex={-1} id="global-form-error"> | ||
<Text>The email is invalid</Text> | ||
</Box> : null} | ||
<TextInput | ||
name="email" | ||
label="Email" | ||
hint="Enter a valid email" | ||
value={values.email} | ||
value={values.displayName} | ||
onChange={handleChange} | ||
/> | ||
<Button type="submit">Submit</Button> | ||
</Form> | ||
)} | ||
</Formik> | ||
</Main> | ||
</Story> | ||
</Canvas> | ||
|
||
### Props | ||
|
||
<ArgsTable of={EmptyStateLayout} /> |
File renamed without changes.
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