Code Monkey home page Code Monkey logo

react-stepz's Introduction

React-Stepz

Hook based multi-step progress bar for React

React Stepz Demo

npm version

Install

npm install --save react-stepz

Usage

react-stepz uses React Contexts to share the current step between components. You can wrap your component with a context provider directly

import { StepProgress } from 'react-stepz`;

...
return (
  <StepProgress>
    <MyComponent>
  </StepProgress>
)

or use our HOC to wrap your component

import { withStepProgress } from 'react-stepz';

export default withStepProgress(MyComponent);

Then you can create your steps and validation functions

// MyComponent.jsx
import { withStepProgress, useStepProgress, Step, StepProgressBar } from 'react-stepz';
import 'react-stepz/dist/index.css';
import { useState } from 'react';

const MyComponent = () => {
  const [isValid, setIsValid] = useState(false);

  const steps = [
    {
      label: 'Step 1',
      name: 'step 1'
    },
    {
      label: 'Step 2',
      name: 'step 2',
      validator: () => isValid
    },
    {
      label: 'Step 3',
      name: 'step 3'
    },
    {
      label: 'Step 4',
      name: 'step 4'
    }
  ];

  const { stepForward, stepBackwards, currentIndex } = useStepProgress({
    steps,
    startingStep: 0
  });

  return (
    <div>
      <StepProgressBar steps={steps} />
      <Step step={0}>
        <h1>First step</h1>
      </Step>
      <Step step={1}>
        <h1>Second step</h1>
      </Step>
      <Step step={2}>
        <h1>Third Step</h1>
      </Step>
      <button onClick={stepForward}>Next</button>
      <button onClick={stepBackwards}>Back</button>
    </div>
  );
};

export default withStepProgress(MyComponent);

CodeSandbox

The above example can be seen at Code Sandbox

Available Props

  • class (string) - CSS class name for the ProgressBarWrapper
  • progressClass (string) - CSS class name for ProgressBar
  • stepClass (string) - CSS class name for ProgressBar step

Show your support

Give a ⭐️ if this project helped you!

CONTRIBUTING & CODE OF CONDUCT

See CODE_OF_CONDUCT.md

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Richard Beattie

💻 🤔

Gaurav Saini

💻 🤔 📖

This project follows the all-contributors specification. Contributions of any kind welcome!

react-stepz's People

Contributors

r-bt avatar allcontributors[bot] avatar saini-g avatar drejkus avatar dependabot[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.