Skip to content

Commit a1b51c2

Browse files
authored
refactor(ui): migrate auth form styles from Tailwind to MUI sx (#1291)
1 parent f66f8a5 commit a1b51c2

File tree

2 files changed

+130
-36
lines changed

2 files changed

+130
-36
lines changed

client/src/modules/user-auth-form/index.tsx

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,39 @@ import { authorizeUser } from './requests';
99
import { useNotifications } from '../../shared/hooks/use-notification';
1010
import React from 'react';
1111
import { AuthorizeUserPayload } from './typings';
12+
import { Button, Typography } from '@mui/material';
13+
import { styled } from '@mui/material/styles';
14+
15+
const StyledSection = styled('section')(({ theme }) => ({
16+
paddingTop: theme.spacing(4),
17+
paddingBottom: theme.spacing(4),
18+
paddingLeft: '5vw',
19+
paddingRight: '5vw',
20+
display: 'flex',
21+
alignItems: 'center',
22+
justifyContent: 'center',
23+
minHeight: `calc(100vh - 80px)`,
24+
}));
25+
26+
const StyledForm = styled('form')(() => ({
27+
width: '80%',
28+
maxWidth: 400,
29+
}));
30+
31+
const StyledTitle = styled(Typography)(({ theme }) => ({
32+
fontSize: '2.5rem',
33+
fontFamily: 'Gelasio, serif',
34+
textTransform: 'capitalize',
35+
textAlign: 'center',
36+
marginBottom: theme.spacing(6),
37+
}));
38+
39+
const StyledFooter = styled('p')(({ theme }) => ({
40+
marginTop: theme.spacing(2.5),
41+
color: theme.palette.text.secondary,
42+
fontSize: '1.125rem',
43+
textAlign: 'center',
44+
}));
1245

1346
const UserAuthForm = ({ type }: { type: string }) => {
1447
const [userAuth, setUserAuth] = useAtom(UserAtom);
@@ -43,7 +76,7 @@ const UserAuthForm = ({ type }: { type: string }) => {
4376

4477
const formRef = React.useRef<HTMLFormElement>(null);
4578

46-
const handleSubmit = (e: React.MouseEvent<HTMLElement, MouseEvent>) => {
79+
const handleSubmit = (e: React.FormEvent<HTMLElement>) => {
4780
e.preventDefault();
4881

4982
const serverRoute =
@@ -101,11 +134,11 @@ const UserAuthForm = ({ type }: { type: string }) => {
101134
<Navigate to="/" />
102135
) : (
103136
<AnimationWrapper keyValue={type}>
104-
<section className="py-4 px-[5vw] md:px-[7vw] lg:px-[10vw] h-cover flex items-center justify-center">
105-
<form id="formElement" className="w-[80%] max-w-[400px]" ref={formRef}>
106-
<h1 className="text-4xl font-gelasio capitalize text-center mb-24">
137+
<StyledSection>
138+
<StyledForm id="formElement" onSubmit={handleSubmit}>
139+
<StyledTitle>
107140
{type === 'login' ? 'Welcome back' : 'Join us today'}
108-
</h1>
141+
</StyledTitle>
109142

110143
{type !== 'login' ? (
111144
<InputBox
@@ -132,27 +165,44 @@ const UserAuthForm = ({ type }: { type: string }) => {
132165
icon="fi-rr-key"
133166
/>
134167

135-
<button
136-
className="btn-dark center mt-14"
168+
<Button
137169
type="submit"
138-
onClick={handleSubmit}
170+
variant="contained"
171+
sx={theme => ({
172+
borderRadius: '999px',
173+
bgcolor: theme.palette.mode === 'dark' ? '#e4e4e7' : '#1f1f1f',
174+
color: theme.palette.mode === 'dark' ? '#1a1a1a' : '#f1f1f1',
175+
padding: theme.spacing(1.5, 3),
176+
fontSize: '1.125rem',
177+
textTransform: 'none',
178+
'&:hover': {
179+
opacity: 0.9,
180+
},
181+
mt: 3.5,
182+
mx: 'auto',
183+
display: 'block',
184+
})}
139185
>
140186
{type === 'login' ? 'Login' : 'Sign Up'}
141-
</button>
187+
</Button>
142188

143-
<p className="mt-10 text-[#a3a3a3] text-xl text-center">
189+
<StyledFooter>
144190
{type === 'login'
145191
? "Don't have an account ?"
146192
: 'Already a member ?'}
147193
<Link
148194
to={type === 'login' ? '/signup' : '/login'}
149-
className="text-black dark:text-[#ededed] text-xl ml-1 underline"
195+
style={{
196+
marginLeft: 8,
197+
textDecoration: 'underline',
198+
color: 'inherit',
199+
}}
150200
>
151201
{type === 'login' ? 'Join us today' : 'Sign in here'}
152202
</Link>
153-
</p>
154-
</form>
155-
</section>
203+
</StyledFooter>
204+
</StyledForm>
205+
</StyledSection>
156206
</AnimationWrapper>
157207
);
158208
};

client/src/shared/components/atoms/input-box/index.tsx

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,43 @@
11
import { Dispatch, SetStateAction, useState } from 'react';
2+
import { TextField, InputAdornment, IconButton } from '@mui/material';
3+
import { Visibility, VisibilityOff } from '@mui/icons-material';
4+
import { styled } from '@mui/material/styles';
5+
6+
const StyledTextField = styled(TextField)(({ theme }) => ({
7+
width: '100%',
8+
'& .MuiOutlinedInput-root': {
9+
borderRadius: '0.375rem',
10+
backgroundColor: theme.palette.mode === 'dark' ? '#09090b' : '#fafafa',
11+
paddingLeft: 0,
12+
'& .input-icon': {
13+
color: theme.palette.mode === 'dark' ? '#a3a3a3' : '#444444',
14+
fontSize: '1.125rem',
15+
lineHeight: 1,
16+
},
17+
border: `1px solid ${theme.palette.divider}`,
18+
color: theme.palette.text.primary,
19+
'& fieldset': {
20+
border: 'none',
21+
},
22+
'&.Mui-focused': {
23+
backgroundColor: 'transparent',
24+
borderColor: theme.palette.primary.main,
25+
},
26+
'& input::placeholder': {
27+
color: theme.palette.mode === 'dark' ? '#fff' : '#000',
28+
opacity: 1,
29+
},
30+
'&.Mui-disabled': {
31+
backgroundColor: theme.palette.action.disabledBackground,
32+
},
33+
},
34+
'& .MuiInputBase-input': {
35+
paddingLeft: '3rem',
36+
},
37+
'& .MuiInputAdornment-root': {
38+
marginLeft: 0,
39+
},
40+
}));
241

342
interface InputBoxProps {
443
name: string;
@@ -28,35 +67,40 @@ const InputBox = ({
2867
const [passwordVisible, setPasswordVisible] = useState(false);
2968

3069
return (
31-
<div className={className + ' relative w-[100%] mb-4'}>
32-
<input
70+
<div className={`${className ?? ''} relative w-full mb-4`}>
71+
<StyledTextField
3372
name={name}
73+
id={id}
3474
type={
35-
type == 'password' ? (passwordVisible ? 'text' : 'password') : type
75+
type === 'password' ? (passwordVisible ? 'text' : 'password') : type
3676
}
77+
value={value}
78+
onChange={e => setValue?.(e.target.value)}
3779
placeholder={placeholder}
38-
defaultValue={value}
39-
id={id}
4080
disabled={disable}
41-
className="input-box"
42-
onChange={e => setValue?.(e.target.value)}
4381
autoComplete={autoComplete}
82+
fullWidth
83+
variant="outlined"
84+
InputProps={{
85+
startAdornment: icon ? (
86+
<InputAdornment position="start">
87+
<i className={`fi ${icon} input-icon`} />
88+
</InputAdornment>
89+
) : undefined,
90+
endAdornment:
91+
type === 'password' ? (
92+
<InputAdornment position="end">
93+
<IconButton
94+
onClick={() => setPasswordVisible(!passwordVisible)}
95+
edge="end"
96+
tabIndex={-1}
97+
>
98+
{passwordVisible ? <Visibility /> : <VisibilityOff />}
99+
</IconButton>
100+
</InputAdornment>
101+
) : undefined,
102+
}}
44103
/>
45-
46-
<i className={'fi ' + icon + ' input-icon'}></i>
47-
48-
{type == 'password' ? (
49-
<i
50-
className={
51-
'fi fi-rr-eye' +
52-
(!passwordVisible ? '-crossed' : '') +
53-
' input-icon left-[auto] right-4 cursor-pointer'
54-
}
55-
onClick={() => setPasswordVisible(!passwordVisible)}
56-
></i>
57-
) : (
58-
''
59-
)}
60104
</div>
61105
);
62106
};

0 commit comments

Comments
 (0)