Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getCardSize() #47

Merged
merged 5 commits into from
Apr 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/components/horizonCard/HorizonCard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,34 @@ export class HorizonCard extends LitElement {
this.processLastHass()
}

/**
* called by HASS to properly distribute card in lovelace view. It should return height
* of the card as a number where 1 is equivalent of 50 pixels.
* @see https://developers.home-assistant.io/docs/frontend/custom-ui/custom-card/#api
*/
public getCardSize (): number {
let height = 4 // Smallest possible card (only graph) is roughly 200px

MrBartusek marked this conversation as resolved.
Show resolved Hide resolved
// Each element of card (title, header, content, footer) adds roughly 50px to the height
if (this.config.title && this.config.title.length > 0) {
height += 1
}

if (this.config.fields?.sunrise || this.config.fields?.sunset) {
height += 1
}

if (this.config.fields?.dawn || this.config.fields?.noon || this.config.fields?.dusk) {
height += 1
}

if (this.config.fields?.azimuth || this.config.fields?.elevation) {
height += 1
}

return height
}

// Visual editor disabled because it's broken, see https://developers.home-assistant.io/blog/2022/02/18/paper-elements/
// static getConfigElement (): HTMLElement {
// return document.createElement(HorizonCardEditor.cardType)
Expand Down