Skip to content

Commit d351d09

Browse files
updated person card with latest flyout updates (#354)
Co-authored-by: Shane Weaver <[email protected]>
1 parent 8349e39 commit d351d09

File tree

2 files changed

+30
-51
lines changed

2 files changed

+30
-51
lines changed

src/components/mgt-person-card/mgt-person-card.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ $color: var(--color, #{$ms-color-neutralDark});
1414

1515
:host .root {
1616
position: relative;
17-
width: 340px;
17+
width: var(--mgt-flyout-set-width, 340px);
1818
background: #ffffff;
1919
font-family: var(--default-font-family);
2020

src/components/mgt-person/mgt-person.ts

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
9-
import { customElement, html, property, TemplateResult } from 'lit-element';
9+
import { customElement, html, property, query, TemplateResult } from 'lit-element';
1010
import { classMap } from 'lit-html/directives/class-map';
1111
import { findPerson, getEmailFromGraphEntity } from '../../graph/graph.people';
1212
import { getContactPhoto, getUserPhoto } from '../../graph/graph.photos';
@@ -15,6 +15,7 @@ import { ProviderState } from '../../providers/IProvider';
1515
import '../../styles/fabric-icon-font';
1616
import { MgtPersonCard } from '../mgt-person-card/mgt-person-card';
1717
import '../sub-components/mgt-flyout/mgt-flyout';
18+
import { MgtFlyout } from '../sub-components/mgt-flyout/mgt-flyout';
1819
import { MgtTemplatedComponent } from '../templatedComponent';
1920
import { PersonCardInteraction } from './../PersonCardInteraction';
2021
import { styles } from './mgt-person-css';
@@ -166,19 +167,15 @@ export class MgtPerson extends MgtTemplatedComponent {
166167
public personCardInteraction: PersonCardInteraction;
167168

168169
/**
169-
* Gets the visibility state of the personCard
170+
* Gets the flyout element
170171
*
171-
* @readonly
172172
* @protected
173-
* @type {boolean}
173+
* @type {MgtFlyout}
174174
* @memberof MgtPerson
175175
*/
176-
protected get isPersonCardVisible(): boolean {
177-
return this._isPersonCardVisible;
178-
}
176+
@query('.flyout') protected flyout: MgtFlyout;
179177

180-
private _isPersonCardVisible: boolean;
181-
private _personCardShouldRender: boolean;
178+
@property({ attribute: false }) private _personCardShouldRender: boolean;
182179
private _personDetails: IDynamicPerson;
183180
private _personAvatarBg: string;
184181

@@ -187,7 +184,6 @@ export class MgtPerson extends MgtTemplatedComponent {
187184

188185
constructor() {
189186
super();
190-
this.handleWindowClick = this.handleWindowClick.bind(this);
191187
this.personCardInteraction = PersonCardInteraction.none;
192188
}
193189

@@ -215,26 +211,6 @@ export class MgtPerson extends MgtTemplatedComponent {
215211
}
216212
}
217213

218-
/**
219-
* Invoked each time the custom element is appended into a document-connected element
220-
*
221-
* @memberof MgtPerson
222-
*/
223-
public connectedCallback() {
224-
super.connectedCallback();
225-
window.addEventListener('click', this.handleWindowClick);
226-
}
227-
228-
/**
229-
* Invoked each time the custom element is disconnected from the document's DOM
230-
*
231-
* @memberof MgtPerson
232-
*/
233-
public disconnectedCallback() {
234-
window.removeEventListener('click', this.handleWindowClick);
235-
super.disconnectedCallback();
236-
}
237-
238214
/**
239215
* Invoked on each update to perform rendering tasks. This method must return
240216
* a lit-html TemplateResult. Setting properties inside this method will *not*
@@ -264,9 +240,7 @@ export class MgtPerson extends MgtTemplatedComponent {
264240

265241
// Flyout template
266242
const flyoutTemplate: TemplateResult =
267-
this.personCardInteraction !== PersonCardInteraction.none && this._personCardShouldRender
268-
? this.renderFlyout()
269-
: html``;
243+
this.personCardInteraction !== PersonCardInteraction.none ? this.renderFlyout(personTemplate) : null;
270244

271245
return html`
272246
<div
@@ -275,7 +249,7 @@ export class MgtPerson extends MgtTemplatedComponent {
275249
@mouseenter=${this.handleMouseEnter}
276250
@mouseleave=${this.handleMouseLeave}
277251
>
278-
${personTemplate} ${flyoutTemplate}
252+
${flyoutTemplate || personTemplate}
279253
</div>
280254
`;
281255
}
@@ -444,12 +418,18 @@ export class MgtPerson extends MgtTemplatedComponent {
444418
* @returns {TemplateResult}
445419
* @memberof MgtPerson
446420
*/
447-
protected renderFlyout(): TemplateResult {
421+
protected renderFlyout(anchor: TemplateResult): TemplateResult {
422+
const flyoutContent = this._personCardShouldRender
423+
? html`
424+
<div slot="flyout">
425+
${this.renderFlyoutContent()}
426+
</div>
427+
`
428+
: html``;
429+
448430
return html`
449-
<mgt-flyout .isOpen=${this.isPersonCardVisible}>
450-
<div slot="flyout" class="flyout">
451-
${this.renderFlyoutContent()}
452-
</div>
431+
<mgt-flyout light-dismiss class="flyout">
432+
${anchor} ${flyoutContent}
453433
</mgt-flyout>
454434
`;
455435
}
@@ -610,14 +590,8 @@ export class MgtPerson extends MgtTemplatedComponent {
610590
return initials;
611591
}
612592

613-
private handleWindowClick(e: MouseEvent) {
614-
if (this.isPersonCardVisible && e.target !== this) {
615-
this.hidePersonCard();
616-
}
617-
}
618-
619593
private handleMouseClick(e: MouseEvent) {
620-
if (this.personCardInteraction !== PersonCardInteraction.click && !this.isPersonCardVisible) {
594+
if (this.personCardInteraction !== PersonCardInteraction.click) {
621595
this.showPersonCard();
622596
}
623597
}
@@ -638,22 +612,27 @@ export class MgtPerson extends MgtTemplatedComponent {
638612
}
639613

640614
private hidePersonCard() {
641-
this._isPersonCardVisible = false;
615+
const flyout = this.flyout;
616+
if (flyout) {
617+
flyout.isOpen = false;
618+
}
619+
642620
const personCard = (this.querySelector('mgt-person-card') ||
643621
this.renderRoot.querySelector('mgt-person-card')) as MgtPersonCard;
644622
if (personCard) {
645623
personCard.isExpanded = false;
646624
}
647-
this.requestUpdate();
648625
}
649626

650627
private showPersonCard() {
651628
if (!this._personCardShouldRender) {
652629
this._personCardShouldRender = true;
653630
}
654631

655-
this._isPersonCardVisible = true;
656-
this.requestUpdate();
632+
const flyout = this.flyout;
633+
if (flyout) {
634+
flyout.isOpen = true;
635+
}
657636
}
658637

659638
private getColorFromName(name) {

0 commit comments

Comments
 (0)