Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/panels/lovelace/create-element/create-row-element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ const LAZY_LOAD_TYPES = {
cast: () => import("../special-rows/hui-cast-row"),
buttons: () => import("../special-rows/hui-buttons-row"),
attribute: () => import("../special-rows/hui-attribute-row"),
text: () => import("../special-rows/hui-text-row"),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to Lazy load?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lazy load is the default. Only ones that are super popular should be considered to be bundled. Requires an editor too.

};
const DOMAIN_TO_ELEMENT_TYPE = {
_domain_not_found: "text",
Expand Down
9 changes: 8 additions & 1 deletion src/panels/lovelace/entity-rows/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@ export interface WeblinkConfig {
icon?: string;
url: string;
}
export interface TextConfig {
type: "text";
name: string;
icon?: string;
text: string;
}
export interface CallServiceConfig extends EntityConfig {
type: "call-service";
service: string;
Expand Down Expand Up @@ -65,7 +71,8 @@ export type LovelaceRowConfig =
| ButtonRowConfig
| ButtonsRowConfig
| ConditionalRowConfig
| AttributeRowConfig;
| AttributeRowConfig
| TextConfig;

export interface LovelaceRow extends HTMLElement {
hass?: HomeAssistant;
Expand Down
69 changes: 69 additions & 0 deletions src/panels/lovelace/special-rows/hui-text-row.ts
Original file line number Diff line number Diff line change
@@ -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`
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we just use the generic row here to keep it the same as the others? Lest maintenance if it changes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generic row relies on an entity.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah didnt realize

<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;
}
}