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

formalization

v1.4.25

Published

A simple and straight-forward wrapper around forms that works as you would expect

Downloads

27

Readme

formalization

NPM JavaScript Style Guide Build Status npm Support

A simple and straight-foward wrapper around forms that works as you would expect. Fully customizable and able to handle files and images, using formdata.

Install

npm install --save formalization

Usage

import * as React from 'react';

import { Form, Input, Group, Text, When, Value } from 'formalization';

export default function App () {
	const onSubmit = (data) => {
		//handle data
	};

	const validateEmail = (value) => {
		if (/*validation fails*/) {
			return "Email not valid";
		}
	}

    return (
		<Form onSubmit={onSubmit}>
			<Group name="user">
				<Input name="email" validates={validateEmail} />
				<div className="error-message">
					<Error name="email" />
				</div>

				<Input name="name" />
			</Group>

			<Toggle name="newsletter" />

			<When name="newsletter">
				Thank you for signing our newsletter <Value pathname="user.name" />
			</When>

			<Text name="message" />
		</Form>
    );
}

Components

Form

The core component of the form, this handles, gathers and set the data. If you return false from the onChange/onSubmit, it will clear the form, if you return any data, it will adjust the form accordling, if you return null, nothing happens.

props

|name|requirement|type|description| |---|---|---|---| |data|optional|[Object, function (newValue)]|A useState array that will be used to interact with an outer object, don't switch between using a controlled state data and uncontrolled| |initialData|optional|Object|Initial state of the form data| |file|optional|boolean|Changes the result of the onChange/onSubmit to a FormData| |onChange|optional|function (data)|Function that returns the data when the form is updated| |onSubmit|required|function (data)|Function that returns the data when the form is submitted| |onError|optional|function (data)|Function that returns errors messages given| |validateOnChange|optional|boolean|Enable callback calls and updates on change, instead of submit|

Group

Group component allow you to nest data inside of objects

props

|name|requirement|type|description| |---|---|---|---| |name|required|string|The key that this object will be recognized inside of the form result|

Error

Displays error messages from the component linked

props

|name|requirement|type|description| |---|---|---|---| |name|required|string|The name that this component will print errors from|

Input | Text | File | Select | Toggle

The form input that handles each type in a specific way, since toggle has some "peculiarities", we handle him separatedly from the input.

props

|name|requirement|type|description| |---|---|---|---| |name|required|string|The key that this object will be recognized inside of the form result| |onChange|optional|function (data, htmlnode)|Callback that let's you know when this component has changed value| |filters|optional|Array<function (data) => any>|An array that can modify the value before it's handled to the form itself|

Wrapper

In case you are using another package or you want to build a component that interacts with the form, you can use the wrapper for this. You can use the filters prop to alter the value cleanly.

props

|name|requirement|type|description| |---|---|---|---| |name|required|string|The key that this object will be recognized inside of the form result| |value|required|any|The value that will be inserted into the form| |setValue|required|function (newValue)|This is required so formalization can set the data innerly| |filters|optional|Array<function (data) => any>|An array that can modify the value before it's handled to the form itself|

Value

You can use this component to display a value from inside of the form without having too much issue about it. You need to use name or pathname.

props

|name|requirement|type|description| |---|---|---|---| |name|optional|string|The name of the key relative to the position in the form| |pathname|optional|string|The absolute path to the key and it's name| |default|optional|any|Default value to be displayed in case there is a null value| |filters|optional|Array<function (data) => any>|An array that can modify the value before it's handled to the form itself|

When

This component allows you to conditionally display it's children based on the condition given. You need to use name or pathname.

props

|name|requirement|type|description| |---|---|---|---| |name|optional|string|The name of the key relative to the position in the form| |pathname|optional|string|The absolute path to the key and it's name| |when|required|boolean or function (value) => boolean|The condition that prevents the children from appearing|

License

BSD-3 © aposoftworks