Add entity row that displays static text (#5516)

* Add entity row that displays text

* Remove hass type
This commit is contained in:
Paulus Schoutsen 2020-04-15 06:59:33 -07:00 committed by GitHub
parent 8383caf6a6
commit 4f81085d0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 78 additions and 1 deletions

View File

@ -41,6 +41,7 @@ const LAZY_LOAD_TYPES = {
cast: () => import("../special-rows/hui-cast-row"), cast: () => import("../special-rows/hui-cast-row"),
buttons: () => import("../special-rows/hui-buttons-row"), buttons: () => import("../special-rows/hui-buttons-row"),
attribute: () => import("../special-rows/hui-attribute-row"), attribute: () => import("../special-rows/hui-attribute-row"),
text: () => import("../special-rows/hui-text-row"),
}; };
const DOMAIN_TO_ELEMENT_TYPE = { const DOMAIN_TO_ELEMENT_TYPE = {
_domain_not_found: "text", _domain_not_found: "text",

View File

@ -29,6 +29,12 @@ export interface WeblinkConfig {
icon?: string; icon?: string;
url: string; url: string;
} }
export interface TextConfig {
type: "text";
name: string;
icon?: string;
text: string;
}
export interface CallServiceConfig extends EntityConfig { export interface CallServiceConfig extends EntityConfig {
type: "call-service"; type: "call-service";
service: string; service: string;
@ -65,7 +71,8 @@ export type LovelaceRowConfig =
| ButtonRowConfig | ButtonRowConfig
| ButtonsRowConfig | ButtonsRowConfig
| ConditionalRowConfig | ConditionalRowConfig
| AttributeRowConfig; | AttributeRowConfig
| TextConfig;
export interface LovelaceRow extends HTMLElement { export interface LovelaceRow extends HTMLElement {
hass?: HomeAssistant; hass?: HomeAssistant;

View File

@ -0,0 +1,69 @@
import {
html,
LitElement,
TemplateResult,
customElement,
property,
css,
CSSResult,
} from "lit-element";
import { LovelaceRow, TextConfig } from "../entity-rows/types";
import "../../../components/ha-icon";
@customElement("hui-text-row")
class HuiTextRow extends LitElement implements LovelaceRow {
@property() private _config?: TextConfig;
public setConfig(config: TextConfig): void {
if (!config || !config.name || !config.text) {
throw new Error("Invalid Configuration: 'name' and 'text' required");
}
this._config = config;
}
protected render(): TemplateResult {
if (!this._config) {
return html``;
}
return html`
<ha-icon .icon="${this._config.icon}"></ha-icon>
<div class="name">${this._config.name}</div>
<div class="text">${this._config.text}</div>
`;
}
static get styles(): CSSResult {
return css`
:host {
display: flex;
align-items: center;
}
ha-icon {
padding: 8px;
color: var(--paper-item-icon-color);
}
div {
flex: 1;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.name {
margin-left: 16px;
}
.text {
text-align: right;
}
`;
}
}
declare global {
interface HTMLElementTagNameMap {
"hui-text-row": HuiTextRow;
}
}