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 🙏

© 2025 – Pkg Stats / Ryan Hefner

formik-custom-form

v1.0.4

Published

Formik Custom Form is a library that provides a set of components for building forms in React using the Formik library.

Downloads

11

Readme

Formik Custom form

Formik Custom Form is a library that provides a set of components for building forms in React using the Formik library.

Installation

Install the dependencies.

npm install formik-custom-form
or
yarn add formik-custom-form

Props

data: Array[]

The data array contains objects with the following properties:

  • labelProps: an object containing properties to be passed to the corresponding Label component.

    • title: a required string property that specifies the text to be displayed on the label.
    • className: an optional string property that specifies the CSS class(es) to be applied to the label element.
  • formType: an optional property used to specify the type of the input field. The supported types are text, select, radio, textarea, and checkbox.

  • formProps: an object containing properties to be passed to the corresponding form input component.

    • id: an optional string property that specifies the ID of the input element.

    • name: a required string property that specifies the name of the input element.

    • value: a required property that can be a string or an array of strings. This property specifies the current value of the input element.

    • className: an optional string property that specifies the CSS class(es) to be applied to the input element.

    • defaultValue: an optional string property that specifies the default value of the input element.

    • placeholder: an optional string property that specifies the placeholder text to be displayed in the input element.

    • type: an optional string property that specifies the type of the input element. This property is used for input elements such as input and select.

    • onChange: an optional function that is called when the input element value changes. This function receives a parameter which can either be a string or a ChangeEvent object, depending on the input element type.

    • component: an optional property that specifies the name of a custom component to be used instead of the default input component. It can also accept a React node that represents the custom component.

    • [restProps: string]: any: This syntax allows for any other additional properties to be included, with their key being a string and their value being any data type.

    • labelClassName (only for radio and checkbox): A string representing the class name for the label of the option

    • labelPosition (only for radio and checkbox): A string indicating whether the label should be positioned "before" or "after" the form element

validationSchema: function

Yup object schema for validation

buttonProps

Specifies the properties that can be passed to a submit button

  • className: an optional string property that specifies the CSS class(es) to be applied to the submit button element.
  • title: an optional string property that specifies the text to be displayed on the submit button.
  • component: an optional property that can be either a string or a React Node, specifying the component that should be used to render the submit button.

errorProps

Specifies the properties that can be passed to an error component. The errorProps interface defines the following properties:

  • className: an optional string property that specifies the CSS class(es) to be applied to the error element.

onSubmit

It is a function that is called when the form is submitted.

onReset

It is a function to resets all form fields to their initial values, and also resets any validation errors that may have been shown.

Examples

 import React from "react";
 import FormikForm from "formik-custom-form";

 const data = [
   {
     labelProps: {
       title: "Email",
     },
     formProps: {
       name: "email",
       value: "",
     },
   },
   {
     labelProps: {
       title: "Password",
     },
     formProps: {
       name: "password",
       value: "",
       type: "password",
     },
   },
 ];

 const Simple = () => {
   const handleSubmit = (values) => {
     console.log(values);
   };
   return <FormikForm data={data} onSubmit={handleSubmit} />;
 };

 export default Simple;
  import React from "react";
  import FormikForm from "formik-custom-form";
  import Form from "react-bootstrap/Form";
  import Button from "react-bootstrap/Button";

  const data = [
    {
      labelProps: {
        title: "Fullname",
      },
      formProps: {
        name: "fullname",
        value: "",
        placeholder: "Enter fullname",
        component: <Form.Control />,
      },
    },
    {
      labelProps: {
        title: "Email",
        className: "",
      },
      formProps: {
        name: "email",
        value: "",
        placeholder: "Enter email",
        component: <Form.Control />,
      },
    },
    {
      labelProps: {
        title: "Password",
        className: "",
      },
      formProps: {
        name: "password",
        value: "",
        placeholder: "Enter password",
        component: <Form.Control />,
      },
    },
  ];


  const buttonProps = {
    component: <Button variant="primary">Submit</Button>,
  }

  const Simple = () => {
    const handleSubmit = (values) => {
      console.log(values);
    };
    return <FormikForm data={data} onSubmit={handleSubmit} buttonProps={buttonProps} />;
  };
export default Simple;
import React from "react";
import FormikForm from "formik-custom-form";

const data = [
  {
    labelProps: {
      title: "Email",
    },
    formProps: {
      name: "email",
      value: "",
      className: "form-control",
    },
  },
  {
    labelProps: {
      title: "Password",
    },
    formProps: {
      name: "password",
      value: "",
      className: "form-control",
      type: "password",
    },
  },
];

const buttonProps = {
  title: "Login",
  className: "btn btn-success mt-2",
}

const Simple = () => {
  const handleSubmit = (values) => {
    console.log(values);
  };
  return <FormikForm data={data} onSubmit={handleSubmit} buttonProps={buttonProps} />;
};

export default Simple;
import React from "react";
import FormikForm from "formik-custom-form";
import { object, string } from "yup";

const userSchema = object({
  email: string().email().required(),
  password: string().required(),
});

const data = [
  {
    labelProps: {
      title: "Email",
    },
    formProps: {
      name: "email",
      value: "",
    },
  },
  {
    labelProps: {
      title: "Password",
    },
    formProps: {
      name: "password",
      value: "",
      type: "password",
    },
  },
];

const Simple = () => {
  const handleSubmit = (values) => {
    console.log(values);
  };
  return (
    <FormikForm
      data={data}
      validationSchema={userSchema}
      onSubmit={handleSubmit}
    />
  );
};

export default Simple;
import FormikForm from "formik-custom-form";
import React from "react";

const data = [
  {
    labelProps: {
      title: "Email",
    },
    formProps: {
      name: "email",
      value: "",
    },
  },
  {
    labelProps: {
      title: "Password",
    },
    formProps: {
      name: "password",
      value: "",
      type: "password",
    },
  },
  {
    formType: "select",
    labelProps: {
      title: "Select",
    },
    formProps: {
      name: "veh",
      value: "car",
      options: [
        {
          id: 1,
          label: "Car",
          value: "car",
        },
        {
          id: 2,
          label: "Jeep",
          value: "jeep",
        },
      ],
    },
  },
  {
    formType: "radio",
    formProps: {
      name: "gender",
      value: "female",
      labelPosition: "after",
      options: [
        {
          id: 1,
          label: "Male",
          value: "male",
        },
        {
          id: 2,
          label: "Female",
          value: "female",
        },
      ],
    },
  },
  {
    formType: "textarea",
    labelProps: {
      title: "Description",
    },
    formProps: {
      name: "description",
      value: "",
      cols: "40",
      rows: "2",
    },
  },
  {
    formType: "checkbox",
    formProps: {
      name: "color",
      value: ["pink"],
      options: [
        {
          id: 1,
          label: "Pink",
          value: "pink",
        },
        {
          id: 2,
          label: "Red",
          value: "red",
        },
        {
          id: 3,
          label: "Black",
          value: "black",
        },
      ],
    },
  },
];

const Simple = () => {
  const handleSubmit = (values) => {
    console.log(values);
  };
  return <FormikForm data={data} onSubmit={handleSubmit} />;
};

export default Simple;

License

MIT