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

formik-wizard-simple

v0.0.10

Published

Multi-step form wizard with Formik

Downloads

9

Readme

formik-wizard-simple

CI Status npm version

Simple multi-step form wizard with Formik.

You are required to implement the stepper, plus the next and previous buttons yourself for flexibility of the UI.

Only peer dependencies are React and Formik.

Wizard

React component to wrap a series of steps.

import React, { FC } from "react";
import { Wizard } from "formik-wizard-simple";

const App: FC = () => {
    return (
        <Wizard
            initialValues={{
                email: "",
                firstName: "",
                lastName: ""
            }}
            onSubmit={onSubmit}
            onRenderAfterStep={<Actions />}
            onRenderBeforeStep={<Stepper />}
            resetTouchedOnMove
        >
            {...}
        </Wizard>
    );
};

Options:

Takes all properties of the FormikConfig except for the validationSchema which is at the Wizard.Step level. Below is a list of addtional properties.

| option | default | Description | | ------------------- | ------- | --------------------------------------------------------------------------------------------- | | resetTouchedOnMove? | false | When moving between steps, reset the touched elements. | | initialStep? | 0 | Set the initial step. | | onRenderBeforeStep? | - | React component for displaying a stepper or any other element. | | onRenderAfterStep | - | React component for displaying the buttons needed to move between steps or any other element. | | formProps? | - | FormikFormProps for the Form element. |

Wizard.Step

React component for each step. These must be a child of the Wizard component.

import React, { FC } from "react";
import { Wizard } from "formik-wizard-simple";

const { Step } = Wizard;

const App: FC = () => {
    return (
        <Wizard
            initialValues={{
                email: "",
                firstName: "",
                lastName: ""
            }}
            onSubmit={onSubmit}
            onRenderAfterStep={<Actions />}
            onRenderBeforeStep={<Stepper />}
        >
            <Step
                validationSchema={Yup.object({
                    firstName: Yup.string().required("required"),
                    lastName: Yup.string().required("required")
                })}
            >
                <div>
                    <label htmlFor="firstName">First Name</label>
                    <Field
                        autoComplete="given-name"
                        component="input"
                        id="firstName"
                        name="firstName"
                        placeholder="First Name"
                        type="text"
                    />
                    <ErrorMessage className="error" component="div" name="firstName" />
                </div>
                <div>
                    <label htmlFor="lastName">Last Name</label>
                    <Field autoComplete="family-name" component="input" id="lastName" name="lastName" placeholder="Last Name" type="text" />
                    <ErrorMessage className="error" component="div" name="lastName" />
                </div>
            </Step>
            <Step
                validationSchema={Yup.object({
                    email: Yup.string().email("Invalid email address").required("required")
                })}
            >
                <div>
                    <label htmlFor="email">Email</label>
                    <Field autoComplete="email" component="input" id="email" name="email" placeholder="Email" type="text" />
                    <ErrorMessage className="error" component="div" name="email" />
                </div>
            </Step>
        </Wizard>
    );
};

Options:

| option | default | Description | | ----------------- | ------- | -------------------------------------------------------------------------- | | onSubmit? | - | Called whenever the submit/next button is clicked with the current values. | | validationSchema? | - | Yup schema for validating the step. | | id? | - | Optional id for the step. Useful for when using nested validation schemas. |

useWizard

A React hook for getting the current state of the Wizard. This hook will primarily be used in the onRenderAfterStep and onRenderBeforeStep components like the example below.

import React, { FC } from "react";
import { Steps, Button } from "antd";
import { useFormikContext } from "formik";
import { useWizard } from "formik-wizard-simple";

export const Actions = () => {
    const { isLastStep, step, onPreviousStep } = useWizard();
    const { isSubmitting } = useFormikContext();

    return (
        <div className="actions">
            {step > 0 && (
                <Button disabled={isSubmitting} onClick={onPreviousStep}>
                    Back
                </Button>
            )}
            <Button disabled={isSubmitting} htmlType="submit" type="primary">
                {isLastStep ? "Submit" : "Next"}
            </Button>
        </div>
    );
};

export const Stepper: FC = () => {
    const { step } = useWizard();

    return (
        <Steps className="stepper" current={step}>
            <Steps.Step title="Personal" />
            <Steps.Step title="Business" />
            <Steps.Step title="Confirm" />
        </Steps>
    );
};

Properties:

| option | default | Description | | -------------- | ------- | ------------------------------------ | | step | 0 | The current step. | | isLastStep | - | Is the current step the last. | | onNextStep | - | Move to the next step. | | onPreviousStep | - | Go back to the previous step. | | onSetStep | - | Go to any step. | | totalSteps | - | Count of step children components | | stepId? | - | id property of the current step node |