-
Notifications
You must be signed in to change notification settings - Fork 32
GAUD-9843 - Skeleton of the panel mixin and the three components #6928
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
Changes from all commits
7f3dfc8
5994bb7
4c09b8b
67d42fd
2c5444a
3d988db
afe40b1
cb0fe91
b1eb358
398112c
7bb5ab3
59495f8
d04f7d6
551d5c7
93af9b4
e66ae71
919577e
d609d92
20a6859
44e581b
c86d890
fa6a9d6
05ddf5d
9509470
5ad1548
ef89a70
36e6b57
69efd70
4425eac
e8d5fb4
a35de39
16df33e
c1adbb5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { css, html, LitElement } from 'lit'; | ||
| import { PagePanelMixin, pagePanelStyles } from './page-panel-mixin.js'; | ||
|
|
||
| /** | ||
| * Component to be placed in the main default slot of d2l-page, providing a panel with optional header | ||
| * @slot - The main content of the main page panel | ||
| * @slot header-start - Optional start content of the main page header | ||
| * @slot header-end - Optional end content of the main page header | ||
| */ | ||
| class PageMain extends PagePanelMixin(LitElement) { | ||
|
|
||
| static styles = [pagePanelStyles, css` | ||
| .panel-header { | ||
| top: var(--d2l-page-header-height, 0); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could also set a variable that the mixin uses to avoid these subclasses knowing much about the internals of the base class.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure what you mean? Like set a different css property with this value like
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, or just
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to adjust this/add a few more uses and variables to fix the sticky stuff (next draft PR going up), so we can figure it out there. It's a bit confusing and I don't love what I have |
||
| } | ||
| `]; | ||
|
|
||
| render() { | ||
| return this._renderPanel(html`<slot></slot>`); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| customElements.define('d2l-page-main', PageMain); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| import '../colors/colors.js'; | ||
| import { css, html } from 'lit'; | ||
| import { classMap } from 'lit/directives/class-map.js'; | ||
|
|
||
| export const pagePanelStyles = css` | ||
| .panel-header:not([hidden]) { | ||
| align-items: center; | ||
| display: flex; | ||
| flex-direction: row; | ||
| justify-content: space-between; | ||
| } | ||
| .panel-header { | ||
| background-color: white; | ||
| border-bottom: 1px solid var(--d2l-color-mica); | ||
| height: 70px; | ||
| overflow: hidden; | ||
| padding: 0 30px; | ||
| position: sticky; | ||
| top: 0; | ||
| z-index: 14; /* To be over sticky content of our core components, but not over the header shadow */ | ||
| } | ||
|
|
||
| .header-start, | ||
| .header-end { | ||
| display: flex; | ||
| gap: 6px; | ||
| } | ||
|
|
||
| .panel { | ||
| padding: 30px; | ||
| } | ||
| `; | ||
|
|
||
| export const PagePanelMixin = superclass => class extends superclass { | ||
|
|
||
| static properties = { | ||
| _hasHeader: { state: true }, | ||
| _slotVisibility: { state: true } | ||
| }; | ||
|
|
||
| constructor() { | ||
| super(); | ||
| this._hasHeader = false; | ||
| this._slotVisibility = {}; | ||
| } | ||
|
|
||
| _renderPanel(content) { | ||
| const panelClasses = { | ||
| 'panel': true, | ||
| 'header-sticky': this._hasHeader | ||
| }; | ||
| const header = html` | ||
| <div ?hidden="${!this._hasHeader}" class="panel-header"> | ||
| <div class="header-start"><slot name="header-start" @slotchange="${this.#handleSlotVisibilityChange}"></slot></div> | ||
| <div class="header-end"><slot name="header-end" @slotchange="${this.#handleSlotVisibilityChange}"></slot></div> | ||
| </div>`; | ||
|
|
||
| return html` | ||
| <div> | ||
| ${header} | ||
| <div class="${classMap(panelClasses)}">${content}</div> | ||
| </div> | ||
| `; | ||
| } | ||
|
|
||
| #handleSlotVisibilityChange(e) { | ||
| const key = e.target.name; | ||
| const nodes = e.target.assignedNodes(); | ||
| this._slotVisibility = { ...this._slotVisibility, [key]: nodes.length !== 0 }; | ||
|
|
||
| this._hasHeader = this._slotVisibility['header-start'] || this._slotVisibility['header-end']; | ||
| } | ||
|
|
||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { html, LitElement } from 'lit'; | ||
| import { PagePanelMixin, pagePanelStyles } from './page-panel-mixin.js'; | ||
|
|
||
| /** | ||
| * Component to be placed in the side-nav slot of d2l-page, providing a panel with optional header | ||
| * @slot - The main content of the side-nav page panel | ||
| * @slot header-start - Optional start content of the side-nav page header | ||
| * @slot header-end - Optional end content of the side-nav page header | ||
| */ | ||
| class PageSideNav extends PagePanelMixin(LitElement) { | ||
|
|
||
| static styles = [pagePanelStyles]; | ||
|
|
||
| render() { | ||
| return this._renderPanel(html`<slot></slot>`); | ||
| } | ||
| } | ||
|
|
||
| customElements.define('d2l-page-side-nav', PageSideNav); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { html, LitElement } from 'lit'; | ||
| import { PagePanelMixin, pagePanelStyles } from './page-panel-mixin.js'; | ||
|
|
||
| /** | ||
| * Component to be placed in the supporting slot of d2l-page, providing a panel with optional header | ||
| * @slot - The main content of the supporting page panel | ||
| * @slot header-start - Optional start content of the supporting page header | ||
| * @slot header-end - Optional end content of the supporting page header | ||
| */ | ||
| class PageSupporting extends PagePanelMixin(LitElement) { | ||
|
|
||
| static styles = [pagePanelStyles]; | ||
|
|
||
| render() { | ||
| return this._renderPanel(html`<slot></slot>`); | ||
| } | ||
| } | ||
|
|
||
| customElements.define('d2l-page-supporting', PageSupporting); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -44,10 +44,14 @@ class Page extends LocalizeCoreElement(LitElement) { | |
| --d2l-page-footer-max-width: 100%; | ||
| } | ||
|
|
||
| .header { | ||
| position: relative; | ||
| z-index: 15; /* To be over sticky content of our core components */ | ||
| } | ||
|
|
||
| .page.header-sticky .header { | ||
| position: sticky; | ||
| top: 0; | ||
| z-index: 15; /* To be over sticky content of our core components */ | ||
| } | ||
|
Comment on lines
+47
to
55
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of this, we could implement one of the strategies @dbatiste describes in this comment, making the panel headers only apply |
||
|
|
||
| .content { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the stuff added in the headers for these demos could be a bit better, but I've run out of time 😅