0.1.2 • Published 1 year ago

react-mui-form-generator v0.1.2

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

react-mui-form-generator

Built on top of @mui, react-hook-form and yup.

Schema builder library for generating and validating (simple) material-ui forms. Just define your schema, add it to the default FormGenerator component with any callback function and create your form.

This library is under development

Features

  • Schema interface for generating Material-ui forms or steppers
  • Support for standard and dynamic forms (2-levels)
  • Easy to personalize - just create your own theme or style a component
  • Uses React-Hook-Forms to control dynamic form elements
  • Supports Yup validation

Table of Content

  • Installation
  • Getting Started
  • Example
  • Table of Contents
  • Building schemas
    • Schema Basics
    • Schema Configurations
    • Form Options
    • Field Properties
    • Field Icon Options

Installation

npm install react-mui-form-generator

Getting Started

  1. Create new react app with create-react-app
  2. Edit App Component
  3. Import FormGenerator component and any (preset) FieldConfugration
  4. Import predefined field definitions (such as login fields)
  5. Define your schema
  6. Code your form callback function
  7. Render your app

Example

Sample of stepper schema with callback function

import React, { useState, useEffect } from 'react';
import { FormGenerator, FormConfiguration, CheckboxFields, DarkTheme } from '../../plugin';

const schema = { 
  ...FieldConfiguration.classic,
  showStepHeader: false,   
    forms: [
        {
            step: 1,                
            fieldDefinitions: [     
               	LoginFields.email,           
                LoginFields.password
            ]               
        },      
    ]
}

const Comp = () => {
    const [formResult, setFormResult] = useState(null);    
    useEffect( () => {            
        if(formResult) {
            alert('Form is ready')            
        }                     
    }, [ formResult ]);

    return (<>
        <DarkTheme>
            <FormGenerator
                schema={schema}
                setFormResult={setFormResult}           
            />
        </DarkTheme>
    </>);
}

export default Comp;
  • Table of Contents
  • Building schemas
    • Schema Basics
    • Schema Configurations
    • Form Options
    • Field Properties
    • Field Icon Options

Quickstart Samples

Table of Contents

Building schemas

Both Forms and Steppers are generated from flexible schemas that use supported @mui fields and field definitions to generate Material-UI forms. A schema defines one or multiple step where each step is considered to be a form. A form definitions has one or multiple fields where each field can have its own Yup validation rule and input type - for instance a textfield or textareafield.

Schema Basics

A Schema is the configuration object that is used to generate any @mui stepper or single form.

Properties

PropertyTypeRequiredValuesDescription
titlestringyes
stepsstring[]yes
stepperIDstringnoIf not provided it is autogenerated
formIDstringnoIdentifier for single step/form
showTitlebooleanyesDefaults to true
showStepHeaderbooleannoShow @mui stepper header. Defaults to false
maxContainerWidthstringnoxs,sm,md,lg,xlDefaults to viewport xs
defaultBackButtonTextstringnoDefault value: 'Back'
defaultStepButtonTextstringnpDefault value: 'Next'
finalStepButtonTextstringnoDefault Value: 'Submit'
showStepContainerbooleannoDefaults to false
validateOnNextStepbooleannoDefaults to false
textFieldVariantstringnostandard, outlined, filledDefaults to standard
textFieldSizestringnosmall, normalDefaults to norrmal
selectFieldVariantstringnostandard, filled
formsobjectyes

Schema Configurations

This library provides three configurations for Material-UI forms to speed up your coding process. To use them import the FieldConfiguration object.

ConfigurationDescription
defaultEnglish button texts, display stepper title, display step header, display step container, normal sized standard @mui textfield, filled @mui select field, display grid with spacing <1>
classicEnglish button texts, display stepper title, display step header, display step container, norma sized outlined @mui textfield, filled @mui select field, display grid with spacing <1>
modernEnglish button texts, display stepper title, display step header, display step container, normal filled standard @mui textfield, filled @mui select field, display grid with spacing <1>

Usage

const schema = {
  ...
  ...FieldConfiguration.classic,
  // your overrides
  showStepHeader: false,   
  ...  
}

More info and schema samples

Form Options

Schema.forms defines one or multiple steps. Each step object holds an identifier and @mui field definitions

OptionTypeRequiredValuesDescription
stepnumberyes1,2,3...
formDefinitionobjectyesinterface IField

More info and field definitions samples

Field Properties

Field Options | Option | Type | Required | Field(s) | Description | |-----------------------|:-------------:|:----------:|:-----------------|:---------------------------------------------------| | fieldName | string | yes | All | | | label | string | yes | | | | value | string, number, string[], number[] | no | Used to set start value | | helperText | string | null | no | | | | startItemText | string | mull | no | | | | headerText | string | null | no | | | | input | string | yes | | Controlled Material-Ui field component. See below for options | | inputType | string | no | TextField | email, password, text, date | | validation | any | no | All | Yup validation rule | | visibility | boolean | yes | All | Show field when form is first displayed | | required | boolean | no | All | Force validation as soon as form is dirty | | icon | object | no | TextField, TextArea | Show icon - see below | | multiline | boolean | no | TextArea | | | rows | number | no | TextArea | | | minRows | number | no | TextArea | |
| maxRows | number | no | TextArea | |

Field Icon Options

OptionTypeRequiredComments
showbooleanyes
componentJSX.ElementyesFor instance any iconimported from '@mui/icons-material/
colorstringnoUnder development
0.0.84

1 year ago

0.0.40

1 year ago

0.0.85

1 year ago

0.0.41

1 year ago

0.0.86

1 year ago

0.0.87

1 year ago

0.0.88

1 year ago

0.0.89

1 year ago

0.0.80

1 year ago

0.0.81

1 year ago

0.0.82

1 year ago

0.0.83

1 year ago

0.0.37

1 year ago

0.0.38

1 year ago

0.0.39

1 year ago

0.0.73

1 year ago

0.0.74

1 year ago

0.0.30

1 year ago

0.0.75

1 year ago

0.0.31

1 year ago

0.0.76

1 year ago

0.0.32

1 year ago

0.0.77

1 year ago

0.0.33

1 year ago

0.0.78

1 year ago

0.0.34

1 year ago

0.0.79

1 year ago

0.0.35

1 year ago

0.0.36

1 year ago

0.0.70

1 year ago

0.0.71

1 year ago

0.0.72

1 year ago

0.1.2

1 year ago

0.1.1

1 year ago

0.0.26

1 year ago

0.0.27

1 year ago

0.0.28

1 year ago

0.0.29

1 year ago

0.0.20

1 year ago

0.0.21

1 year ago

0.0.22

1 year ago

0.0.23

1 year ago

0.0.24

1 year ago

0.0.25

1 year ago

0.0.15

1 year ago

0.0.16

1 year ago

0.0.17

1 year ago

0.0.18

1 year ago

0.0.19

1 year ago

0.0.95

1 year ago

0.0.51

1 year ago

0.0.96

1 year ago

0.0.52

1 year ago

0.0.97

1 year ago

0.0.53

1 year ago

0.0.98

1 year ago

0.0.54

1 year ago

0.0.10

1 year ago

0.0.99

1 year ago

0.0.55

1 year ago

0.0.11

1 year ago

0.0.56

1 year ago

0.0.12

1 year ago

0.0.13

1 year ago

0.0.14

1 year ago

0.0.90

1 year ago

0.0.91

1 year ago

0.0.92

1 year ago

0.0.93

1 year ago

0.0.94

1 year ago

0.0.50

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.5

1 year ago

0.0.4

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago

0.0.3

1 year ago