forked from upmostly/custom-react-hooks-forms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form.js
70 lines (66 loc) · 2.3 KB
/
Form.js
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
import React from 'react';
import "rbx/index.css";
import { Button, Checkbox, Column, Container, Control, Field, Input, Label, Section, Select } from 'rbx';
import useForm from "./useForm";
const Form = () => {
const [values, handleChange] = useForm(
['email', 'password', 'human', 'homeworld'],
{ homeworld: 'Earth' },
);
function login(event) {
event.preventDefault();
console.log(values);
}
return (
<Section>
<Container>
<Column.Group>
<Column size={4} offset={4}>
<form onSubmit={login}>
<Field>
<Control>
<Input type="email" placeholder="Email" name="email" onChange={handleChange} value={values.email} required />
</Control>
</Field>
<Field>
<Control>
<Input type="password" placeholder="Password" name="password" onChange={handleChange} value={values.password} required />
</Control>
</Field>
<Field>
<Control>
<Label>
<Checkbox id="human" name="human" onChange={handleChange} checked={values.human} required />
I am not a robot.
</Label>
</Control>
</Field>
<Field>
<Control>
<Select.Container>
<Select name="homeworld" onChange={handleChange} value={values.homeworld}
required pattern="">
<Select.Option value=''>Homeworld...</Select.Option>
{
['Mercury', 'Venus', 'Mars', 'Earth', 'Jupiter',
'Saturn', 'Neptune', 'Uranus'].map(w => (
<Select.Option key={w} value={w}>{w}</Select.Option>
))
}
</Select>
</Select.Container>
</Control>
</Field>
<Field>
<Control>
<Button type="submit" color="primary" >Submit</Button>
</Control>
</Field>
</form>
</Column>
</Column.Group>
</Container>
</Section>
);
};
export default Form;