diff --git a/collapsable-cards.js b/collapsable-cards.js index d90bfcd..1e85d23 100644 --- a/collapsable-cards.js +++ b/collapsable-cards.js @@ -25,6 +25,7 @@ class VerticalStackInCard extends HTMLElement { this._config = config; this._refCards = []; + this._titleCard = null; this.renderCard(); } @@ -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 @@ -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 @@ -158,6 +167,9 @@ class VerticalStackInCard extends HTMLElement { card.hass = hass; }); } + if (this._titleCard) { + this._titleCard.hass = hass; + } } _computeCardSize(card) {