66 */
77
88import { User } from '@microsoft/microsoft-graph-types' ;
9- import { customElement , html , property } from 'lit-element' ;
9+ import { customElement , html , property , query } from 'lit-element' ;
10+ import { classMap } from 'lit-html/directives/class-map' ;
1011import { Providers } from '../../Providers' ;
1112import { ProviderState } from '../../providers/IProvider' ;
1213import '../../styles/fabric-icon-font' ;
1314import { MgtBaseComponent } from '../baseComponent' ;
1415import '../mgt-person/mgt-person' ;
16+ import { MgtFlyout } from '../sub-components/mgt-flyout/mgt-flyout' ;
1517import { styles } from './mgt-login-css' ;
1618
1719/**
@@ -52,13 +54,27 @@ export class MgtLogin extends MgtBaseComponent {
5254 } )
5355 public userDetails : User ;
5456
55- private _image : string ;
57+ /**
58+ * Gets the flyout element
59+ *
60+ * @protected
61+ * @type {MgtFlyout }
62+ * @memberof MgtLogin
63+ */
64+ @query ( '.flyout' ) protected flyout : MgtFlyout ;
5665
5766 /**
5867 * determines if login menu popup should be showing
5968 * @type {boolean }
6069 */
61- @property ( { attribute : false } ) private _showFlyout : boolean ;
70+ @property ( { attribute : false } ) private _isFlyoutOpen : boolean ;
71+
72+ private _image : string ;
73+
74+ constructor ( ) {
75+ super ( ) ;
76+ this . _isFlyoutOpen = false ;
77+ }
6278
6379 /**
6480 * Invoked each time the custom element is appended into a document-connected element
@@ -68,17 +84,6 @@ export class MgtLogin extends MgtBaseComponent {
6884 public connectedCallback ( ) {
6985 super . connectedCallback ( ) ;
7086 this . addEventListener ( 'click' , e => e . stopPropagation ( ) ) ;
71- window . addEventListener ( 'click' , e => this . handleWindowClick ( e ) ) ;
72- }
73-
74- /**
75- * Invoked each time the custom element is disconnected from the document's DOM
76- *
77- * @memberof MgtLogin
78- */
79- public disconnectedCallback ( ) {
80- window . removeEventListener ( 'click' , e => this . handleWindowClick ( e ) ) ;
81- super . disconnectedCallback ( ) ;
8287 }
8388
8489 /**
@@ -172,8 +177,12 @@ export class MgtLogin extends MgtBaseComponent {
172177 * @memberof MgtLogin
173178 */
174179 protected renderButton ( ) {
180+ const classes = {
181+ 'login-button' : true ,
182+ 'no-click' : this . _isFlyoutOpen
183+ } ;
175184 return html `
176- < button ?disabled ="${ this . isLoadingState } " @click =${ this . onClick } class ="login-button" role="button">
185+ < button ?disabled ="${ this . isLoadingState } " @click =${ this . onClick } class =${ classMap ( classes ) } role="button">
177186 ${ this . renderButtonContent ( ) }
178187 </ button >
179188 ` ;
@@ -187,8 +196,13 @@ export class MgtLogin extends MgtBaseComponent {
187196 */
188197 protected renderFlyout ( ) {
189198 return html `
190- < mgt-flyout .isOpen =${ this . _showFlyout } >
191- < div slot ="flyout " class ="flyout ">
199+ < mgt-flyout
200+ class ="flyout "
201+ light-dismiss
202+ @opened =${ ( ) => ( this . _isFlyoutOpen = true ) }
203+ @closed =${ ( ) => ( this . _isFlyoutOpen = false ) }
204+ >
205+ < div slot ="flyout ">
192206 ${ this . renderFlyoutContent ( ) }
193207 </ div >
194208 </ mgt-flyout >
@@ -255,7 +269,10 @@ export class MgtLogin extends MgtBaseComponent {
255269 * @memberof MgtLogin
256270 */
257271 protected showFlyout ( ) : void {
258- this . _showFlyout = true ;
272+ const flyout = this . flyout ;
273+ if ( flyout ) {
274+ flyout . open ( ) ;
275+ }
259276 }
260277
261278 /**
@@ -265,26 +282,15 @@ export class MgtLogin extends MgtBaseComponent {
265282 * @memberof MgtLogin
266283 */
267284 protected hideFlyout ( ) : void {
268- this . _showFlyout = false ;
269- }
270-
271- /**
272- * Toggle the state of the flyout.
273- *
274- * @protected
275- * @memberof MgtLogin
276- */
277- protected toggleFlyout ( ) : void {
278- this . _showFlyout = ! this . _showFlyout ;
279- }
280-
281- private handleWindowClick ( e : MouseEvent ) {
282- this . hideFlyout ( ) ;
285+ const flyout = this . flyout ;
286+ if ( flyout ) {
287+ flyout . close ( ) ;
288+ }
283289 }
284290
285- private onClick ( event : MouseEvent ) {
291+ private onClick ( ) {
286292 if ( this . userDetails ) {
287- this . toggleFlyout ( ) ;
293+ this . showFlyout ( ) ;
288294 } else {
289295 this . login ( ) ;
290296 }
0 commit comments