0.1.2 • Published 2 years ago

react-headless-multi-stepper v0.1.2

Weekly downloads
-
License
MIT
Repository
-
Last release
2 years ago

React Headless Multi Stepper

Design your own Multi Stepper component without having to worry about the logic. Then this tiny and performant package is for you. react-headless-multi-stepper is ideal if you are working with a utility-based css framework like TailwindCSS. react-headless-multi-stepper offers plenty of customization through generics and is also fully typed.

npm

issues stargazers

Install

yarn add react-headless-multi-stepper

Demo: Unstyled & TailwindCSS

Storybook

Usage

import { MultiStepper } from "react-headless-multi-stepper";

...
return (
  <MultiStepper
    {...args}
    RootContainer={<div />}
    MainLabelContainer={<ul />}
    SubLabelContainer={<ul />}
    ContentContainer={<div />}
    onChange={(step)}
    onCompleted={() => alert("onCompleted")}
    renderMainLabel={(props) => <li>{props.label}</li>}
    renderSubLabel={(props) => <li>{props.label}</li>}
  >
    <MultiStepper.VerticalStep name="1" label="step 1">
      <MultiStepper.HorizontalStep name="1.1" label="1.1">
        {({ goPrevious, goNext }) => (
          <div>
            Content 1.1
            <button onClick={goPrevious}>previous</button>
            <button onClick={goNext}>next</button>
          </div>
        )}
      </MultiStepper.HorizontalStep>
      <MultiStepper.HorizontalStep name="1.2" label="1.2">
        {({ goPrevious, goNext }) => (
          <div>
            Content 1.2
            <button onClick={goPrevious}>previous</button>
            <button onClick={goNext}>next</button>
          </div>
        )}
      </MultiStepper.HorizontalStep>
      <MultiStepper.HorizontalStep name="1.3" label="1.3">
        {({ goPrevious, goNext }) => (
          <div>
            Content 1.3
            <button onClick={goPrevious}>previous</button>
            <button onClick={goNext}>next</button>
          </div>
        )}
      </MultiStepper.HorizontalStep>
    </MultiStepper.VerticalStep>
    <MultiStepper.VerticalStep name="2" label="step 2">
      <MultiStepper.HorizontalStep name="2.1" label="2.1">
        {({ goPrevious, goNext }) => (
          <div>
            Content 2.1
            <button onClick={goPrevious}>previous</button>
            <button onClick={goNext}>next</button>
          </div>
        )}
      </MultiStepper.HorizontalStep>
      <MultiStepper.HorizontalStep name="2.2" label="2.2">
        {({ goPrevious, goNext }) => (
          <div>
            Content 2.2
            <button onClick={goPrevious}>previous</button>
            <button onClick={goNext}>next</button>
          </div>
        )}
      </MultiStepper.HorizontalStep>
      <MultiStepper.HorizontalStep name="2.3" label="2.3">
        {({ goPrevious, goNext }) => (
          <div>
            Content 2.3
            <button onClick={goPrevious}>previous</button>
            <button onClick={goNext}>next</button>
          </div>
        )}
      </MultiStepper.HorizontalStep>
    </MultiStepper.VerticalStep>
    <MultiStepper.VerticalStep name="3" label="step 3">
      <MultiStepper.HorizontalStep name="3.1" label="3.1">
        {({ goPrevious, goNext }) => (
          <div>
            Content 3.1
            <button onClick={goPrevious}>previous</button>
            <button onClick={goNext}>next</button>
          </div>
        )}
      </MultiStepper.HorizontalStep>
    </MultiStepper.VerticalStep>
  </MultiStepper>
);

An example of a styled version can be found in stories/MultiStepper.stories.tsx.

MultiStepper props

The following table contains all optional and required props for the MultiStepper. The library is strictly typed and uses generics to support many different kinds of data.

NameTypeDefaultDescription
dataTestIdstringPlaces a data-testid on several elements
RootContainerReact.ReactElementdivRoot element of the MultiStepper.
MainLabelContainerReact.ReactElementulContaining element for the main labels.
SubLabelContainerReact.ReactElementulContaining element for the sub labels.
ContentContainerReact.ReactElementdivContaining element for the SubLabelContainer and step content.
renderMainLabel*IRenderLabel**Render prop for the label of the vertical step.
renderSubLabel*IRenderLabel**Render prop for the label of the horizontal step.
onChange*(name: string) => voidFires for every next and previous navigation action. Name refers to the newly activated step.
onCompleted*() => voidFires on completion of the entire flow.
children*React.ReactElement <IVerticalStep>[]A number of VerticalStep components.

*these are required \ **IRenderLabel contains all information to render your horizontal or vertical label (i.e. activeIndex, label, name, index, array).

VerticalStep props

The following table contains all optional and required props for the VerticalStep component. VerticalSteps are placed as children inside the MultiStepper.

NameTypeDescription
name*stringUnique string to distinguish between all vertical steps
label*stringDisplay this value to the user in the stepper.
children*React.ReactElement<IHorizontalStep> or React.ReactElement<IHorizontalStep>[]A number of HorizontalStep components.

*these are required

HorizontalStep props

The following table contains all optional and required props for the HorizontalStep component. HorizontalSteps are placed as children inside the VerticalStep.

NameTypeDescription
name*stringUnique string to distinguish between all horizontal steps
label*stringDisplay this value to the user in the stepper.
children*({goPrevious,goNext})Render prop for children

*these are required \ ** IHorizontalStep: goPrevious and goNext are both callback functions that return nothing.

Authors