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

@cat-react/form

v0.1.2

Published

A simple yet powerful library which helps creating validated forms in react.

Downloads

67

Readme

@cat-react / form Build Status codecov npm version

A simple yet powerful library which helps creating validated forms in react. This project is inspired by formsy-react.

Installation

npm package

  • Install the dependency @cat-react/form (e.g. with yarn add @cat-react/form or npm install @cat-react/form --save)
  • Import the Components with import {Form, Input} from '@cat-react/form';

Getting Started

| API Documentation | Examples | |---|---|

Are you looking for a simple way to create validated forms with React?

Congratulations! Your search is over, because @cat-react/form offers you a simple way to create either frontend- or backend-validated forms. Validations can either be processed synchronous or asynchronous and the state of the form is being refreshed in real time.

Take a look at the examples to find out how to create the form of your desire.

<Form>
    <MyInput name="email"
             validations={{
                 isEmail: true,
                 isRequired: true
             }}/>
    <MyInput name="email_confirm"
             validations={{
                 isRequired: true,
                 equalsField: 'email'
             }}
             messages={{
                 isRequired: 'Please confirm your email address.',
                 equalsField: 'The email addresses do not match each other.'
             }}/>
</Form>

Example Custom TextInput

Here you can see an example of an custom TextInput which shows how you can implement your own Inputs:

import React from 'react';
import {Input} from '@cat-react/form'

@Input
export default class BasicInput extends React.Component {
    onChange(event) {
        this.props.setValue(event.target.value);
    }

    getClassName() {
        let className = 'form-control';
        if (!this.props.isPristine()) {
            if (this.props.isValid()) {
                const isWarning = this.props.getMessages().length > 0;
                if (isWarning) {
                    className += ' warning';
                }
            } else {
                className += ' error';
            }
        }
        return className;
    }

    renderMessages() {
        let messages = [];
        if (!this.props.isPristine()) {
            messages = this.props.getMessages();
        }

        if (!messages || messages.length <= 0) {
            return null;
        }

        let className = 'errorText';
        if (this.props.isValid()) {
            className = 'warningText';
        }

        return <ul className={className}>{messages.map((message, i) => <li key={i}>{message}</li>)}</ul>;
    }

    render() {
        return (
            <div className="form-group">
                <label htmlFor={this.props.name}>{this.props.label} {this.props.isRequired() ? '*' : null}</label>
                <input type={this.props.type}
                       className={this.getClassName()}
                       id={this.props.name}
                       aria-describedby={this.props.name}
                       placeholder={this.props.placeholder}
                       value={this.props.getValue()}
                       onChange={this.onChange.bind(this)}
                       onBlur={this.props.touch}/>
                {this.renderMessages()}
            </div>
        );
    }
}

Note: You need the babel-plugin-transform-decorators plugin to use the @Input decorator. If you don't want or cannot add this plugin to you webpack config you need to use the HOC as a function (like the connect() HOC of Redux).

Example: export default Input(BasicInput)

See the Babel Documentation for a detailed guide about how to add decorators to your application.

Contribution

The project requires at least the latest stable version of node and npm. You also need to have yarn installed globally.

Two simple steps to get the things running on your local machine:

  • Fork the repo
  • Execute yarn

You can run the examples with yarn run examples and the tests with yarn test.

How to build a release

  • update the CHANGELOG.md with all changes regarding the new release
  • update the release version in the package.json
  • push the changes
  • build the project locally with npm run build
  • cd into the dist folder and run npm publish --access public
  • draft a new release at Github with the contents of the CHANGELOG.md file

License

MIT License

Copyright (c) 2018 Catalysts GmbH