0.0.3 • Published 3 years ago

formik-stepper-with-file-upload v0.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

React Formik Stepper Component

This is a reusable and scalable React component based on the Formik library. By adding validationSchema it will not go to the next step, unless the entries are validated, You can experiment and the example below illustrates the props

Installation

Using npm:

npm install formik-stepper

Using yarn

yarn add formik-stepper

FormikStepper Props

PropertiesTypeDefault valueDescription
Formik ...Props...........Click to learn more
labelsColorStringsecondaryThe text label color can be root variables or css => #fff
withStepperLineBooleanfalsedefault and If it is false, it hides stepper line
nextBtnLabelStringNextLabel the "Moving to Next Step" button
prevBtnLabelStringPrevLabel the "Moving to Previous Step" button
submitBtnLabelStringSubmitLabel the "Submit Form" button
nextBtnColorStringprimaryColor the "Moving to Next Step" button can be root variables or css => #fff
prevBtnColorStringdangerColor the "Moving to Previous Step" button can be root variables or css => #fff
submitBtnColorStringsuccessColor the "Submit Form" button can be root variables or css => #fff

FormikStep Props

PropertiesTypeDefault valueDescription
labelString....The text label of Step
withIconsString....to add icon into the circle must add icon as class Name like Fontawesome
withNumbersBooleantrueIf it was true when you added withIcons, it hides the icon and shows the step number
iconColorStringwhiteThe color of Step icon can be root variables or css => #fff
circleColorStringblueThe color of Step circle can be root variables or css => #fff

InputField Props

PropertiesTypeDefault valueDescription
typeStringtextClick to learn more
labelString....The text label of Input Field
placeholderStringValue of label propThe text placeholder of Input Field
classNameString....The className of your custem style css
iconStartString....To Add icon in prepend of input field
symbolString....To Text in prepend of input field
iconString....To Add icon in append of input field

Example

import React from "react";
import * as Yup from "yup"
import { FormikStepper, FormikStep, InputField } from "formik-stepper";



const validationSchema = Yup.object().shape({
  firstName: Yup.string().required("The First Name field is required"),
  lastName: Yup.string().required("The Last Name field is required"),
  email: Yup.string()
    .email("The email must be a valid email address.")
    .required("The Email field is required"),
  password: Yup.string()
    .required("The Password field is required")
    .matches(
      /^(?=.*[A-Za-z])(?=.*\d)(?=.*)[A-Za-z\d]{8,}$/,
      `Must Contain 8 Characters, One Uppercase, One Lowercase,
      One Number and one special case Character [@$!%*#?&-_]`
    ),
  privacy: Yup.boolean()
    .isTrue()
    .oneOf([true], "The terms and conditions must be accepted."),
});



export const FormStepper = () => {

const onSubmit = async ( values, { setSubmitting } ) => {
      console.log(values);
      setSubmitting(false); //// Important
  };

    return(
       <FormikStepper
            /// Accept all Formik props
            onSubmit={onSubmit} /// onSubmit Function
            initialValues={{
              firstName: "",
              lastName: "",
              email: "",
              password: "",
              privacy: false,
            }}
            validationSchema={validationSchema}
            labelsColor="secondary" /// The text label color can be root variables or css => #fff
            withStepperLine /// false as default and If it is false, it hides stepper line
            nextBtnLabel="step" /// Next as default
            prevBtnLabel="return" /// Prev as default
            submitBtnLabel="Done" /// Submit as default
            nextBtnColor="primary" /// as default and The color can be root variables or css => #fff
            prevBtnColor="danger" /// as default and The color can be root variables or css => #fff
            submitBtnColor="success" /// as default and The color can be root variables or css => #fff
          >
            {/*  First Step */}
            <FormikStep
              label="Profile Info" /// The text label of Step
              withIcons="fa fa-user" // to add icon into the circle must add icon as class Name like Fontawesome
              withNumbers /// If true, it hides the icon and shows the step number
              iconColor="white" /// The color can be root variables or css => #fff
              circleColor="danger" /// The color can be root variables or css => #fff
            >
              <InputField name="firstName" label="First Name"></InputField>
              <InputField name="lastName" label="Last Name" />
            </FormikStep>
            {/* Second Step */}
            <FormikStep
              label="Login Info"
              withIcons="fa fa-lock"
              iconColor="white"
              circleColor="danger"
            >
              <InputField name="email" label="Email" type="email" />
              <InputField name="password" label="password" type="password" />
              <div>
                <InputField name="privacy" label="privacy" type="checkbox" />
              </div>
            </FormikStep>
          </FormikStepper>
    );
);