-
Notifications
You must be signed in to change notification settings - Fork 19
/
paper-social-button.html
357 lines (328 loc) · 11 KB
/
paper-social-button.html
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
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
<!--
@license
Copyright (c) 2016 Convoo All Rights Reserved.
Use of this source code is governed by a MIT license that can be found in the
LICENSE file or at https://github.com/convoo/login-fire/blob/master/LICENSE.
-->
<link rel="import" href="../polymer/polymer.html">
<link rel="import" href="./localize-behavior.html">
<link rel="import" href="../iron-icon/iron-icon.html">
<link rel="import" href="../paper-progress/paper-progress.html">
<link rel="import" href="../paper-button/paper-button.html">
<link rel="import" href="./login-fire-styles.html">
<link rel="import" href="./icons.html">
<!--
A paper-button that integrates social medias icons and styles.
Example:
```
<paper-social-button provider="{'id': 'facebook', 'name': 'Facebook'}" on-tap="signIn"></paper-social-button>
<paper-social-button provider="{'id': 'google', 'name': 'Google'}" on-tap="signIn" mini></paper-social-button>
<paper-social-button provider="{'id': 'twitter', 'name': 'Twitter'}" on-tap="signIn" mini flat></paper-social-button>
```
### Styling
Style the buttons with CSS as you would a normal DOM element. The following
custom properties and mixins are available:
| Custom property | Description | Default
| -- | -- | --
| `--login-fire-button` | Mixin applied on the button | `{}`
| `--login-fire-button-anonymous` | Mixin applied on the anonymous button | `{}`
| `--login-fire-button-anonymous-hover` | Mixin applied on the anonymous button when mouve hovers it | `{}`
| `--login-fire-button-facebook` | Mixin applied on the Facebook button | `{}`
| `--login-fire-button-facebook-hover` | Mixin applied on the Facebook button when mouve hovers it | `{}`
| `--login-fire-button-github` | Mixin applied on the GitHub button | `{}`
| `--login-fire-button-github-hover` | Mixin applied on the GitHub button when mouve hovers it | `{}`
| `--login-fire-button-google` | Mixin applied on the Google button | `{}`
| `--login-fire-button-google-hover` | Mixin applied on the Google button when mouve hovers it | `{}`
| `--login-fire-button-icon` | Mixin applied on the icon of the button | `{}`
| `--login-fire-button-text` | Mixin applied on the text of the button | `{}`
| `--login-fire-button-twitter` | Mixin applied on the Twitter button | `{}`
| `--login-fire-button-twitter-hover` | Mixin applied on the Twitter button when mouve hovers it | `{}`
| `--login-fire-btn-signout` | Mixin applied to the sign-out button | `{}`
| `--login-fire-btn-signout-hover` | Mixin applied to the sign-out button when mouve hovers it | `{}`
| `--login-fire-progress-active-color` | The color that is applied to the paper-progress bar as active color | `--google-green-500`
| `--login-fire-progress-container-color` | The color that is applied to the paper-progress-container | `--google-grey-300`
@customElement
@polymer
@demo demo/paper-social-button.html
-->
<dom-module id="paper-social-button">
<template>
<style include="login-fire-styles">
:host {
display: inline-block;
@apply --login-fire-button;
}
.btn {
text-align: left;
text-transform: none;
min-height: 40px;
display: flex;
@apply --login-fire-button;
}
.btn--google {
@apply --login-fire-button-google;
}
.btn--google:hover {
@apply --login-fire-button-google-hover;
}
.btn--twitter {
@apply --login-fire-button-twitter;
}
.btn--twitter:hover {
@apply --login-fire-button-twitter-hover;
}
.btn--facebook {
@apply --login-fire-button-facebook;
}
.btn--facebook:hover {
@apply --login-fire-button-facebook-hover;
}
.btn--github {
@apply --login-fire-button-github;
}
.btn--github:hover {
@apply --login-fire-button-github-hover;
}
.btn--anonymous {
@apply --login-fire-button-anonymous;
}
.btn--anonymous:hover {
@apply --login-fire-button-anonymous-hover;
}
.btn__icon {
width: 30px;
height: 16px;
@apply --login-fire-button-icon;
}
.btn__text {
text-align: center;
width: 100%;
overflow-x: hidden;
text-overflow: ellipsis;
@apply --login-fire-button-text;
}
.btn--signed-out {
background-color: transparent;
color: grey;
text-align: center;
@apply --login-fire-btn-signout;
}
.btn--signed-out:hover {
background-color: lightgray;
@apply --login-fire-btn-signout-hover;
}
.btn:not([mini]) {
min-width: 150px;
}
[mini] {
max-width: 120px;
min-width: 80px;
}
[hidden] {
display: none !important;
}
paper-button {
margin: 0;
}
</style>
<paper-button class$="btn [[_providerClass]]" on-tap="__retargetingEvent" mini$="[[mini]]" raised$="[[!flat]]" disabled$="[[disabled]]">
<iron-icon class="btn__icon" icon="login-fire-icons:[[_iconName]]"></iron-icon>
<span class="btn__text">[[_text]]</span>
<paper-progress class="btn-progress" hidden$="[[!showProgressBar]]" disabled$="[[!showProgressBar]]" indeterminate></paper-progress>
</paper-button>
</template>
<script>
Polymer({
is: 'paper-social-button',
behaviors: [
Convoo.LocalizeBehavior
],
properties: {
/**
* Mini format, yes or no.
*
* @type {Boolean}
*/
mini: {
type: Boolean,
value: false
},
/**
* Button disabled, yes or no.
*
* @type {Boolean}
*/
disabled: {
type: Boolean,
value: false
},
/**
* Flat button, yes or no.
*
* @type {Boolean}
*/
flat: {
type: Boolean,
value: false
},
/**
* Auth provider. The list of auth providers available is defined in the
* *Convoo._firebaseProviders* property inside the
* <a href="./#Convoo.LoginFireCommonBehavior">Convoo.LoginFireCommonBehavior</a>.
*
* @type {{id: String, name: String, isSocialNetwork: Boolean, scopes: String}}
*/
provider: {
type: Object,
value: null
},
/**
* Shows the sign-up button (when `true`). The `showSignOut` property
* prevails over this one.
*
* @type {Boolean}
*/
showSignUp: {
type: Boolean,
value: false
},
/**
* Shows the sign-out button (when `true`). It prevails over the
* `showSignUp` property.
*
* @type {Boolean}
*/
showSignOut: {
type: Boolean,
value: false
},
/**
* Shows a progress bar at the bottom of the button.
*
* @type {Boolean}
*/
showProgressBar: {
type: Boolean,
value: false
},
/**
* Defines if the provider icon must be hidden or not.
*
* @type {Boolean}
*/
_iconName: {
type: Boolean,
computed: '_computeIconName(provider, showSignOut, disabled)'
},
/**
* CSS class added when the button has mini format.
*
* @type {String}
*/
_miniClass: {
type: String,
computed: '_computeMiniClass(mini)'
},
/**
* CSS class added when the log-out button is shown.
*
* @type {String}
*/
_providerClass: {
type: String,
computed: '_computeProviderClass(provider, showSignOut, disabled)'
},
/**
* Button text.
*
* @type {String}
*/
_text: {
type: String,
computed: '_computeButtonText(provider, showSignUp, showSignOut, localize, mini, language)'
}
},
/**
* The provider logo is shown when the user can sign in and is not yet signed
* in or when they can not sign out. It is hidden otherwise.
*
* @param {Boolean} showSignOut Tells if the sign-out view must be shown
* @return {Boolean} The icon name to be displayed next to
* the button text.
*/
_computeIconName: function(provider, showSignOut) {
if (showSignOut || !provider) {
return 'logout';
}
if (this.disabled && provider.id == 'google') {
return 'google-grey';
}
return provider.id;
},
/**
* Computes the CSS class to add according to the mini format of the
* element.
*
* @param {Boolean} isMini Tells if the button is in mini format
* @return {String} A CSS class name to add on the button to turn
* it in mini format.
*/
_computeMiniClass: function(isMini) {
return isMini ? 'btn--mini' : '';
},
/**
* Computes the CSS class to add when the user is currently signed in.
*
* @param {Boolean} showSignOut Tells if the sign-out view must be shown
* @return {String} A CSS class name to add on the button to
* display its sign-out view.
*/
_computeProviderClass: function(provider, showSignOut) {
if (this.disabled) {
return '';
}
if (showSignOut || !provider) {
return 'btn--signed-out';
}
return `btn--${provider.id}`;
},
/**
* Computes the text to be displayed inside the button.
*
* @param {{id: String, name: String, isSocialNetwork: Boolean, scopes: String}} provider Used for the authentication
* @param {Boolean} showSignUp Tells if the sign-up view must be shown
* @param {Boolean} showSignOut Tells if the sign-out view must be shown
* @param {Function} localize Function from the Polymer.AppLocalizeBehavior behavior
* @param {Boolean} isMini Tells if the mode "mini" is enabled
* @return {String} The text to be displayed inside the button.
*/
_computeButtonText: function(provider, showSignUp, showSignOut, localize, isMini) {
// User logged in.
if (showSignOut || !provider) {
return localize('lf-signout');
}
// User not logged in and mini format.
if (isMini) {
return provider.name;
}
return localize(`lf-sign${showSignUp ? 'up': 'in'}-${provider.id}`);
},
/**
* Retargets native event. It normalizes events fired by replaceing the
* original target (that can be a child of the paper-social-button) by the
* `paper-social-button` itself.
*
* @param {Object} event The event to be retargeted
*/
__retargetingEvent: function(event) {
event.preventDefault();
event.stopPropagation();
if (!this.disabled) {
this.dispatchEvent(new Event(event.type, Object.assign({}, event, {
target: this,
})));
}
},
});
</script>
</dom-module>