zubair-react-form-builder
                                
                                
                                
                                    zubair-react-form-builder copied to clipboard
                            
                            
                            
                        React Form Builder
Zubair React From Builder
Zubair React Form Builder help you to build forms with drag and drop you can also inject your own component.
Installation
  npm i zubair-react-form-builder
  import { FormContainer, ToolBox } from 'zubair-react-form-builder'; 


FormContainer Props
- custom : Array
 - onSave(form) : Function
 - updateForm(callback) : Function
 - updateOnMount : Boolean
 - debug : Boolean
 - loader: Boolean // set save button on loading state
 
// Note OnSave Props also turn on Save Button on <FormContainer />
ToolBox Props
- custom : Array
 
Example
You can pass custom components to the form builder
const myCustoms = [
    {
        container : < ContainerComponent/>,
        preview : < PreviewComponent/>,
        toolbox : {
            title : 'Component',
            icon : 'fa fa-user',
            name : 'CUSTOM_COM'
        },
        states : {
            toolType: 'CUSTOM_COM',
            num1 : 1,
            num2 : 2
        }
    }
]
class App extends React.Component {
    render(){
        /* Simply pass myCustoms to */
        <div className="app"/>
            <div className="row"/>
                <div className="col-8"/>
                    <FormContainer
                        debug={true} // turn on debuging mode
                        updateOnMount={true} // update on mount
                        updateForm={this.updateForm} 
                        onSave={this.save} 
                        custom={ myCustoms } />
                </div>
                <div className="col-8"/>
                    < ToolBox custom={ myCustoms } />
                 </div>
            </div/>
        </div/>
    }
    
    save(form){
        // you will receive form
        console.log(form);
    }
    
    updateForm(callback){
        // fetch form and set it to callback
        let form = axios.......
        callback(form)
    }
}
Required Props Methods Of Custom Component
- 
this.props.changeState(state, this.props.index)
 - 
this.props.removeField(index)
 
Example Props Methods
        // on change state
        changeValue(stateFor, value){
            switch (stateFor){
                case "TITLE" :
                    this.setState( { title : value } )
                    break;
                default:
                    return;
            };
            setTimeout(() => {
                return this.props.changeState(this.state, this.props.index);
            }, 0)
        }
        
       
         this.changeValue('TITLE', e.target.value)} />
        
         // on remove field   
         this.props.removeField(this.props.index)}>x