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

@sbacic/react-wizard

v1.0.3

Published

A wizard helper for React forms.

Downloads

51

Readme

React-Wizard

React-Wizard is a React library for handling multi-page forms.

Features

  • Clean layout
  • Flexible
  • Supports optional pages
  • Uses Typescript

Installation

yarn add @sbacic/react-wizard

Examples

Basic example:

import { Wizard } from "@sbacic/react-wizard";

<Wizard>
  <Page1 />
  <Page2 />
  <Page3 />
</Wizard>

With optional pages:

import { Wizard, Optional } from "@sbacic/react-wizard";

<Wizard>
  <Page1 />
  <Page2 />
  <Page3 />
  <Optional>
    <Step1a />
    <Step1b />
  </Optional>
</Wizard>

With additional context added in:

import { Wizard, Optional, Steps, useWizard } from "@sbacic/react-wizard";
import { Formik } from "formik";

const FormWithFormikContext = () => {
    const initialValues = {name: "John Smith"};
    const { values, step, next, store, optional } = useWizard();
    const submit = (values) => {
        if (step < 3) {
            store(values);
            next();
        } else {
            // Submit the data
        }
    }
    const schema = [
        {/* schema for first page*/},
        {/* schema for second page*/},
        {/* schema for third page*/}
    ];

    const optionalSchema = [
        {/* schema for first page*/},
        {/* schema for second page*/},
    ];

    const validationSchema = optional === undefined ? optionalSchema[optional] : schema[step];

    return (
        <Formik onSubmit={submit} initialValues={{...initialValues, ...values}} validationSchema={validationSchema}>
        <Steps>
            <Page1 />
            <Page2 />
            <Page3 />
            <Optional>
                <Step1a />
                <Step1b />
            </Optional>
        </Steps>
    </Formik>
    )
}

const Form = () => {
    return (
        <Wizard useWizardRenderer={false}>
          <FormWithFormikContext />
        </Wizard>
    )
}

API

<Wizard>

Your form pages should be wrapped in this to receive the Wizard context. It accepts the following props:

Props

startingStep: number

The starting step of the Wizard. Default is 0.

startingOptional: number

An Optional step to render on the first render. Default is undefined.

wrapInSteps: boolean

Whether to wrap the children in <Steps> or render them normally. Default is true.

<Steps>

Must be a child of Wizard to inherit the wizard context. Will render only the child that matches the current step of the wizard. If the step is less than 0, it shows the first step. If the step is greater than the number of children, shows the last child.

<Optional>

Must be a child of Wizard to inherit the wizard context. Renders optional pages. These are only renderered if you manually send the user there (see go(), below). If the step is less than 0, it shows the first step. If the step is greater than the number of children, shows the last child.

useWizard()

This hook provides functions to switch between forms and store form values for later submission.

Props

next()

Go to the next page in form. If used on an optional page, it returns you to the next non-optional page (eg: if you were on step 2 of a wizard it sends you to step 3).

back()

Go to the previous page in the form. If used on an optional page, it returns you to the main page you were at (eg: if you were on step 2 and went to an optional page, it returns you to step 2).

go(step: number, goToOptional?: true)

Jump to a specific step in the form. If goToOptional is set to true, it jumps to that optional page instead.

store(fields: { [key: string]: unknown })

Stores an object of key/value pairs for later submission.

clear(keys?: string[])

Clear the stored values by key. If no keys are provided, the entire store is emptied.

values

A dictionary of values stored with store().

step

A number representing the current step in the wizard. Zero-indexed.

optional

A number representing the current optional step. If undefined, no optional page is shown.

isFirst

Whether the current step is the first step in the Wizard.

isLast

Whether the current step is the last step in the Wizard.

Development

  1. Clone the repository:

git clone https://github.com/sbacic/react-wizard

  1. Pack the tarball:

yarn pack

or

npm pack

  1. Install it in your test application:

yarn add react-wizard-VERSION.tgz

or

npm add react-wizard-VERSION.tgz

Demo

https://sbacic.github.io/react-wizard-demo/