Skip to content

Commit

Permalink
make nav steps sticky for horizontal stepper
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-deshmukh committed Jan 2, 2025
1 parent 0dd66ac commit 3669218
Show file tree
Hide file tree
Showing 13 changed files with 53 additions and 20 deletions.
2 changes: 1 addition & 1 deletion lib/index.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tyk-ui.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tyk-ui.css.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tyk-ui.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/tyk-ui.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tyk-technologies/tyk-ui",
"version": "4.4.12",
"version": "4.4.13",
"description": "Tyk UI - ui reusable components",
"main": "src/index.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/components/Stepper/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const ExampleStepper = () => {
stepValidator={validateStep}
stepErrMessage="Please complete all required fields before proceeding."
onChange={(step) => console.log("Step Changed : ", step)}
onSkip={(step) => console.log("SKIP", step)}
>
<Stepper.Step id="personal-info" title="Step-1">
<input type="text" placeholder="Full Name" />
Expand Down
10 changes: 9 additions & 1 deletion src/components/Stepper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ const Stepper = ({
contentHeight,
nextBtnTxt = "Continue",
finishBtnTxt = "Finish",
skipBtnTxt = "Skip",
backBtnTxt = "Back",
onChange = () => {}
onChange = () => {},
onSkip = null,
}) => {
const [activeStep, setActiveStep] = useState(0);
const [errors, setErrors] = useState({});
Expand All @@ -41,6 +43,7 @@ const Stepper = ({
validationAttempted,
setValidationAttempted,
orientation,
onSkip
};

return (
Expand Down Expand Up @@ -68,6 +71,7 @@ const Stepper = ({
nextBtnTxt={nextBtnTxt}
finishBtnTxt={finishBtnTxt}
backBtnTxt={backBtnTxt}
skipBtnTxt={skipBtnTxt}
/>
</div>
</div>
Expand Down Expand Up @@ -100,6 +104,10 @@ Stepper.propTypes = {
/**
* Callback triggered on step change.
*/
onSkip: PropTypes.func,
/**
* Callback triggered on step skip.
*/
stepValidator: PropTypes.func,
/**
* Error message to display when a step is invalid.
Expand Down
35 changes: 26 additions & 9 deletions src/components/Stepper/js/StepperButtons.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import React from 'react';
import PropTypes from 'prop-types';
import Button from '../../Button';
import { useStepper } from '../StepperContext';
import React from "react";
import PropTypes from "prop-types";
import Button from "../../Button";
import { useStepper } from "../StepperContext";

const StepperButtons = ({nextBtnTxt, finishBtnTxt, backBtnTxt}) => {
const StepperButtons = ({
nextBtnTxt,
finishBtnTxt,
backBtnTxt,
skipBtnTxt,
}) => {
const {
activeStep,
steps,
setActiveStep,
setErrors,
onFinish,
onChange,
onSkip,
stepValidator,
stepErrMessage,
setValidationAttempted
setValidationAttempted,
} = useStepper();

const isLastStep = activeStep === steps.length - 1;
Expand All @@ -34,7 +40,7 @@ const StepperButtons = ({nextBtnTxt, finishBtnTxt, backBtnTxt}) => {
} else {
setErrors((prev) => ({
...prev,
[activeStep]: stepErrMessage
[activeStep]: stepErrMessage,
}));
}
};
Expand All @@ -47,8 +53,19 @@ const StepperButtons = ({nextBtnTxt, finishBtnTxt, backBtnTxt}) => {
}
};

const onSkipStep = () => {
onSkip(steps[activeStep]?.props?.id);
};

return (
<div className="stepper-buttons">
{onSkip && (
<div className="skip-btn">
<Button onClick={onSkipStep} theme="secondary-outline">
{skipBtnTxt}
</Button>
</div>
)}
{activeStep > 0 && (
<Button onClick={goToPreviousStep} theme="secondary">
{backBtnTxt}
Expand All @@ -64,7 +81,7 @@ const StepperButtons = ({nextBtnTxt, finishBtnTxt, backBtnTxt}) => {
StepperButtons.propTypes = {
nextBtnTxt: PropTypes.string.isRequired,
finishBtnTxt: PropTypes.string.isRequired,
backBtnTxt: PropTypes.string.isRequired
backBtnTxt: PropTypes.string.isRequired,
};

export default StepperButtons;
export default StepperButtons;
9 changes: 8 additions & 1 deletion src/components/Stepper/stepper.css
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
.step-list-horizontal {
display: flex;
padding-bottom: 5px;
position: relative;
position: sticky;
top: 0;
z-index: 10;
background-color: white;
}

.step-list-horizontal::after {
Expand Down Expand Up @@ -186,6 +189,10 @@
padding-top: 20px;
margin-top: 20px;
border-top: 1.5px solid var(--color-secondary-dark);
gap: 8px;
.skip-btn {
margin-right: auto;
}
}


Expand Down

0 comments on commit 3669218

Please sign in to comment.