Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add close tray button to popover test. #5327

Merged
merged 1 commit into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion components/popover/demo/popover.html
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ <h2>Popover (mobile tray)</h2>
<d2l-test-popover mobile-tray-location="inline-start" style="max-width: 400px;">
<d2l-link href="https://pirateipsum.me/" target="_blank">Pirate Ipsum</d2l-link>
<div>Sink me piracy Gold Road quarterdeck wherry long boat line pillage walk the plank Plate Fleet. Haul wind black spot strike colors deadlights lee Barbary Coast yo-ho-ho ballast gally Shiver me timbers. Sea Legs quarterdeck yard scourge of the seven seas coffer plunder lanyard holystone code of conduct belay.</div>
<d2l-button-subtle text="Close"></d2l-button-subtle>
</d2l-test-popover>
<script>
window.wireUpPopover(document.currentScript.parentNode);
Expand Down
1 change: 1 addition & 0 deletions components/popover/popover-mixin.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export const PopoverMixin = superclass => class extends superclass {
const backdrop = this._mobileTrayLocation ?
html`<d2l-backdrop for-target="content-wrapper" ?shown="${this._showBackdrop}"></d2l-backdrop>` :
nothing;

return html`${content}${backdrop}${pointer}`;

}
Expand Down
50 changes: 36 additions & 14 deletions components/popover/test/popover.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { css, html, LitElement } from 'lit';
import { classMap } from 'lit/directives/class-map.js';
import { PopoverMixin } from '../popover-mixin.js';
import { styleMap } from 'lit/directives/style-map.js';

class Popover extends PopoverMixin(LitElement) {

Expand Down Expand Up @@ -67,8 +66,8 @@ class Popover extends PopoverMixin(LitElement) {
* @type {boolean}
*/
trapFocus: { type: Boolean, reflect: true, attribute: 'trap-focus' },
_hasFooter: { state: true },
_hasHeader: { state: true }
_hasFooterSlotContent: { state: true },
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just renamed these to make it clearer, since they are specifically in regard to whether the consumer has placed content in the header or footer slots.

_hasHeaderSlotContent: { state: true }
};
}

Expand All @@ -88,9 +87,25 @@ class Popover extends PopoverMixin(LitElement) {
.test-no-header {
display: none;
}
.test-footer {
box-sizing: border-box;
max-width: 100%;
padding: 0 1rem 1rem 1rem;
width: 100%;
}
.test-no-footer {
display: none;
}
.test-close {
margin-block-start: 12px;
width: 100%;
}
.test-no-close {
display: none;
}
.test-close-no-margin {
margin-block-start: 0;
}
`];
}

Expand All @@ -102,8 +117,8 @@ class Popover extends PopoverMixin(LitElement) {
this.opened = false;
this.trapFocus = false;

this._hasFooter = false;
this._hasHeader = false;
this._hasFooterSlotContent = false;
this._hasHeaderSlotContent = false;
}

connectedCallback() {
Expand All @@ -116,26 +131,29 @@ class Popover extends PopoverMixin(LitElement) {

const headerClasses = {
'test-header': true,
'test-no-header': !this._hasHeader
'test-no-header': !this._hasHeaderSlotContent
};
const headerStyle = {};

const footerClasses = {
'test-footer': true,
'test-no-footer': !this._hasFooter
'test-no-footer': !(this._hasFooterSlotContent || (this._mobile && this._mobileTrayLocation))
};
const closeButtonClasses = {
'test-close': true,
'test-no-close': !(this._mobile && this._mobileTrayLocation),
'test-close-no-margin': !this._hasFooterSlotContent
};
const footerStyle = {};

const content = html`
<div class="test-content-layout">
<div class="${classMap(headerClasses)}" style="${styleMap(headerStyle)}">
<div class="${classMap(headerClasses)}">
<slot name="header" @slotchange="${this.#handleHeaderSlotChange}"></slot>
</div>
<div class="test-content" @scroll="${this.#handleContentScroll}">
<slot></slot>
</div>
<div class=${classMap(footerClasses)} style=${styleMap(footerStyle)}>
<div class="${classMap(footerClasses)}">
<slot name="footer" @slotchange="${this.#handleFooterSlotChange}"></slot>
<d2l-button class="${classMap(closeButtonClasses)}" @click=${this.#handleCloseButtonClick}>Close</d2l-button>
</div>
</div>
`;
Expand Down Expand Up @@ -168,17 +186,21 @@ class Popover extends PopoverMixin(LitElement) {
return this.shadowRoot.querySelector('.test-content');
}

#handleCloseButtonClick() {
this.close();
}

#handleContentScroll() {
// eslint-disable-next-line
console.log('handle content scroll');
}

#handleFooterSlotChange(e) {
this._hasFooter = e.target.assignedNodes().length !== 0;
this._hasFooterSlotContent = e.target.assignedNodes().length !== 0;
}

#handleHeaderSlotChange(e) {
this._hasHeader = e.target.assignedNodes().length !== 0;
this._hasHeaderSlotContent = e.target.assignedNodes().length !== 0;
}

#handlePopoverClose() {
Expand Down
Loading