Advertisement
Guest User

Untitled

a guest
Aug 17th, 2017
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. import React, { Component } from 'react';
  2. import PropTypes from 'prop-types';
  3. import styled, { keyframes } from 'styled-components';
  4. import { darken } from 'polished';
  5.  
  6. import TextField from './TextField';
  7.  
  8. const propTypes = {
  9. onAuthSuccess: PropTypes.func.isRequired,
  10. };
  11.  
  12. class TwerkForm extends Component {
  13. state = {
  14. grantAccess: null,
  15. username: '',
  16. password: '',
  17. }
  18.  
  19. handleChange = ({ target }) => {
  20. this.setState({
  21. [target.name]: target.value,
  22. grantAccess: null,
  23. });
  24. };
  25.  
  26. handleSubmit = event => {
  27. event.preventDefault();
  28.  
  29. const { username, password } = this.state;
  30. if (username === 'Rick' && password === 'Morty') {
  31. this.props.onAuthSuccess();
  32. } else {
  33. this.setState({ grantAccess: false });
  34. }
  35. };
  36.  
  37. render() {
  38. const { grantAccess, username, password } = this.state;
  39.  
  40. return (
  41. <Form
  42. twerk={grantAccess === false}
  43. onSubmit={this.handleSubmit}
  44. >
  45. <Title>
  46. Login to get schwifty
  47. </Title>
  48.  
  49. <TextField
  50. value={username}
  51. label="Username"
  52. name="username"
  53. onChange={this.handleChange}
  54. />
  55.  
  56. <Gutter vertical />
  57.  
  58. <TextField
  59. value={password}
  60. label="Password"
  61. name="password"
  62. type="password"
  63. onChange={this.handleChange}
  64. />
  65.  
  66. <Gutter vertical amount={24} />
  67.  
  68. <Submit type="submit">
  69. Get Ricked son!
  70. </Submit>
  71. </Form>
  72. );
  73. }
  74. }
  75.  
  76. const twerk = keyframes`
  77. 0% { transform: rotate(0deg); }
  78. 16.67% { transform: rotate(-10deg); }
  79. 33.33% { transform: rotate(10deg); }
  80. 50% { transform: rotate(-10deg); }
  81. 66.67% { transform: rotate(10deg); }
  82. 83.33% { transform: rotate(-10deg); }
  83. 100% { transform: rotate(0deg); }
  84. `;
  85.  
  86. const Form = styled.form`
  87. background-color: ${props => props.theme.contentBg};
  88. padding: 32px;
  89. width: 420px;
  90. border-radius: 6px;
  91. display: flex;
  92. flex-direction: column;
  93. box-shadow: 0px 2px 12px rgba(0,0,0,0.2);
  94. animation: ${props => props.twerk ? twerk : 'none'} 0.7s;
  95. `;
  96. const Title = styled.h1`
  97. font-size: 32px;
  98. font-weight: 700;
  99. margin: 0px 0px 16px 0px;
  100. color: ${props => props.theme.titleColor};
  101. text-align: center;
  102. `;
  103. const Gutter = styled.div`
  104. padding-right: ${props => !props.vertical ? props.amount || 8 : 0}px;
  105. padding-top: ${props => props.vertical ? props.amount || 8 : 0}px;
  106. `;
  107. const Submit = styled.button`
  108. width: 100%;
  109. padding: 16px;
  110. border: none;
  111. border-radius: 3px;
  112. text-align: center;
  113. font-size: 16px;
  114. color: #fff;
  115. background-color: ${props => props.theme.buttonBg};
  116. outline: none;
  117. transition: background-color 0.2s ease;
  118.  
  119. &:hover {
  120. background-color: ${props => darken(0.1, props.theme.buttonBg)};
  121. }
  122.  
  123. &:active {
  124. background-color: ${props => darken(0.2, props.theme.buttonBg)};
  125. }
  126. `;
  127.  
  128. TwerkForm.propTypes = propTypes;
  129.  
  130. export default TwerkForm;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement