Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
siriwatknp committed Aug 14, 2019
1 parent 291be50 commit 153ca58
Showing 1 changed file with 131 additions and 3 deletions.
134 changes: 131 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,137 @@
MUI Formik
=====
# MUI Formik

A toolbox for building sustainable MaterialUI form with formik

### [Storybook Demo](https://siriwatknp.github.io/mui-formik/?path=/story/form--profile-form)
### [Storybook Demo](https://siriwatknp.github.io/mui-formik)

## Example

```jsx harmony
import React, { useState } from 'react';
import { Formik } from 'formik';
import { Button, Link } from '@material-ui/core';
import { HEROES, COUNTRIES } from './mock';
import {
TabsField,
TextField,
DownshiftSelectField,
DownshiftMultiSelectField,
CheckLabelField,
} from 'mui-formik';

const App = () => {
const [state, setState] = useState({});
console.log(state);
return (
<Formik
onSubmit={values => setState(values)}
onReset={() => setState({})}
initialValues={{
email: '',
password: '',
name: {
en: '',
th: '',
},
profile: {
favorite: {
hero: '',
countries: [],
},
},
}}
>
{({ handleSubmit, handleReset }) => (
<form onSubmit={handleSubmit}>
<TextField {...TextField.baseProps} name="email" label="Email" />
<TextField
{...TextField.baseProps}
name="password"
label="Password"
type="password"
/>
<TabsField
name={'name'}
tabs={[
{ label: 'English', value: 'en' },
{ label: 'Thai', value: 'th' },
]}
>
{tab => (
<TextField
{...TextField.baseProps}
name={`name.${tab}`}
label={tab}
/>
)}
</TabsField>
<DownshiftSelectField
{...DownshiftSelectField.baseProps}
name={`profile.favorite.hero`}
options={HEROES}
itemToValue={item => (item ? item.id : '')}
itemToLabel={item => (item ? item.name : '')}
label={'Hero'}
required
/>
<DownshiftMultiSelectField
{...DownshiftMultiSelectField.baseProps}
options={COUNTRIES}
name={`profile.favorite.countries`}
label={'Countries'}
placeholder={'Type a name'}
/>
<CheckLabelField
{...CheckLabelField.baseProps}
name={'accepted'}
label={
<>
{' '}
I accept the <Link color={'secondary'}>
new Terms of Service
</Link>
</>
}
/>
<Button type={'submit'} variant={'contained'} color={'primary'}>
Submit
</Button>
<Button style={{ marginLeft: 16 }} onClick={handleReset}>
Reset
</Button>
</form>
)}
</Formik>
);
};

export default App;
```

## Components

#### `CheckGroupField`

#### `CheckLabelField`

#### `InputBaseField`

#### `DownshiftSelectField`

#### `DownshiftMultiSelectField`

#### `MultiSelectField`

#### `RadioGroupField`

#### `TextField`

#### `TabsField`

## Styling

#### use [mui-styling](https://github.com/siriwatknp/mui-styling) internally

## License

MIT

0 comments on commit 153ca58

Please sign in to comment.