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

super-simple-react-form

v0.0.9

Published

A Dead Simple Form For React

Downloads

13

Readme

A Dead Simple Form For React

Motivation:

I feel the direction of form libraries in the market is like trying to bundle everything at once. The common direction of these libraries is to create isolated state inside the form, and provide API for developer to manipulate the isolated state.

Problems:

  1. A need to create custom component to work with the Form library.
  2. Problem to integrate another React's components on npm with the form's component.
  3. Components that has been created / modified is locked to certain Form library.
  4. Need to continuously learn API depends on the flavour of the library.

Then comes the idea:

  1. Why can't there be a form that just do validation and that it will work with any kind of component?
  2. Leave the rest of data manipulation to developer. This way we can easily cover infinite cases.

Concept:

  1. Simple Rules are better than many APIs
  2. User just need to provide 2 props: value, data-validators
  3. SimpleForm will check for these 2 props, and validate if these 2 props existed.

Example:

import { SimpleForm, validations } from 'super-simple-react-form';
const { required, minValue } = validations;

export default class Component extends React.Component {
    constructor(props){
      super(props);
      this.state = {
        input1: '',
      };
    }
    render(){
        return (
            <SimpleForm onSubmit={this.handleSubmit.bind(this)}>
                <div>                                               {/* 1 */}
                    <input
                       value={this.state.input1}                    {/* 2 */} 
                       data-validators={[required, minValue(10)]}   {/* 3 */}
                       onChange={e => this.setState({input1: e.target.value})}
                    />
                </div>
                <div>
                    <CustomInput 
                        value='hello'                    {/* 2 */}
                        data-validators={[required]}     {/* 3 */}
                    />
                </div>
                <div errorElement={<CustomErrorElement/>}>   {/* 4 */}
                    <CustomInput 
                        value='hello'                        {/* 2 */}
                        data-validators={[required]}         {/* 3 */}
                    />
                </div>
            </SimpleForm>
        );
    }
    handleSubmit(e, {isValids}){
        e.preventDefault();
        console.log(isValids);
    }
};

const CustomInput = props => {
    return <div>
        <input {...props}/>
    </div>
}

Rules:

1) Wrap the input element with div, SimpleForm will inject errorElement and render the errorMessages here.

2) Provide the value props.

3) Provide the validator functions to props data-validators

4) Please provide custom errorElement if you wish.

Validations

List of supported Validations:

  1. minLength(String)
  2. maxLength(String)
  3. minValue(Number)
  4. maxValue(Number)
  5. oneOfValue(array)
  6. preventScriptTag(String)

Future Features:

  1. validate onBlur
  2. mark the invalid input, as invalid attributes, like the usual HTML <input invalid/>