mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 12:56:37 +00:00
Add additional weblink attributes (#8295)
This commit is contained in:
parent
db9cea81db
commit
13ac14d449
@ -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";
|
||||||
|
@ -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 {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user