From 44fbf2e3d89f793f2e6e6239c6d40d830638dedb Mon Sep 17 00:00:00 2001 From: Anna Stith Date: Tue, 18 Dec 2018 00:57:18 -0800 Subject: [PATCH] Use imports directory --- imports/accounts-ui.jsx | 201 +++++++++++++++++++++++++++++++++++++++ main.jsx | 204 +--------------------------------------- 2 files changed, 206 insertions(+), 199 deletions(-) create mode 100644 imports/accounts-ui.jsx diff --git a/imports/accounts-ui.jsx b/imports/accounts-ui.jsx new file mode 100644 index 0000000..a6d6e57 --- /dev/null +++ b/imports/accounts-ui.jsx @@ -0,0 +1,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 ( +
this.form = ref} className={[ "accounts ui form", className ].join(' ')}> + {Object.keys(fields).length > 0 ? ( + + ): null } + { buttons['switchToPasswordReset'] ? ( +
+ +
+ ): null } + {_.values(_.omit(buttons, 'switchToPasswordReset', 'switchToSignIn', + 'switchToSignUp', 'switchToChangePassword', 'switchToSignOut', 'signOut')).map((button, i) => + + ); + } +} +class Fields extends Accounts.ui.Fields { + render () { + let { fields = {}, className = "field" } = this.props; + return ( +
+ {Object.keys(fields).map((id, i) => + + )} +
+ ); + } +} +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 ? ( +
+ +
+ + this.input = ref } + autoCapitalize={ type == 'email' ? 'none' : false } + autoCorrect="off" + onChange={ onChange } + placeholder={ hint } defaultValue={ defaultValue } /> +
+
+ ) : 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 ( +

+ { `${T9n.get('orUse')} ${ labels.join(' / ') }` } +

+ ); + } + return null; + } +} +class SocialButtons extends Accounts.ui.SocialButtons { + render() { + let { oauthServices = {}, className = "social-buttons" } = this.props; + return( +
+ {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 ( + + ); + })} +
+ ); + } +} +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; diff --git a/main.jsx b/main.jsx index a6d6e57..f85bdc9 100644 --- a/main.jsx +++ b/main.jsx @@ -1,201 +1,7 @@ -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 ( -
this.form = ref} className={[ "accounts ui form", className ].join(' ')}> - {Object.keys(fields).length > 0 ? ( - - ): null } - { buttons['switchToPasswordReset'] ? ( -
- -
- ): null } - {_.values(_.omit(buttons, 'switchToPasswordReset', 'switchToSignIn', - 'switchToSignUp', 'switchToChangePassword', 'switchToSignOut', 'signOut')).map((button, i) => - - ); - } -} -class Fields extends Accounts.ui.Fields { - render () { - let { fields = {}, className = "field" } = this.props; - return ( -
- {Object.keys(fields).map((id, i) => - - )} -
- ); - } -} -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 ? ( -
- -
- - this.input = ref } - autoCapitalize={ type == 'email' ? 'none' : false } - autoCorrect="off" - onChange={ onChange } - placeholder={ hint } defaultValue={ defaultValue } /> -
-
- ) : 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 ( -

- { `${T9n.get('orUse')} ${ labels.join(' / ') }` } -

- ); - } - return null; - } -} -class SocialButtons extends Accounts.ui.SocialButtons { - render() { - let { oauthServices = {}, className = "social-buttons" } = this.props; - return( -
- {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 ( - - ); - })} -
- ); - } -} -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; +import { Accounts, STATES } from './imports/accounts-ui'; // Export the themed version. -export { Accounts, STATES }; -export default Accounts; +export { + Accounts, + STATES, +};