npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

form-builder-redux

v1.0.2

Published

Form Builder for preexisting inputs

Downloads

6

Readme

#Form Builder

Is a component that generates a form using predefined input elements. The input elements available are:

##Form Builder Items

Form builder for line items. Some usage examples would be purchase orders, work orders and invoices where there is a main table and an items table related to it(hasMany relationships)

TODOS

  • [ ] Unit tests (Jest)
  • [ ] Continuous Integration (Circle Ci)
  • [ ] Extend for custom inputs
  • [ ] Documentation for FormBuilderItems
  • [ ] Add examples
  • [ ] Webpack tests

###Props

It receives the following props:

| Prop | Default Value | Description | |------|---------------|-------------| | value| Empty String | value of the controlled input| | label| Empty String | label of the input| | labelOn| False Boolean | flag to show label| | name| Empty String | html name attribute | | labelClasses| Empty String | classes of label tag| | inputContainerClasses | Empty String | classes of div containing input| | onChange | Callback Function | callback that modifies value| | disabled | False Boolean | flag that disables input interaction| | options | Empty Array | on select inputs, array of all options that can be selected| | multiple | False Boolean | on select inputs, enables multiple selection| | placeholder | Empty String | placeholder html attribute | | inputAttributes | Empty Object | key-value pairs of input attributes (e.g placeholder, type, number)

###Form Configuration File

This is an array of fields and its props that will be passed FormBuilder.

Fields array example:

const fields = [
  {
    name: 'code',
    elt: Inputs.TextInput,
    label: 'Code',
    labelOn: true,
    labelClasses: 'col-sm-3',
    inputContainerClasses: 'col-sm-6'
    inputAttributes: {
      type: 'number',
      step: 0.1
    }
  },
  {
    name: 'description',
    elt: Inputs.TextArea,
    label: 'Description',
    labelOn: true,
    labelClasses: 'col-sm-3',
    inputContainerClasses: 'col-sm-6'
  }
];

####FormBuilder with React:

import React from 'react';
import {render} from 'react-dom'
import update from 'immutability-helper';
import FormBuilder from 'form_builder';

class Item extends React.Component{
    constructor(props){
        this.state = {
            form: {
                code: '',
                description: ''
            } // must have a form key
        }
    }

    onChange(field, value){
        this.setState({
          header: update(this.state.form,{
            $merge:{
              [field]: value
            }
          })
        });
    }

    render(){
        return (
            <FormBuilder
                fields={fields}
                form={this.state}
                formClasses='form-horizontal'
                onChange={this.onChange.bind(this)}
            />
        )
    }
}

render(
  <Item/>,
  document.getElementById('root')
)

####FormBuilder with React and Redux:

import React from 'react';
import {render} from 'react-dom'
import {Provider, connect} from 'react-redux';
import {bindActionCreators, createStore} from 'redux'
import * as itemActions from './actions/item_actions.js'
import rootReducer from './reducers/index.js';
import FormBuilder from 'form_builder';

// Set up form
const FormBuilderRedux = connect(
  state => state, 
  dispatch => ({actions: bindActionCreators(itemActions, dispatch)})
)(FormBuilder);

class Item extends React.Component{
    render(){
      return(
        <FormBuilderRedux
            fields={fields}
            formName='item'
            formClasses='form-horizontal'
            onChange='update'
        />
      )
    }
}

// Configure Store
const store = createStore(
    rootReducer,
);

//Render Component
render(
  <Provider store={store}>
    <Items/>
  </Provider>, 
  document.getElementById('root')
);

Item Actions (item_actions.js)

export const update = (name, value) =>({
  type: 'FORM_UPDATE_VALUE',
  name, 
  value
});

Reducer (item_reducer.js)

const initialState={
    item:{
        form:{
            code: '',
            description: ''
        }
    }
};

const item = (state=initialState.item, action) => {
  switch(action.type){
    case 'FORM_UPDATE_VALUE':
      return {
        ...state,
        form: {
            ...state.form
            [action.name]: action.value
        }
      }

    default:
      return state;
  }
}

import {combineReducers} from 'redux';

const rootReducer = combineReducers({
  item
})

export default rootReducer;

Redux: dispatch -> action -> reducer -> update state