diff --git a/gallery/src/components/demo-card.js b/gallery/src/components/demo-card.js new file mode 100644 index 0000000000..211f20bdc4 --- /dev/null +++ b/gallery/src/components/demo-card.js @@ -0,0 +1,61 @@ +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'; + +class DemoCard extends PolymerElement { + static get template() { + return html` + +
+ `; + } + + static get properties() { + return { + type: String, + config: { + type: Object, + observer: '_configChanged' + } + }; + } + + _configChanged(config) { + const root = this.$.root; + while (root.lastChild) { + root.removeChild(root.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]); + el.hass = hass; + root.appendChild(el); + const yaml = document.createElement('pre'); + yaml.innerText = config.config.trim(); + root.appendChild(yaml); + } +} + +customElements.define('demo-card', DemoCard); diff --git a/gallery/src/components/demo-cards.js b/gallery/src/components/demo-cards.js new file mode 100644 index 0000000000..aea00bbcdf --- /dev/null +++ b/gallery/src/components/demo-cards.js @@ -0,0 +1,47 @@ +import { html } from '@polymer/polymer/lib/utils/html-tag.js'; +import { PolymerElement } from '@polymer/polymer/polymer-element.js'; + +import './demo-card.js'; + +class DemoCards extends PolymerElement { + static get template() { + return html` + +
+ `; + } + + static get properties() { + return { + type: String, + configs: { + type: Object, + observer: '_configsChanged' + } + }; + } + + _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 4cf77d876d..59cb4f526d 100644 --- a/gallery/src/demos/demo-hui-glance-card.js +++ b/gallery/src/demos/demo-hui-glance-card.js @@ -1,77 +1,146 @@ import { html } from '@polymer/polymer/lib/utils/html-tag.js'; import { PolymerElement } from '@polymer/polymer/polymer-element.js'; -import '../../../src/panels/lovelace/cards/hui-glance-card.js'; - -import HomeAssistant from '../data/hass.js'; -import demoStates from '../data/demo_dump.js'; +import '../components/demo-cards.js'; const CONFIGS = [ { - entities: [ - 'binary_sensor.movement_backyard', - 'light.bed_light', - 'binary_sensor.basement_floor_wet', - 'sensor.outside_temperature', - 'light.ceiling_lights', - 'switch.ac', - 'lock.kitchen_door' - ], - type: 'glance', - title: 'Glance card sample' + heading: 'Basic example', + config: ` +- type: glance + entities: + - device_tracker.demo_paulus + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + - lock.kitchen_door + - light.ceiling_lights + ` }, { - entities: [ - 'binary_sensor.movement_backyard', - 'light.bed_light', - 'binary_sensor.basement_floor_wet', - 'sensor.outside_temperature', - 'light.ceiling_lights', - 'switch.ac', - 'lock.kitchen_door' - ], - type: 'glance', + heading: 'With title', + config: ` +- type: glance + title: This is glance + entities: + - device_tracker.demo_paulus + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + - lock.kitchen_door + - light.ceiling_lights + ` }, { - entities: [ - 'lock.kitchen_door' - ], - type: 'glance', + heading: 'Custom column width', + config: ` +- type: glance + column_width: calc(100% / 7) + entities: + - device_tracker.demo_paulus + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + - lock.kitchen_door + - light.ceiling_lights + ` + }, + { + heading: 'No name', + config: ` +- type: glance + show_name: false + entities: + - device_tracker.demo_paulus + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + - lock.kitchen_door + - light.ceiling_lights + ` + }, + { + heading: 'No state', + config: ` +- type: glance + show_state: false + entities: + - device_tracker.demo_paulus + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + - lock.kitchen_door + - light.ceiling_lights + ` + }, + { + heading: 'No name and no state', + config: ` +- type: glance + show_name: false + show_state: false + entities: + - device_tracker.demo_paulus + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + - lock.kitchen_door + - light.ceiling_lights + ` + }, + { + heading: 'Custom name', + config: ` +- type: glance + entities: + - entity: device_tracker.demo_paulus + name: ¯\\_(ツ)_/¯ + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + - lock.kitchen_door + - light.ceiling_lights + ` + }, + { + heading: 'Custom tap action', + config: ` +- type: glance + entities: + - entity: lock.kitchen_door + tap_action: toggle + - entity: light.ceiling_lights + tap_action: turn-on + - device_tracker.demo_paulus + - media_player.living_room + - sun.sun + - cover.kitchen_window + - light.kitchen_lights + ` }, - ]; class DemoPicEntity extends PolymerElement { static get template() { return html` - -
-
+ `; } - ready() { - super.ready(); - - const root = this.$.root; - const hass = new HomeAssistant(); - hass.states = demoStates; - console.log(demoStates); - CONFIGS.forEach((config) => { - const el = document.createElement('hui-glance-card'); - el.setConfig(config); - el.hass = hass; - root.appendChild(el); - }); + static get properties() { + return { + _configs: { + type: Object, + value: CONFIGS + } + }; } } diff --git a/gallery/src/ha-gallery.js b/gallery/src/ha-gallery.js index c39f216aed..ffaa3a9a0c 100644 --- a/gallery/src/ha-gallery.js +++ b/gallery/src/ha-gallery.js @@ -20,7 +20,7 @@ class HaGallery extends PolymerElement { -moz-user-select: initial; } app-header-layout { - height: 100vh; + min-height: 100vh; } paper-icon-button.invisible { visibility: hidden; diff --git a/package.json b/package.json index dc2969f82e..1a561668f4 100644 --- a/package.json +++ b/package.json @@ -70,6 +70,7 @@ "fecha": "^2.3.3", "home-assistant-js-websocket": "2.0.1", "intl-messageformat": "^2.2.0", + "js-yaml": "^3.12.0", "leaflet": "^1.3.1", "marked": "^0.4.0", "mdn-polyfills": "^5.8.0",