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

@zecos/inputs-basic

v0.0.13

Published

`@zecos/inputs` is a library for quickly creating form fields for rapid prototyping.

Downloads

8

Readme

@zecos/inputs-basic

@zecos/inputs-basic is a library for quickly creating form fields for rapid prototyping.

@zecos/inputs-basic is based on the @zecos/inputs library, which allows you to create your own UI input components with minimal boilerplate.

Installation

yarn add @zecos/inputs-basic

npm i -S @zecos/inputs-basic

Example

example

import React from "react"
import { nameValidator } from "@zecos/validators"
import { Text, TextArea, Select } from "@zecos/inputs-basic"

export const InputForm = () => {
  const {FirstName, firstNameState} = Text({
    validate: nameValidator,
    name: "firstName"
  })

  const {DescribeYourself, describeYourselfState} = TextArea({
    name: "describeYourself"
  })
  
  const {FavoriteColor, favoriteColorState} = Select({
    init: "blue",
    name: "favoriteColor",
  })

  return (
    <form className="form">
      {/* These are your inputs */}
      <FirstName />
      <DescribeYourself />
      <FavoriteColor options={{Blue: "blue", Red: "red"}}/>

      {/* display the data */}
      First Name State: {firstNameState.value}<br />
      Describe Yourself: {describeYourselfState.value}<br />
      Favorite Color: {favoriteColorState.value}
    </form>
  )
}

How it works

You pick an input type:

  • Text
  • TextArea
  • Select

Then pass it its options:

*name: string: will determine the classname, label, etc. THIS MUST BE CAMEL CASE. *validate?: fn => Error: an optional function to return an array of errors to display. Do not throw the errors. This works seamlessly with the @zecos/validators library.

  • init?: string | number: an optional initial value for the field. The default is "".

All together, for a text input, it looks like this:

const [FirstName, firstNameState, firstNameActions] = text({
  validate: nameValidator,
  name: "firstName"
})

This returns an array of 3 values:

  • 0: the input component ()
  • 1: the field state, which includes:
    • value: value of the field
    • touched: whether or not the user has focused and blurred the input
    • errors: the errors returned by your validate function
    • pristine: whether or not the field data has been manipulated
  • 2: the field actions, which include:
    • getState: returns the same thing as 1
    • setValue: set the value of the field (also runs validation and sets pristine to false)
    • reset: sets the field back to its original state (pristine, untouched, with the original init values)
    • setTouched: set the touched value to true

So, you see, you can manipulate the field data yourself, but it also manages the field data for you.

The component can then be used as your input with no additional setup:

<FirstName />

This is very powerful and enables you to eliminate a lot of the boilerplate of writing forms while maintaining flexibility.

You can rapidly prototype your forms, and, when you outgrow and need more customization, it's very easy to write your own library with @zecos/inputs.