Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added enhancement in stepper project #484

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/javascript/src/challenges/dice-game/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

---

<br>
</br>

## **Description 📃**

Expand Down
6 changes: 5 additions & 1 deletion apps/react/src/challenges/stepper/App.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
background-color: #ccc;
border: 2px solid black;
border-radius: 50%;
cursor: pointer;
}

.step.active .step-number {
Expand Down Expand Up @@ -72,13 +73,16 @@
}

.action-container .btn {
width: 70px;
height: 40px;
padding: 10px;
margin: 10px 50px;
font-size: 20px;
cursor: pointer;
background: none;
background-color: #ccc;
border: none;
border-radius: 5px;
}
button:disabled {
cursor: not-allowed !important;
}
30 changes: 25 additions & 5 deletions apps/react/src/challenges/stepper/Stepper.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,23 @@ const Stepper = ({ stepConfig = [] }) => {

const ActiveComponent = stepConfig[currentStep - 1]?.Component;

const handleClick = () => {
const handleClick = (index) => {
setIsCompleted(false);
setCurrentStep(index);
};

const handlePrevClick = () => {
setCurrentStep((prevStep) => {
if (prevStep < stepConfig.length + 1 && isCompleted) {
setIsCompleted(false);
return prevStep;
} else {
return prevStep - 1;
}
});
};

const handleNextClick = () => {
setCurrentStep((prevStep) => {
if (prevStep === stepConfig.length) {
setIsCompleted(true);
Expand All @@ -33,7 +49,7 @@ const Stepper = ({ stepConfig = [] }) => {
currentStep > index + 1 || isCompleted ? styles.complete : ''
}`}
>
<div className={styles['step-number']}>
<div className={styles['step-number']} onClick={() => handleClick(index + 1)}>
{currentStep > index + 1 || isCompleted ? <span>&#10003;</span> : index + 1}
</div>

Expand Down Expand Up @@ -62,11 +78,15 @@ const Stepper = ({ stepConfig = [] }) => {
<div className={styles['action-container']}>
{!isCompleted && <ActiveComponent />}
{isCompleted && <div>Order Delivered successfully!🎉</div>}
{!isCompleted && (
<button className={styles.btn} onClick={handleClick}>
<span>
<button disabled={currentStep === 1} className={styles.btn} onClick={handlePrevClick}>
Previous
</button>

<button disabled={isCompleted} className={styles.btn} onClick={handleNextClick}>
{currentStep === stepConfig.length ? 'Finish' : 'Next'}
</button>
)}
</span>
</div>
</>
);
Expand Down