-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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 two pane view to calendar panel #18286
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6b8380d
Add two pane view to calendar panel
bramkragten 4e458bf
Update logging-mixin.ts
bramkragten 4e7b537
fix initialization
bramkragten 5ee6321
Update src/components/ha-button-menu.ts
bramkragten aa1e886
dont shrink pane
bramkragten e081cca
dont close menu when item is selected
bramkragten 0328b75
Add resize controller
bramkragten bc843a8
Update ha-panel-calendar.ts
bramkragten File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,320 @@ | ||
import { | ||
addHasRemoveClass, | ||
BaseElement, | ||
} from "@material/mwc-base/base-element"; | ||
import { supportsPassiveEventListener } from "@material/mwc-base/utils"; | ||
import { MDCTopAppBarAdapter } from "@material/top-app-bar/adapter"; | ||
import { strings } from "@material/top-app-bar/constants"; | ||
import MDCFixedTopAppBarFoundation from "@material/top-app-bar/fixed/foundation"; | ||
import { html, css, nothing } from "lit"; | ||
import { property, query, customElement } from "lit/decorators"; | ||
import { classMap } from "lit/directives/class-map"; | ||
import { styles } from "@material/mwc-top-app-bar/mwc-top-app-bar.css"; | ||
import { haStyleScrollbar } from "../resources/styles"; | ||
|
||
export const passiveEventOptionsIfSupported = supportsPassiveEventListener | ||
? { passive: true } | ||
: undefined; | ||
|
||
@customElement("ha-two-pane-top-app-bar-fixed") | ||
export abstract class TopAppBarBaseBase extends BaseElement { | ||
protected override mdcFoundation!: MDCFixedTopAppBarFoundation; | ||
|
||
protected override mdcFoundationClass = MDCFixedTopAppBarFoundation; | ||
|
||
@query(".mdc-top-app-bar") protected mdcRoot!: HTMLElement; | ||
|
||
// _actionItemsSlot should have type HTMLSlotElement, but when TypeScript's | ||
// emitDecoratorMetadata is enabled, the HTMLSlotElement constructor will | ||
// be emitted into the runtime, which will cause an "HTMLSlotElement is | ||
// undefined" error in browsers that don't define it (e.g. IE11). | ||
@query('slot[name="actionItems"]') protected _actionItemsSlot!: HTMLElement; | ||
|
||
protected _scrollTarget!: HTMLElement | Window; | ||
|
||
@property({ type: Boolean }) centerTitle = false; | ||
|
||
@property({ type: Boolean, reflect: true }) prominent = false; | ||
|
||
@property({ type: Boolean, reflect: true }) dense = false; | ||
|
||
@property({ type: Boolean }) pane = false; | ||
|
||
@property({ type: Boolean }) footer = false; | ||
|
||
@query(".content") private _contentElement!: HTMLElement; | ||
|
||
@query(".pane .ha-scrollbar") private _paneElement?: HTMLElement; | ||
|
||
@property({ type: Object }) | ||
get scrollTarget() { | ||
return this._scrollTarget || window; | ||
} | ||
|
||
set scrollTarget(value) { | ||
this.unregisterListeners(); | ||
const old = this.scrollTarget; | ||
this._scrollTarget = value; | ||
this.updateRootPosition(); | ||
this.requestUpdate("scrollTarget", old); | ||
this.registerListeners(); | ||
} | ||
|
||
protected updateRootPosition() { | ||
if (this.mdcRoot) { | ||
const windowScroller = this.scrollTarget === window; | ||
// we add support for top-app-bar's tied to an element scroller. | ||
this.mdcRoot.style.position = windowScroller ? "" : "absolute"; | ||
} | ||
} | ||
|
||
protected barClasses() { | ||
return { | ||
"mdc-top-app-bar--dense": this.dense, | ||
"mdc-top-app-bar--prominent": this.prominent, | ||
"center-title": this.centerTitle, | ||
"mdc-top-app-bar--fixed": true, | ||
"mdc-top-app-bar--pane": this.pane, | ||
}; | ||
} | ||
|
||
protected contentClasses() { | ||
return { | ||
"mdc-top-app-bar--fixed-adjust": !this.dense && !this.prominent, | ||
"mdc-top-app-bar--dense-fixed-adjust": this.dense && !this.prominent, | ||
"mdc-top-app-bar--prominent-fixed-adjust": !this.dense && this.prominent, | ||
"mdc-top-app-bar--dense-prominent-fixed-adjust": | ||
this.dense && this.prominent, | ||
"mdc-top-app-bar--pane": this.pane, | ||
}; | ||
} | ||
|
||
protected override render() { | ||
const title = html`<span class="mdc-top-app-bar__title" | ||
><slot name="title"></slot | ||
></span>`; | ||
return html` | ||
<header class="mdc-top-app-bar ${classMap(this.barClasses())}"> | ||
<div class="mdc-top-app-bar__row"> | ||
${this.pane | ||
? html`<section | ||
class="mdc-top-app-bar__section mdc-top-app-bar__section--align-start" | ||
id="title" | ||
> | ||
<slot | ||
name="navigationIcon" | ||
@click=${this.handleNavigationClick} | ||
></slot> | ||
${title} | ||
</section>` | ||
: nothing} | ||
<section class="mdc-top-app-bar__section" id="navigation"> | ||
${this.pane | ||
? nothing | ||
: html`<slot | ||
name="navigationIcon" | ||
@click=${this.handleNavigationClick} | ||
></slot | ||
>${title}`} | ||
</section> | ||
<section | ||
class="mdc-top-app-bar__section mdc-top-app-bar__section--align-end" | ||
id="actions" | ||
role="toolbar" | ||
> | ||
<slot name="actionItems"></slot> | ||
</section> | ||
</div> | ||
</header> | ||
<div class=${classMap(this.contentClasses())}> | ||
${this.pane | ||
? html`<div class="pane"> | ||
<div class="shadow-container"></div> | ||
<div class="ha-scrollbar"> | ||
<slot name="pane"></slot> | ||
</div> | ||
${this.footer | ||
? html`<div class="footer"> | ||
<slot name="pane-footer"></slot> | ||
</div>` | ||
: nothing} | ||
</div>` | ||
: nothing} | ||
<div class="main"> | ||
${this.pane ? html`<div class="shadow-container"></div>` : nothing} | ||
<div class="content"> | ||
<slot></slot> | ||
</div> | ||
</div> | ||
</div> | ||
`; | ||
} | ||
|
||
protected updated(changedProperties) { | ||
super.updated(changedProperties); | ||
if ( | ||
changedProperties.has("pane") && | ||
changedProperties.get("pane") !== undefined | ||
) { | ||
this.unregisterListeners(); | ||
this.registerListeners(); | ||
} | ||
} | ||
|
||
protected createAdapter(): MDCTopAppBarAdapter { | ||
return { | ||
...addHasRemoveClass(this.mdcRoot), | ||
setStyle: (prprty: string, value: string) => | ||
this.mdcRoot.style.setProperty(prprty, value), | ||
getTopAppBarHeight: () => this.mdcRoot.clientHeight, | ||
notifyNavigationIconClicked: () => { | ||
this.dispatchEvent( | ||
new Event(strings.NAVIGATION_EVENT, { | ||
bubbles: true, | ||
cancelable: true, | ||
}) | ||
); | ||
}, | ||
getViewportScrollY: () => | ||
this.scrollTarget instanceof Window | ||
? this.scrollTarget.pageYOffset | ||
: this.scrollTarget.scrollTop, | ||
getTotalActionItems: () => | ||
(this._actionItemsSlot as HTMLSlotElement).assignedNodes({ | ||
flatten: true, | ||
}).length, | ||
}; | ||
} | ||
|
||
protected handleTargetScroll = () => { | ||
this.mdcFoundation.handleTargetScroll(); | ||
}; | ||
|
||
protected handlePaneScroll = (ev) => { | ||
if (ev.target.scrollTop > 0) { | ||
ev.target.parentElement.classList.add("scrolled"); | ||
} else { | ||
ev.target.parentElement.classList.remove("scrolled"); | ||
} | ||
}; | ||
|
||
protected handleNavigationClick = () => { | ||
this.mdcFoundation.handleNavigationClick(); | ||
}; | ||
|
||
protected registerListeners() { | ||
if (this.pane) { | ||
this._paneElement!.addEventListener( | ||
"scroll", | ||
this.handlePaneScroll, | ||
passiveEventOptionsIfSupported | ||
); | ||
this._contentElement.addEventListener( | ||
"scroll", | ||
this.handlePaneScroll, | ||
passiveEventOptionsIfSupported | ||
); | ||
return; | ||
} | ||
this.scrollTarget.addEventListener( | ||
"scroll", | ||
this.handleTargetScroll, | ||
passiveEventOptionsIfSupported | ||
); | ||
} | ||
|
||
protected unregisterListeners() { | ||
this._paneElement?.removeEventListener("scroll", this.handlePaneScroll); | ||
this._contentElement.removeEventListener("scroll", this.handlePaneScroll); | ||
this.scrollTarget.removeEventListener("scroll", this.handleTargetScroll); | ||
} | ||
|
||
protected override firstUpdated() { | ||
super.firstUpdated(); | ||
this.updateRootPosition(); | ||
this.registerListeners(); | ||
} | ||
|
||
override disconnectedCallback() { | ||
super.disconnectedCallback(); | ||
this.unregisterListeners(); | ||
} | ||
|
||
static override styles = [ | ||
styles, | ||
haStyleScrollbar, | ||
css` | ||
.mdc-top-app-bar__row { | ||
height: var(--header-height); | ||
border-bottom: var(--app-header-border-bottom); | ||
} | ||
.mdc-top-app-bar--fixed-adjust { | ||
padding-top: var(--header-height); | ||
} | ||
.shadow-container { | ||
position: absolute; | ||
top: calc(-1 * var(--header-height)); | ||
width: 100%; | ||
height: var(--header-height); | ||
z-index: 1; | ||
transition: box-shadow 200ms linear; | ||
} | ||
.scrolled .shadow-container { | ||
box-shadow: var( | ||
--mdc-top-app-bar-fixed-box-shadow, | ||
0px 2px 4px -1px rgba(0, 0, 0, 0.2), | ||
0px 4px 5px 0px rgba(0, 0, 0, 0.14), | ||
0px 1px 10px 0px rgba(0, 0, 0, 0.12) | ||
); | ||
} | ||
.mdc-top-app-bar { | ||
--mdc-typography-headline6-font-weight: 400; | ||
color: var(--app-header-text-color, var(--mdc-theme-on-primary, #fff)); | ||
background-color: var( | ||
--app-header-background-color, | ||
var(--mdc-theme-primary) | ||
); | ||
} | ||
.mdc-top-app-bar--pane.mdc-top-app-bar--fixed-scrolled { | ||
box-shadow: none; | ||
} | ||
#title { | ||
border-right: 1px solid rgba(255, 255, 255, 0.12); | ||
box-sizing: border-box; | ||
flex: 0 0 var(--sidepane-width, 250px); | ||
width: var(--sidepane-width, 250px); | ||
} | ||
div.mdc-top-app-bar--pane { | ||
display: flex; | ||
height: calc(100vh - var(--header-height)); | ||
} | ||
.pane { | ||
border-right: 1px solid var(--divider-color); | ||
box-sizing: border-box; | ||
display: flex; | ||
flex: 0 0 var(--sidepane-width, 250px); | ||
width: var(--sidepane-width, 250px); | ||
flex-direction: column; | ||
position: relative; | ||
} | ||
.pane .ha-scrollbar { | ||
flex: 1; | ||
} | ||
.pane .footer { | ||
border-top: 1px solid var(--divider-color); | ||
} | ||
.main { | ||
min-height: 100%; | ||
} | ||
.mdc-top-app-bar--pane .main { | ||
position: relative; | ||
flex: 1; | ||
height: 100%; | ||
} | ||
.mdc-top-app-bar--pane .content { | ||
height: 100%; | ||
overflow: auto; | ||
} | ||
`, | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
FYI, this introduced a duplicate of
@lit/reactive-element
(bumping it to the next major version).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.
Adjusted in #18484