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

@loft/multistep-form

v0.2.4

Published

[![Actions Status](https://github.com/loft-br/multistep-form/workflows/Build%20and%20Test/badge.svg)](https://github.com/loft-br/multistep-form/actions) [![Test Coverage](https://api.codeclimate.com/v1/badges/b1604a3d8b002cbab16a/test_coverage)](https://c

Downloads

12

Readme

Actions Status Test Coverage Maintainability NPM Version License

Introduction

Multistep-form is an open-source lib written in React created by @Loft's software engineering team to facilitate the development of a multi-step form. It abstracts all the logic necessary for the form to work: next, previous and skip to step n, in addition to facilitating the calculation of progress.

Installation

To have access to multistep-form, simply install using npm:

npm i --save @loft/multistep-form

or yarn:

yarn add @loft/multistep-form

Usage

To make use of the facilities that the multistep-form provides, simply use the MultiStep component passing the steps configuration and your children will receive all the intelligence through the props:

import { MultiStep } from '@loft/multistep-form';

<MultiStep steps={steps} stepId={stepId}>
  {Children}
</MultiStep>;

or

import { MultiStep } from '@loft/multistep-form';

<MultiStep steps={steps} stepId={stepId}>
  {(props) => {
    /* Content */
  }}
</MultiStep>;

When using this component, a React context will be created that you can access using the useMultiStepContext hook:

import { useMultiStepContext } from '@loft/multistep-form';

const MyComponent = () => {
  const context = useMultiStepContext();

  return <Fragment>blah</Fragment>;
};

Properties accepted by the MultiStep component

Steps

The steps property is a list of configuration objects, it's the initial information regarding the steps of the form, here's an example:

const steps = [
  {
    id: 'first-step',
    Component: () => <p>I am a dummy component</p>,
  },
  {
    id: 'second-step',
    Component: () => <p>I am another dummy component</p>,
  },
  {
    id: 'jumped-step',
    Component: () => <p>I am a jumped step</p>,
  },
  {
    id: 'third-step',
    Component: () => <p>I am third dummy component</p>,
  },
];

As we can see in the example above, each step is composed of an id and a component may it be functional or not.

StepId

The stepId property is the identifier of the first step that will be displayed when rendering, it's optional and if it's not provided, the identifier of the first step of the configuration list is assumed, here is an example:

const stepId = 'second-step';

Properties injected by MultiStep into the children

Step

The step property injected by the MultiStep component is the current step the user is in, it's the following signature:

// Container component
const Container = ({ step: { id, Component, nextStepId }, next }) => {
  return (
    <Fragment>
      <p>
        You're in step with id <span>{id}</span>
      </p>
      <Component />
      {nextStepId && <button onClick={next}>Next</button>}
    </Fragment>
  );
};

// Using provider
const MyForm = () => {
  return <Multistep steps={steps}>{Container}</Multistep>;
};

Progress

The progress property injected by the MultiStep component is the progress of the steps completed by the user.

// Container component
const Container = ({
  progress: { first, current, last },
  step: { Component },
}) => {
  return (
    <Fragment>
      <p>
        You're in step <span>{current}</span>
        of the form that starts at <span>{first}</span>
        and ends at <span>{last}</span>
      </p>
      <Component />
    </Fragment>
  );
};

// Using provider
const MyForm = () => {
  return <Multistep steps={steps}>{Container}</Multistep>;
};

Methods injected by MultiStep into the children

Next

The next method is responsible for transitioning the step, it's linear, that is, the user will go to the next step provided in the configuration.

// Container component
const Container = ({ step: { Component }, next }) => {
  return (
    <Fragment>
      <Component />
      <button onClick={next}>Next</button>
    </Fragment>
  );
};

// Using provider
const MyForm = () => {
  return <Multistep steps={steps}>{Container}</Multistep>;
};

Previous

The previous method is useful for returning to the previous step.

// Container component
const Container = ({ step: { Component }, previous }) => {
  return (
    <Fragment>
      <Component />
      <button onClick={previous}>Previous</button>}
    </Fragment>
  );
};

// Using provider
const MyForm = () => {
  return <Multistep steps={steps}>{Container}</Multistep>;
};

JumpTo

The jumpTo method allows you to jump directly to a step, which can be before or after the current step.

// Container component
const Container = ({ step: { Component }, jumpTo }) => {
  return (
    <Fragment>
      <Component />
      <button onClick={() => jumpTo('third-step')}>Jump!</button>
    </Fragment>
  );
};

// Using provider
const MyForm = () => {
  return <Multistep steps={steps}>{Container}</Multistep>;
};

Examples

TBD