forked from studiointeract/accounts-material
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.jsx
270 lines (255 loc) · 6.12 KB
/
main.jsx
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import React from 'react';
import {Accounts, STATES} from './fix.js'; // TODO: back to normal once std:accounts-ui is fixed
import {RaisedButton, FlatButton, FontIcon, TextField, Divider, Snackbar} from 'material-ui';
import {socialButtonsColors, socialButtonIcons} from './social_buttons_config';
import {green500, red500, yellow600, lightBlue600} from 'material-ui/styles/colors';
/**
* Form.propTypes = {
* fields: React.PropTypes.object.isRequired,
* buttons: React.PropTypes.object.isRequired,
* error: React.PropTypes.string,
* ready: React.PropTypes.bool
* };
*/
class LoginForm extends Accounts.ui.LoginForm {
componentWillMount() {
// FIXME hack to solve issue #18
}
}
class Form extends Accounts.ui.Form {
render() {
const {
hasPasswordService,
oauthServices,
fields,
buttons,
error,
message,
ready = true,
className,
formState
} = this.props;
return (
<form
ref={(ref) => this.form = ref}
className={["accounts", className].join(' ')}>
{Object.keys(fields).length > 0
? (<Accounts.ui.Fields fields={fields}/>)
: null}
<Accounts.ui.Buttons buttons={buttons}/>
<br/>
{formState == STATES.SIGN_IN || formState == STATES.SIGN_UP
? (
<div className="or-sep">
<Accounts.ui.PasswordOrService oauthServices={oauthServices}/>
</div>
)
: null}
{formState == STATES.SIGN_IN || formState == STATES.SIGN_UP
? (<Accounts.ui.SocialButtons oauthServices={oauthServices}/>)
: null}
<br/>
<Accounts.ui.FormMessage {...message}/>
</form>
);
}
}
class Buttons extends Accounts.ui.Buttons {}
class Button extends Accounts.ui.Button {
render() {
const {
label,
href = null,
type,
disabled = false,
onClick,
className,
icon
} = this.props;
return type == 'link'
? (
<FlatButton
href={href}
label={label}
icon={icon
? <FontIcon className={`fa ${icon}`}/>
: null}
className={className}
onTouchTap={onClick}
disabled={disabled}
style={{marginRight: '5px'}}
/>
)
: (
<RaisedButton
label={label}
icon={icon
? <FontIcon className={`fa ${icon}`}/>
: null}
primary={true}
type={type}
className={className}
onTouchTap={onClick}
disabled={disabled}
style={{marginRight: '5px'}}
/>
)
}
}
class Fields extends Accounts.ui.Fields {
render() {
let {
fields = {},
className = ""
} = this.props;
return (
<div className={[className].join(' ')}>
{Object.keys(fields).map((id, i) => <div key={i}>
<Accounts.ui.Field {...fields[id]}/>
<br/>
</div>)}
</div>
);
}
}
class Field extends Accounts.ui.Field {
render() {
const {
id,
hint,
label,
type = 'text',
onChange,
required = false,
className,
defaultValue = ""
} = this.props;
const {
mount = true
} = this.state;
return mount
? (<TextField
floatingLabelText={label}
hintText={hint}
onChange={onChange}
fullWidth={true}
defaultValue={defaultValue}
name={id}
type={type}
ref={(ref) => this.input = ref}
required={required
? "required"
: ""}
autoCapitalize={type == 'email'
? 'none'
: false}
autoCorrect="off"/>)
: null;
}
}
class SocialButtons extends Accounts.ui.SocialButtons {
render() {
let {
oauthServices = {},
className = "social-buttons"
} = this.props;
if (Object.keys(oauthServices).length > 0) {
return (
<div className={[className].join(' ')}>
{Object.keys(oauthServices).map((id, i) => {
let serviceClass = id.replace(/google|meteor\-developer/gi, (matched) => {
return socialButtonIcons[matched];
});
const {label, type, onClick, disabled} = oauthServices[id];
return (
<RaisedButton
key={i}
label={label}
type={type}
onTouchTap={onClick}
disabled={disabled}
className={serviceClass.length > 0
? `${serviceClass}`
: ''}
icon={serviceClass.length > 0
? <FontIcon className={`fa fa-${serviceClass}`}/>
: ''}
backgroundColor={socialButtonsColors[id].background}
labelColor={socialButtonsColors[id].label}
style={{marginRight: '5px'}}
/>
);
})}
</div>
)
} else {
return null;
}
}
}
class FormMessage extends Accounts.ui.FormMessage {
constructor(props) {
super(props);
this.state = {
open: false
};
}
componentWillReceiveProps(nextProps) {
if (nextProps.message) {
this.setState({open: true});
}
}
handleRequestClose() {
this.setState({open: false});
};
render() {
const {message, type} = this.props;
let bodyStyle;
switch (type) {
case 'warning':
bodyStyle = {
backgroundColor: yellow600
}
break;
case 'success':
bodyStyle = {
backgroundColor: green500
}
break;
case 'error':
bodyStyle = {
backgroundColor: red500
}
break;
case 'info':
bodyStyle = {
backgroundColor: lightBlue600
}
break;
}
return message
? (<Snackbar
open={this.state.open}
message={message}
bodyStyle={bodyStyle}
action="OK"
autoHideDuration={4000}
onActionTouchTap={this.handleRequestClose.bind(this)}
onRequestClose={this.handleRequestClose.bind(this)}/>)
: null;
}
}
// Notice! Accounts.ui.LoginForm manages all state logic at the moment, so avoid overwriting this
// one, but have a look at it and learn how it works. And pull requests altering how that works are
// welcome. Alter provided default unstyled UI.
Accounts.ui.LoginForm = LoginForm;
Accounts.ui.Form = Form;
Accounts.ui.Buttons = Buttons;
Accounts.ui.Button = Button;
Accounts.ui.Fields = Fields;
Accounts.ui.Field = Field;
Accounts.ui.FormMessage = FormMessage;
Accounts.ui.SocialButtons = SocialButtons;
// Export the themed version.
export {Accounts, STATES};
export default Accounts;