Skip to content

Commit

Permalink
toggle cards handle
Browse files Browse the repository at this point in the history
  • Loading branch information
ngocjohn committed Jun 5, 2024
1 parent 0faa73a commit 89c7b8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
6 changes: 3 additions & 3 deletions dist/vehicle-info-card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions src/vehicle-info-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -418,10 +418,10 @@ export class VehicleCard extends LitElement {
<ha-icon icon="mdi:close"></ha-icon>
</div>
<div class="card-toggle ">
<div class="headder-btn" @click="${this.togglePrevCard.bind(this)}">
<div class="headder-btn" @click="${() => this.togglePrevCard()}">
<ha-icon icon="mdi:chevron-left"></ha-icon>
</div>
<div class="headder-btn" @click="${this.toggleNextCard.bind(this)}">
<div class="headder-btn" @click="${() => this.toggleNextCard()}">
<ha-icon icon="mdi:chevron-right"></ha-icon>
</div>
</div>
Expand Down Expand Up @@ -453,9 +453,14 @@ export class VehicleCard extends LitElement {

private toggleCard(cardType: string): void {
if (this.additionalCards[cardType] && this.additionalCards[cardType].length > 0) {
// If the added card type is defined and has cards, toggle between added card types
this.activeCardType = this.activeCardType === cardType ? null : cardType;
} else {
this.activeCardType = this.activeCardType === cardType ? null : `default-${cardType}`;
// If the added card type is null or has no cards, cycle through default card types
const defaultCardTypes = ['default-tripCards', 'default-vehicleCards', 'default-ecoCards', 'default-tyreCards'];
const currentIndex = defaultCardTypes.indexOf(this.activeCardType || '');
const newIndex = (currentIndex + 1) % defaultCardTypes.length;
this.activeCardType = defaultCardTypes[newIndex];
}
}

Expand Down

0 comments on commit 89c7b8e

Please sign in to comment.