-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
114 lines (111 loc) · 3.63 KB
/
App.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import Box from '@mui/material/Box';
import { Button, Paper, TextField, Typography } from '@mui/material';
import { Stack } from '@mui/system';
import { useInput } from './hooks/useInput';
function App() {
const email = useInput('', {
isEmpty: true,
minLength: 3,
isEmail: true,
maxLength: 30,
});
const password = useInput('', { isEmpty: true, minLength: 5, maxLength: 8 });
return (
<Box
sx={{
p: '1em',
width: '100%',
minHeight: '100vh',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
}}>
<Paper
elevation={3}
sx={{ p: '2em', maxWidth: '500px', flex: 1, borderRadius: '12px' }}>
<form>
<Stack sx={{ gap: '32px' }}>
<Typography
variant='h3'
textAlign='center'
sx={{ fontWeight: 700 }}>
Login
</Typography>
<Stack sx={{ gap: '24px' }}>
<Stack sx={{ gap: '16px' }}>
<TextField
label='Email'
name='email'
variant='outlined'
value={email.value}
onChange={e => email.onChange(e)}
onBlur={e => email.onBlur(e)}
sx={{
'& .MuiInputBase-root': {
borderRadius: '12px',
},
}}
/>
<Stack>
{email.isDirty && email.isEmpty && (
<div style={{ color: 'red' }}>Field cannot be empty</div>
)}
{email.isDirty && email.isMinLengthError && (
<div style={{ color: 'red' }}>
Field must have minimal length
</div>
)}
{email.isDirty && email.isMaxLengthError && (
<div style={{ color: 'red' }}>Too long email</div>
)}
{email.isDirty && email.isEmailError && (
<div style={{ color: 'red' }}>Incorrect email pattern</div>
)}
</Stack>
</Stack>
<Stack sx={{ gap: '16px' }}>
<TextField
label='Password'
name='password'
type='password'
variant='outlined'
value={password.value}
onChange={e => password.onChange(e)}
onBlur={e => password.onBlur(e)}
sx={{
'& .MuiInputBase-root': {
borderRadius: '12px',
},
}}
/>
<Stack>
{password.isDirty && password.isEmpty && (
<div style={{ color: 'red' }}>Field cannot be empty</div>
)}
{password.isDirty && password.isMinLengthError && (
<div style={{ color: 'red' }}>
Field must have minimal length
</div>
)}
</Stack>
</Stack>
<Button
type='submit'
variant='contained'
disabled={!email.isInputValid || !password.isInputValid}
sx={{
p: '.8em 2em',
textTransform: 'none',
fontSize: 'inherit',
borderRadius: '12px',
}}>
Submit
</Button>
</Stack>
</Stack>
</form>
</Paper>
</Box>
);
}
export default App;