mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-23 17:26:42 +00:00
Love: Add column and row card
This commit is contained in:
parent
b55004d73b
commit
e0ccc1999a
48
src/panels/lovelace/cards/hui-column-card.js
Normal file
48
src/panels/lovelace/cards/hui-column-card.js
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
import createCardElement from '../common/create-card-element.js';
|
||||||
|
import createErrorConfig from '../common/create-error-card-config.js';
|
||||||
|
|
||||||
|
class HuiColumnCard extends HTMLElement {
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
this._elements = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
getCardSize() {
|
||||||
|
return 7;
|
||||||
|
}
|
||||||
|
|
||||||
|
set config(config) {
|
||||||
|
this._elements = [];
|
||||||
|
const root = this;
|
||||||
|
|
||||||
|
while (root.lastChild) {
|
||||||
|
root.removeChild(root.lastChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (config && config.cards && Array.isArray(config.cards)) {
|
||||||
|
const elements = [];
|
||||||
|
config.cards.forEach(card => {
|
||||||
|
const element = createCardElement(card);
|
||||||
|
element.style.setProperty('margin', '4px');
|
||||||
|
elements.push(element);
|
||||||
|
root.appendChild(element);
|
||||||
|
});
|
||||||
|
elements[0].style.marginTop = '0';
|
||||||
|
elements[(elements.length - 1)].style.marginBottom = '0';
|
||||||
|
this._elements = elements;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
const error = 'Card config incorrect.';
|
||||||
|
const element = createCardElement(createErrorConfig(error, config));
|
||||||
|
root.appendChild(element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
set hass(hass) {
|
||||||
|
this._elements.forEach(element => {
|
||||||
|
element.hass = hass;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
customElements.define('hui-column-card', HuiColumnCard);
|
@ -1,6 +1,7 @@
|
|||||||
import fireEvent from '../../../common/dom/fire_event.js';
|
import fireEvent from '../../../common/dom/fire_event.js';
|
||||||
|
|
||||||
import '../cards/hui-camera-preview-card.js';
|
import '../cards/hui-camera-preview-card.js';
|
||||||
|
import '../cards/hui-column-card.js';
|
||||||
import '../cards/hui-entities-card.js';
|
import '../cards/hui-entities-card.js';
|
||||||
import '../cards/hui-entity-filter-card.js';
|
import '../cards/hui-entity-filter-card.js';
|
||||||
import '../cards/hui-glance-card';
|
import '../cards/hui-glance-card';
|
||||||
@ -19,6 +20,7 @@ import createErrorCardConfig from './create-error-card-config.js';
|
|||||||
|
|
||||||
const CARD_TYPES = [
|
const CARD_TYPES = [
|
||||||
'camera-preview',
|
'camera-preview',
|
||||||
|
'column',
|
||||||
'entities',
|
'entities',
|
||||||
'entity-filter',
|
'entity-filter',
|
||||||
'entity-picture',
|
'entity-picture',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user