Skip to content

Commit

Permalink
feat: add components
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyguidomadrid committed Nov 8, 2024
1 parent e79e4fb commit 00cf1bf
Show file tree
Hide file tree
Showing 32 changed files with 2,303 additions and 141 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,15 @@
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.13.3",
"@emotion/styled": "^11.13.0",
"@mui/icons-material": "^6.1.6",
"@mui/material": "^6.1.6",
"@reduxjs/toolkit": "^2.3.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
"react-dom": "^18.3.1",
"react-redux": "^9.1.2",
"redux": "^5.0.1"
},
"devDependencies": {
"@eslint/js": "^9.13.0",
Expand Down
42 changes: 0 additions & 42 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,42 +0,0 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}

.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}

@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}

.card {
padding: 2em;
}

.read-the-docs {
color: #888;
}
7 changes: 7 additions & 0 deletions src/App.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Box, styled } from "@mui/material";

export const AppWrapper = styled(Box)(({ theme }) => ({
maxWidth: theme.breakpoints.values.sm,
margin: "auto",
padding: theme.spacing(5),
}));
43 changes: 13 additions & 30 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,18 @@
import { useState } from 'react'
import reactLogo from './assets/react.svg'
import viteLogo from '/vite.svg'
import './App.css'
import { Provider } from "react-redux";
import "./App.css";
import { AppWrapper } from "./App.styles";
import { Wizard } from "./components/Wizard/Wizard";
import { STEPS } from "./components/Wizard/Wizard.constant";
import store from "./redux/store";

function App() {
const [count, setCount] = useState(0)

return (
<>
<div>
<a href="https://vite.dev" target="_blank">
<img src={viteLogo} className="logo" alt="Vite logo" />
</a>
<a href="https://react.dev" target="_blank">
<img src={reactLogo} className="logo react" alt="React logo" />
</a>
</div>
<h1>Vite + React</h1>
<div className="card">
<button onClick={() => setCount((count) => count + 1)}>
count is {count}
</button>
<p>
Edit <code>src/App.tsx</code> and save to test HMR
</p>
</div>
<p className="read-the-docs">
Click on the Vite and React logos to learn more
</p>
</>
)
<Provider store={store}>
<AppWrapper>
<Wizard steps={STEPS} />
</AppWrapper>
</Provider>
);
}

export default App
export default App;
18 changes: 18 additions & 0 deletions src/components/Wizard/Wizard.constant.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NameForm, ReviewScreen } from "./components/Steps";
import { SelectForm } from "./components/Steps/SelectForm/SelectForm";
import { Step } from "./Wizard.types";

export const STEPS: Step[] = [
{
label: "Step 1",
content: <NameForm />,
},
{
label: "Step 2",
content: <SelectForm />,
},
{
label: "Step 3",
content: <ReviewScreen />,
},
];
7 changes: 7 additions & 0 deletions src/components/Wizard/Wizard.styles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Box, styled } from "@mui/material";

export const ContentWrapper = styled(Box)(({ theme }) => ({
minHeight: "200px",
margin: "auto",
paddingTop: theme.spacing(7),
}));
26 changes: 26 additions & 0 deletions src/components/Wizard/Wizard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { useState } from "react";
import { WizardProps } from "./Wizard.types";
import { WizardHeader } from "./components";
import { WizardButtons } from "./components/WizardButtons";
import { ContentWrapper } from "./Wizard.styles";

export const Wizard: React.FC<WizardProps> = ({ steps }) => {
const [step, setStep] = useState(0);
const { content } = steps[step];
const headerSteps: string[] = steps.map(({ label }) => {
return label;
});

return (
<section>
<WizardHeader steps={headerSteps} setStep={setStep} currentStep={step} />
<ContentWrapper>{content}</ContentWrapper>
<WizardButtons
setStep={setStep}
currentStep={step}
isFirstStep={step === 0}
isLastStep={step === steps.length - 1}
/>
</section>
);
};
8 changes: 8 additions & 0 deletions src/components/Wizard/Wizard.types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export type Step = {
label: string;
content: React.ReactNode;
};

export type WizardProps = {
steps: Step[];
};
43 changes: 43 additions & 0 deletions src/components/Wizard/components/Steps/NameForm/NameForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { FormEvent } from "react";
import { useUserName } from "../../../../../hooks/useUserName";
import { TextField, Button } from "@mui/material";

export const NameForm: React.FC = () => {
const { name, updateUserName } = useUserName();

const onSubmit = (e: FormEvent) => {
e.preventDefault();
// onFirstStepSubmit();
};

return (
<form onSubmit={onSubmit}>
{/* {hasError && (
<Typography color="error">
There was an error, please try again.
</Typography>
)} */}

<TextField
label="Your Name"
value={name}
onChange={(e) => updateUserName(e.target.value)}
fullWidth
variant="outlined"
margin="normal"
slotProps={{ htmlInput: { maxLength: 63 } }}
autoFocus
/>

<Button
type="submit"
variant="contained"
color="primary"
role="submit"
// disabled={isLoading}
>
Submit
</Button>
</form>
);
};
1 change: 1 addition & 0 deletions src/components/Wizard/components/Steps/NameForm/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./NameForm";
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { styled, Typography } from "@mui/material";

