Skip to content

Commit 2de2181

Browse files
committed
temporary commit
1 parent 38e4e35 commit 2de2181

File tree

3 files changed

+164
-15
lines changed

3 files changed

+164
-15
lines changed

index.html

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
<!-- <script src="./dist/bundle/mgt-loader.js"></script> -->
1515

1616
<script type="module" src="dist/es6/index.js"></script>
17+
<script type="module" src="dist/es6/components/sub-components/mgt-flyout/mgt-flyout.js"></script>
1718
<script type="module" src="./dist/es6/mock/mgt-mock-provider.js"></script>
1819
</head>
1920

@@ -32,10 +33,12 @@
3233
<!-- <mgt-mock-provider></mgt-mock-provider> -->
3334

3435
<mgt-login></mgt-login>
35-
<mgt-person person-query="me" show-name show-email person-card="hover"></mgt-person>
36-
<mgt-people-picker></mgt-people-picker>
37-
<mgt-tasks data-source="todo"></mgt-tasks>
38-
<mgt-agenda group-by-day></mgt-agenda>
39-
<mgt-people></mgt-people>
36+
<!-- <mgt-person person-query="me" show-name show-email person-card="click"></mgt-person>
37+
<mgt-tasks></mgt-tasks> -->
38+
39+
<mgt-flyout>
40+
<div>hello</div>
41+
<div slot="flyout">you</div>
42+
</mgt-flyout>
4043
</body>
4144
</html>

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

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
99
import { customElement, html, property, PropertyValues } from 'lit-element';
1010
import { classMap } from 'lit-html/directives/class-map';
11+
import { styleMap } from 'lit-html/directives/style-map';
1112
import { Providers } from '../../Providers';
1213
import { ProviderState } from '../../providers/IProvider';
1314
import '../../styles/fabric-icon-font';
@@ -342,26 +343,24 @@ export class MgtPerson extends MgtTemplatedComponent {
342343
const personRect = this.renderRoot.querySelector('.root').getBoundingClientRect();
343344
const leftEdge = personRect.left;
344345
const rightEdge = (window.innerWidth || document.documentElement.clientWidth) - personRect.right;
345-
this._openLeft = rightEdge < leftEdge;
346+
// this._openLeft = rightEdge < leftEdge;
346347

347348
// logic for rendering up
348349
const bottomEdge = (window.innerHeight || document.documentElement.clientHeight) - personRect.bottom;
349350
this._openUp = bottomEdge < 175;
350351

351352
// find position to renderup to
352-
let customStyle = null;
353+
const customStyle: any = {};
353354
if (this._openUp) {
354355
const personSize = this.getBoundingClientRect().bottom - this.getBoundingClientRect().top;
355-
customStyle = `bottom: ${personSize / 2 + 8}px`;
356+
customStyle.bottom = `${personSize / 2 + 8}px`;
356357
}
357358

358-
// right edge vs width of person-card
359-
let rightSpace = rightEdge - 340;
360-
361359
// determines if there is space to render on right side
362-
if (rightSpace < 0 && (window.innerWidth || document.documentElement.clientWidth) > 340) {
363-
rightSpace = rightEdge - 340;
364-
customStyle = customStyle + `; transform: translate(${rightSpace}px)`;
360+
if (rightEdge < 340) {
361+
customStyle.left = `${rightEdge - 350}px`;
362+
} else if (leftEdge > 20) {
363+
customStyle.left = '-20px';
365364
}
366365

367366
const flyoutClasses = {
@@ -374,7 +373,7 @@ export class MgtPerson extends MgtTemplatedComponent {
374373
const image = this.getImage();
375374

376375
return html`
377-
<div style="${customStyle}" class=${classMap(flyoutClasses)}>
376+
<div style=${styleMap(customStyle)} class=${classMap(flyoutClasses)}>
378377
${this.renderTemplate('person-card', { person: this.personDetails, personImage: image }) ||
379378
html`
380379
<mgt-person-card .personDetails=${this.personDetails} .personImage=${image}> </mgt-person-card>
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
import { css, customElement, html, LitElement, property } from 'lit-element';
2+
import { PersonCardInteraction } from '../../PersonCardInteraction';
3+
4+
/**
5+
*
6+
*
7+
* @export
8+
* @class mgt-flyout
9+
* @extends {MgtTemplatedComponent}
10+
*/
11+
@customElement('mgt-flyout')
12+
export class MgtFlyout extends LitElement {
13+
/**
14+
* Array of styles to apply to the element. The styles should be defined
15+
* using the `css` tag function.
16+
*/
17+
static get styles() {
18+
return css`
19+
.title {
20+
color: red;
21+
}
22+
`;
23+
}
24+
25+
// TODO: create new type
26+
@property({
27+
attribute: 'person-card',
28+
converter: (value, type) => {
29+
value = value.toLowerCase();
30+
if (typeof PersonCardInteraction[value] === 'undefined') {
31+
return PersonCardInteraction.none;
32+
} else {
33+
return PersonCardInteraction[value];
34+
}
35+
}
36+
})
37+
public personCardInteraction: PersonCardInteraction = PersonCardInteraction.hover;
38+
39+
/**
40+
*
41+
*
42+
* @type {string}
43+
* @memberof MgtComponent
44+
*/
45+
@property({
46+
attribute: 'my-title',
47+
type: String
48+
})
49+
public myTitle: string = 'My First Component';
50+
private _mouseLeaveTimeout;
51+
private _mouseEnterTimeout;
52+
private _openLeft: boolean = false;
53+
private _openUp: boolean = false;
54+
@property({ attribute: false }) private _isPersonCardVisible: boolean = false;
55+
@property({ attribute: false }) private _personCardShouldRender: boolean = false;
56+
57+
/**
58+
* Synchronizes property values when attributes change.
59+
*
60+
* @param {*} name
61+
* @param {*} oldValue
62+
* @param {*} newValue
63+
* @memberof MgtPersonCard
64+
*/
65+
public attributeChangedCallback(name, oldval, newval) {
66+
super.attributeChangedCallback(name, oldval, newval);
67+
68+
// TODO: handle when an attribute changes.
69+
//
70+
// Ex: load data when the name attribute changes
71+
// if (name === 'person-id' && oldval !== newval){
72+
// this.loadData();
73+
// }
74+
}
75+
76+
/**
77+
* Invoked when the element is first updated. Implement to perform one time
78+
* work on the element after update.
79+
*
80+
* Setting properties inside this method will trigger the element to update
81+
* again after this update cycle completes.
82+
*
83+
* * @param _changedProperties Map of changed properties with old values
84+
*/
85+
public firstUpdated() {}
86+
87+
/**
88+
* Invoked on each update to perform rendering tasks. This method must return
89+
* a lit-html TemplateResult. Setting properties inside this method will *not*
90+
* trigger the element to update.
91+
*/
92+
protected render() {
93+
return html`
94+
<div
95+
class="root"
96+
@mouseenter=${this._handleMouseEnter}
97+
@mouseleave=${this._handleMouseLeave}
98+
@click=${this._handleMouseClick}
99+
>
100+
<slot></slot>
101+
<slot name="flyout"></slot>
102+
</div>
103+
`;
104+
}
105+
106+
private _handleMouseClick() {
107+
if (this.personCardInteraction === PersonCardInteraction.click && !this._isPersonCardVisible) {
108+
this._showPersonCard();
109+
} else {
110+
this._hidePersonCard();
111+
}
112+
}
113+
114+
private _handleMouseEnter(e: MouseEvent) {
115+
if (this.personCardInteraction !== PersonCardInteraction.hover) {
116+
return;
117+
}
118+
119+
clearTimeout(this._mouseEnterTimeout);
120+
clearTimeout(this._mouseLeaveTimeout);
121+
this._mouseEnterTimeout = setTimeout(this._showPersonCard.bind(this), 500);
122+
}
123+
124+
private _handleMouseLeave(e: MouseEvent) {
125+
clearTimeout(this._mouseEnterTimeout);
126+
clearTimeout(this._mouseLeaveTimeout);
127+
this._mouseLeaveTimeout = setTimeout(this._hidePersonCard.bind(this), 500);
128+
}
129+
130+
private _showPersonCard() {
131+
if (!this._personCardShouldRender) {
132+
this._personCardShouldRender = true;
133+
}
134+
135+
this._isPersonCardVisible = true;
136+
}
137+
138+
private _hidePersonCard() {
139+
this._isPersonCardVisible = false;
140+
141+
// TODO expose an event to do this outside of the component
142+
// const personCard = this.querySelector('mgt-person-card') as MgtPersonCard;
143+
// if (personCard) {
144+
// personCard.isExpanded = false;
145+
// }
146+
}
147+
}

0 commit comments

Comments
 (0)