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

form-bender

v0.1.8

Published

A simple and quick way to create and handle forms

Downloads

4

Readme

React form-bender

A simple and quick way to create and handle forms

Install

npm:

npm install form-bender

yarn

yarn add form-bender

Once the installation is completed, You can start using the components by importing them from:

import { FormTextInput, TextInput, useFormManager } from 'form-bender'

Why form-bender?

Form-bender makes forms easier by taking the hassle out of working with form-state, errors, validation, and inputs. it has a great input restriction on numbers & prices, fantastic parser & correct outs.

FormTextInput

This is the main input component it accepts multiple validation strategies, and you can rely on useFormManager to handle the form state for you.

the default validation strategy is any

you can use this component like this in your code:

import { useFormManager, FormTextInput } from "form-bender";
function App() {
  const folder = useFormManager({ name: "", age: 18, email: "" });
  return (
    <div>
      <FormTextInput name="name" label="Name" folder={folder} strategy="text" />
      <FormTextInput name="age" label="Age" folder={folder} strategy="number" />
      <FormTextInput name="email" label="Email" folder={folder} strategy="email" />
    </div>
  );
}

Strategies

all these strategies will return a string and it accepts only a string or number as an initial value. other data types like array, objects etc... will disable the input.

text will not throw any error except for the data type error.

email will show a validation error when the inputted value is not an email.

username will show a validation error when the inputted value is not a username.

password will show a validation error when the inputted value is not a strong password [at least one uppercase] [at least one uppercase] [at least one number] [at least one symbol] [at least 8 characters].

number will parse strings and always return a number. it will not throw any error except for a data type error.

price will parse strings and always return a price like 10.00 with fixed cents, so 45.1 is returned 45.10. it will not throw any error except for a data type error.

any will allow string or number but always output string. it will not throw any error except for a data type error.

TextInput

This component is very similar to FormTextInput, but you should not use it with useFormManager although it's possible to do that, it's not recommended.

It's better to look at this component as a simple Input component, here is an example of how to use it:

import { TextInput } from "form-bender";
function App() {
  const [state, setState] = useState({ name: "", age: "" });
  const handleChange = useCallback((value: string, key: string) => {
    setState((prev) => ({ ...prev, [key]: value }));
  }, []);
  return (
    <div>
      <TextInput name="name" label="Name" value={state.name} onChange={handleChange} />
      <TextInput name="age" label="Age" value={state.age} onChange={handleChange} />
    </div>
  );
}

useFormManager

This is the form Manager, it will reurn the folder that is used by FormTextInput, Folder = { state, action }:

state

dirty: shows whether the form has been edited.

initialValues: Holds the current form's version initial values.

values: Holds the live values derived from the inputs.

errors: Holds the errors derived from the inputs.

touched: Marks the touched inputs, it is triggered by onBlur.

version: The current version of the form. changing this value will update the form and inputs will reset.

action

onChange: used to change a value in the state, use this carefully! calling this method will re-render the component.

reset: used to reset the form to initialValues.

clear: used to clear the values in the form of an empty string.

update: used to create a new form structure. it will reset & overwrite with new form values.

get: will return { name, value, touched, errors, initialValue } of a specific field.

FormTheme

Though you can hand-pick the colors of each input by passing them through their respective props, you also can theme the inputs by containing them inside the FormTheme component. this component will only theme its children, which means you can have multiple themes side by side.

Putting it in the root file will theme all the inputs everywhere.

import { useFormManager, FormTextInput } from "form-bender";
function App() {
  const folder = useFormManager({ name: "", age: 18, email: "" });
  return (
    <FormTheme errorColor="orange">
      <FormTextInput name="name" label="Name" folder={folder} strategy="text" />
      <FormTextInput name="age" label="Age" folder={folder} strategy="number" />
      <FormTextInput name="email" label="Email" folder={folder} strategy="email" />
    </FormTheme>
  );
}