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

react-build-form

v1.3.15

Published

Make dynamic forms. It uses antd ui library, formik, yup, dayjs

Downloads

158

Readme

What is this?

Build dynamic , complex forms more easy.

Requirements.

For components - ANTD ui library, Form - formik, Validation - Yup, Bootstrap for grid system (It will be removed next updates)

Installation

npm i react-build-form add : @import "bootstrap/scss/bootstrap" to your scss file

Usage

```
import {FormBuilder} from "react-build-form"

export default function YourComponent(){
    function doSmth(values){
        ....
    }

    return <FormBuilder inputScheme={[
           {
                label:'Username',
                field:'login',
                type:"text",
                col:"col-12",
                initialValue:null,
                validation:Yup.string().required(),
                required:true,
                props:{
                    placeholder:'Username or email',
                    size:'large',
                    prefix:<UsernameIcon/>,
                    style:{
                        padding:"12px"
                    }
                }

            }
        ]}
         onSubmit={(values)=>doSmth(values)} 
         button={{
            title:"Verify",
            props: {
                size:'large',
                style:{
                    width:"100%",
                    backgroundColor:'#7F56D9',
                    color:'white',
                    padding:"14px",
                    height:"auto"
                },
                className:'mb-3'
            }
        }}  />
}
```

Explanation

  1. inputScheme

    1. label : label for Input
    2. field : write value's key (Above example values is {login:'any value you wrote'})
    3. type : there is 9 types:
    4. text : it renders simple Input component in ANTD
    5. text-area : it renders TextArea component in ANTD
    6. selection : it renders Select component in ANTD
    7. tree-select : it renders Tree-select component in ANTD
    8. switch : it renders switch component in ANTD
    9. date : it renders Date component in ANTD
    10. range : it renders Range component (Date component in range) in ANTD
    11. upload : it renders Upload component in ANTD and all uploaded files store in key
    12. custom : any custom component you want can render
    13. container type : responsible for grouping inputs in one component :
     {
          type:'container',
          component:(nodesComingFromSchema)=><YourContainerComponent>{nodesComingFromSchema}</YourContainerComponent>,
          schema:[
              {
                  type:'text',
                  field:'test',
                  initialValue:null,
                  validation:Yup.string(),
                  col:'col-12',
                     
              }
          ]
      },

    then test input will placed in YourContainerComponent

    1. col : it is bootstap column clases for (col-1 , col-md-1 , etc.)
    2. initialValue : it is initial value of form field
    3. validation : only accept yup validation schema
    4. required: this field is responsible red star, if required you can easily add red star
    5. props : it has all types of ANTD component props
    6. linear : default value is false | if true then input field items ordered horizontally
    7. showOn : receives array , first index of array is null or string[] (other fields name which depends on this fields) ,second index is callback that return boolen if true then shows othwerwise not shown
[{
            field:"other",
            initialValue:null,
            validation:Yup.string().nullable(),
            col: 'col-12 col-md-6 col-lg-4',
            type:'text',
            
        },
    {
            field:"parent",
            initialValue:null,
            validation:Yup.string().nullable(),
            col: 'col-12 col-md-6 col-lg-4',
            type:'text',
            
        },
        {
            field:'children',
            label:"Təsdiq edən şəxs",
            type:"text",
            required:true,
            initialValue:null,
            validation:Yup.number().nullable(),
            col:'col-12 col-md-6 col-lg-4',
            showOn:[['parent'],(values)=>{
                return  values[0] === condition
            }],
           
        },]

meaning : children input only depends on parent and values is array ([parent]) first index is parents value, if you want depends on both parent and other

{
           field:'children',
           label:"Təsdiq edən şəxs",
           type:"text",
           required:true,
           initialValue:null,
           validation:Yup.number().nullable(),
           col:'col-12 col-md-6 col-lg-4',
           showOn:[['parent','other'],([parentVal,otherVal])=>{
               return  ...your condition
           }],
          
       }
  1. calculateValue : it means calculate inputs value depends on other inputs value
    [
{
        field:"parent",
        initialValue:null,
        validation:Yup.string().nullable(),
        col: 'col-12 col-md-6 col-lg-4',
        type:'text',
        
    },
    {
        field:'children',
        label:"Təsdiq edən şəxs",
        type:"text",
        required:true,
        initialValue:null,
        validation:Yup.number().nullable(),
        col:'col-12 col-md-6 col-lg-4',
        calculateValue:[['parent'],([parentValue])=>{
            return  parentValue + ' world '
        }],
       
    },]

```
meaning if parents value is (hello)  then children value is 'hello world'
  1. onSubmit : this is function called after submit button click and all field is valid
  2. button :
    1. title : button text
    2. props: similar to ANTD button props
  3. customButtons : you can add more buttons to form and receives array
    customButtons={[
                    (values, customSubmit)=>{
                       return <Button>Second button</Button>
                    }
                    ]}
    values is : form's values customSubmit : validates form if valid return true otherwise false

Author

@elvinmurshudlu