From 7cc0299f8718e6953bce97efc38729e767ddcf4d Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 30 Sep 2024 15:54:51 +0530 Subject: [PATCH] adress reviews --- src/components/Stepper/Readme.md | 39 ++++++++++++++----- src/components/Stepper/index.css | 7 +++- src/components/Stepper/index.js | 5 ++- .../Stepper/js/NavigationButtons.js | 3 +- src/components/Stepper/js/StepContent.js | 23 +++++++---- 5 files changed, 57 insertions(+), 20 deletions(-) diff --git a/src/components/Stepper/Readme.md b/src/components/Stepper/Readme.md index 26acd720..e7143094 100644 --- a/src/components/Stepper/Readme.md +++ b/src/components/Stepper/Readme.md @@ -1,12 +1,17 @@ -```js -const DefaultStepContent = ({ title }) => ( + +```jsx +import React, { useState } from "react"; +import Message from "../Message" + +// Default content for each step +const DefaultStepContent = ({ title, onChange }) => (
-

{title}

Hello {title}

); +// Define the steps for the stepper const steps = [ { title: 'Step 1', @@ -25,9 +30,25 @@ const steps = [ }, ]; - console.log("LAST STEP")} - onStepChange={(s) => console.log("STEP CHANGED", s)} -/> -``` \ No newline at end of file +const StepperExample = () => { + const [error, setError] = useState(null); + const errorMessage = ERROR + + return ( + console.log("LAST STEP")} + onStepChange={(step) => { + console.log("STEP CHANGED", step); + if (step.title === "Step 2") { + setError("Step 2 error"); + } else { + setError(null); + } + }} + error={error ? errorMessage : null} + /> + ); +}; + + \ No newline at end of file diff --git a/src/components/Stepper/index.css b/src/components/Stepper/index.css index 9a64f8ef..4829da2d 100644 --- a/src/components/Stepper/index.css +++ b/src/components/Stepper/index.css @@ -7,7 +7,6 @@ .step { display: flex; margin-bottom: 20px; - } .step-indicator { @@ -61,4 +60,10 @@ justify-content: right; margin-top: 20px; } + + .error-step { + border: 1px solid var(--color-danger-dark); + border-radius: var(--form-control-border-radius); + padding: 5px; + } } \ No newline at end of file diff --git a/src/components/Stepper/index.js b/src/components/Stepper/index.js index 92cd2e43..cc08f85d 100644 --- a/src/components/Stepper/index.js +++ b/src/components/Stepper/index.js @@ -9,6 +9,7 @@ const Stepper = ({ onFinish = () => {}, onStepChange = () => {}, finishBtnText = "Finish", + error, }) => { const [currentStep, setCurrentStep] = useState(0); @@ -37,7 +38,7 @@ const Stepper = ({ return (
-
+
{steps.map((step, index) => ( { return (
@@ -21,7 +22,7 @@ const NavigationButtons = ({ diff --git a/src/components/Stepper/js/StepContent.js b/src/components/Stepper/js/StepContent.js index a6722d84..975c7b1b 100644 --- a/src/components/Stepper/js/StepContent.js +++ b/src/components/Stepper/js/StepContent.js @@ -1,20 +1,27 @@ import React from "react"; -const StepContent = ({ step, index, currentStep, children }) => { +const StepContent = ({ step, index, currentStep, children, error }) => { const isStepComplete = index < currentStep; + const isActive = index === currentStep; + function getStepClassName() { + return [ + "step", + index === currentStep ? "active" : "", + isStepComplete ? "completed" : "", + ] + .filter(Boolean) + .join(" "); + } return ( -
+
{children} -
+

{step.title}

{step.description}

+ {index === currentStep &&
{error}
} {index === currentStep && ( -
{step.component}
+
{step.component}
)}