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

gsd-form

v1.0.0

Published

Formik-based React library to create forms from plain JS objects

Downloads

33

Readme

GsdForm

Formik-based React library to create forms from plain JS objects (or JSON!)

Demo

Single fields object

Multiple field sets

Installing

yarn add gsd-form

Usage

import GsdForm from 'gsd-form'
import 'gsd-form/style.css' // Optional

class App extends Component {
  render() {
    return <GsdForm data={data} />
  }
}

Form data example

data = {
  form: {
    submitButton: {
      text: 'Send', // Optional. Default : Submit
      component: CustomComponent,
    },
    fields: { ... }, // Inline form
    // For forms sections you can use an array with nested fields
    // P.S.: These fields will be flattened on submit
    fields: [
      {
        name: 'String',
        fields: { ... } // Equal inline form
      }
    ],
  },
  recaptcha: {
    size: 'invisible', // one of compact, normal, invisible
    sitekey: 'SITEKEY_CODE',
  },
  showFormState: Boolean // Optional
  honeypot: Boolean // Optional
}

Field props

| Property | Type | Description | |:---- | ---- | ------ | | label | String | Label text | | name | String | Field (HTML input) name | | component | String | Options - input, textarea, select | | fieldClass | String | - | | disabled | String | disabled | | value | String | Initial (default) value | | format | String | Options - numeric, phone, date | | validate | Array<String> | [Yup validator, Optional custom error message]ex.: validate: [ 'string', ['email', 'Invalid email format'], 'required', ]More | | Field Select | - | - | | options | Array<Object> | Options for select inputs - [{ value: 'One', label: 'One' }] | | placeholder | String | select placeholder text' | | noOptionsMessage | String | Fallback text for empty select options |

You can also pass any other ReactSelect prop to select fields, such as menuIsOpen.

Method props

class App extends Component {
  handleSubmit (value, setters) {
    // send to a REST API ...
    console.log('onSubmit', value)
    setters.setSubmitting(false)
  }

  handleChanges (name, value) {
    // Called when each field changes
    console.log('handleChanges', name, value)
  }

  buttonProps (form) {
    // Called when each field changes
    console.log('buttonProps', form)
  }

  render() {
    return (
      <GsdForm
        data={data}
        handleSubmit={this.handleSubmit}
        handleChanges={(name, value) => this.handleChanges(name, value)}
        buttonProps={form => this.buttonProps(form)}
      />
    )
  }
}

export default App

See that the handleSubmit function has both parameters passed by Formik: values and a series of setters (errors, values, submitting, ...). You could use those to use backend validation or manage the loading/submitting state, for example.

You can use the handleChanges prop to, for example, change the available options for interdependent select inputs, such as country/state/city.

Another useful GsdForm prop is values, which can be used to pass dynamic values to Formik and make whatever desired inputs fully controlled by your parent component.

Dependencies

Contributing and developing

The projectwas created using create-react-library, so it should have its] basic structure updated soon. Right now, all the lib content should reside inside src, everything else can be used when developing or as examples.

You can start the dev server running:

yarn start

A production version can be generated using:

yarn build