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-basic-stepper

v1.0.5

Published

A simple stepper provides a wizard-like workflow by dividing content into logical steps.

Downloads

16

Readme

react-basic-stepper

A simple stepper provides a wizard-like workflow by dividing content into logical steps.

step1

Install

npm install --save react-basic-stepper

Usage

The react-basic-stepper provide a two component to recreate a wizard-like workflow by dividing content into logical steps. You have Stepper that is the wrapper steps components and the Step component. You must import the styles of these components

import 'react-basic-stepper/dist/index.css';

1. Simple basic usage

...
import { Stepper, Step } from 'react-basic-stepper';
import 'react-basic-stepper/dist/index.css';
...
return (
    <Stepper>
        <Step>
            <h3>Step1</h3>
        </Step>
        <Step>
            <h3>Step2</h3>
        </Step>
         <Step>
            <h3>Step3</h3>
        </Step>
    </Stepper>
    )

step1 You can set labels for each Step component

...
import { Stepper, Step } from 'react-basic-stepper';
import 'react-basic-stepper/dist/index.css';
...
return (
    <Stepper>
        <Step label="Step1">
            <h3>Step1</h3>
        </Step>
        <Step label="Step1">
            <h3>Step2</h3>
        </Step>
        <Step label="Step1">
            <h3>Step3</h3>
        </Step>
    </Stepper>
        )

2. Vertical Stepper with labels for each step

 ...
return (
    <Stepper mode='vertical'>
        <Step label='Step #1'>
            <h3>Step1</h3>
         </Step>
         <Step label='Step #2'>
            <h3>Step2</h3>
            <p>
              Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem
              nesciunt eum, error explicabo alias, architecto beatae, ducimus
              vitae optio repellat minima iure id quisquam eius voluptatem
              voluptates. Iusto, accusamus mollitia!
            </p>
         </Step>
        <Step label='Step #3'>
            <h3>Step3</h3>
            <p>
              Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem
              nesciunt eum, error explicabo alias, architecto beatae, ducimus
              vitae optio repellat minima iure id quisquam eius voluptatem
              voluptates. Iusto, accusamus mollitia!
            </p>
            <p>
              Lorem, ipsum dolor sit amet consectetur adipisicing elit. Quidem
              nesciunt eum, error explicabo alias, architecto beatae, ducimus
              vitae optio repellat minima iure id quisquam eius voluptatem
              voluptates. Iusto, accusamus mollitia!
            </p>
         </Step>
    </Stepper>
    )

step1

3. Stepper wizzard component

For the creation of medium and complex wizards, the Step component has a property disabled to disable its access based on logical conditions. The Stepper component has a linear property that allows access only to the immediate next step. To control the action of the next and previous steps, you can use a ref to pointer the Stepper and set nextStep and prevStep programmatically.

...
import { Step, Stepper, StepperRef } from 'react-basic-stepper';
function StepperControlled(): JSX.Element {
  ....
  const [mode, setMode] = useState<any>(window.innerWidth < 756 ? 'vertical' : 'horizontal');
  const stepper = useRef<StepperRef>();
  ...
  return (
  <Stepper ref={stepper} mode={mode}>
      <Step label='User Data'>
        <ComponentForm1></ComponentForm1>
        <Button onClick={() => {
            if (!componentForm1DataValid) {
              alert('ComponentFrom1 data form must be valid');
              return;
            }
            stepper.current?.nextStep();
          }}>Next</Button>
      </Step>
    <Step label='Email' disabled={!componentForm1DataValid}>
      <ComponentForm2></ComponentForm2>
      <Button
          style={{ marginRight: '8px', backgroundColor: '#aaa' }}
          onClick={() => {
            stepper.current?.prevStep();
          }}>Back</Button>
      <Button onClick={() => {
            if (!componentForm1DataValid) {
              alert('ComponentForm1Data data form must be valid');
              return;
            }
            stepper.current?.nextStep();
          }}>Next</Button>
    </Step>
    <Step disabled={!componentForm1DataValid || !componentForm2DataValid}
      label='Materials selected'>
       <ComponentForm3></ComponentForm3>
       <Button style={{ marginRight: '8px', backgroundColor: '#aaa' }}
          onClick={() => {
            stepper.current?.prevStep();
          }}>Back</Button>
       <Button
          onClick={() => {
            if (!componentForm3DataValid) {
              alert('ComponentForm3 data form must be valid');
              return;
            }
            stepper.current?.nextStep();
          }}
        >Next</Button>
    </Step>
    <Step
      disabled={!componentForm1DataValid || !componentForm2DataValid || !componentForm3DataValid}
      label='Done'
    >
      <Button
        style={{ marginRight: '8px', backgroundColor: '#aaa' }}
        onClick={() => {
          stepper.current?.prevStep();
        }}
      >
        Back
      </Button>
      <Button> Save</Button>
    </Step>
  </Stepper>
  }

step1

The Stepper component has props to customize some styles of the steps header sections

export interface HeaderStepStyles {
  color?: string; // Setting the color of the circles.
  activatedStepBackground?: string; // Setting the backgroundColor of the current circle (Current Step).
  stepsBackgroud?: string; // Setting the backgroundColor of the circles except the circle associated with the current step on.
  lineColor?: string; // Setting the color of the line between of the steps circles
}

Example of a Stepper with the red color activated and the blue line between the circles

...
import { Stepper, Step } from 'react-basic-stepper';
...
return (
    <Stepper
          headerStyles={{
            activatedStepBackground: 'red',
            color: '#fff',
            lineColor: 'blue'
          }}
        >
          <Step>
            <h3>Step1</h3>
          </Step>
          <Step>
            <h3>Step2</h3>
          </Step>
          <Step>
            <h3>Step3</h3>
          </Step>
          <Step>
            <h3>Step4</h3>
          </Step>
        </Stepper>
)

step4

4. Stepper Interfaces

export interface StepperProps {
  children: Array<ReactElement> | ReactElement | any; // Steps component inside the Stepper
  indexStep?: number; // Set the initial activated Step, default = 0
  stepChange?: Function; // Callback function that return the current step on
  headerStyles?: HeaderStepStyles; // Object to change the styles of the Stepper header
  linearMode?: boolean; // Linear mode for the transitions of each step, default = false
  verticalLabels?: boolean; // Allow Step header text labels to be placed at the bottom or to the right of the circles, default = true
  hideLabels?: boolean; // Allow to hide the text labels, default = false
  hideLines?: boolean; // Allow to hide the line between each step header circles, default = false
  mode?: 'vertical' | 'horizontal'; // Allow to display the stepper 'vertical' or 'horizontal', default = 'horizontal'
}
export interface StepperRef {
  nextStep: Function; // function in the ref object of the Stepper which sets the next step programmatically
  prevStep: Function; // function in the ref object of the Stepper which sets the previous step programmatically
}

export interface Steps {
  children?: any; // Any JSX.Element or ReactElement to render inside the Step component
  label?: string; // Label to be displayed in the header for every step
  disabled?: boolean | null | undefined | number | string; // allow the access to the Step, default = true
}

Demo

Related Pakages

1. react-hook-modal

2. tabs-react-component

3. ngp-image-picker

License

MIT © josealejandro2928