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

reactstrap-input

v1.0.8

Published

clone this project

Downloads

22

Readme

clone this project

npm install

Commands:

starts development server with example page

npm run start

builds file into dist folder

npm run transpile

to get local changes instantly:

link this package locally

npm link

start watching files and build latest changes by running

npm run watch

in the project folder where you want to see latest changes, install the project

npm install --save <project name>

to get local changes to this package to show up in your project instantly

npm link <project name>

Note: you will probably have to relink files after each install.

Getting Started

How this works:

InputComponent/InputGroupComponent are controlled components that take in "typical" controlled component props such as value and handleChange. handleChange should be a function that uses event.target.value and event.target.id dispatches an action to update state. (valueKey is placed in event.target.id)

There should also be an empty object initialized in your store/state/reducer to store validation results. this should be passed to InputComponent as validationObj.

InputComponent will check validationObj for items validated via approvejs, and update the reactstrap components accordingly.

As of now, validation is "manual". Hence, Inputs will not be validated upon load unless implemented.

Typically, the handleChange function should update the InputComponent's value, and also update (or initialize) validationObj each time it is called.

If no corresponding key is found in validationObj , validation will be skipped (assumed to be passed).

Validation will also be skipped if saveButtonPressed is false.

// example reducer default state
defaultState = {
    fields: {
        firstName: '',
        lastName: ''
        // ...other fields as needed
    },
    validation: {} // for storing validation results
}

And in your InputComponent:

// this.props = {...defaultState}
<InputComponent
    value={this.props.fields.value}
    validationObj={this.props.validation}
    ...
/>

Example onChange function, in mapDispatchToProps:

handleChange: (e) => {
    dispatch({
        type: CHANGE_FIELD_VALUE
        key: e.target.id,
        value: e.target.value,
    })
}

And in your reducer:

case 'CHANGE_FIELD_VALUE':
    // update field value
    newState.fields = Object.assign({}, state.fields);
    newState.fields[action.key] = action.value;

    // update validation result object with approvejs
    newState.validation = Object.assign({}, state.validation);
    newState.validation[action.key] = validationlib.validate(action.key, action.value);
    return newState;

In validationlib:

    validate: (key, value) => {
        if (!validationTypes[key]) {
            // no validation specified for key
            return false;
        }
        // see approvejs documentation for more info regarding rules
        let rules = validationTypes[key] ? validationTypes[key] : null;
        return approve.value(value, rules);
    }

InputComponent Props

    handleChange // onChange function that should update a) the Input's value and b) validationObj
    saveButtonPressed // validation will only trigger if this is true
    validationObj // the validation object in state that stores validation results
    inputProps // props that will be passed to the reactstrap Input component
    value // value of the input
    valueKey // key used for controlled component and validation. passed in as input.id
    type // type of input, e.g 'text', 'textarea', 'number'
    rows // only applies if type === 'textarea'
    noFeedback // remove the FormFeedback portion
    colWidth // bootstrap col width for inline inputs
    label
    defaultValue

TODO:

  • use data-* props instead of hogging id prop
  • rethink about forcing validation at start/proper initialization of validationObj
  • CI to publish changes made in this repository to npm