Add additional weblink attributes (#8295)

This commit is contained in:
Marc Mueller 2021-02-24 17:34:44 +01:00 committed by GitHub
parent db9cea81db
commit 13ac14d449
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -29,6 +29,8 @@ export interface WeblinkConfig {
name?: string; name?: string;
icon?: string; icon?: string;
url: string; url: string;
new_tab?: boolean;
download?: boolean;
} }
export interface TextConfig { export interface TextConfig {
type: "text"; type: "text";

View File

@ -7,6 +7,7 @@ import {
LitElement, LitElement,
TemplateResult, TemplateResult,
} from "lit-element"; } from "lit-element";
import { ifDefined } from "lit-html/directives/if-defined";
import "../../../components/ha-icon"; import "../../../components/ha-icon";
import { HomeAssistant } from "../../../types"; import { HomeAssistant } from "../../../types";
import { LovelaceRow, WeblinkConfig } from "../entity-rows/types"; import { LovelaceRow, WeblinkConfig } from "../entity-rows/types";
@ -37,8 +38,9 @@ class HuiWeblinkRow extends LitElement implements LovelaceRow {
return html` return html`
<a <a
href=${this._config.url} href=${this._config.url}
target=${this._config.url.indexOf("://") !== -1 ? "_blank" : ""} target=${ifDefined(this._computeTargetValue())}
rel="noreferrer" rel="noreferrer"
?download=${this._config.download}
> >
<ha-icon .icon="${this._config.icon}"></ha-icon> <ha-icon .icon="${this._config.icon}"></ha-icon>
<div>${this._config.name}</div> <div>${this._config.name}</div>
@ -66,6 +68,15 @@ class HuiWeblinkRow extends LitElement implements LovelaceRow {
} }
`; `;
} }
protected _computeTargetValue(): string | undefined {
return this._config &&
(this._config.url.indexOf("://") !== -1 ||
this._config.new_tab === true ||
this._config.download === true)
? "_blank"
: undefined;
}
} }
declare global { declare global {