-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.jsx
122 lines (118 loc) · 3.58 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
import React from 'react';
import { Accounts, STATES } from 'meteor/std:accounts-ui';
import { _ } from 'meteor/underscore';
/**
* 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",
className,
ready ? "ready" : null
].join(' ')}>
{Object.keys(fields).length > 0 ? (
<Accounts.ui.Fields fields={ fields } />
): null }
{ buttons['switchToPasswordReset'] ? (
<Accounts.ui.Button className="forgot-password"
{...buttons['switchToPasswordReset']} />
): null }
<Accounts.ui.Buttons buttons={ _.omit(buttons, 'switchToPasswordReset') } />
{ 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 {...message} />
</form>
);
}
}
class Buttons extends Accounts.ui.Buttons {}
class Button extends Accounts.ui.Button {}
class Fields extends Accounts.ui.Fields {}
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="field-group">
<label htmlFor={ id }>{ label }</label>
<div className="field">
<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;
}
}
class SocialButtons extends Accounts.ui.SocialButtons {
render() {
let { oauthServices = {}, className = "social-buttons" } = this.props;
return(
<div className={ [
className,
`cols-${ Object.keys(oauthServices).length }`
].join(' ') }>
{Object.keys(oauthServices).map((id, i) => {
return (
<div className="col" key={i}>
<Accounts.ui.Button className={`button ${id}`} {..._.omit(oauthServices[id], 'className')} />
</div>
);
})}
</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.SocialButtons = SocialButtons;
Accounts.ui.FormMessage = FormMessage;
// Export the themed version.
export { Accounts, STATES };
export default Accounts;