|
5 | 5 | LICENSE file or at https://github.com/convoo/login-fire/blob/master/LICENSE.
|
6 | 6 | -->
|
7 | 7 | <link rel="import" href="../polymer/polymer.html">
|
8 |
| -<link rel="import" href="./login-fire-common-behavior.html"> |
| 8 | +<link rel="import" href="./localize-behavior.html"> |
| 9 | +<link rel="import" href="./login-fire-social-behavior.html"> |
9 | 10 | <link rel="import" href="../iron-flex-layout/iron-flex-layout.html">
|
10 |
| -<link rel="import" href="./login-fire-button.html"> |
| 11 | +<link rel="import" href="./paper-social-button.html"> |
11 | 12 |
|
12 | 13 | <!--
|
13 | 14 | A panel of buttons to authenticate a user with federated identity providers such as
|
|
25 | 26 | <login-fire-social app-name="myApp" providers="google, facebook, twitter, github, anonymous"></login-fire-social>
|
26 | 27 | ```
|
27 | 28 |
|
28 |
| -### Localization |
29 |
| -
|
30 |
| -You can specify the following codes and language in a JSON file passed to the |
31 |
| -`localesFile` property to update the text used. Here are the defaults: |
32 |
| -
|
33 |
| -``` |
34 |
| -"en": { |
35 |
| - "lf-signup-facebook": "Sign up with Facebook", |
36 |
| - "lf-signup-google": "Sign up with Google", |
37 |
| - "lf-signup-twitter": "Sign up with Twitter", |
38 |
| - "lf-signup-github": "Sign up with GitHub", |
39 |
| - "lf-signup-anonymous": "Sign up anonymously", |
40 |
| - "lf-signin-facebook": "Sign in with Facebook", |
41 |
| - "lf-signin-google": "Sign in with Google", |
42 |
| - "lf-signin-twitter": "Sign in with Twitter", |
43 |
| - "lf-signin-github": "Sign in with GitHub", |
44 |
| - "lf-signin-anonymous": "Sign in anonymously" |
45 |
| -} |
46 |
| -``` |
47 |
| -
|
48 | 29 | ### Styling
|
49 | 30 |
|
50 | 31 | Style the buttons with CSS as you would a normal DOM element. The following
|
51 |
| -custom properties and mixins are available: |
| 32 | +custom properties and mixins are available. You can find more custom CSS |
| 33 | +properties in the "Styling" section of the `paper-social-button` element |
| 34 | +documentation. |
52 | 35 |
|
53 | 36 | Custom property | Description | Default
|
54 | 37 | -- | -- | --
|
|
77 | 60 | @apply --login-fire-social;
|
78 | 61 | }
|
79 | 62 |
|
80 |
| - login-fire-button { |
| 63 | + paper-social-button { |
81 | 64 | width: 100%;
|
82 | 65 | margin-bottom: 10px;
|
83 | 66 | }
|
84 | 67 |
|
85 |
| - :host([horizontal]) login-fire-button { |
| 68 | + :host([horizontal]) paper-social-button { |
86 | 69 | width: inherit;
|
87 | 70 | min-width: 140px;
|
88 | 71 | margin-bottom: 0;
|
89 | 72 | }
|
90 | 73 | </style>
|
91 | 74 |
|
92 |
| - <template is="dom-if" if="[[_showOneButton]]"> |
93 |
| - <login-fire-button |
94 |
| - app-name="[[appName]]" |
95 |
| - user="{{_user}}" |
96 |
| - status-known="{{_statusKnown}}" |
97 |
| - signed-in="{{_signedIn}}" |
| 75 | + <template is="dom-if" if="[[_showOneButton]]" restamp> |
| 76 | + <paper-social-button |
| 77 | + signed-in="[[_signedIn]]" |
98 | 78 | mini$="[[mini]]"
|
99 | 79 | flat$="[[flat]]"
|
100 |
| - no-sign-in="[[noSignIn]]" |
101 |
| - no-sign-out="[[noSignOut]]" |
102 |
| - show-sign-up="{{showSignUp}}" |
| 80 | + no-sign-in |
103 | 81 | locales-file="[[localesFile]]"
|
104 | 82 | language="[[language]]"
|
105 |
| - debug="[[debug]]"> |
106 |
| - </login-fire-button> |
| 83 | + in-progress="[[inProgress]]" |
| 84 | + disabled$="[[inProgress]]" |
| 85 | + on-tap="signOut"> |
| 86 | + </paper-social-button> |
107 | 87 | </template>
|
108 | 88 |
|
109 |
| - <template is="dom-if" if="[[!_showOneButton]]"> |
| 89 | + <template is="dom-if" if="[[!_showOneButton]]" restamp> |
110 | 90 | <template is="dom-repeat" items="{{_providers}}">
|
111 |
| - <login-fire-button |
112 |
| - id="lfb[[item.id]]" |
113 |
| - app-name="[[appName]]" |
114 |
| - provider="[[item.id]]" |
115 |
| - scopes="[[item.scopes]]" |
116 |
| - user="{{_user}}" |
117 |
| - status-known="{{_statusKnown}}" |
118 |
| - signed-in="{{_signedIn}}" |
| 91 | + <paper-social-button |
| 92 | + provider="[[item]]" |
| 93 | + signed-in="[[_signedIn]]" |
119 | 94 | mini$="[[mini]]"
|
120 | 95 | flat$="[[flat]]"
|
121 |
| - redirect="[[redirect]]" |
122 | 96 | no-sign-in="[[noSignIn]]"
|
123 | 97 | no-sign-out="[[noSignOut]]"
|
124 | 98 | show-sign-up="{{showSignUp}}"
|
125 | 99 | locales-file="[[localesFile]]"
|
126 | 100 | language="[[language]]"
|
127 |
| - debug="[[debug]]"> |
128 |
| - </login-fire-button> |
| 101 | + in-progress="[[inProgress]]" |
| 102 | + disabled$="[[inProgress]]" |
| 103 | + on-tap="_onClick"> |
| 104 | + </paper-social-button> |
129 | 105 | </template>
|
130 | 106 | </template>
|
131 | 107 |
|
|
135 | 111 | Polymer({
|
136 | 112 | is: 'login-fire-social',
|
137 | 113 |
|
138 |
| - behaviors: [Convoo.LoginFireCommonBehavior], |
| 114 | + behaviors: [ |
| 115 | + Convoo.LocalizeBehavior, |
| 116 | + Convoo.LoginFireSocialBehavior |
| 117 | + ], |
139 | 118 |
|
140 | 119 | properties: {
|
141 | 120 |
|
|
149 | 128 | value: false
|
150 | 129 | },
|
151 | 130 |
|
| 131 | + /** |
| 132 | + * Flat buttons, yes or no. |
| 133 | + * |
| 134 | + * @type {Boolean} |
| 135 | + */ |
| 136 | + flat: { |
| 137 | + type: Boolean, |
| 138 | + value: false |
| 139 | + }, |
| 140 | + |
152 | 141 | /**
|
153 | 142 | * Providers names. A list of the providers names, seperated by comma, to
|
154 | 143 | * use for authentication. A button is displayed for each provider.
|
|
219 | 208 | '_scopesChanged(facebookScopes, githubScopes, googleScopes)'
|
220 | 209 | ],
|
221 | 210 |
|
222 |
| - /** |
223 |
| - * Signs the user out. The provider used for the sign-in has no incidence. |
224 |
| - */ |
225 |
| - signOut: function() { |
226 |
| - this.$$('login-fire-button').signOut(); |
227 |
| - }, |
228 |
| - |
229 | 211 | /**
|
230 | 212 | * Signs the user in using the target provider.
|
231 | 213 | *
|
232 | 214 | * @param {String} provider name
|
233 | 215 | */
|
234 | 216 | signInWith: function(provider) {
|
235 |
| - var btn = this.$$('#lfb' + provider); |
236 |
| - if (btn) { |
237 |
| - btn.signIn(); |
| 217 | + let prov = this._providers.find(p => p.id == provider); |
| 218 | + if (prov) { |
| 219 | + this._signInWithProvider(prov); |
238 | 220 | }
|
239 | 221 | },
|
240 | 222 |
|
|
277 | 259 | 'github': githubScopes,
|
278 | 260 | 'google': googleScopes
|
279 | 261 | };
|
280 |
| - this._providers.forEach(function(provider, index) { |
| 262 | + this._providers.forEach((provider, index) => { |
281 | 263 | if (provider.isSocialNetwork) {
|
282 | 264 | provider.scopes = scopes[provider.id];
|
283 | 265 | this.notifyPath('_providers.' + index + '.scopes');
|
284 | 266 | }
|
285 |
| - }.bind(this)); |
| 267 | + }); |
| 268 | + }, |
| 269 | + |
| 270 | + _onClick: function(event) { |
| 271 | + this._signInWithProvider(event.target.provider); |
| 272 | + }, |
| 273 | + |
| 274 | + /** |
| 275 | + * Signs in using the given provider. |
| 276 | + * |
| 277 | + * @param {Object} provider the provider to be used to sign in |
| 278 | + */ |
| 279 | + _signInWithProvider: function(provider) { |
| 280 | + this.set('provider', provider.id); |
| 281 | + this.set('scopes', provider.scopes); |
| 282 | + this.signInOrOut(); |
286 | 283 | }
|
287 | 284 | });
|
288 | 285 | </script>
|
|
0 commit comments