Skip to content

Commit

Permalink
Ensure ha-card is defined for vertical-stack
Browse files Browse the repository at this point in the history
  • Loading branch information
jcwillox committed Jul 6, 2020
1 parent 209902e commit efd4615
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
5 changes: 2 additions & 3 deletions src/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ export const DEFAULT_SECONDARY_INFO = [
"last-triggered",
];

export const VERTICAL_STACK_IN_CARD_STYLE =
`
export const VERTICAL_STACK_IN_CARD_STYLE = `
#root > *:not(:first-child) {
margin-top: -24px;
}
` + customElements.get("ha-card").getStyles().cssText;
`;

export const NO_CARD_STYLE = {
boxShadow: "none",
Expand Down
32 changes: 19 additions & 13 deletions src/modules/vertical-stack.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,25 @@ if (moduleEnabled(MODULE)) {
}
};

createModule(ELEMENT, function () {
if (
this._config.in_card === true &&
extensionEnabled(this._config, "in_card")
) {
// remove space between cards in the stack add ha-card background.
let styleElement = document.createElement("style");
styleElement.innerHTML = VERTICAL_STACK_IN_CARD_STYLE;
this.shadowRoot.appendChild(styleElement);
// require ha-card to be defined so we can take its style
customElements.whenDefined("ha-card").then(() => {
const IN_CARD_STYLE =
VERTICAL_STACK_IN_CARD_STYLE +
customElements.get("ha-card").getStyles().cssText;
createModule(ELEMENT, function () {
if (
this._config.in_card === true &&
extensionEnabled(this._config, "in_card")
) {
// remove space between cards in the stack add ha-card background.
let styleElement = document.createElement("style");
styleElement.innerHTML = IN_CARD_STYLE;
this.shadowRoot.appendChild(styleElement);

// remove style from all ha-card child elements.
let divElement = this.shadowRoot.querySelector("#root");
applyStyles(divElement);
}
// remove style from all ha-card child elements.
let divElement = this.shadowRoot.querySelector("#root");
applyStyles(divElement);
}
});
});
}

0 comments on commit efd4615

Please sign in to comment.