A form generator who use React, Material UI and Formik as dependencies (an some others). A lot of fields types but feel free to install the minimum of dependencies.
https://grachet.github.io/formik-generator-materialui/
npm install --save formik-generator-materialui
- react: ^16.8.0
- react-dom: ^16.8.0
- formik: ^2.1.0
- @material-ui/core: ^4.9.0
- @material-ui/icons: ^4.9.0
- prop-types: ^15.5.4
npm install --save formik @material-ui/core @material-ui/icons prop-types
- @material-ui/lab: ^4.0.0 (autocomplete)
- @material-ui/pickers: ^3.2.0 (date)
- @date-io/moment: ^1.3.0 (date)
- moment: ^2.24.0 (date)
- yup: ^0.28.1 (field verification)
- react-quill: ^2.0.0-beta.1 (RTE)
npm install --save @material-ui/lab @material-ui/pickers yup react-quill@beta @date-io/moment@1.x moment
import React, { Component } from 'react'
import {FormGenerator} from "formik-generator-materialui";
import * as Yup from "yup";
function Example {
const formRef = useRef(null);
return (
<div>
<FormGenerator
onSubmit={(values) => {
console.log(values) // {fullname : "john", ...}
}}
fields={[
{
title: "Full Name",
path: ["fullname"],
typeField: "text"
},
{...},
]}
formRef={formRef}
initialValues={{
fullname: "john"
}}
validationSchema={Yup.object().shape({
fullname: Yup.string().required(),
})}
readOnly={false}
isValidateOnlyOnSubmit={false}
/>
<button onClick={() => formRef.current.submitForm()} />
</div>
)
}
- initialValues: object (reinitialize form on change)
- fields: array of objects
- getFields: function with form values who return fields props (replace fields props) : (formValues) => [{},...]
- onSubmit: func
- readOnly: bool
- formRef: object.isRequired (to get form functions)
- validateOnBlur: bool (less validation, less memory) default true
- validateOnChange: bool (less validation, less memory) default true
- validateOnMount: bool (less validation, less memory)
- onError: func
- shouldTriggerErrors: func
import React, { Component } from 'react'
import {FormDialogue} from "formik-generator-materialui";
import * as Yup from "yup";
function Example {
let [open, setOpen] = useState(false);
return (
<div>
<FormDialogue
open={open}
onCancel={() => setOpen(false)}
onOk={(values) => {
console.log(values)
}}
title={"Your title"}
text={"Your text here"}
initialValues={{
fullname: "john"
}}
validationSchema={Yup.object().shape({
fullname: Yup.string().required(),
})}
fields={[
{
title: "Full Name",
path: ["fullname"],
typeField: "text",
},
{...},
]}
/>
<button onClick={() => setOpen(true)}>open<button>
</div>
)
}
- onOk: function
- onCancel: function
- disableCancelOnOK: bool
- okText: string
- title: string
- maxWidth: 'xs', 'sm', 'md', 'lg', 'xl', false
- open: bool
- component: object
- link: { name: "string", url: "string"})
- text: string
- readOnly: bool
- initialValues: object (reinitialize form on change)
- fields: array of object
- validateOnBlur: bool (less validation, less memory) default true
- validateOnChange: bool (less validation, less memory) default true
- validateOnMount: bool (less validation, less memory)
- shouldTriggerErrors: func
- readOnly: bool
- hint: string
- warning: string
- title: string
- subfields: array of objects
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- multiline: bool
- isLink: bool
- required: bool
- hint: string
- warning: string
- title: string
- multiline: bool
- yup: object
- transformation: function
- separator: string
- display: array
- isLink: bool
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- choices: array
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- openTo: string ("year")
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- placeholder: string
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- emptyAddText: string
- noBorder: bool
- subfields: array of objects
- withSwap: bool
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- emptyAddText: string
- noBorder: bool
- subfield: object
- renderRightButton: react component (should be material ui IconButton)
- withSwap: bool
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- freeSolo: bool
- options: array
- getOptionLabel: function
- placeholder: string
- path: string (Required)
- readOnly: bool
- required: bool
- hint: string
- warning: string
- title: string
- freeSolo: bool
- getOptionLabel: function
- getAsyncOptions: function required
- placeholder: string
- npm start
- cd example
- npm start
- npm run deploy
- go to https://grachet.github.io/formik-generator-materialui
- new version in package.json
- npm login
- npm publish
Looking for collaborators to update the tool
MIT © grachet