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-bunch

v2.0.2

Published

Form-bunch is a component like plugin that make it easier to write form, you could add the most of components what you want to form-bunch for build various forms

Downloads

1

Readme

form-bunch

NPM Status

Form-bunch is a component like plugin that make it easier to write form. You could add the most of components what you want to form-bunch for build various form. You could also easily change the settings to get the verification or layout you want. Hope you enjoy it, and if you like it, star it pllllllllllz. :)

Advantages:

  • Customizable. You can add whatever you want if it's possible, like components of Material-UI, Ant Design or customized components.
  • Small. it will give you performance and convenience for building form.
  • Easy. You can change the settings easily - see below

DEMO

Installation

  • YARN
yarn add form-bunch
  • NPM
npm install form-bunch

Usage

First of all, initialize form-bunch. Assume that you would like to use components of antd, the components should match two rules: 1. it has two fields —— value, onChange 2. the param(e) of onChange(e) => void must be corresponding to value. if one component has no value or onChange key, or it doesn't match form-bunch, you should replace them like following.

// index.tsx 
import { DatePicker, Input, Switch } from 'antd';

const extensions = {
  datePick: DatePicker,
  input: [
    Input,
    {
      // change the `e.target.value` to `value`
      // assume that original filed `onChange` is `onSelect`, 
      // then it should be `onChange: ['onSelect', 'e.target.value']`
      onChange: ['onChange', 'e.target.value'],
    },
  ],
  switch: [
    Switch,
    {
      // change the field `checked` to `value`
      value: 'checked'
    }
  ]
};

export type TExtensions = typeof extensions;

const MyFormBunch = formBunchInit<TExtensions>(extensions);

export default MyFormBunch;

And then, set style after verification failed in form-bunch-error-box className, then import it.

/* index.css */
.form-bunch-error-box .ant-input {
    border: 1px solid red;
    box-shadow: none
}

.form-bunch-error-box .ant-input:hover {
    border: 1px solid red;
}

.form-bunch-error-box .ant-input:active {
    border: 1px solid red;
}
// index.tsx
import './index.css'

...

export default MyFormBunch;

Finally, config form-bunch, and there are many apis for usage.

<MyFormBunch
  ref={formBunchRef}
  value={value}
  items={[
    {
      key: 'a',
      type: 'input',
    },
    {
      labelCol: '80px',
      offset: '40px',
      key: 'b',
      defaultValue: 'test',
      type: 'input',
      verify: (value) => value.length > 5,
    },
  ]}
  onChange={(value) => {
    setValue(value);
  }}
/>

Click DEMO for more details about usage.

API

Form

| Property | Description | Type | Default | | -------- | ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------- | ------- | | items | config of each form item, see Items API for more details | IFormItem | - | | onChange | the callback function when form data changes | (form: IFormValue, item: any, key: string) => void | - | | setting | global setting of form, Priority: items > setting, see Setting API for more details | IFormSetting | - | | value | form data | IFormValue | - |

Items

| Property | Description | Type | Default | | ------------ | ------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------- | ------- | | className | class of the formItem | string | - | | col | like flex-basic, the space that formItem takes up | number | string | '100%' | | controlCol | like flex-basic, the space that control of formItem takes up | number | string | '80%' | | defaultValue | default value, you can also change initial value of form API to set it | any | - | | error | the message after verification fails | string | - | | key | property of formItem | string | - | | label | label of formItem | string | - | | labelAlign | type of label alignment | 'left' | 'right' | 'center' | 'right' | | labelCol | like flex-basic, the space that label of formItem takes up | number | string | 20% | | offset | like margin-left, the space offset from the left | number | string | 0 | | render | render type of formItem control, require that only one is provided between property [type] and [render] | (value: any, setValue: (state: any) => void) => JSX.Element | - | | required | set formItem value to be required | boolean | false | | type | render type of formItem control, require that only one is provided between property [type] and [render] | string | - | | typeProps | when use [type], then [typeProps] is its original props | object | - | | verify | function that to verify the formItem value, it supports regex.when it return string, the string will replace corresponding error tip | RegExp | ((value?: any, form?: IFormValue) => boolean | string) | - |

Setting

| Property | Description | Type | Default | | ---------- | ------------------------------------------------------------ | ----------------------------- | ------- | | col | like flex-basic, the space that formItem takes up | number | string | '100% | | controlCol | like flex-basic, the space that control of formItem takes up | number | string | '80%' | | hasTips | determine if there is space left for error tips | boolean | false | | labelAlign | type of label alignment | "left" | "right" | "center" | 'right' | | labelCol | like flex-basic, the space that label of formItem takes up | number | string | '20%' | | offset | like margin-left, the space offset from the left | number | string | 0 |

Ref

| Property | Description | Type | Default | | -------- | --------------------------------------------- | ------------- | ------- | | validate | validate all values of form and return result | () => boolean | - | | reset | reset all value of form and result of verify | () => void | - |

Bug tracker

If you find a bug, please report it here on Github!