InitialForm.jsx 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. import React, { useState } from 'react'
  2. import { Button, Input, Checkbox, Form } from 'antd'
  3. import { Typography, Col, Row } from 'antd'
  4. import { LockOutlined, UserOutlined } from '@ant-design/icons';
  5. const { Title } = Typography
  6. const InitialForm = ({ onLogin, children }) => {
  7. const [login, setLogin] = useState('')
  8. const [password, setPassword] = useState('')
  9. const [checked, setChecked] = useState(false)
  10. const input = () => {
  11. onLogin(login, password) && setPassword('') && setLogin('')
  12. }
  13. return (
  14. <>
  15. <Form
  16. size="medium"
  17. name="basic"
  18. className="LoginForm-Form"
  19. // labelCol={{ span: 12}}
  20. // wrapperCol={{ span: 17 }}
  21. // labelCol={{xs}}
  22. autoComplete="off"
  23. >
  24. {/* <Col xs={{ span: 10 }}
  25. sm={16} md={12} lg={8} xl={4}> */}
  26. <Title level={2}> {children} </Title>
  27. <Form.Item
  28. name="login"
  29. size="large"
  30. rules={[
  31. {
  32. required: true,
  33. message: 'Please input login!',
  34. },
  35. ]}
  36. style={{marginBottom: '5px'}}
  37. wrapperCol={{ offset: 4, span: 15 }}
  38. >
  39. <Input prefix={<UserOutlined className="site-form-item-icon" />}
  40. placeholder="Login"
  41. value={login}
  42. size="medium"
  43. onChange={(e) => setLogin(e.target.value)}
  44. />
  45. </Form.Item>
  46. <Form.Item
  47. style={{margin:'0 auto'}}
  48. wrapperCol={{ offset: 4, span: 14 }}
  49. >
  50. <p
  51. >
  52. {' '}
  53. * Login must be at least 5 characters{' '}
  54. </p>
  55. </Form.Item>
  56. <Form.Item
  57. name="password"
  58. size="large"
  59. rules={[
  60. {
  61. required: true,
  62. message: 'Please input your password!',
  63. },
  64. ]}
  65. style={{ padding: '0 auto',marginBottom: '5px'}}
  66. wrapperCol={{ offset: 4, span: 15 }}
  67. >
  68. <Input
  69. prefix={<LockOutlined className="site-form-item-icon" />}
  70. placeholder="Password"
  71. size="medium"
  72. type={checked ? 'text' : 'password'}
  73. value={password}
  74. onChange={(e) => setPassword(e.target.value)}
  75. />
  76. {/* <Input
  77. size="medium"
  78. type={checked ? 'text' : 'password'}
  79. value={password}
  80. onChange={(e) => setPassword(e.target.value)}
  81. /> */}
  82. </Form.Item>
  83. <Form.Item
  84. style={{margin:'0 auto'}}
  85. wrapperCol={{ offset: 3, span: 15 }}
  86. >
  87. <p>
  88. * Use a combination of 8 or more letters, numbers, and symbols
  89. </p>
  90. </Form.Item>
  91. {/* <Text type="secondary" style={{ color: 'rgb(35, 60, 107)' }}> */}
  92. {/* style={{ width: '250px', marginLeft: '90px' }} */}
  93. {/* <Text type="secondary" style={{ color: 'rgb(35, 60, 107)'}}>
  94. Password must contain at least eight characters, include letters,
  95. numbers and special symbols{' '}
  96. </Text> */}
  97. <Form.Item
  98. name="checked"
  99. valuePropName="checked"
  100. wrapperCol={{ offset: 3, span: 17 }}
  101. style={{margin: '10px 0px'}}
  102. >
  103. <Checkbox
  104. checked={checked}
  105. onChange={(e) => {
  106. setChecked(e.target.checked)
  107. }}
  108. size="medium"
  109. >
  110. See the password
  111. </Checkbox>
  112. </Form.Item>
  113. <Form.Item wrapperCol={{ offset: 4, span: 15 }}>
  114. <Button
  115. size="large"
  116. type="primary"
  117. htmlType="submit"
  118. primary
  119. style={{ width: '100%' }}
  120. disabled={
  121. login.length < 5 ||
  122. !/(?=.*[0-9])(?=.*[!@#$%^&*])(?=.*[a-z])(?=.*[A-Z])[0-9!@#$%^&*a-zA-Z]{8,}/g.test(
  123. password,
  124. )
  125. }
  126. onClick={input}
  127. >
  128. {children}
  129. </Button>
  130. </Form.Item>
  131. {/* </Col> */}
  132. </Form>
  133. </>
  134. )
  135. }
  136. export default InitialForm