export const CenteredTypography = styled(Typography)(() => ({
textAlign: 'center'
}))
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Grid } from "@mui/material";
import { CenteredTypography } from "./ReviewScreen.styles";
import { useUserName } from "../../../../../hooks/useUserName";

export const ReviewScreen = () => {
const { name } = useUserName();

return (
<Grid
container
spacing={2}
flexDirection="column"
justifyContent="center"
alignItems="center"
>
<Grid item xs={8}>
<CenteredTypography variant="h6">Name</CenteredTypography>
<CenteredTypography>{name}</CenteredTypography>
</Grid>
<Grid item xs={4}>
<CenteredTypography variant="h6">Age</CenteredTypography>
<CenteredTypography>Name</CenteredTypography>
</Grid>
</Grid>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./ReviewScreen";
30 changes: 30 additions & 0 deletions src/components/Wizard/components/Steps/SelectForm/SelectForm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
FormControl,
InputLabel,
Select,
MenuItem,
SelectChangeEvent,
} from "@mui/material";
import { useState } from "react";

export const SelectForm = () => {
const [age, setAge] = useState("");

const handleChange = (e: SelectChangeEvent<string>) => setAge(e.target.value);
return (
<FormControl fullWidth>
<InputLabel id="demo-simple-select-label">Age</InputLabel>
<Select
labelId="demo-simple-select-label"
id="demo-simple-select"
value={age}
label="Age"
onChange={handleChange}
>
<MenuItem value={10}>Ten</MenuItem>
<MenuItem value={20}>Twenty</MenuItem>
<MenuItem value={30}>Thirty</MenuItem>
</Select>
</FormControl>
);
};
Empty file.
3 changes: 3 additions & 0 deletions src/components/Wizard/components/Steps/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./NameForm";
export * from "./SelectForm";
export * from "./ReviewScreen";
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Box, styled } from "@mui/material";

export const ButtonWrapper = styled(Box)(({ theme }) => ({
display: "flex",
justifyContent: "space-between",
paddingTop: theme.spacing(2),
}));
33 changes: 33 additions & 0 deletions src/components/Wizard/components/WizardButtons/WizardButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Box, Button } from "@mui/material";
import { WizardButtonsProps } from "./WizardButtons.types";
import { ButtonWrapper } from "./WizardButtons.styles";

export const WizardButtons: React.FC<WizardButtonsProps> = ({
currentStep,
setStep,
isFirstStep,
isLastStep,
}) => {
const onPreviousStepChange = () => {
setStep(currentStep - 1);
};

const onNextStepChange = () => {
if (isLastStep) {
console.log("hello");
} else {
setStep(currentStep + 1);
}
};

return (
<ButtonWrapper>
<Button disabled={isFirstStep} onClick={onPreviousStepChange}>
Previous
</Button>
<Button onClick={onNextStepChange}>
{isLastStep ? "Submit" : "Next"}
</Button>
</ButtonWrapper>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export type WizardButtonsProps = {
setStep: (step: number) => void;
currentStep: number;
isFirstStep: boolean;
isLastStep: boolean;
};
1 change: 1 addition & 0 deletions src/components/Wizard/components/WizardButtons/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./WizardButtons";
23 changes: 23 additions & 0 deletions src/components/Wizard/components/WizardHeader/WizardHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Stepper, Step, StepLabel } from "@mui/material";
import { WizardHeaderProps } from "./WizardHeader.types";

export const WizardHeader: React.FC<WizardHeaderProps> = ({
currentStep,
steps,
setStep,
}) => {
return (
// <div>
// {steps.map((label, index) => {
// return <button onClick={() => setStep(index)}>{label}</button>;
// })}
// </div>
<Stepper activeStep={currentStep} alternativeLabel>
{steps.map((label) => (
<Step key={label}>
<StepLabel>{label}</StepLabel>
</Step>
))}
</Stepper>
);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type WizardHeaderProps = {
steps: string[];
setStep: (step: number) => void;
currentStep: number;
};
1 change: 1 addition & 0 deletions src/components/Wizard/components/WizardHeader/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./WizardHeader";
2 changes: 2 additions & 0 deletions src/components/Wizard/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./WizardButtons";
export * from "./WizardHeader";
1 change: 1 addition & 0 deletions src/components/Wizard/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Wizard";
1 change: 1 addition & 0 deletions src/components/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./Wizard";
Loading

0 comments on commit 00cf1bf

Please sign in to comment.