generated from ludeeus/integration_blueprint
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding GroupedCard to improve style
- Loading branch information
Showing
10 changed files
with
273 additions
and
214 deletions.
There are no files selected for viewing
321 changes: 177 additions & 144 deletions
321
custom_components/linus_dashboard/www/linus-strategy.js
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { AbstractCard } from "./AbstractCard"; | ||
import { EntityCardConfig } from "../types/lovelace-mushroom/cards/entity-card-config"; | ||
import { SwipeCard } from "./SwipeCard"; | ||
import { SwipeCardConfig } from "../types/lovelace-mushroom/cards/swipe-card-config"; | ||
|
||
|
||
// noinspection JSUnusedGlobalSymbols Class is dynamically imported. | ||
/** | ||
* Grouped Card Class | ||
* | ||
* Used to create a card for controlling an entity of the light domain. | ||
* | ||
* @class | ||
* @extends AbstractCard | ||
*/ | ||
class GroupedCard { | ||
|
||
/** | ||
* Configuration of the card. | ||
* | ||
* @type {AbstractCard} | ||
*/ | ||
config: { cards: (AbstractCard | EntityCardConfig)[] } = { | ||
cards: [], | ||
}; | ||
|
||
/** | ||
* Class constructor. | ||
* | ||
* @param {AbstractCard[]} cards The hass entity to create a card for. | ||
* @throws {Error} If the Helper module isn't initialized. | ||
*/ | ||
constructor(cards: (AbstractCard | EntityCardConfig)[]) { | ||
|
||
this.config.cards = cards; | ||
} | ||
|
||
/** | ||
* Get a card. | ||
* | ||
* @return {AbstractCard} A card object. | ||
*/ | ||
getCard(): EntityCardConfig | SwipeCardConfig { | ||
|
||
// Group entity cards into pairs and create vertical stacks | ||
const groupedEntityCards = []; | ||
for (let i = 0; i < this.config.cards.length; i += 2) { | ||
groupedEntityCards.push({ | ||
type: "vertical-stack", | ||
cards: this.config.cards.slice(i, i + 2), | ||
}); | ||
} | ||
|
||
// If there are more than 2 groups, use a GroupedCard, otherwise use a horizontal stack | ||
const groupedCards = groupedEntityCards.length > 2 | ||
? new SwipeCard(groupedEntityCards).getCard() | ||
: { | ||
type: "horizontal-stack", | ||
cards: groupedEntityCards, | ||
} | ||
|
||
return groupedCards; | ||
} | ||
} | ||
|
||
export { GroupedCard }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters