0.0.19 • Published 12 months ago

tst-toolkit v0.0.19

Weekly downloads
-
License
TST
Repository
-
Last release
12 months ago

Table of contents

Requirements

First, install the library below:

  • Reactstrap: yarn add reactstrap or npm i reactstrap

Installation

npm i tst-toolkit

or

yarn add tst-toolkit

How to use Form

Example Code

import * as React from "react";
import { FormView } from "tst-toolkit";

const FormComponent = () => {
  const ArrayOfInputFields = [
    {
      Label: "Name",
      input: {
        id: "name",
        type: "text",
        required: false,
      },
      validation: (value) => value !== "",
      containerClassName: "text",
      errorMessage: "Please Enter First Name",
    },
    {
      Label: "email",
      input: {
        id: "email",
        type: "text",
        required: false,
      },
      validation: "email",
      containerClassName: "text",
      errorMessage: "Please Enter Email",
    },
    {
      Label: "Country",
      input: {
        id: "country",
        type: "select",
        required: false,
      },
      options:[
          {
            id: 0,
            value: "1",
            label: "One",
          },
          {
            id: 1,
            value: "2",
            label: "Three",
          },
        ]
      containerClassName: "text",
    }
  ];
  return (
    <FormView
      formInputList={CORPORATE_MODAL}
      onSubmit={(payload) => {
        console.log(payload);
      }}
    />
  );
};

Form Props

PropTypeDefault valueDescription
formInputListArray of Object[]Using formInputList we can add and remove input fields in from
onSubmitFunction(value) => {}OnSubmit function returns the value of form when form is submitted
defaultValueobject{}Using defaultValue we can preset value of input field. to prefill data use keyID is fieldID as a key and value as per you need and add this key value pair into defaultValue object
isFormPayloadbooleanfalseIf value is true will get response in fromData formate in onSubmit function's value parameter
targetFormbooleanfalseIf value is true will get response in event in onSubmit function's value parameter

Example of default value props

import * as React from "react";
import { FormView } from "tst-toolkit";

const FormComponent = () => {
  const ArrayOfInputFields = [
    {
      Label: "Name",
      input: {
        id: "name",
        type: "text",
        required: false,
      },
      validation: (value) => value !== "",
      containerClassName: "text",
      errorMessage: "Please Enter First Name",
    },
    {
      Label: "email",
      input: {
        id: "email",
        type: "text",
        required: false,
      },
      validation: "email",
      containerClassName: "text",
      errorMessage: "Please Enter Email",
    },
    {
      Label: "Country",
      input: {
        id: "country",
        type: "select",
        required: false,
      },
      options:[
          {
            id: 0,
            value: "1",
            label: "One",
          },
          {
            id: 1,
            value: "2",
            label: "Three",
          },
        ]
      containerClassName: "text",
    }
  ];
  return (
    <FormView
      formInputList={CORPORATE_MODAL}
      defaultValue={{ country: "2", name: "Daxesh Italiya" }}
      onSubmit={(payload) => {
        console.log(payload);
      }}
    />
  );
};

FormInputList props

Using FormInputList props we can customize below properties :

  • Input container style : using containerClassName
  • Input style : using className in input object
  • Error Message : using errorMessage
  • All input properties : using input object we can apply all properties of input like id, name, required etc.
  • Input validation : suing validation method for notEmpty validation use validation='notEmpty' for notEmpty validation use validation='email' else rou can pass validation function which return boolean value like
  {
    ...
    validation: (value) => value !== "",
    ...
  }
0.0.19

12 months ago

0.0.18

1 year ago

0.0.17

1 year ago

0.0.16

1 year ago

0.0.15

1 year ago

0.0.14

1 year ago

0.0.13

1 year ago

0.0.12

1 year ago

0.0.11

1 year ago

0.0.9

1 year ago

0.0.8

1 year ago

0.0.7

1 year ago

0.0.6

1 year ago

0.0.3

1 year ago

0.0.2

1 year ago

0.0.1

1 year ago