1.0.30 • Published 5 years ago

material-ui-form-builder v1.0.30

Weekly downloads
13
License
ISC
Repository
-
Last release
5 years ago

material-ui-form-builder

This project is used by Lessence.One for build easily Material-UI forms with every built-in or 3rd party material ui component like material-ui-chip-input. We continuously increase the number of components when we need it or by pull requests.

Disclaimer

This is just a quick tentative try to create a component where we have form state management, form builder and material ui. Later we would like to replace the quick solutions with existing ones to provide as many feature as we can.

Installation

npm i --save material-ui-form-builder

Usage

import React from 'react';
import ReactDOM from 'react-dom';
import { MuiThemeProvider, createMuiTheme } from '@material-ui/core/styles';

import Form from 'material-ui-form-builder';

const fields = [{ name: 'name', type: 'text' }, { name: 'limit', type: 'number' }];
const theme = createMuiTheme({
  palette: {
    primary: { main: '#8BC3D1' },
  },
});

ReactDOM.render(
  <div>
    <MuiThemeProvider theme={theme}>
      <Form
        fieldContainerStyle={{ backgroundColor: '#fefefe', padding: 10 }}
        onChange={(values) => console.log(values)}
        fields={fields}
        values={{ name: 'test', limit: 10 }}
        errors={{ limit: 'This field is required.' }}
      />
    </MuiThemeProvider>
  </div>,
  document.getElementById('root')
);

Form fields

text

Example: {name: 'name', type: 'text'}

PropertyTypeDefaultDescription
defaultstringThe default value for the field
disabledboolSet true to disable the field
keystringkeyThe identifier in the values object
namestringfieldThe label of the field

multiLineText

Example: {name: 'name', type: 'multiLineText', rows: 5}

PropertyTypeDefaultDescription
defaultnumberThe default value for the field
disabledboolSet true to disable the field
keystringkeyThe identifier in the values object
namestringfieldThe label of the field
rowsnumber1Number of rows to display
rowsMaxnumber2Maximum number of rows to display
emojiboolfalseSet true to make visible the emoji-picker

number

Example: {name: 'name', type: 'number'}

PropertyTypeDefaultDescription
defaultstringThe default value for the field
disabledboolSet true to disable the field
keystringkeyThe identifier in the values object
namestringfieldThe label of the field

select

Example: {name: 'name', type: 'select', items: [{value: 1, title: 'item'}]}

PropertyTypeDefaultDescription
defaultmixedThe default value for the field
disabledboolSet true to disable the field
itemsarrayThe list for select items.
keystringkeyThe identifier in the values object
multipleboolfalseWill support multiple selections, if value is trues
namestringfieldThe label of the field
dialogActiveboolfalseIf it is true, alert dialog will pop up every time when the value is changing
dialogContentstringThe content of the alert dialog
dialogTitlestringThe title of the alert dialog

checkbox

Example: {name: 'name', type: 'checkbox'}

PropertyTypeDefaultDescription
defaultmixedThe default value for the field
disabledboolSet true to disable the field
keystringkeyThe identifier in the values object
namestringfieldThe label of the field

chip

Example: {name: 'name', type: 'chip', items: [{value: 1, title: 'item'}]}

PropertyTypeDefaultDescription
defaultmixedThe default value for the field
keystringkeyThe identifier in the values object
namestringfieldThe label of the field

Properties

NameTypeDefaultDescription
delayTimenumberIn case when you would like to fire a delayed event about value changes.
delayTriggersarrayThe field elements that fire the onDelayedChange callback when these fields are changed, delayed by the delayTime prop. Every other field has 0 delay time.
errorsobjectThe object to show errors by field. Example: {name: 'This field is required.'}
focusStyleobjectThe style object to use to override floating label styles when focused.
handleChangefunctionCallback function that is fired when one of the field's value changes. Signature: function(field: string, value: mixed) => void
onChangefunctionCallback function that is fired when the form values changes. Signature: function(values: object) => void
onDelayedChangefunctionCallback function that is fired delayed when the form values changes. Signature: function(values: object) => void
saveFormfunctionIf this property passed to the component then a save button is displayed. Callback function that is fired when click to save button. Signature: function(values: object) => void
valuesobjectThe values for the form fields

Please open an issue if something is missing or does not work as expected.

1.0.30

5 years ago

1.0.29

5 years ago

1.0.28

5 years ago

1.0.27

5 years ago

1.0.26

5 years ago

1.0.25

5 years ago

1.0.24

5 years ago

1.0.23

5 years ago

1.0.22

5 years ago

1.0.21

5 years ago

1.0.20

5 years ago

1.0.19

5 years ago

1.0.18

5 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago

1.0.12

6 years ago

1.0.11

6 years ago

1.0.9

6 years ago

1.0.8

6 years ago

1.0.7

6 years ago

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago