Skip to content

Commit

Permalink
make button text dynamic and horizontal content height fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jay-deshmukh committed Dec 9, 2024
1 parent 8c0ca90 commit bcaf4a7
Show file tree
Hide file tree
Showing 13 changed files with 114 additions and 47 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.8-alpha1",
"version": "4.4.8-alpha5",
"description": "Tyk UI - ui reusable components",
"main": "src/index.js",
"scripts": {
Expand Down
79 changes: 60 additions & 19 deletions src/components/Stepper/Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ const ExampleStepper = () => {
```

```jsx
import React from 'react';
import Stepper from "./index.js"
import React from "react";
import Stepper from "./index.js";

const ExampleStepper = () => {
const handleFinish = () => {
console.log('All steps completed!');
console.log("All steps completed!");
};

const validateStep = (stepId) => {
Expand All @@ -58,23 +58,64 @@ const ExampleStepper = () => {
onFinish={handleFinish}
stepValidator={validateStep}
stepErrMessage="Please complete all required fields before proceeding."
orientation = "horizontal"
orientation="horizontal"
backBtnTxt="Previous"
nextBtnTxt="Next"
finishBtnTxt="Done"
>
<Stepper.Step id="personal-info" title="Step-1">
<input type="text" placeholder="Full Name" />
</Stepper.Step>

<Stepper.Step id="address" title="Step-2">
<input type="text" placeholder="Street Address" />
</Stepper.Step>

<Stepper.Step id="review" title="Step-3">
<p>Please review your entered information before submitting.</p>
</Stepper.Step>

<Stepper.Step id="review2" title="Step-4">
<p>Please review your entered information before submitting.</p>
</Stepper.Step>
<Stepper.Step id="personal-info" title="Step-1">
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
<br />
<input type="text" placeholder="Full Name" />
</Stepper.Step>

<Stepper.Step id="address" title="Step-2">
<input type="text" placeholder="Street Address" />
</Stepper.Step>

<Stepper.Step id="review" title="Step-3">
<p>Please review your entered information before submitting.</p>
</Stepper.Step>

<Stepper.Step id="review2" title="Step-4">
<p>Please review your entered information before submitting.</p>
</Stepper.Step>
</Stepper>
);
};
Expand Down
32 changes: 30 additions & 2 deletions src/components/Stepper/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ const Stepper = ({
stepValidator,
stepErrMessage = "ERROR",
orientation = "vertical",
contentHeight = "200px",
nextBtnTxt = "Continue",
finishBtnTxt = "Finish",
backBtnTxt = "Back",
}) => {
const [activeStep, setActiveStep] = useState(0);
const [errors, setErrors] = useState({});
const [validationAttempted, setValidationAttempted] = useState(false);
const isHorizontal = orientation === "horizontal";

const steps = useMemo(() => {
return React.Children.toArray(children).filter(
Expand All @@ -41,8 +46,27 @@ const Stepper = ({
<div className={`stepper-container stepper-${orientation}`}>
<StepList />
<div className="stepper-content-wrapper">
{orientation === "horizontal" && steps[activeStep]}
<StepperButtons />
{isHorizontal && (
<div
className="no-scrollbar"
style={
isHorizontal
? {
height: contentHeight,
maxHeight: contentHeight,
overflow: "scroll",
}
: {}
}
>
{isHorizontal && steps[activeStep]}
</div>
)}
<StepperButtons
nextBtnTxt={nextBtnTxt}
finishBtnTxt={finishBtnTxt}
backBtnTxt={backBtnTxt}
/>
</div>
</div>
</StepperProvider>
Expand Down Expand Up @@ -75,6 +99,10 @@ Stepper.propTypes = {
* Error message to display when a step is invalid.
*/
stepErrMessage: PropTypes.string,
/**
* height of the content (for horizontal stepper)
*/
contentHeight: PropTypes.string,
/**
* Stepper orientation
*/
Expand Down
6 changes: 3 additions & 3 deletions src/components/Stepper/js/StepperButtons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import Button from '../../Button';
import { useStepper } from '../StepperContext';

const StepperButtons = () => {
const StepperButtons = ({nextBtnTxt, finishBtnTxt, backBtnTxt}) => {
const {
activeStep,
steps,
Expand Down Expand Up @@ -47,11 +47,11 @@ const StepperButtons = () => {
<div className="stepper-buttons">
{activeStep > 0 && (
<Button onClick={goToPreviousStep} theme="secondary">
Back
{backBtnTxt}
</Button>
)}
<Button onClick={goToNextStep} theme="primary">
{isLastStep ? 'Finish' : 'Continue'}
{isLastStep ? finishBtnTxt : nextBtnTxt}
</Button>
</div>
);
Expand Down
26 changes: 12 additions & 14 deletions src/components/Stepper/stepper.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

.step-list-horizontal {
display: flex;
padding-bottom: 20px;
margin-bottom: 20px;
padding-bottom: 5px;
position: relative;
}

Expand Down Expand Up @@ -179,7 +178,6 @@

.stepper-content-wrapper {
flex: 1;
padding: 20px 0;
overflow: hidden;
}

Expand All @@ -188,22 +186,22 @@
display: flex;
justify-content: flex-end;
padding-top: 20px;
margin-top: auto;
gap: 10px;
margin-top: 20px;
border-top: 1.5px solid var(--color-secondary-dark);
}

.stepper-buttons button {
padding: 8px 16px;
border-radius: 4px;
border: none;
cursor: pointer;
font-weight: 500;
}


.error-message {
color: var(--color-danger-base);
margin-top: 5px;
font-size: 14px;
}
}

.no-scrollbar {
-ms-overflow-style: none; /* IE and Edge */
scrollbar-width: none; /* Firefox */
}

.no-scrollbar::-webkit-scrollbar {
display: none; /* Chrome, Safari and Opera */
}

0 comments on commit bcaf4a7

Please sign in to comment.