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

react-boilerplate-form

v0.1.2

Published

Tiny library that provides a boilerplate form components and validators for ReactJS.

Downloads

22

Readme

Build Status Coverage Status install size

React-boilerplate-form

React-boilerplate-form is tiny library that provides boilerplate form components and validators for ReactJS. Main goal of this library is to separate business logic from UI and keep it pure and clean.

Library provides common form elements (e.g. Input, Form, Select) and few specific (Errors, Profile) as React components. Additional functionalities (e.g. isDirty, isValid, isBusy) are available when Form component is used as FaaC. Components do not have any styling. Hence, classes and styles should be applied to them as to any other React components.

Also, many custom sync or async validators for complete form or particular field can be defined although basic set of rules are provided (e.g. min, max, greater, least, size, required).

Main features

  • Expressive and intuitive syntax
  • Custom field validation rules (sync and async)
  • Custom form validation rules (sync and async)
  • Custom field value decorators
  • React components that match common HTML form tags
  • Support for different profiles (e.g. insert, update)

Install

Install it with NPM

npm install react-boilerplate-form --save

Prerequisites

  • ReactJS 16.4+

Usage

Form should be defined in two steps:

  1. define rules (validations and decorators) for form fields
    const fieldset = new FormFieldset(new TextFormField('firstname').min(3));
  1. create UI
    <form fields={fieldset} onSubmit={(values)=>console.log(values)}>
        <Input name="firstname" />
        <button type="submit">Submit</button>
    </form>

Complete example:

import React from 'react';
import {FormFieldRules, FormRules, TextFormField, NumberFormField, Form, Input} from 'react-boilerplate-form';

function SimpleForm(){
    
    const fieldRules = new FormFieldRules(
        new NumberFormField('id'),
        new TextFormField('title')
    );
    const formRules = new FormRules();

    const onSubmit = values=>console.log(values);
    const initalValues = {'id': 1};

    return (
        <Form fieldRules={fieldRules} values={initalValues} onSubmit={onSubmit}>
            <label htmlFor="id">ID:</label>
            <Input name="id" />
            <label htmlFor="title">Title:</label>
            <Input name="title" />
            <button type="submit">Submit</button>
        </Form>
    );
}
export default SimpleForm;

Form as FaaC example:

import React from 'react';
import {FormFieldRules, FormRules, TextFormField, NumberFormField, Form, Input} from 'react-boilerplate-form';

function SimpleForm(){
    
    const fieldRules = new FormFieldRules(
        new TextFormField('firstname'),
        new NumberFormField('age')
    );

    const onSubmit = values=>console.log(values);
    const initalValues = {'age': 18};

    return (
        <Form fieldRules={fieldRules} values={initalValues} onSubmit={onSubmit}>{
            ({isDirty})=>(
                <React.Fragment>
                    <label htmlFor="firstname">Firstname:{isDirty('firstname') && <small>changed</small>}</label>
                    <Input name="firstname" />
                    <label htmlFor="age">Age:{isDirty('age') && <small>changed</small>}</label>
                    <Input name="age" />
                    <button type="submit">Submit</button>
                </React.Fragment>
            )
        }
        </Form>
    );
}

Please go on wiki for more examples and complete API.

License

MIT