2.0.3 • Published 3 years ago

react-form-stepper v2.0.3

Weekly downloads
702
License
MIT
Repository
github
Last release
3 years ago

react-form-stepper

version GitHub Workflow Status (branch) David David License Downloads

NPM

A simple react stepper component for multi-step forms inspired by the Stepper component from Material-UI.

react-form-stepper preview

Examples

For examples of react-form-stepper go to: https://m0ky.github.io/react-form-stepper/.

Getting started

Install the library by running:

npm install react-form-stepper --save

or

yarn add react-form-stepper

Usage

import { Stepper } from 'react-form-stepper';

There are 2 possible ways of defining the steps in the Stepper component:

  • Using the steps prop
  • Using the Stepper as a HOC with Step as children

Using the steps prop

<Stepper
  steps={[{ label: 'Step 1' }, { label: 'Step 2' }, { label: 'Step 3' }]}
  activeStep={2}
/>

Using the Stepper as a HOC with Step as children

<Stepper activeStep={1}>
  <Step label="Children Step 1" />
  <Step label="Children Step 2" />
  <Step label="Children Step 3" />
</Stepper>

Using with SSR

When developing an SSR application with a framework like Next.js you might face your console being polluted with the following message Warning: [JSS] Rule is not linked. Missing sheet option "link: true". caused by the underlying dependency react-jss. A workaround is to use the dynamic import module like in the example below.

// CustomStepper.js
const CustomStepper = () => {
  return <Stepper steps={[{ label: 'Step 1' }, { label: 'Step 2' }]} activeStep={1} />;
};

export default CustomStepper;
// MultiStepForm.js
import dynamic from 'next/dynamic';

const StepperComponent = dynamic(() => import('./CustomStepper'), {
  ssr: false,
});

Stepper props

PropsOptionsDefaultDescription
steps[StepsDTO]noneArray of objecst defining the steps
activeStepnumber0Value defining the active step
connectorStateColorsbooleanfalseUse different colors for connector lines based on adjacent steps state
classNamestringnoneAdd css classes to the Stepper component
stepClassNamestringnoneAdd css classes to Step components
hideConnectorsboolean |'inactive'falseValue defining connectors visibility
nonLinearbooleanfalseAllow users to enter the flow at any point
styleConfigStepStyleDTO---Object containing Step style defaults
connectorStyleConfigConnectorStyleProps---Object containing Connector style defaults

ConnectorStyleProps

PropsOptionsDefaultDescription
disabledColorstring'#bdbdbd'Define the disabled connector line color
activeColorstring'#ed1d24'Define the active connector line color
completedColorstring'#a10308'Define the completed connector line color
sizeReact.ReactText1Define the thickness of the connector line
stepSizeReact.ReactText'2em'Value defaulting to the step size, used to calculate the padded space between the step and connector line start
stylestring'solid'Define the style of the connector line

StepsDTO

PropsOptionsDefaultDescription
labelstring''Value to be displayed under each step
activebooleanfalseValue to indicate should the step be displayed as active
completedbooleanfalseValue to indicate should the step be displayed as completed

StepStyleDTO

PropsOptionsDefaultDescription
activeBgColorstring'#ed1d24'Define the background color for active steps
activeTextColorstring'#ffffff'Define the text color for active steps
completedBgColorstring'#a10308'Define the background color for completed steps
completedTextColorstring'#ffffff'Define the background color for completed steps
inactiveBgColorstring'#e0e0e0'Define the background color for inactive steps
inactiveTextColorstring'#ffffff'Define the background color for inactive steps
sizestring or number'2em'Value representing the width and height of the step
circleFontSizestring or number'1rem'Font size of the step content
labelFontSizestring or number'0.875rem'Font size of step labels
borderRadiusstring or number'50%'Step border radius
fontWeightstring or number500Step label font weight

Step props

PropsOptionsDefaultDescription
labelstring''Value to be displayed under each step
activebooleanfalseValue to indicate should the step be displayed as active
completedbooleanfalseValue to indicate should the step be displayed as completed
indexnumber0Index value of the step
classNamestringnoneAdd css classes to the Step component
childrenReact.ReactNodeStep indexValue inside the step
2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.4.3

3 years ago

1.4.2

3 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.11

4 years ago

1.2.10

4 years ago

1.2.8

4 years ago

1.2.9

4 years ago

1.2.7

4 years ago

1.2.6

4 years ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.0

5 years ago