-
Notifications
You must be signed in to change notification settings - Fork 817
Expand file tree
/
Copy pathlogin-form.tsx
More file actions
129 lines (112 loc) · 3.02 KB
/
login-form.tsx
File metadata and controls
129 lines (112 loc) · 3.02 KB
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import React, { Component } from 'react';
import styled, { css } from 'react-emotion';
import { size } from 'polished';
import Button from './button';
import space from '../assets/images/space.jpg';
import { ReactComponent as Logo } from '../assets/logo.svg';
import { ReactComponent as Curve } from '../assets/curve.svg';
import { ReactComponent as Rocket } from '../assets/rocket.svg';
import { colors, unit } from '../styles';
import * as LoginTypes from '../pages/__generated__/login';
interface LoginFormProps {
login: (a: { variables: LoginTypes.LoginVariables }) => void;
}
interface LoginFormState {
email: string;
}
export default class LoginForm extends Component<LoginFormProps, LoginFormState> {
state = { email: '' };
onChange = (event: React.ChangeEvent<HTMLInputElement>) => {
const email = (event.target as HTMLInputElement).value;
this.setState(s => ({ email }));
};
onSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
this.props.login({ variables: { email: this.state.email } });
};
render() {
return (
<Container>
<Header>
<StyledCurve />
<StyledLogo />
</Header>
<StyledRocket />
<Heading>Space Explorer</Heading>
<StyledForm onSubmit={(e) => this.onSubmit(e)}>
<StyledInput
required
type="email"
name="email"
placeholder="Email"
data-testid="login-input"
onChange={(e) => this.onChange(e)}
/>
<Button type="submit">Log in</Button>
</StyledForm>
</Container>
);
}
}
/**
* STYLED COMPONENTS USED IN THIS FILE ARE BELOW HERE
*/
const Container = styled('div')({
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
flexGrow: 1,
paddingBottom: unit * 6,
color: 'white',
backgroundColor: colors.primary,
backgroundImage: `url(${space})`,
backgroundSize: 'cover',
backgroundPosition: 'center',
});
const svgClassName = css({
display: 'block',
fill: 'currentColor',
});
const Header = styled('header')(svgClassName, {
width: '100%',
marginBottom: unit * 5,
padding: unit * 2.5,
position: 'relative',
});
const StyledLogo = styled(Logo)(size(56), {
display: 'block',
margin: '0 auto',
position: 'relative',
});
const StyledCurve = styled(Curve)(size('100%'), {
fill: colors.primary,
position: 'absolute',
top: 0,
left: 0,
});
const Heading = styled('h1')({
margin: `${unit * 3}px 0 ${unit * 6}px`,
});
const StyledRocket = styled(Rocket)(svgClassName, {
width: 250,
});
const StyledForm = styled('form')({
width: '100%',
maxWidth: 406,
padding: unit * 3.5,
borderRadius: 3,
boxShadow: '6px 6px 1px rgba(0, 0, 0, 0.25)',
color: colors.text,
backgroundColor: 'white',
});
const StyledInput = styled('input')({
width: '100%',
marginBottom: unit * 2,
padding: `${unit * 1.25}px ${unit * 2.5}px`,
border: `1px solid ${colors.grey}`,
fontSize: 16,
outline: 'none',
':focus': {
borderColor: colors.primary,
},
});