|
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="./paper-social-button.html"> |
8 | 9 | <link rel="import" href="./login-fire-social-behavior.html">
|
9 |
| -<link rel="import" href="../polymerfire/firebase-auth.html"> |
10 |
| -<link rel="import" href="../paper-button/paper-button.html"> |
11 |
| -<link rel="import" href="./login-fire-styles.html"> |
12 |
| -<link rel="import" href="../iron-icon/iron-icon.html"> |
13 |
| -<link rel="import" href="./icons.html"> |
14 |
| -<link rel="import" href="../paper-progress/paper-progress.html"> |
| 10 | +<link rel="import" href="./localize-behavior.html"> |
15 | 11 |
|
16 | 12 | <!--
|
17 | 13 | A button to authenticate a user with a federated identity provider such as Google, Facebook, Twitter or GitHub.
|
|
38 | 34 |
|
39 | 35 | ### Styling
|
40 | 36 |
|
41 |
| -Style the buttons with CSS as you would a normal DOM element. The following |
42 |
| -custom properties and mixins are available: |
43 |
| -
|
44 |
| -| Custom property | Description | Default |
45 |
| -| -- | -- | -- |
46 |
| -| `--login-fire-button` | Mixin applied on the button | `{}` |
47 |
| -| `--login-fire-button-anonymous` | Mixin applied on the anonymous button | `{}` |
48 |
| -| `--login-fire-button-anonymous-hover` | Mixin applied on the anonymous button when mouve hovers it | `{}` |
49 |
| -| `--login-fire-button-facebook` | Mixin applied on the Facebook button | `{}` |
50 |
| -| `--login-fire-button-facebook-hover` | Mixin applied on the Facebook button when mouve hovers it | `{}` |
51 |
| -| `--login-fire-button-github` | Mixin applied on the GitHub button | `{}` |
52 |
| -| `--login-fire-button-github-hover` | Mixin applied on the GitHub button when mouve hovers it | `{}` |
53 |
| -| `--login-fire-button-google` | Mixin applied on the Google button | `{}` |
54 |
| -| `--login-fire-button-google-hover` | Mixin applied on the Google button when mouve hovers it | `{}` |
55 |
| -| `--login-fire-button-icon` | Mixin applied on the icon of the button | `{}` |
56 |
| -| `--login-fire-button-text` | Mixin applied on the text of the button | `{}` |
57 |
| -| `--login-fire-button-twitter` | Mixin applied on the Twitter button | `{}` |
58 |
| -| `--login-fire-button-twitter-hover` | Mixin applied on the Twitter button when mouve hovers it | `{}` |
59 |
| -| `--login-fire-btn-signout` | Mixin applied to the sign-out button | `{}` |
60 |
| -| `--login-fire-btn-signout-hover` | Mixin applied to the sign-out button when mouve hovers it | `{}` |
61 |
| -| `--login-fire-progress-active-color` | The color that is applied to the paper-progress bar as active color | `--google-green-500` |
62 |
| -| `--login-fire-progress-container-color` | The color that is applied to the paper-progress-container | `--google-grey-300` |
| 37 | +See the "Styling" section of the `paper-social-button` element documentation. |
63 | 38 |
|
64 | 39 | @customElement
|
65 | 40 | @polymer
|
66 | 41 | @demo demo/login-fire-button.html
|
67 | 42 | -->
|
68 | 43 | <dom-module id="login-fire-button">
|
69 | 44 | <template>
|
70 |
| - <style include="login-fire-styles"> |
71 |
| - :host { |
72 |
| - display: inline-block; |
73 |
| - @apply --login-fire-button; |
74 |
| - } |
75 |
| - .btn { |
76 |
| - text-align: left; |
77 |
| - text-transform: none; |
78 |
| - min-height: 40px; |
79 |
| - display: flex; |
80 |
| - @apply --login-fire-button; |
81 |
| - } |
82 |
| - .btn--google{ |
83 |
| - @apply --login-fire-button-google; |
84 |
| - } |
85 |
| - .btn--google:hover{ |
86 |
| - @apply --login-fire-button-google-hover; |
87 |
| - } |
88 |
| - .btn--twitter{ |
89 |
| - @apply --login-fire-button-twitter; |
90 |
| - } |
91 |
| - .btn--twitter:hover{ |
92 |
| - @apply --login-fire-button-twitter-hover; |
93 |
| - } |
94 |
| - .btn--facebook{ |
95 |
| - @apply --login-fire-button-facebook; |
96 |
| - } |
97 |
| - .btn--facebook:hover{ |
98 |
| - @apply --login-fire-button-facebook-hover; |
99 |
| - } |
100 |
| - .btn--github{ |
101 |
| - @apply --login-fire-button-github; |
102 |
| - } |
103 |
| - .btn--github:hover{ |
104 |
| - @apply --login-fire-button-github-hover; |
105 |
| - } |
106 |
| - .btn--anonymous{ |
107 |
| - @apply --login-fire-button-anonymous; |
108 |
| - } |
109 |
| - .btn--anonymous:hover{ |
110 |
| - @apply --login-fire-button-anonymous-hover; |
111 |
| - } |
112 |
| - .btn__icon { |
113 |
| - padding-left: 8px; |
114 |
| - width: 30px; |
115 |
| - height: 16px; |
116 |
| - @apply --login-fire-button-icon; |
117 |
| - } |
118 |
| - .btn__text { |
119 |
| - text-align: center; |
120 |
| - width: 100%; |
121 |
| - @apply --login-fire-button-text; |
122 |
| - } |
123 |
| - .btn__signed-out{ |
124 |
| - background-color: transparent; |
125 |
| - color: grey; |
126 |
| - text-align: center; |
127 |
| - width: 170px; |
128 |
| - @apply --login-fire-btn-signout; |
129 |
| - } |
130 |
| - |
131 |
| - .btn__signed-out:hover { |
132 |
| - background-color: lightgray; |
133 |
| - @apply --login-fire-btn-signout-hover; |
134 |
| - } |
135 |
| - |
136 |
| - [hidden] { |
137 |
| - display: none !important; |
138 |
| - } |
139 |
| - </style> |
140 |
| - |
141 |
| - <paper-button class$="btn btn--[[provider]] [[_miniClass]] [[_signOutClass]]" raised$="[[!flat]]" disabled$="[[inProgress]]"> |
142 |
| - <iron-icon class="btn__icon" icon="login-fire-icons:[[provider]]" hidden$="[[_hideIcon]]"></iron-icon> |
143 |
| - <iron-icon class="btn__icon" icon="login-fire-icons:logout" hidden$="[[!_hideIcon]]"></iron-icon> |
144 |
| - <span class="btn__text">[[_text]]</span> |
145 |
| - <paper-progress class="btn-progress" hidden$="[[!inProgress]]" disabled$="[[!inProgress]]" indeterminate></paper-progress> |
146 |
| - </paper-button> |
147 |
| - |
148 |
| - <firebase-auth id="auth" |
149 |
| - app-name="[[appName]]" |
150 |
| - provider="[[provider]]" |
151 |
| - user="{{_user}}" |
152 |
| - status-known="{{_statusKnown}}" |
153 |
| - signed-in="{{_signedIn}}"> |
154 |
| - </firebase-auth> |
| 45 | + <paper-social-button |
| 46 | + provider="[[config.provider]]" |
| 47 | + no-sign-in="[[noSignIn]]" |
| 48 | + no-sign-out="[[noSignOut]]" |
| 49 | + language="[[language]]" |
| 50 | + show-sign-out$="[[_signedIn]]" |
| 51 | + show-sign-up$="[[showSignUp]]" |
| 52 | + show-progress-bar$="[[inProgress]]" |
| 53 | + flat$="[[flat]]" |
| 54 | + mini$="[[mini]]" |
| 55 | + disabled$="[[inProgress]]" |
| 56 | + on-tap="signInOrOut"> |
| 57 | + </paper-social-button> |
155 | 58 | </template>
|
156 | 59 |
|
157 | 60 | <script>
|
158 | 61 | Polymer({
|
159 | 62 | is: 'login-fire-button',
|
160 |
| - behaviors: [Convoo.LoginFireSocialBehavior], |
| 63 | + |
| 64 | + behaviors: [ |
| 65 | + Convoo.LocalizeBehavior, |
| 66 | + Convoo.LoginFireSocialBehavior |
| 67 | + ], |
161 | 68 |
|
162 | 69 | properties: {
|
163 | 70 | /**
|
|
171 | 78 | },
|
172 | 79 |
|
173 | 80 | /**
|
174 |
| - * Defines if the provider icon must be hidden or not. |
| 81 | + * Flat button, yes or not. |
175 | 82 | *
|
176 | 83 | * @type {Boolean}
|
177 | 84 | */
|
178 |
| - _hideIcon: { |
| 85 | + flat: { |
179 | 86 | type: Boolean,
|
180 |
| - computed: '_computeHideIcon(noSignIn, noSignOut, signedIn)' |
181 |
| - }, |
182 |
| - |
183 |
| - /** |
184 |
| - * CSS class added when the button has mini format. |
185 |
| - * |
186 |
| - * @type {String} |
187 |
| - */ |
188 |
| - _miniClass: { |
189 |
| - type: String, |
190 |
| - computed: '_computeMiniClass(mini)' |
191 |
| - }, |
192 |
| - |
193 |
| - /** |
194 |
| - * CSS class added when the log-out button is shown. |
195 |
| - * |
196 |
| - * @type {String} |
197 |
| - */ |
198 |
| - _signOutClass: { |
199 |
| - type: String, |
200 |
| - computed: '_computeSignOutClass(noSignIn, noSignOut, signedIn)' |
201 |
| - }, |
202 |
| - |
203 |
| - /** |
204 |
| - * Button text. |
205 |
| - * |
206 |
| - * @type {String} |
207 |
| - */ |
208 |
| - _text: { |
209 |
| - type: String, |
210 |
| - computed: '_computeButtonText(config.provider, showSignUp, noSignIn, noSignOut, signedIn, localize, language)' |
211 |
| - } |
212 |
| - }, |
213 |
| - |
214 |
| - listeners: { |
215 |
| - 'click': 'signInOrOut' |
216 |
| - }, |
217 |
| - |
218 |
| - /** |
219 |
| - * The provider logo is shown when the user can sign in and is not yet signed |
220 |
| - * in or when they can not sign out. It is hidden otherwise. |
221 |
| - * |
222 |
| - * @param {Boolean} noSignIn is `false` if a user can sign in |
223 |
| - * @param {Boolean} noSignOut is `false` if the element can sign out |
224 |
| - * @param {Boolean} signedIn is `true` if a user is actually signed in |
225 |
| - * @return {Boolean} `true` if the element can sign out and a |
226 |
| - * user is currently signed in. |
227 |
| - */ |
228 |
| - _computeHideIcon: function(noSignIn, noSignOut, signedIn) { |
229 |
| - return !((!noSignIn && !signedIn) || noSignOut); |
230 |
| - }, |
231 |
| - |
232 |
| - /** |
233 |
| - * Computes the CSS class to add according to the mini format of the |
234 |
| - * element. |
235 |
| - * |
236 |
| - * @param {Boolean} isMini `true` if the button is in mini format |
237 |
| - * @return {String} a CSS class name to add when `isMini` is true, |
238 |
| - * else returns an empty string. |
239 |
| - */ |
240 |
| - _computeMiniClass: function(isMini) { |
241 |
| - return isMini ? 'btn--mini' : ''; |
242 |
| - }, |
243 |
| - |
244 |
| - /** |
245 |
| - * Computes the CSS class to add when the user is currently signed in. |
246 |
| - * |
247 |
| - * @param {Boolean} noSignOut is `false` if the element can sign out |
248 |
| - * @param {Boolean} signedIn is `true` if a user is actually signed in |
249 |
| - * @return {String} a CSS class name to add when element can sign out |
250 |
| - */ |
251 |
| - _computeSignOutClass: function(noSignIn, noSignOut, signedIn) { |
252 |
| - if (noSignIn || (!noSignOut && signedIn)) { |
253 |
| - return 'btn__signed-out'; |
254 |
| - } |
255 |
| - }, |
256 |
| - |
257 |
| - /** |
258 |
| - * Computes the text to be displayed inside the button. |
259 |
| - * |
260 |
| - * @param {Object} user logged-in |
261 |
| - * @param {Object} provider used for the authentication |
262 |
| - * @return {String} the text to be displayed inside the button. |
263 |
| - */ |
264 |
| - _computeButtonText: function(provider, showSignUp, noSignIn, noSignOut, signedIn, localize, language) { |
265 |
| - // User logged in. |
266 |
| - if (noSignIn || (!noSignOut && signedIn) || !provider) { |
267 |
| - return localize('lf-signout'); |
268 |
| - } |
269 |
| - |
270 |
| - // User not logged in and mini format. |
271 |
| - if (this.mini) { |
272 |
| - return provider.name; |
273 |
| - } |
274 |
| - |
275 |
| - if (showSignUp && !noSignIn) { |
276 |
| - // User doesn't have account |
277 |
| - return localize('lf-signup-' + provider.id); |
278 |
| - } else if (!noSignIn) { |
279 |
| - // User has account |
280 |
| - return localize('lf-signin-' + provider.id); |
| 87 | + value: false |
281 | 88 | }
|
282 | 89 | }
|
283 | 90 | });
|
|
0 commit comments