LoginForm.js 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import React, { useState } from 'react';
  2. import LockOutlinedIcon from '@mui/icons-material/LockOutlined';
  3. import Button from '@mui/material/Button';
  4. import { Container, CssBaseline, TextField, Avatar, Typography, FormControlLabel, Checkbox, Grid, Link } from '@mui/material';
  5. import { Box } from '@mui/system';
  6. const LoginForm = ({ onLogin }) => {
  7. const [login, setLogin] = useState('');
  8. const [password, setPassword] = useState('');
  9. const isButtonActive = login?.length > 3 && password?.length > 3;
  10. return (
  11. <Container component="main" maxWidth="xs">
  12. <CssBaseline />
  13. <Box
  14. sx={{
  15. marginTop: 8,
  16. display: 'flex',
  17. flexDirection: 'column',
  18. alignItems: 'center',
  19. }}
  20. >
  21. <Avatar sx={{ m: 1, bgcolor: 'secondary.main' }}>
  22. <LockOutlinedIcon />
  23. </Avatar>
  24. <Typography component="h1" variant="h5">
  25. Sign in
  26. </Typography>
  27. <TextField
  28. fullWidth
  29. margin="normal"
  30. autoFocus
  31. required
  32. id="login-input"
  33. label="Login"
  34. size="small"
  35. defaultValue=""
  36. onChange={e => setLogin(e.target.value)}
  37. />
  38. <TextField
  39. fullWidth
  40. margin="normal"
  41. required
  42. id="password-input"
  43. label="Password"
  44. type="password"
  45. size="small"
  46. defaultValue=""
  47. onChange={e => setPassword(e.target.value)}
  48. />
  49. <FormControlLabel
  50. control={<Checkbox value="remember" color="primary" />}
  51. label="Remember me"
  52. />
  53. <Button
  54. variant="contained"
  55. sx={{ mt: 3, mb: 2 }}
  56. fullWidth
  57. type="submit"
  58. disabled={!isButtonActive}
  59. onClick={() => { onLogin({ login, password }) }}>
  60. Login...
  61. </Button>
  62. <Grid container>
  63. <Grid item xs>
  64. <Link href="#" variant='body2'>
  65. Forgot password?
  66. </Link>
  67. </Grid>
  68. <Grid item>
  69. <Link href="#" variant='body2'>
  70. {"Don't have an account? Sign Up"}
  71. </Link>
  72. </Grid>
  73. </Grid>
  74. </Box>
  75. </Container>
  76. )
  77. }
  78. export { LoginForm };