66 */
77
88import * as MicrosoftGraph from '@microsoft/microsoft-graph-types' ;
9- import { customElement , html , property } from 'lit-element' ;
9+ import { customElement , html , property , PropertyValues } from 'lit-element' ;
1010import { classMap } from 'lit-html/directives/class-map' ;
1111import { Providers } from '../../Providers' ;
1212import { ProviderState } from '../../providers/IProvider' ;
@@ -26,6 +26,14 @@ import { styles } from './mgt-person-css';
2626 */
2727@customElement ( 'mgt-person' )
2828export class MgtPerson extends MgtTemplatedComponent {
29+ /**
30+ * Array of styles to apply to the element. The styles should be defined
31+ * user the `css` tag function.
32+ */
33+ static get styles ( ) {
34+ return styles ;
35+ }
36+
2937 /**
3038 * allows developer to define name of person for component
3139 * @type {string }
@@ -132,14 +140,6 @@ export class MgtPerson extends MgtTemplatedComponent {
132140 }
133141 }
134142
135- /**
136- * Array of styles to apply to the element. The styles should be defined
137- * user the `css` tag function.
138- */
139- static get styles ( ) {
140- return styles ;
141- }
142-
143143 /**
144144 * Invoked when the element is first updated. Implement to perform one time
145145 * work on the element after update.
@@ -181,6 +181,26 @@ export class MgtPerson extends MgtTemplatedComponent {
181181 ` ;
182182 }
183183
184+ /**
185+ * Invoked whenever the element is updated. Implement to perform
186+ * post-updating tasks via DOM APIs, for example, focusing an element.
187+ *
188+ * Setting properties inside this method will trigger the element to update
189+ * again after this update cycle completes.
190+ *
191+ * * @param changedProperties Map of changed properties with old values
192+ */
193+ protected updated ( changedProps : PropertyValues ) {
194+ super . updated ( changedProps ) ;
195+
196+ const initials = this . renderRoot . querySelector ( '.initials-text' ) as HTMLElement ;
197+ if ( initials && initials . parentNode && ( initials . parentNode as HTMLElement ) . getBoundingClientRect ) {
198+ const parent = initials . parentNode as HTMLElement ;
199+ const height = parent . getBoundingClientRect ( ) . height ;
200+ initials . style . fontSize = `${ height * 0.5 } px` ;
201+ }
202+ }
203+
184204 private async loadData ( ) {
185205 const provider = Providers . globalProvider ;
186206
@@ -357,8 +377,15 @@ export class MgtPerson extends MgtTemplatedComponent {
357377
358378 private renderDetails ( ) {
359379 if ( this . showEmail || this . showName ) {
380+ const isLarge = this . showEmail && this . showName ;
381+
382+ const detailsClasses = {
383+ Details : true ,
384+ small : ! isLarge
385+ } ;
386+
360387 return html `
361- < span class ="Details ${ this . getImageSizeClass ( ) } ">
388+ < span class ="${ classMap ( detailsClasses ) } ">
362389 ${ this . renderNameAndEmail ( ) }
363390 </ span >
364391 ` ;
@@ -370,40 +397,55 @@ export class MgtPerson extends MgtTemplatedComponent {
370397 private renderImage ( ) {
371398 if ( this . personDetails ) {
372399 const title = this . personCardInteraction === PersonCardInteraction . none ? this . personDetails . displayName : '' ;
373-
374400 const image = this . getImage ( ) ;
401+ const isLarge = this . showEmail && this . showName ;
402+ const imageClasses = {
403+ initials : ! image ,
404+ 'row-span-2' : isLarge ,
405+ small : ! isLarge ,
406+ 'user-avatar' : true
407+ } ;
408+
409+ let imageHtml ;
375410
376411 if ( image ) {
377- return html `
378- < img
379- class ="user-avatar ${ this . getImageRowSpanClass ( ) } ${ this . getImageSizeClass ( ) } "
380- title =${ title }
381- aria-label =${ title }
382- alt=${ title }
383- src=${ image }
384- />
412+ imageHtml = html `
413+ < img alt =${ title } src =${ image } />
385414 ` ;
386415 } else {
387- return html `
388- < div
389- class ="user-avatar initials ${ this . getImageRowSpanClass ( ) } ${ this . getImageSizeClass ( ) } "
390- title =${ title }
391- aria-label =${ title }
392- >
393- < span class ="initials-text " aria-label ="${ this . getInitials ( ) } ">
394- ${ this . getInitials ( ) }
395- </ span >
396- </ div >
416+ const initials = this . getInitials ( ) ;
417+
418+ imageHtml = html `
419+ < img />
420+ < span class ="initials-text " aria-label ="${ initials } ">
421+ ${ initials }
422+ </ span >
397423 ` ;
398424 }
425+
426+ return html `
427+ < div class =${ classMap ( imageClasses ) } title =${ title } aria-label=${ title } >
428+ ${ imageHtml }
429+ </ div >
430+ ` ;
399431 }
400432
401433 return this . renderEmptyImage ( ) ;
402434 }
403435
404436 private renderEmptyImage ( ) {
437+ const isLarge = this . showEmail && this . showName ;
438+
439+ const imageClasses = {
440+ 'avatar-icon' : true ,
441+ 'ms-Icon' : true ,
442+ 'ms-Icon--Contact' : true ,
443+ 'row-span-2' : isLarge ,
444+ small : ! isLarge
445+ } ;
446+
405447 return html `
406- < i class =" ms-Icon ms-Icon--Contact avatar-icon ${ this . getImageRowSpanClass ( ) } ${ this . getImageSizeClass ( ) } " > </ i >
448+ < i class =${ classMap ( imageClasses ) } > </ i >
407449 ` ;
408450 }
409451
@@ -456,20 +498,4 @@ export class MgtPerson extends MgtTemplatedComponent {
456498
457499 return initials ;
458500 }
459-
460- private getImageRowSpanClass ( ) {
461- if ( this . showEmail && this . showName ) {
462- return 'row-span-2' ;
463- }
464-
465- return '' ;
466- }
467-
468- private getImageSizeClass ( ) {
469- if ( ! this . showEmail || ! this . showName ) {
470- return 'small' ;
471- }
472-
473- return '' ;
474- }
475501}
0 commit comments