Skip to content

Commit 79a901f

Browse files
committed
Improved styling (shadow encapsulation) and close popups on clicking links
1 parent c8e3c59 commit 79a901f

File tree

3 files changed

+55
-50
lines changed

3 files changed

+55
-50
lines changed

lovelace-home-feed-card.js

Lines changed: 8 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@ class HomeFeedCard extends LitElement {
3838
};
3939
}
4040

41-
createRenderRoot() {
42-
return this;
43-
}
44-
4541
get pageRoot() {
4642
let root = document.querySelector("home-assistant");
4743
root = root && root.shadowRoot;
@@ -58,9 +54,8 @@ class HomeFeedCard extends LitElement {
5854

5955

6056

61-
static get stylesheet() {
62-
return html`
63-
<style>
57+
static get styles() {
58+
return css`
6459
ha-card {
6560
padding: 0 16px 16px 16px;
6661
}
@@ -152,14 +147,12 @@ class HomeFeedCard extends LitElement {
152147
white-space: nowrap;
153148
overflow: hidden;
154149
text-overflow: ellipsis;
155-
}
156-
</style>
157-
`;
150+
}`;
158151
}
159152

160153
async updated(changedProperties) {
161154
if(!this.configuredScrollbars){
162-
var root = this.querySelector("ha-card #notifications");
155+
var root = this.shadowRoot.querySelector("ha-card #notifications");
163156
if(root && this._config){
164157
if(this._config.scrollbars_enabled !== false || this._config.max_height){
165158
root.style.maxHeight = this._config.max_height ? this._config.max_height : "28em";
@@ -196,7 +189,6 @@ class HomeFeedCard extends LitElement {
196189
this.style.display = "block";
197190

198191
return html`
199-
${HomeFeedCard.stylesheet}
200192
<ha-card id="card">
201193
${this._config.header
202194
? this.renderHeaderFooter(this._config.header, "header")
@@ -713,6 +705,15 @@ class HomeFeedCard extends LitElement {
713705
this.fireEvent("hass-more-info", {entityId: entity});
714706
}
715707

708+
findPopUpCard(cardType){
709+
let root = document.querySelector("home-assistant");
710+
root = root && root.shadowRoot;
711+
root = root && root.querySelector("card-tools-popup");
712+
root = root && root.shadowRoot;
713+
root = root && root.querySelector("ha-dialog");
714+
return root.querySelector(cardType);
715+
}
716+
716717
_handleClick(ev) {
717718
let item = ev.currentTarget.item;
718719

@@ -729,13 +730,10 @@ class HomeFeedCard extends LitElement {
729730

730731
setTimeout(()=>{
731732

732-
let popupRoot = document.querySelector("home-assistant").shadowRoot.querySelector("card-tools-popup").shadowRoot;
733-
let card = popupRoot.querySelector("ha-dialog")
734-
.querySelector("hui-entities-card");
735-
736-
if(card){
737-
card.hass = mock_hass;
738-
let states = card.shadowRoot.querySelector("ha-card #states");
733+
let popup = this.findPopUpCard("hui-entities-card");
734+
if(popup){
735+
popup.hass = mock_hass;
736+
let states = popup.shadowRoot && popup.shadowRoot.querySelector("ha-card #states");
739737
if(states) {
740738
states.querySelectorAll("div")[1]
741739
.querySelector("hui-history-graph-card")
@@ -759,15 +757,20 @@ class HomeFeedCard extends LitElement {
759757

760758
setTimeout(()=>{
761759

762-
let popupRoot = document.querySelector("home-assistant").shadowRoot.querySelector("card-tools-popup").shadowRoot;
763-
let card = popupRoot.querySelector("ha-dialog")
764-
.querySelector("hui-markdown-card")
765-
.shadowRoot.querySelector("ha-card");
760+
let popup = this.findPopUpCard("hui-markdown-card");
761+
let card = popup && popup.shadowRoot && popup.shadowRoot.querySelector("ha-card");
766762

767763
if(card){
768764
card.style.boxShadow = "none";
769765
card.style.maxHeight = "300px";
770766
card.style.overflow = "auto";
767+
768+
let markdownElement = card.querySelector("ha-markdown").shadowRoot.querySelector("ha-markdown-element");
769+
if(markdownElement){
770+
markdownElement.querySelectorAll("a").forEach(link => {
771+
link.addEventListener("click", closePopUp);
772+
});
773+
}
771774
}
772775
},100);
773776
}
@@ -776,9 +779,6 @@ class HomeFeedCard extends LitElement {
776779
let notification = item.original_notification;
777780
if(!notification.title) notification.title = this.notificationIdToTitle(notification.notification_id);
778781

779-
//let popup = document.createElement("home-feed-notification-popup");
780-
//popup.notification = notification;
781-
//popup.hass = this._hass;
782782
let config = {"type":"custom:home-feed-notification-popup", "notification": notification};
783783

784784
popUp(notification.title, config, false);
@@ -1094,7 +1094,7 @@ class HomeFeedCard extends LitElement {
10941094
this.refreshEntityHistory().then(() => {});
10951095
}
10961096

1097-
this.querySelectorAll("ha-card .header-footer > *").forEach(
1097+
this.shadowRoot.querySelectorAll("ha-card .header-footer > *").forEach(
10981098
(element) => {
10991099
element.hass = hass;
11001100
}

src/popup.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,16 @@ import { closePopUp } from "card-tools/src/popup";
44
export class HomeFeedNotificationPopup extends LitElement {
55
constructor() {
66
super();
7-
this.pushStateInterceptor();
87
}
98

10-
createRenderRoot() {
11-
return this;
12-
}
13-
149
setConfig(config){
1510
this._notification = config.notification;
1611
}
1712

18-
render() {
19-
return html`
20-
<style type="text/css">
21-
.contents {
13+
static get styles()
14+
{
15+
return css`
16+
.contents {
2217
padding: 16px;
2318
-ms-user-select: text;
2419
-webkit-user-select: text;
@@ -52,7 +47,22 @@ export class HomeFeedNotificationPopup extends LitElement {
5247
border-top: 1px solid #e8e8e8;
5348
padding: 5px 16px;
5449
}
55-
</style>
50+
`;
51+
}
52+
render() {
53+
setTimeout(() => {
54+
let root = this.shadowRoot;
55+
let card =root.querySelector("ha-card");
56+
57+
let markdownElement = card && card.querySelector("ha-markdown").shadowRoot.querySelector("ha-markdown-element");
58+
if(markdownElement){
59+
markdownElement.querySelectorAll("a").forEach(link => {
60+
link.addEventListener("click", closePopUp);
61+
});
62+
}
63+
},100);
64+
65+
return html`
5666
<ha-card>
5767
<div class="contents">
5868
<ha-markdown .hass="${this._hass}" .content="${this._notification.message}"></ha-markdown>

0 commit comments

Comments
 (0)