diff --git a/package-lock.json b/package-lock.json index 49df429..042a041 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@berrywhite/lovelace-shutter-row", - "version": "0.3.2", + "version": "0.3.3", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@berrywhite/lovelace-shutter-row", - "version": "0.3.2", + "version": "0.3.3", "license": "MIT", "dependencies": { "@mdi/js": "^7.0.96", diff --git a/package.json b/package.json index 567ca58..81abd15 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@berrywhite/lovelace-shutter-row", "private": true, - "version": "0.3.2", + "version": "0.3.3", "description": "Home Assistant Lovelace Shutter Row Card", "main": "shutter-row.js", "module": "shutter-row.js", diff --git a/shutter-row.js b/shutter-row.js index ea07508..0d79f67 100644 --- a/shutter-row.js +++ b/shutter-row.js @@ -136,7 +136,7 @@ var mdiStop = "M18,18H6V6H18V18Z"; const HASSIO_CARD_ID = "shutter-row"; const HASSIO_CARD_EDITOR_ID = HASSIO_CARD_ID + "-editor"; const HASSIO_CARD_NAME = "Shutter Row"; -const VERSION = "0.3.2"; +const VERSION = "0.3.3"; // SVG PATHS const PATH_SHUTTER_100 = @@ -687,36 +687,40 @@ ha-icon-button.active-icon { color: #fdd835 !important; color: var(--paper-item-icon-active-color, #fdd835) !important; } +div.content { + cursor: pointer; +} div.card-row { --card-row-height: 48px; + --ha-icon-height: 40px; display: flex; align-items: center; height: var(--card-row-height); } -div.card-row.first-row ha-icon { - width: 40px; - height: 40px; - line-height: 40px; -} -div.card-row.first-row ha-icon-button { - width: var(--card-row-height); - height: var(--card-row-height); - line-height: var(--card-row-height); -} div.card-row.first-row ha-icon, -div.card-row.first-row ha-icon-button { +div.card-row.first-row ha-svg-icon-box { display: inline-block; text-align: center; - cursor: pointer; -} -div.entity-icon ha-icon { color: #44739e; color: var(--paper-item-icon-color, #44739e); + width: var(--ha-icon-height); + height: var(--ha-icon-height); + line-height: var(--ha-icon-height); + margin-right: 8px; +} +div.card-row.first-row ha-svg-icon-box { + flex: 0 0 var(--ha-icon-height); + position: relative; + display: inline-block; + border-radius: 50%; + text-align: center; + background-size: cover; + vertical-align: middle; + box-sizing: border-box; } div.card-row.first-row span.entity-name { - margin-left: 16px; + margin-left: 8px; margin-right: 8px; - cursor: pointer; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; @@ -728,11 +732,11 @@ div.card-row.first-row div.controls { } div.card-row.second-row ha-slider { width: 100%; - padding-left: var(--card-row-height); + margin-left: 42px; box-sizing: border-box; } div.card-row.second-row div.infos { - width: 175px; + width: 215px; text-align: right; } div.card-row.preset-buttons { @@ -744,7 +748,6 @@ div.card-row.preset-buttons { div.card-row.preset-buttons div.button { position: relative; padding: 0.5em 0.75em; - cursor: pointer; } div.card-row.preset-buttons div.button span { margin-left: 0.25em; @@ -994,19 +997,21 @@ class ShutterRow extends s { * @returns html */ renderIcon() { + let getClassName = () => { + if (this.config.state_color != undefined && this.config.state_color && this.stateDisplay != "closed") + return "active-icon"; + return ""; + }; + let getIconElementById = (icon) => { - return y``; + return y``; }; let getIconElementByPath = (path) => { - return y``; + return y` + + + + `; }; // Check for moving @@ -1015,7 +1020,6 @@ class ShutterRow extends s { // Check for entity defined icon if (this.state.attributes.icon != undefined) return getIconElementById(this.state.attributes.icon); - this.getPosition(); // Use dynamic icon if (this.downReached()) return getIconElementByPath(PATH_SHUTTER_100); @@ -1051,9 +1055,10 @@ class ShutterRow extends s {
${this.renderIcon()}
- ${this.getName()} + ${this.getName()}
{ presetsHtml.push(this.renderPreset(presetConfig)); }); - return y`
${presetsHtml}
`; + return y`
${presetsHtml}
`; } /** @@ -1152,13 +1160,13 @@ class ShutterRow extends s { return y`
- - ${presetConfig.name} + + ${presetConfig.name} ${ripple}
`; @@ -1171,7 +1179,15 @@ class ShutterRow extends s { renderContent() { if (this.config.disable_position) return y` ${this.renderFirstRow()} ${this.renderPresetsRow()} `; - return y` ${this.renderFirstRow()} ${this.renderSecondRow()} ${this.renderPresetsRow()} `; + return y`${this.renderFirstRow()} ${this.renderSecondRow()} ${this.renderPresetsRow()}`; + } + + /** + * Render card container with content + * @returns html + */ + renderContainer() { + return y`
${this.renderContent()}
`; } /** @@ -1239,10 +1255,10 @@ class ShutterRow extends s { this.setMeta(); // If card is part of group, root element is not needed - if (this.config.group) return this.renderContent(); + if (this.config.group) return this.renderContainer(); // Render card with element - return y` ${this.renderContent()} `; + return y`${this.renderContainer()}`; } /* @@ -1362,7 +1378,10 @@ class ShutterRow extends s { /** * Open HA more info */ - moreInfo() { + onMoreClick(event) { + // Exclude already binded elements + if (event.target.classList.contains("exclude-on-click")) return; + let entityId = this.config.entity; ne( this, diff --git a/src/const.js b/src/const.js index ef8991a..932e55f 100644 --- a/src/const.js +++ b/src/const.js @@ -2,7 +2,7 @@ export const HASSIO_CARD_ID = "shutter-row"; export const HASSIO_CARD_EDITOR_ID = HASSIO_CARD_ID + "-editor"; export const HASSIO_CARD_NAME = "Shutter Row"; -export const VERSION = "0.3.2"; +export const VERSION = "0.3.3"; // SVG PATHS export const PATH_SHUTTER_100 = diff --git a/src/shutter-row.js b/src/shutter-row.js index 3425551..a3bfa16 100644 --- a/src/shutter-row.js +++ b/src/shutter-row.js @@ -261,19 +261,21 @@ class ShutterRow extends LitElement { * @returns html */ renderIcon() { + let getClassName = () => { + if (this.config.state_color != undefined && this.config.state_color && this.stateDisplay != "closed") + return "active-icon"; + return ""; + }; + let getIconElementById = (icon) => { - return html``; + return html``; }; let getIconElementByPath = (path) => { - return html``; + return html` + + + + `; }; // Check for moving @@ -282,7 +284,6 @@ class ShutterRow extends LitElement { // Check for entity defined icon if (this.state.attributes.icon != undefined) return getIconElementById(this.state.attributes.icon); - this.getPosition(); // Use dynamic icon if (this.downReached()) return getIconElementByPath(PATH_SHUTTER_100); @@ -318,9 +319,10 @@ class ShutterRow extends LitElement {
${this.renderIcon()}
- ${this.getName()} + ${this.getName()}
{ presetsHtml.push(this.renderPreset(presetConfig)); }); - return html`
${presetsHtml}
`; + return html`
${presetsHtml}
`; } /** @@ -419,13 +424,13 @@ class ShutterRow extends LitElement { return html`
- - ${presetConfig.name} + + ${presetConfig.name} ${ripple}
`; @@ -438,7 +443,15 @@ class ShutterRow extends LitElement { renderContent() { if (this.config.disable_position) return html` ${this.renderFirstRow()} ${this.renderPresetsRow()} `; - return html` ${this.renderFirstRow()} ${this.renderSecondRow()} ${this.renderPresetsRow()} `; + return html`${this.renderFirstRow()} ${this.renderSecondRow()} ${this.renderPresetsRow()}`; + } + + /** + * Render card container with content + * @returns html + */ + renderContainer() { + return html`
${this.renderContent()}
`; } /** @@ -506,10 +519,10 @@ class ShutterRow extends LitElement { this.setMeta(); // If card is part of group, root element is not needed - if (this.config.group) return this.renderContent(); + if (this.config.group) return this.renderContainer(); // Render card with element - return html` ${this.renderContent()} `; + return html`${this.renderContainer()}`; } /* @@ -629,7 +642,10 @@ class ShutterRow extends LitElement { /** * Open HA more info */ - moreInfo() { + onMoreClick(event) { + // Exclude already binded elements + if (event.target.classList.contains("exclude-on-click")) return; + let entityId = this.config.entity; fireEvent( this, diff --git a/src/style.css b/src/style.css index 185cf98..02f5b95 100644 --- a/src/style.css +++ b/src/style.css @@ -10,35 +10,39 @@ ha-icon.active-icon, ha-icon-button.active-icon { color: var(--paper-item-icon-active-color, #fdd835) !important; } +div.content { + cursor: pointer; +} div.card-row { --card-row-height: 48px; + --ha-icon-height: 40px; display: flex; align-items: center; height: var(--card-row-height); } -div.card-row.first-row ha-icon { - width: 40px; - height: 40px; - line-height: 40px; -} -div.card-row.first-row ha-icon-button { - width: var(--card-row-height); - height: var(--card-row-height); - line-height: var(--card-row-height); -} div.card-row.first-row ha-icon, -div.card-row.first-row ha-icon-button { +div.card-row.first-row ha-svg-icon-box { display: inline-block; text-align: center; - cursor: pointer; -} -div.entity-icon ha-icon { color: var(--paper-item-icon-color, #44739e); + width: var(--ha-icon-height); + height: var(--ha-icon-height); + line-height: var(--ha-icon-height); + margin-right: 8px; +} +div.card-row.first-row ha-svg-icon-box { + flex: 0 0 var(--ha-icon-height); + position: relative; + display: inline-block; + border-radius: 50%; + text-align: center; + background-size: cover; + vertical-align: middle; + box-sizing: border-box; } div.card-row.first-row span.entity-name { - margin-left: 16px; + margin-left: 8px; margin-right: 8px; - cursor: pointer; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; @@ -50,11 +54,11 @@ div.card-row.first-row div.controls { } div.card-row.second-row ha-slider { width: 100%; - padding-left: var(--card-row-height); + margin-left: 42px; box-sizing: border-box; } div.card-row.second-row div.infos { - width: 175px; + width: 215px; text-align: right; } div.card-row.preset-buttons { @@ -66,7 +70,6 @@ div.card-row.preset-buttons { div.card-row.preset-buttons div.button { position: relative; padding: 0.5em 0.75em; - cursor: pointer; } div.card-row.preset-buttons div.button span { margin-left: 0.25em;