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

react-advancer

v1.0.0

Published

A component that manages steps for advancing through a step-based workflow

Downloads

3

Readme

The problem

You need to manage a step-based workflow and you want to be able to move between steps. You also want the flexibility to be able to control the rendering of your steps.

This solution

This is a component that manages the state of your steps while providing you the flexibility to render your workflow in any way that you need to. It uses a render prop to give you the flexibility you need to render your workflow without having to think about managing the state of which step is active.

Installation

npm install --save react-advancer

Usage

import Advancer from 'react-advancer';

function SimpleWorkflow({ steps }) {
  return (
    <Advancer
      steps={steps}
      stepSelector={step => step.props.id}
      render={({ getSteps, getStepActions }) => {
          const { activatePreviousStep, activateNextStep } = getStepActions();
          const { previousStep, activeStep, nextStep } = getSteps();
          return (
            <div>
              {previousStep !== undefined ? <button onClick={activatePreviousStep}>Previous</button> : null}
              {React.cloneElement(activeStep)}
              {nextStep !== undefined ? <button onClick={activateNextStep}>Next</button> : null}
            </div>
          )}}
    />
  );
}

function App() {
  const steps = [
    <div id='step-1'>I am the first step</div>,
    <div id='step-2'>I am the second step</div>,
    <div id='step-3'>I am the third step</div>,
    <div id='step-4'>I am the fourth step</div>,
    <div id='step-5'>I am the fifth step</div>
  ];

  return <SimpleWorkflow steps={steps} />;
}

Advancer is the only component. It does not render anything itself. It calls the render function and renders that.

Props

steps

arrayOf(PropTypes.object) | required

Pass an array of steps that will be used by the component to determine the previous, active, and next steps.

stepSelector

PropTypes.func | required

Pass a function to invoke on each step in the steps prop in order to find a match.

initialStep

PropTypes.object

The step that will be set as the first active step.

render

PropTypes.func | required

This is called with an object. Read more about the properties passed to the render function in the section "Render Function prop".

Render Function prop

This is the function that will determine what to render based on the state of the Advancer component. The function is passed as the render prop <Advancer steps={[...]} render={/* here */} />.

getStepActions

These are actions that can be invoked to change the state of the Advancer component

| property | type | description | |---------------------- |-------------------------------- |------------------------------------------------------------------------------------------------------------ | | activateFirstStep | function() | Activate the first step in the workflow regardless of its current state | | activateLastStep | function() | Activate the last step in the workflow regardless of its current state | | activatePreviousStep | function() | Activate the previous step in the workflow. If there is no previous step to activate, this is a noop | | activateNextStep | function() | Activate the next step in the workflow. If there is no next step to activate, this is a noop | | createStepActivator | function(selector: Function) | Activate a step based on the selector function |

getSteps

These are the steps from the array that can be used within render

| property | type | description | |-------------- |------------------------ |-------------------------------------- | | previousStep | object / undefined | The step that was previously active | | activeStep | object | The step that is currently active | | nextStep | object / undefined | The step that will be activated next |

Inspiration

The goal was to make a simple API for managing workflow states while still giving a lot of flexibility control to the users. The methods used in this project were inspired by Kent C. Dodds and his work on the downshift project.

License

MIT