From 009387e9dc427af0be5e7c2ab2ba812385cababc Mon Sep 17 00:00:00 2001 From: Jay Date: Mon, 30 Sep 2024 13:30:32 +0530 Subject: [PATCH] refactoring --- src/components/Stepper/index.css | 108 +++++++++--------- src/components/Stepper/index.js | 74 +++++------- .../Stepper/js/NavigationButtons.js | 32 ++++++ src/components/Stepper/js/StepContent.js | 24 ++++ src/components/Stepper/js/StepIndicator.js | 18 +++ 5 files changed, 156 insertions(+), 100 deletions(-) create mode 100644 src/components/Stepper/js/NavigationButtons.js create mode 100644 src/components/Stepper/js/StepContent.js create mode 100644 src/components/Stepper/js/StepIndicator.js diff --git a/src/components/Stepper/index.css b/src/components/Stepper/index.css index 452d752f..9a64f8ef 100644 --- a/src/components/Stepper/index.css +++ b/src/components/Stepper/index.css @@ -1,68 +1,64 @@ -.wizard-container { - max-width: 600px; - margin: 0 auto; - padding: 20px; -} +.tyk-stepper { + .steps-container { + display: flex; + flex-direction: column; + } -.steps-container { - display: flex; - flex-direction: column; -} + .step { + display: flex; + margin-bottom: 20px; -.step { - display: flex; - margin-bottom: 20px; + } -} + .step-indicator { + display: flex; + flex-direction: column; + align-items: center; + margin-right: 20px; + } -.step-indicator { - display: flex; - flex-direction: column; - align-items: center; - margin-right: 20px; -} + .step-number { + width: 30px; + height: 30px; + border-radius: 50%; + display: flex; + align-items: center; + justify-content: center; + margin-bottom: 10px; + border: 1px solid var(--color-secondary-dark); + } -.step-number { - width: 30px; - height: 30px; - border-radius: 50%; - display: flex; - align-items: center; - justify-content: center; - margin-bottom: 10px; - border: 1px solid var(--color-secondary-dark); -} + .step-line { + width: 1px; + flex-grow: 1; + background-color: var(--color-secondary-dark); + } -.step-line { - width: 1px; - flex-grow: 1; - background-color: var(--color-secondary-dark); -} + .step.completed .step-number { + color: var(--color-success-base); + border-color: var(--color-success-base); + } -.step.completed .step-number { - color: var(--color-success-base); - border-color: var(--color-success-base); -} + .step-content { + flex-grow: 1; + } -.step-content { - flex-grow: 1; -} + .step-content h3 { + margin: 0 0 5px 0; + } -.step-content h3 { - margin: 0 0 5px 0; -} + .step-content p { + margin: 0 0 10px 0; + } -.step-content p { - margin: 0 0 10px 0; -} + .step-component { + margin-top: 10px; + padding: 15px; + } -.step-component { - margin-top: 10px; - padding: 15px; -} - -.navigation-buttons { - display: flex; - justify-content: right; - margin-top: 20px; + .navigation-buttons { + display: flex; + justify-content: right; + margin-top: 20px; + } } \ No newline at end of file diff --git a/src/components/Stepper/index.js b/src/components/Stepper/index.js index 0fa3a6e6..92cd2e43 100644 --- a/src/components/Stepper/index.js +++ b/src/components/Stepper/index.js @@ -1,6 +1,7 @@ import React, { useState, useEffect } from "react"; -import Button from "../Button"; -import Icon from "../Icon"; +import StepIndicator from "./js/StepIndicator"; +import StepContent from "./js/StepContent"; +import NavigationButtons from "./js/NavigationButtons"; const Stepper = ({ steps, @@ -35,51 +36,36 @@ const Stepper = ({ const isLastStep = currentStep === steps.length - 1; return ( -
-
- {steps.map((step, index) => { - const isStepComplete = index < currentStep; - return ( -
+
+
+ {steps.map((step, index) => ( + -
-
- {isStepComplete ? : index + 1} -
- {index < steps.length - 1 &&
} -
-
-

{step.title}

-

{step.description}

- {index === currentStep && ( -
{step.component}
- )} -
-
- ); - })} -
-
- {currentStep >= 1 && ( - - )} -   - + + + ))} +
+
); }; -export default Stepper; \ No newline at end of file +export default Stepper; diff --git a/src/components/Stepper/js/NavigationButtons.js b/src/components/Stepper/js/NavigationButtons.js new file mode 100644 index 00000000..d7674144 --- /dev/null +++ b/src/components/Stepper/js/NavigationButtons.js @@ -0,0 +1,32 @@ +import React from "react"; +import Button from "../../Button"; + +const NavigationButtons = ({ + currentStep, + isLastStep, + isDisableFinish, + handleBack, + handleNext, + onFinish, + finishBtnText, +}) => { + return ( +
+ {currentStep >= 1 && ( + + )} +   + +
+ ); +}; + +export default NavigationButtons; diff --git a/src/components/Stepper/js/StepContent.js b/src/components/Stepper/js/StepContent.js new file mode 100644 index 00000000..a6722d84 --- /dev/null +++ b/src/components/Stepper/js/StepContent.js @@ -0,0 +1,24 @@ +import React from "react"; + +const StepContent = ({ step, index, currentStep, children }) => { + const isStepComplete = index < currentStep; + + return ( +
+ {children} +
+

{step.title}

+

{step.description}

+ {index === currentStep && ( +
{step.component}
+ )} +
+
+ ); +}; + +export default StepContent; diff --git a/src/components/Stepper/js/StepIndicator.js b/src/components/Stepper/js/StepIndicator.js new file mode 100644 index 00000000..3ade1176 --- /dev/null +++ b/src/components/Stepper/js/StepIndicator.js @@ -0,0 +1,18 @@ +import React from "react"; +import Icon from "../../Icon"; + +const StepIndicator = ({ index, currentStep, stepsLength }) => { + const isStepComplete = index < currentStep; + const isShowStepLine = index < stepsLength - 1; + + return ( +
+
+ {isStepComplete ? : index + 1} +
+ {isShowStepLine &&
} +
+ ); +}; + +export default StepIndicator;