-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.jsx
129 lines (125 loc) · 4.13 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
import React from 'react';
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 { fields, buttons, error, message, ready } = this.props;
return (
<form className={[
"ui form",
ready ? "" : "loading"
].join(' ')} onSubmit={ evt => evt.preventDefault() }>
{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="button" />
): null }
{ buttons['switchToSignUp'] ? (
<Button {...buttons['switchToSignUp']} type="button" />
): null }
{ buttons['switchToChangePassword'] ? (
<Button {...buttons['switchToChangePassword']} type="button" />
): null }
{ buttons['switchToSignOut'] ? (
<Button {...buttons['switchToSignOut']} type="button" />
): 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, type, disabled = false, onClick, className } = this.props;
return type == 'link' ? (
<a style={{cursor: 'pointer'}} className={ className } onClick={ onClick }>{ label }</a>
) : (
<button className={ [
'ui',
type === 'submit' ? 'btn waves-effect waves-light' : 'btn-flat',
disabled ? 'disabled' : '',
className
].join(' ') } type={ type } disabled={ disabled }
onClick={ onClick }>
{ label }
{ type == 'submit' ? <i className="material-icons right">send</i> : null }
</button>
);
}
}
class Fields extends Accounts.ui.Fields {
render () {
let { fields = {}, className = "field row" } = 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={["input-field col s12 m7", required ? "required" : ""].join(' ')}>
<input id={ id }
name={ id }
type={ type }
ref={ (ref) => this.input = ref }
autoCapitalize={ type == 'email' ? 'none' : false }
autoCorrect="off"
onChange={ onChange }
className="validate"
placeholder={ hint } defaultValue={ defaultValue } />
<label htmlFor={ id } className="active">{ label }</label>
</div>
) : null;
}
}
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.FormMessage = FormMessage;
// Export the themed version.
export { Accounts, STATES };
export default Accounts;