mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 04:46:34 +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;
|
||||
icon?: string;
|
||||
url: string;
|
||||
new_tab?: boolean;
|
||||
download?: boolean;
|
||||
}
|
||||
export interface TextConfig {
|
||||
type: "text";
|
||||
|
@ -7,6 +7,7 @@ import {
|
||||
LitElement,
|
||||
TemplateResult,
|
||||
} from "lit-element";
|
||||
import { ifDefined } from "lit-html/directives/if-defined";
|
||||
import "../../../components/ha-icon";
|
||||
import { HomeAssistant } from "../../../types";
|
||||
import { LovelaceRow, WeblinkConfig } from "../entity-rows/types";
|
||||
@ -37,8 +38,9 @@ class HuiWeblinkRow extends LitElement implements LovelaceRow {
|
||||
return html`
|
||||
<a
|
||||
href=${this._config.url}
|
||||
target=${this._config.url.indexOf("://") !== -1 ? "_blank" : ""}
|
||||
target=${ifDefined(this._computeTargetValue())}
|
||||
rel="noreferrer"
|
||||
?download=${this._config.download}
|
||||
>
|
||||
<ha-icon .icon="${this._config.icon}"></ha-icon>
|
||||
<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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user