-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.jsx
201 lines (196 loc) · 6.33 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
import React from 'react';
import { _ } from 'meteor/underscore';
import { Accounts, STATES } from 'meteor/std:accounts-ui';
/**
* Form.propTypes = {
* fields: React.PropTypes.object.isRequired,
* buttons: React.PropTypes.object.isRequired,
* error: React.PropTypes.string,
* ready: React.PropTypes.bool
* };
*/
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 ui form", className ].join(' ')}>
{Object.keys(fields).length > 0 ? (
<Accounts.ui.Fields fields={ fields } />
): null }
{ buttons['switchToPasswordReset'] ? (
<div className="field">
<Accounts.ui.Button {...buttons['switchToPasswordReset']} />
</div>
): null }
{_.values(_.omit(buttons, 'switchToPasswordReset', 'switchToSignIn',
'switchToSignUp', 'switchToChangePassword', 'switchToSignOut', 'signOut')).map((button, i) =>
<Button {...button} key={i} />
)}
{ buttons['signOut'] ? (
<Button {...buttons['signOut']} type="submit" />
): null }
{ buttons['switchToSignIn'] ? (
<Button {...buttons['switchToSignIn']} type="link" className="ui button" />
): null }
{ buttons['switchToSignUp'] ? (
<Button {...buttons['switchToSignUp']} type="link" className="ui button" />
): null }
{ buttons['switchToChangePassword'] ? (
<Button {...buttons['switchToChangePassword']} type="link" className="ui button" />
): null }
{ buttons['switchToSignOut'] ? (
<Button {...buttons['switchToSignOut']} type="link" className="ui button" />
): null }
{ 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 }
<Accounts.ui.FormMessage className="ui message" style={{display: 'block'}} {...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' ? (
<a href={ href }
style={{cursor: 'pointer'}}
className={ className }
onClick={ onClick }>{ icon ? (<i className={["icon", icon].join(' ')} />) : null }{ label }</a>
) : (
<button className={ [
'ui button',
type == 'submit' ? 'primary' : '',
disabled ? 'disabled' : '',
className
].join(' ') }
type={ type }
disabled={ disabled }
onClick={ onClick }>{ icon ? (<i className={["icon", icon].join(' ')} />) : null }{ label }</button>
);
}
}
class Fields extends Accounts.ui.Fields {
render () {
let { fields = {}, className = "field" } = this.props;
return (
<div className={ className }>
{Object.keys(fields).map((id, i) =>
<Accounts.ui.Field {...fields[id]} key={i} />
)}
</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 ? (
<div className={["ui field", required ? "required" : ""].join(' ')}>
<label htmlFor={ id }>{ label }</label>
<div className="ui fluid input">
<input id="password" name="password" style={{display: 'none'}} />
<input id={ id }
name={ id }
type={ type }
ref={ (ref) => this.input = ref }
autoCapitalize={ type == 'email' ? 'none' : false }
autoCorrect="off"
onChange={ onChange }
placeholder={ hint } defaultValue={ defaultValue } />
</div>
</div>
) : null;
}
}
export class PasswordOrService extends Accounts.ui.PasswordOrService {
render() {
let { className, style = {} } = this.props;
let { hasPasswordService, services } = this.state;
labels = services;
if (services.length > 2) {
labels = [];
}
if (hasPasswordService && services.length > 0) {
return (
<p style={ style } className={ className }>
{ `${T9n.get('orUse')} ${ labels.join(' / ') }` }
</p>
);
}
return null;
}
}
class SocialButtons extends Accounts.ui.SocialButtons {
render() {
let { oauthServices = {}, className = "social-buttons" } = this.props;
return(
<div className={ className }>
{Object.keys(oauthServices).map((id, i) => {
var mapObj = {
google:"google plus",
"meteor-developer": ""
};
let serviceClass = id.replace(/google|meteor\-developer/gi, (matched) => {
return mapObj[matched];
});
return (
<Accounts.ui.Button key={i}
className={["ui button", serviceClass].join(' ')}
icon={serviceClass} {..._.omit(oauthServices[id], "className")} />
);
})}
</div>
);
}
}
class FormMessage extends Accounts.ui.FormMessage {}
// 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.Form = Form;
Accounts.ui.Buttons = Buttons;
Accounts.ui.Button = Button;
Accounts.ui.Fields = Fields;
Accounts.ui.Field = Field;
Accounts.ui.PasswordOrService = PasswordOrService;
Accounts.ui.SocialButtons = SocialButtons;
Accounts.ui.FormMessage = FormMessage;
// Export the themed version.
export { Accounts, STATES };
export default Accounts;