diff --git a/gallery/src/components/demo-card.js b/gallery/src/components/demo-card.js index 211f20bdc4..86ac0ea766 100644 --- a/gallery/src/components/demo-card.js +++ b/gallery/src/components/demo-card.js @@ -2,59 +2,65 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js'; import JsYaml from 'js-yaml'; -import '../../../src/panels/lovelace/cards/hui-glance-card.js'; -import '../../../src/panels/lovelace/cards/hui-picture-entity-card.js'; -import '../../../src/panels/lovelace/cards/hui-picture-glance-card.js'; - import HomeAssistant from '../data/hass.js'; import demoStates from '../data/demo_dump.js'; +import createCardElement from '../../../src/panels/lovelace/common/create-card-element.js'; class DemoCard extends PolymerElement { static get template() { return html` -
+

[[config.heading]]

+
+
+ +
`; } static get properties() { return { - type: String, config: { type: Object, observer: '_configChanged' - } + }, + showConfig: Boolean, }; } _configChanged(config) { - const root = this.$.root; - while (root.lastChild) { - root.removeChild(root.lastChild); + const card = this.$.card; + while (card.lastChild) { + card.removeChild(card.lastChild); } const hass = new HomeAssistant(); hass.states = demoStates; - const heading = document.createElement('h2'); - heading.innerText = config.heading; - root.appendChild(heading); - const el = document.createElement(this.type); - el.setConfig(JsYaml.safeLoad(config.config)[0]); + const el = createCardElement(JsYaml.safeLoad(config.config)[0]); el.hass = hass; - root.appendChild(el); - const yaml = document.createElement('pre'); - yaml.innerText = config.config.trim(); - root.appendChild(yaml); + card.appendChild(el); + } + + _trim(config) { + return config.trim(); } } diff --git a/gallery/src/components/demo-cards.js b/gallery/src/components/demo-cards.js index aea00bbcdf..ef628f1aef 100644 --- a/gallery/src/components/demo-cards.js +++ b/gallery/src/components/demo-cards.js @@ -1,5 +1,7 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js'; +import '@polymer/app-layout/app-toolbar/app-toolbar.js'; +import '@polymer/paper-toggle-button/paper-toggle-button.js'; import './demo-card.js'; @@ -7,41 +9,52 @@ class DemoCards extends PolymerElement { static get template() { return html` -
+ +
+ Show config +
+
+
+ +
`; } static get properties() { return { - type: String, configs: { type: Object, - observer: '_configsChanged' + }, + showConfig: { + type: Boolean, + value: false, } }; } - - _configsChanged(configs) { - const root = this.$.root; - while (root.lastChild) { - root.removeChild(root.lastChild); - } - - configs.forEach((config) => { - const el = document.createElement('demo-card'); - el.config = config; - el.type = this.type; - root.appendChild(el); - }); - } } customElements.define('demo-cards', DemoCards); diff --git a/gallery/src/demos/demo-hui-glance-card.js b/gallery/src/demos/demo-hui-glance-card.js index 59cb4f526d..c0f2f6c8e8 100644 --- a/gallery/src/demos/demo-hui-glance-card.js +++ b/gallery/src/demos/demo-hui-glance-card.js @@ -130,7 +130,7 @@ const CONFIGS = [ class DemoPicEntity extends PolymerElement { static get template() { return html` - + `; }