How can we create stepper that is multi-step form in Reactjs for multiple step form submission. Currently i am not showing component for each step
I want to return div component for each step for that i am not able to apply logic for that..
For now i am able to return the component but it return all the component at same time, as i want to return step by step in center
Here is code for stepper
import React, { useState, useEffect } from "react";
import PropTypes from "prop-types";
import "./Stepper.scss";
const Stepper = ({ stepColor, steps, direction, currentStep }) => {
const [stepState, setStepState] = useState([]);
useEffect(() => {
let createSteps = steps.map((step, idx) => ({
description: step.label,
component: step.component,
completed: idx < currentStep - 1, // past are completed
selected: idx <= currentStep - 1, // past & present are colored
highlighted: idx === currentStep - 1 // only present is highlighted
}));
setStepState(createSteps);
}, [steps, currentStep]);
return (
<div className={`stepper-wrapper-${direction}`}>
{stepState.map(
({ selected, completed, highlighted, description, component }, idx) => (
<div className="step-wrapper" key={idx}>
<div
className={`step-number step-number-${
selected ? "active" : "disabled"
}`}
style={{ background: `${selected ? stepColor : "none"}` }}
>
{completed ? "✔" : idx + 1}
</div>
<div
className={`step-description ${
highlighted ? "step-description-active" : ""
}`}
>
{description}
</div>
{idx + 1 !== stepState.length && (
<div
className={`divider-line divider-line-${stepState.length}`}
/>
)}
<div>{component}</div>
</div>
)
)}
</div>
);
};
Stepper.propTypes = {
direction: PropTypes.string.isRequired,
steps: PropTypes.array.isRequired
};
export default Stepper;