Skip to content

Commit 4f4a65d

Browse files
feat: add steps play (#1572)
* feat: add steps play * chore: avoid targeting elements directly use classnames instead --------- Co-authored-by: Priyankar Pal <[email protected]>
1 parent a2c399a commit 4f4a65d

File tree

8 files changed

+206
-0
lines changed

8 files changed

+206
-0
lines changed

src/plays/steps/App.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import React from 'react';
2+
3+
import StepsWrapper from './components/StepsWrapper';
4+
5+
const App = () => {
6+
return <StepsWrapper />;
7+
};
8+
9+
export default App;

src/plays/steps/Readme.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Steps
2+
3+
A web app with “next” and “previous” navigation buttons, where the “next” button helps users move forward through steps, similar to the flow in e-commerce applications, and the “previous” button allows them to step back.
4+
5+
## Play Demographic
6+
7+
- Language: ts
8+
- Level: Beginner
9+
10+
## Creator Information
11+
12+
- User: aaqib605
13+
- Gihub Link: https://github.com/aaqib605
14+
- Blog: https://hashnode.com/@aaqib605
15+
- Video:
16+
17+
## Implementation Details
18+
19+
Update your implementation idea and details here
20+
21+
## Consideration
22+
23+
Update all considerations(if any)
24+
25+
## Resources
26+
27+
Update external resources(if any)

src/plays/steps/Steps.tsx

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import React from 'react';
2+
3+
import PlayHeader from 'common/playlists/PlayHeader';
4+
import App from './App';
5+
import './styles.css';
6+
7+
function Steps(props: any) {
8+
return (
9+
<>
10+
<div className="play-details">
11+
<PlayHeader play={props} />
12+
<div className="play-details-body">
13+
<App />
14+
</div>
15+
</div>
16+
</>
17+
);
18+
}
19+
20+
export default Steps;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React, { ReactNode, MouseEventHandler } from 'react';
2+
3+
interface ButtonProps {
4+
bgColor: string;
5+
textColor: string;
6+
disable: boolean;
7+
onClick: MouseEventHandler<HTMLButtonElement>;
8+
children: ReactNode;
9+
}
10+
11+
export default function Button({ textColor, bgColor, onClick, disable, children }: ButtonProps) {
12+
const disabledStyles = { background: 'grey', color: 'white', cursor: 'not-allowed' };
13+
14+
return (
15+
<button
16+
style={disable ? disabledStyles : { backgroundColor: bgColor, color: textColor }}
17+
onClick={onClick}
18+
>
19+
{children}
20+
</button>
21+
);
22+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react';
2+
3+
interface StepMessageProps {
4+
step: number;
5+
children: React.ReactNode;
6+
}
7+
8+
export default function StepMessage({ step, children }: StepMessageProps) {
9+
return (
10+
<div className="steps_message">
11+
<h3>Step {step}</h3>
12+
{children}
13+
</div>
14+
);
15+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import React, { useState } from 'react';
2+
3+
import StepMessage from './StepMessage';
4+
import Button from './Button';
5+
6+
export default function StepsWrapper() {
7+
const [step, setStep] = useState(1);
8+
9+
const messages = ['Learn React ⚛️', 'Apply for jobs 💼', 'Invest your new income 🤑'];
10+
11+
function handlePrevious() {
12+
if (step > 1) setStep((s) => s - 1);
13+
}
14+
15+
function handleNext() {
16+
if (step < 3) {
17+
setStep((s) => s + 1);
18+
}
19+
}
20+
21+
return (
22+
<div>
23+
<div className="steps">
24+
<div className="steps_numbers">
25+
<div className={step >= 1 ? 'steps_active' : ''}>1</div>
26+
<div className={step >= 2 ? 'steps_active' : ''}>2</div>
27+
<div className={step >= 3 ? 'steps_active' : ''}>3</div>
28+
</div>
29+
30+
<StepMessage step={step}>{messages[step - 1]}</StepMessage>
31+
32+
<div className="steps_buttons">
33+
<Button bgColor="#7950f2" disable={step === 1} textColor="#fff" onClick={handlePrevious}>
34+
<span>👈</span> Previous
35+
</Button>
36+
37+
<Button bgColor="#7950f2" disable={step === 3} textColor="#fff" onClick={handleNext}>
38+
Next <span>👉</span>
39+
</Button>
40+
</div>
41+
</div>
42+
</div>
43+
);
44+
}

src/plays/steps/cover.png

355 KB
Loading

src/plays/steps/styles.css

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
.steps {
2+
width: 600px;
3+
background-color: #f7f7f7;
4+
border-radius: 7px;
5+
padding: 25px 100px;
6+
margin: 100px auto;
7+
}
8+
9+
.steps_numbers {
10+
display: flex;
11+
justify-content: space-between;
12+
}
13+
14+
.steps_numbers > div {
15+
height: 40px;
16+
aspect-ratio: 1;
17+
background-color: #e7e7e7;
18+
border-radius: 50%;
19+
display: flex;
20+
align-items: center;
21+
justify-content: center;
22+
font-size: 18px;
23+
}
24+
25+
.steps_numbers .steps_active {
26+
background-color: #7950f2;
27+
color: #fff;
28+
}
29+
30+
.steps_message {
31+
text-align: center;
32+
font-size: 20px;
33+
margin: 40px 0;
34+
font-weight: bold;
35+
36+
display: flex;
37+
flex-direction: column;
38+
align-items: center;
39+
}
40+
41+
.steps_buttons {
42+
display: flex;
43+
justify-content: space-between;
44+
}
45+
46+
.steps_buttons button {
47+
border: none;
48+
cursor: pointer;
49+
padding: 10px 15px;
50+
border-radius: 100px;
51+
font-size: 14px;
52+
font-weight: bold;
53+
54+
display: flex;
55+
align-items: center;
56+
justify-content: center;
57+
gap: 10px;
58+
min-width: 8rem;
59+
}
60+
61+
.steps_buttons button span {
62+
font-size: 16px;
63+
line-height: 1;
64+
}
65+
66+
.steps_message h3 {
67+
margin: 0;
68+
text-transform: uppercase;
69+
}

0 commit comments

Comments
 (0)