Skip to content

Commit

Permalink
Add title_card option (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
andrzejl authored Nov 15, 2022
1 parent d5e5fa2 commit 417209f
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion collapsable-cards.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class VerticalStackInCard extends HTMLElement {

this._config = config;
this._refCards = [];
this._titleCard = null;
this.renderCard();
}

Expand All @@ -36,6 +37,10 @@ class VerticalStackInCard extends HTMLElement {
const promises = config.cards.map((config) => this.createCardElement(config));
this._refCards = await Promise.all(promises);

if (config.title_card) {
this._titleCard = await this.createCardElement(config.title_card);
}

// Create the card
const card = document.createElement('ha-card');
this.card = card
Expand Down Expand Up @@ -78,7 +83,11 @@ class VerticalStackInCard extends HTMLElement {

createToggleButton() {
const toggleButton = document.createElement('button');
toggleButton.innerHTML = this._config.title || 'Toggle'
if (this._titleCard) {
toggleButton.append(this._titleCard);
} else {
toggleButton.innerHTML = this._config.title || 'Toggle';
}
toggleButton.className = 'card-content toggle-button-' + this.id
toggleButton.addEventListener('click', () => {
this.isToggled = !this.isToggled
Expand Down Expand Up @@ -158,6 +167,9 @@ class VerticalStackInCard extends HTMLElement {
card.hass = hass;
});
}
if (this._titleCard) {
this._titleCard.hass = hass;
}
}

_computeCardSize(card) {
Expand Down

0 comments on commit 417209f

Please sign in to comment.