Skip to content

Commit

Permalink
readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
staff0rd committed Mar 29, 2023
1 parent 5ac5875 commit 38eeb5d
Show file tree
Hide file tree
Showing 8 changed files with 378 additions and 154 deletions.
6 changes: 6 additions & 0 deletions .changeset/metal-bikes-switch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@makerx/forms-ionic': patch
'@makerx/forms-mui': patch
---

Readme updates
152 changes: 4 additions & 148 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,152 +1,8 @@
# @makerx/forms

Add typed & validated forms to your React app quickly. Currently supports ionic [(demo)](https://makerxstudio.github.io/forms/ionic-example) & mui [(demo)](https://makerxstudio.github.io/forms/mui-example)
Add typed & validated forms to your React app quickly.

## Installation
Currently supports:

### mui

```bash
npm i @makerx/forms-mui react-hook-form
```

#### Example

![Example](mui-example.png?raw=true)

```tsx
import { ValidatedForm, z, zfd } from '@makerx/forms-mui';
import { formatISO, parseISO } from 'date-fns';

/**
* Define schema
*/
export const formSchema = zfd.formData({
myString: zfd.text(z.string().trim().min(1, 'Required')),
myArray: zfd.repeatable(
z
.array(zfd.text(z.string().trim().min(1, 'Required')))
.min(2, 'Must have at least 2 values')
),
myDateTime: zfd.text(),
});

/**
* Initialise with defaults
*/
const defaultValues: z.infer<typeof formSchema> = {
myString: '',
myArray: ['one value'],
myDateTime: '',
};

/**
* Render form
*/
function App() {
const onSubmit = (data: z.infer<typeof formSchema>) =>
console.log('Received data:', data);

return (
<ValidatedForm
validator={formSchema}
onSubmit={onSubmit}
defaultValues={defaultValues}
>
{(helper) => (
<>
{helper.textField({
label: 'This is required',
field: 'myString',
})}

{helper.textFields({
label: 'Should be two or more',
field: 'myArray',
minimumItemCount: 2,
})}

{helper.dateTimeField({
label: 'Date',
field: 'myDateTime',
fromISO: parseISO,
toISO: formatISO,
})}

{helper.submitButton({ label: 'Submit' })}
</>
)}
</ValidatedForm>
);
}
```

[Styled example](https://github.com/MakerXStudio/forms/blob/main/packages/mui-example/src/App.tsx) | [Live demo](https://makerxstudio.github.io/forms/mui-example)

### ionic

```bash
npm i @makerx/forms-ionic react-hook-form
```

#### Example

![Example](ionic-example.png?raw=true)

```tsx
import { IonCol, IonContent, IonGrid, IonPage, IonRow } from '@ionic/react';
import { ValidatedForm, z, zfd } from '@makerx/forms-ionic';

/**
* Define schema
*/
export const formSchema = zfd.formData({
myString: zfd.text(z.string().trim().min(1, 'Required')),
myOptionalParagraph: zfd.text(z.string().optional()),
});

/**
* Initialise with defaults
*/
const defaultValues: z.infer<typeof formSchema> = {
myString: '',
myOptionalParagraph: 'something already here',
};

/**
* Render form
*/

function App() {
const onSubmit = (data: z.infer<typeof formSchema>) =>
console.log('Received data:', data);
return (
<ValidatedForm
validator={formSchema}
onSubmit={onSubmit}
defaultValues={defaultValues}
>
{(helper) => (
<div>
<h2>ionic-example</h2>

{helper.textField({
label: 'This is required',
field: 'myString',
})}
{helper.textareaField({
label: 'This is not required',
field: 'myOptionalParagraph',
})}

{helper.submitButton({ label: 'Submit' })}
</div>
)}
</ValidatedForm>
);
}

export default App;
```

[Styled example](https://github.com/MakerXStudio/forms/blob/main/packages/ionic-example/src/App.tsx) | [Live demo](https://makerxstudio.github.io/forms/ionic-example)
- Ionic Framework [docs](https://github.com/MakerXStudio/forms/tree/main/packages/ionic) | [npm](https://www.npmjs.com/package/@makerx/forms-ionic) | [demo](https://makerxstudio.github.io/forms/ionic-example)
- MUI [docs](https://github.com/MakerXStudio/forms/tree/main/packages/mui) | [npm](https://www.npmjs.com/package/@makerx/forms-ionic) | [demo](https://makerxstudio.github.io/forms/mui-example)
Loading

0 comments on commit 38eeb5d

Please sign in to comment.