Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
react-form-maker
Advanced tools
make a react form faster by Object
In my opinion, It takes a lot of time on dealing with make pairs with & when creating a form setting the id & htmlFor. Moreover, usually, the pairs would share the same className or style. so, why not use a tool to deal with them. And you still can set className, style and so on for any pairs.
npm i react-form-maker
import React from 'react'
import { ReactFormMaker } from 'react-form-maker'
import 'react-form-maker/dist/index.css'
import 'bootstrap/dist/css/bootstrap.min.css'
const formClassName = {
formGroupClassName: 'form-group',
labelClassName: '',
inputClassName: 'form-control'
}
const formItems = [
{ id: 'name', label: 'Name:', type: 'text', defaultValue: 'test' },
{ id: 'account' },
{ id: 'phone', type: 'number' },
{ id: 'birthday', type: 'date' },
{
id: 'gender',
type: 'select',
options: [{ value: 'male', tag: 'Male' }, { value: 'female' }]
},
{
value: 'Submit',
type: 'submit',
className: 'btn btn-primary'
}
]
const App = () => {
return (
<ReactFormMaker
className='container'
header={<h1>react-form-maker demo</h1>}
formItems={formItems}
formClassName={formClassName}
/>
)
}
export default App
Bootstrap is used for demo, however, this module don't dependency on Bootstrap. It's Not necessary to use Bootstrap.
for most of the & pair of formItem would be like:
<div>
<label></label>
<input />
</div>
the div tag would be called "formGroup"
if you use button or submit, there would be no div of formGroup.
formClassName : Object formGroupClassName: string (className of the formGroup) labelClassName:string (className of the label) inputClassName:string (className of the input)
formStyle : Object formGroupStyle: Object (style of the formGroup) labelStyle: Object (style of the label) inputStyle: Object (style of the input)
Ps.The way to write the ClassName and style is the way you write in JSX
formItems : Object For more detail, please read the next section.
header : JSX Add any content before the formItems by JSX.
footer : JSX Add any content after the formItems by JSX.
other attributes Those Would be the attributes of
id : string This is the id of the and the htmlFor of the
label : string The text in the The default is the defined "id"
formGroupClassName: string (className of the formGroup)
labelClassName:string (className of the label)
inputClassName:string (className of the input)
formGroupStyle: Object (style of the formGroup)
labelStyle: Object (style of the label)
inputStyle: Object (style of the input)
Ps.The way to write the ClassName and style is the way you write in JSX "className" or "style" in formItems have priority than in the formClassName or formStyle
other attributes Those Would be the attributes of
{type:selection} Use (options : array) to create list of In options use Object to create each , which contain key value & text. Key of 'text' would be the text in , the default is the defined "value"
{type:button} If you use button or submit, there would be no div of formGroup. Simply use "className" or "style" to change the style.
MIT © ronny1020
FAQs
make a react form faster by object
The npm package react-form-maker receives a total of 1 weekly downloads. As such, react-form-maker popularity was classified as not popular.
We found that react-form-maker demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.