66 */
77
88import * as MicrosoftGraph from '@microsoft/microsoft-graph-types' ;
9- import { customElement , html , property , PropertyValues } from 'lit-element' ;
9+ import { customElement , html , property , PropertyValues , TemplateResult } from 'lit-element' ;
1010import { classMap } from 'lit-html/directives/class-map' ;
11+ import { styleMap } from 'lit-html/directives/style-map' ;
1112import { Providers } from '../../Providers' ;
1213import { ProviderState } from '../../providers/IProvider' ;
1314import '../../styles/fabric-icon-font' ;
1415import { getEmailFromGraphEntity } from '../../utils/GraphHelpers' ;
1516import { MgtPersonCard } from '../mgt-person-card/mgt-person-card' ;
17+ import '../sub-components/mgt-flyout/mgt-flyout' ;
1618import { MgtTemplatedComponent } from '../templatedComponent' ;
1719import { PersonCardInteraction } from './../PersonCardInteraction' ;
1820import { styles } from './mgt-person-css' ;
@@ -116,13 +118,11 @@ export class MgtPerson extends MgtTemplatedComponent {
116118 } )
117119 public personCardInteraction : PersonCardInteraction = PersonCardInteraction . none ;
118120
119- @property ( { attribute : false } ) private _isPersonCardVisible : boolean = false ;
120- @property ( { attribute : false } ) private _personCardShouldRender : boolean = false ;
121+ @property ( { attribute : false } ) private isPersonCardVisible : boolean = false ;
122+ @property ( { attribute : false } ) private personCardShouldRender : boolean = false ;
121123
122124 private _mouseLeaveTimeout ;
123125 private _mouseEnterTimeout ;
124- private _openLeft : boolean = false ;
125- private _openUp : boolean = false ;
126126
127127 /**
128128 * Synchronizes property values when attributes change.
@@ -174,11 +174,11 @@ export class MgtPerson extends MgtTemplatedComponent {
174174 return html `
175175 < div
176176 class ="root "
177- @mouseenter =${ this . _handleMouseEnter }
178- @mouseleave =${ this . _handleMouseLeave }
179- @click=${ this . _handleMouseClick }
177+ @mouseenter =${ this . handleMouseEnter }
178+ @mouseleave =${ this . handleMouseLeave }
179+ @click=${ this . handleMouseClick }
180180 >
181- ${ person } ${ this . renderPersonCard ( image ) }
181+ ${ this . renderFlyout ( person ) }
182182 </ div >
183183 ` ;
184184 }
@@ -288,40 +288,41 @@ export class MgtPerson extends MgtTemplatedComponent {
288288 this . requestUpdate ( ) ;
289289 }
290290
291- private _handleMouseClick ( ) {
292- if ( this . personCardInteraction === PersonCardInteraction . click && ! this . _isPersonCardVisible ) {
293- this . _showPersonCard ( ) ;
291+ private handleMouseClick ( ) {
292+ if ( this . personCardInteraction === PersonCardInteraction . click && ! this . isPersonCardVisible ) {
293+ this . showPersonCard ( ) ;
294294 } else {
295- this . _hidePersonCard ( ) ;
295+ this . hidePersonCard ( ) ;
296296 }
297297 }
298298
299- private _handleMouseEnter ( e : MouseEvent ) {
299+ private handleMouseEnter ( e : MouseEvent ) {
300300 clearTimeout ( this . _mouseEnterTimeout ) ;
301301 clearTimeout ( this . _mouseLeaveTimeout ) ;
302302 if ( this . personCardInteraction !== PersonCardInteraction . hover ) {
303303 return ;
304304 }
305- this . _mouseEnterTimeout = setTimeout ( this . _showPersonCard . bind ( this ) , 500 ) ;
305+ this . _mouseEnterTimeout = setTimeout ( this . showPersonCard . bind ( this ) , 500 ) ;
306306 }
307307
308- private _handleMouseLeave ( e : MouseEvent ) {
308+ private handleMouseLeave ( e : MouseEvent ) {
309309 clearTimeout ( this . _mouseEnterTimeout ) ;
310310 clearTimeout ( this . _mouseLeaveTimeout ) ;
311- this . _mouseLeaveTimeout = setTimeout ( this . _hidePersonCard . bind ( this ) , 500 ) ;
311+ this . _mouseLeaveTimeout = setTimeout ( this . hidePersonCard . bind ( this ) , 500 ) ;
312312 }
313313
314- private _showPersonCard ( ) {
315- if ( ! this . _personCardShouldRender ) {
316- this . _personCardShouldRender = true ;
314+ private showPersonCard ( ) {
315+ if ( ! this . personCardShouldRender ) {
316+ this . personCardShouldRender = true ;
317317 }
318318
319- this . _isPersonCardVisible = true ;
319+ this . isPersonCardVisible = true ;
320320 }
321321
322- private _hidePersonCard ( ) {
323- this . _isPersonCardVisible = false ;
324- const personCard = this . querySelector ( 'mgt-person-card' ) as MgtPersonCard ;
322+ private hidePersonCard ( ) {
323+ this . isPersonCardVisible = false ;
324+ const personCard = ( this . querySelector ( 'mgt-person-card' ) ||
325+ this . renderRoot . querySelector ( 'mgt-person-card' ) ) as MgtPersonCard ;
325326 if ( personCard ) {
326327 personCard . isExpanded = false ;
327328 }
@@ -336,44 +337,28 @@ export class MgtPerson extends MgtTemplatedComponent {
336337 return null ;
337338 }
338339
339- private renderPersonCard ( image : string ) {
340- // ensure person card is only rendered when needed
341- if ( this . personCardInteraction === PersonCardInteraction . none || ! this . _personCardShouldRender ) {
342- return ;
343- }
344- // logic for rendering left if there is no space
345- const personRect = this . renderRoot . querySelector ( '.root' ) . getBoundingClientRect ( ) ;
346- const leftEdge = personRect . left ;
347- const rightEdge = ( window . innerWidth || document . documentElement . clientWidth ) - personRect . right ;
348- this . _openLeft = rightEdge < leftEdge ;
349-
350- // logic for rendering up
351- const bottomEdge = ( window . innerHeight || document . documentElement . clientHeight ) - personRect . bottom ;
352- this . _openUp = bottomEdge < 175 ;
353-
354- // find position to renderup to
355- let customStyle = null ;
356- if ( this . _openUp ) {
357- const personSize = this . getBoundingClientRect ( ) . bottom - this . getBoundingClientRect ( ) . top ;
358- customStyle = `bottom: ${ personSize / 2 + 8 } px` ;
340+ private renderFlyout ( anchor : TemplateResult ) {
341+ if ( this . personCardInteraction === PersonCardInteraction . none ) {
342+ return anchor ;
359343 }
360344
361- const flyoutClasses = {
362- flyout : true ,
363- openLeft : this . _openLeft ,
364- openUp : this . _openUp ,
365- visible : this . _isPersonCardVisible
366- } ;
367- if ( this . _isPersonCardVisible ) {
368- return html `
369- < div style ="${ customStyle } " class =${ classMap ( flyoutClasses ) } >
370- ${ this . renderTemplate ( 'person-card' , { person : this . personDetails , personImage : image } ) ||
371- html `
372- < mgt-person-card .personDetails =${ this . personDetails } .personImage =${ image } > </ mgt-person-card >
373- ` }
374- </ div >
375- ` ;
376- }
345+ const image = this . getImage ( ) ;
346+ const flyout = this . personCardShouldRender
347+ ? html `
348+ < div slot ="flyout " class ="flyout ">
349+ ${ this . renderTemplate ( 'person-card' , { person : this . personDetails , personImage : image } ) ||
350+ html `
351+ < mgt-person-card .personDetails =${ this . personDetails } .personImage =${ image } > </ mgt-person-card >
352+ ` }
353+ </ div >
354+ `
355+ : null ;
356+
357+ return html `
358+ < mgt-flyout .isOpen =${ this . isPersonCardVisible } >
359+ ${ anchor } ${ flyout }
360+ </ mgt-flyout >
361+ ` ;
377362 }
378363
379364 private renderDetails ( ) {
0 commit comments