@@ -2,8 +2,8 @@ import * as React from 'react'
2
2
import * as fetch from 'isomorphic-fetch'
3
3
import Popup from './Popup'
4
4
import { throttle } from 'lodash'
5
- import * as cn from 'classnames'
6
5
import { Button } from './Button'
6
+ import { styled , css , withProps } from '../styled'
7
7
8
8
export interface Props {
9
9
onRequestClose : ( endpoint : string ) => void
@@ -16,8 +16,7 @@ export interface State {
16
16
}
17
17
18
18
export default class EndpointPopup extends React . Component < Props , State > {
19
- // TODO remove `as any` once typescript 2.7 is released
20
- checkEndpoint = ( throttle as any ) ( ( ) => {
19
+ checkEndpoint = throttle ( ( ) => {
21
20
if ( this . state . endpoint . match ( / ^ h t t p s ? : \/ \/ \w + ( \. \w + ) * ( : [ 0 - 9 ] + ) ? \/ ? .* $ / ) ) {
22
21
fetch ( this . state . endpoint , {
23
22
method : 'post' ,
@@ -41,7 +40,7 @@ export default class EndpointPopup extends React.Component<Props, State> {
41
40
this . setState ( { valid : false } )
42
41
} )
43
42
}
44
- } , 500 )
43
+ } , 500 ) as any
45
44
46
45
constructor ( props ) {
47
46
super ( props )
@@ -58,67 +57,27 @@ export default class EndpointPopup extends React.Component<Props, State> {
58
57
const { valid } = this . state
59
58
return (
60
59
< Popup onRequestClose = { this . close } darkBg = { true } >
61
- < div className = "content" >
62
- < style jsx = { true } > { `
63
- .content {
64
- @p: .bbox;
65
- }
66
- form {
67
- @p: .flex, .flexAuto, .w100;
68
- }
69
- input {
70
- @p: .bgWhite10, .br2, .pv16, .ph25, .fw6, .white, .f16, .db, .w100,
71
- .tc, .flexAuto, .flex;
72
- transition: 0.25s color;
73
- }
74
- input.valid {
75
- @p: .green;
76
- }
77
- input.invalid {
78
- @p: .red;
79
- }
80
- .content :global(.button) {
81
- @p: .ph16;
82
- background: #da1b7f;
83
- }
84
- .content :global(.button:hover) {
85
- @p: .ph16, .bgPurple;
86
- }
87
- h1 {
88
- @p: .white80, .fw4, .ml38;
89
- }
90
- .logo-wrapper {
91
- @p: .flex, .justifyCenter, .itemsCenter;
92
- }
93
- .logo {
94
- @p: .flex, .itemsCenter, .mb60, .justifyBetween;
95
- }
96
- .logo img {
97
- width: 78px;
98
- height: 78px;
99
- }
100
- ` } </ style >
101
- < div className = "logo-wrapper" >
102
- < div className = "logo" >
60
+ < Wrapper >
61
+ < LogoWrapper >
62
+ < Logo >
103
63
< img src = { require ( '../assets/logo.png' ) } alt = "" />
104
- < h1 > GraphQL Playground</ h1 >
105
- </ div >
106
- </ div >
107
- < form action = "" onSubmit = { this . submit } >
108
- < input
64
+ < Heading > GraphQL Playground</ Heading >
65
+ </ Logo >
66
+ </ LogoWrapper >
67
+ < Form action = "" onSubmit = { this . submit } >
68
+ < Input
109
69
type = "text"
110
70
placeholder = "Enter an endpoint url..."
111
71
value = { this . state . endpoint }
112
72
onChange = { this . onChangeEndpoint }
113
- className = { cn ( {
114
- valid : typeof valid === 'boolean' && valid ,
115
- invalid : typeof valid === 'boolean' && ! valid ,
116
- } ) }
73
+ valid = { typeof valid === 'boolean' && valid }
74
+ invalid = { typeof valid === 'boolean' && ! valid }
117
75
autoFocus = { true }
118
76
/>
77
+
119
78
{ valid && < Button onClick = { this . close } > Use Endpoint</ Button > }
120
- </ form >
121
- </ div >
79
+ </ Form >
80
+ </ Wrapper >
122
81
</ Popup >
123
82
)
124
83
}
@@ -138,3 +97,79 @@ export default class EndpointPopup extends React.Component<Props, State> {
138
97
}
139
98
}
140
99
}
100
+
101
+ const Wrapper = styled . div `
102
+ box-sizing: border-box;
103
+ `
104
+
105
+ const Form = styled . form `
106
+ width: 100%;
107
+ display: flex;
108
+ flex: 1 1 auto;
109
+
110
+ .button.button {
111
+ padding-right: ${ p => p . theme . sizes . small16 } ;
112
+ padding-left: ${ p => p . theme . sizes . small16 } ;
113
+ background: #da1b7f;
114
+
115
+ &:hover {
116
+ background: ${ p => p . theme . colours . purple } ;
117
+ }
118
+ }
119
+ `
120
+
121
+ interface InputProps {
122
+ valid : boolean
123
+ invalid : boolean
124
+ }
125
+
126
+ // prettier-ignore
127
+ const Input = withProps < InputProps > ( ) ( styled . input ) `
128
+ background: ${ p => p . theme . colours . white10 } ;
129
+ border-radius: ${ p => p . theme . sizes . smallRadius } ;
130
+ padding: ${ p => p . theme . sizes . small16 } ${ p => p . theme . sizes . medium25 } ;
131
+ font-weight: ${ p => p . theme . sizes . fontSemiBold } ;
132
+ color: white;
133
+ font-size: 16px;
134
+ display: block;
135
+ width: 100%;
136
+ text-align: center;
137
+ flex: 1 1 auto;
138
+ display: flex;
139
+
140
+ transition: 250ms color;
141
+
142
+ ${ ( p : any ) =>
143
+ p . valid ? css `
144
+ color: ${ k => k . theme . colours . green } ;
145
+ `
146
+ : p . invalid ? css `
147
+ color: ${ k => k . theme . colours . red } ;
148
+ `
149
+ : ``
150
+ }
151
+ `
152
+
153
+ const Heading = styled . h1 `
154
+ margin-left: 38px;
155
+ font-weight: 400;
156
+ color: ${ p => p . theme . colours . white80 } ;
157
+ `
158
+
159
+ const LogoWrapper = styled . div `
160
+ display: flex;
161
+ justify-content: center;
162
+ align-items: center;
163
+ `
164
+
165
+ const Logo = styled . div `
166
+ display: flex;
167
+ justify-content: space-between;
168
+ align-items: center;
169
+ margin-bottom: 60px;
170
+
171
+ img {
172
+ width: 78px;
173
+ height: 78px;
174
+ }
175
+ `
0 commit comments