# mui-dataforms

> Dynamically generated data forms for use with Material-UI

Latest version **0.2.2** (published 2019-07-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install mui-dataforms
pnpm add mui-dataforms
yarn add mui-dataforms
bun add mui-dataforms
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.2 |
| Published | 2019-07-09 |
| First published | 2019-07-07 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 29.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alex Krush |
| Maintainers | alexkrush |
| Keywords | data, form, dataform, dataforms, forms |

## Links

- npm: https://www.npmjs.com/package/mui-dataforms
- Repository: https://github.com/iKrushYou/mui-dataforms
- Homepage: https://github.com/iKrushYou/mui-dataforms#readme
- Issues: https://github.com/iKrushYou/mui-dataforms/issues
- npm.io page: https://npm.io/package/mui-dataforms

## Dependencies (3)

- [moment](https://npm.io/package/moment.md) ^2.24.0
- [@date-io/moment](https://npm.io/package/@date-io/moment.md) ^1.3.8
- [@material-ui/pickers](https://npm.io/package/@material-ui/pickers.md) ^3.1.2

## Alternatives

- [mobx-react](https://npm.io/package/mobx-react.md) — 2.8M weekly downloads
- [rc-tree](https://npm.io/package/rc-tree.md) — 2.6M weekly downloads
- [@react-oauth/google](https://npm.io/package/@react-oauth/google.md) — 1.3M weekly downloads
- [@wagmi/connectors](https://npm.io/package/@wagmi/connectors.md) — 877.0K weekly downloads
- [vee-validate](https://npm.io/package/vee-validate.md) — 836.4K weekly downloads

## Recent versions

- 0.2.2 (latest) — 2019-07-09
- 0.3.1-0 (dev) — 2020-03-11
- 0.2.4 — 2019-09-10
- 0.2.3 — 2019-09-09
- 0.2.1 — 2019-07-09
- 0.2.0 — 2019-07-09
- 0.1.1-23 — 2019-07-09
- 0.1.1-20 — 2019-07-09
- 0.1.1-14 — 2019-07-09
- 0.1.1-15 — 2019-07-09
- 0.1.1-19 — 2019-07-09
- 0.1.1-13 — 2019-07-07
- 0.1.1-12 — 2019-07-07
- 0.1.1-11 — 2019-07-07
- 0.1.1-10 — 2019-07-07
- … 4 more at https://npm.io/package/mui-dataforms/versions

## README

## Material-UI Dataforms

[![Build Status](https://travis-ci.com/iKrushYou/mui-dataforms.svg?branch=master)](https://travis-ci.com/iKrushYou/mui-dataforms)
[![npm package](https://img.shields.io/npm/v/mui-dataforms/latest.svg)](https://www.npmjs.com/package/mui-dataforms)
[![NPM Downloads](https://img.shields.io/npm/dt/mui-dataforms.svg?style=flat)](https://npmcharts.com/compare/mui-dataforms?minimal=true)

MUI Dataforms is a library intended to assist in creating dynamic forms based on a JSON input. Fields are completely dynamic with a multitude of pre-defined components (with the option of custom components). 

## Getting Started
### Installation

```
npm install mui-dataforms
```
or
```
yarn add mui-dataforms
```
### Using the forms
```
import MuiDataform from 'mui-dataforms'
```
#### Define your fields
```
const fields = [
    {
        title: "Personal Information",
        description: "Some info about yourself.",
        fields: [
            {
                id: 'first-name',
                title: 'First Name',
                type: 'text',
                validation: {
                    required: true,
                    min: 3,
                    max: 16,
                },
                size: {
                    xs: 12,
                    md: 6,
                },
            },
        ]
    }
]
```
#### Set up a state
```
const [values, setValues] = useState({"first-name": "Alex"})

const handleOnChange = (key) => (value) => {
	setValues(prevValues => ({...prevValues, [key]: value}))
}
```
#### Implementation
```
<MuiDataform title={"My Form"} fields={fields} values={values} onChange={handleOnChange}/>
```


## API


#### &lt;MuiDataform />

The component accepts the following props:

|Name|Type|Default|Required|Description
|:--:|:-----|:-----|:-----|:-----|
|**`title`**|string|`''`|false|Title of the form
|**`fields`**|array|`[]`|true|Data used to describe the fields. Array of [`section`](#options-section) objects.
|**`values`**|object|`{}`|false|Object containing the values of the form. Each value's key is linked to the `id` of the relative field.
|**`onChange`**|function||true|A function that will be triggered when the field changes. <br />`key => value => ()`

#### <a name="options-section"></a>section:
|Name|Type|Default|Required|Description
|:--:|:-----|:--|:-----|:-----|
|**`title`**|string|`''`|false|Title of the section.
|**`description`**|string|`''`|false|Description of the section.
|**`fields`**|array|`[]`|false|Fields for the section. Array of [`field`](#options-field) objects.


#### <a name="options-field"></a>field:
|Name|Type|Default|Required|Description
|:--:|:-----|:--|:-----|:-----|
|**`id`**|string||true|Reference to the value stored in the `values` object. Required unless `type` is set to `spacer`.
|**`title`**|string||false|Title of the field
|**`type`**|string||true|Type of field to display.<br/>`enum(text, number, select, date, time, datetime, checkbox, switch, spacer, custom)`
|**`validation`**|object||false|Title of the field.
|**`validation.required`**|bool|`false`|false|Title of the field.
|**`validation.min`**|int||false|Minimum length or size of input.
|**`validation.max`**|int||false|Maximum length or size of input.
|**`size`**|object|`{xs: 12}`|false|Grid sizing of each field. Uses same sizing from MUI: `xs`, `sm`, `md`, `lg`, `xl`.
|**`props`**|object||false|Additional props to pass through.
|**`options`**|array||false|Required for `type: select`. List of options defined by an array of objects with `value` and `label`.
|**`validator`**|function||false|Custom validation logic that returns whether the input is valid and an optional `errorMessage` to display to the client.<br/>`(value) => {valid, errorMessage}`

---
_Source: https://npm.io/package/mui-dataforms · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
