mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-18 23:06:40 +00:00
Request darktheme optimized brand images if dark theme is used (#9777)
This commit is contained in:
parent
b12e062d94
commit
aab0b8a3ce
@ -41,7 +41,12 @@ class StepFlowPickFlow extends LitElement {
|
|||||||
<img
|
<img
|
||||||
slot="item-icon"
|
slot="item-icon"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
src=${brandsUrl(flow.handler, "icon", true)}
|
src=${brandsUrl({
|
||||||
|
domain: flow.handler,
|
||||||
|
type: "icon",
|
||||||
|
useFallback: true,
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -96,7 +96,12 @@ class StepFlowPickHandler extends LitElement {
|
|||||||
<img
|
<img
|
||||||
slot="item-icon"
|
slot="item-icon"
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
src=${brandsUrl(handler.slug, "icon", true)}
|
src=${brandsUrl({
|
||||||
|
domain: handler.slug,
|
||||||
|
type: "icon",
|
||||||
|
useFallback: true,
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
@ -11,13 +11,19 @@ class IntegrationBadge extends LitElement {
|
|||||||
|
|
||||||
@property() public badgeIcon?: string;
|
@property() public badgeIcon?: string;
|
||||||
|
|
||||||
|
@property({ type: Boolean }) public darkOptimizedIcon?: boolean;
|
||||||
|
|
||||||
@property({ type: Boolean, reflect: true }) public clickable = false;
|
@property({ type: Boolean, reflect: true }) public clickable = false;
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
return html`
|
return html`
|
||||||
<div class="icon">
|
<div class="icon">
|
||||||
<img
|
<img
|
||||||
src=${brandsUrl(this.domain, "icon")}
|
src=${brandsUrl({
|
||||||
|
domain: this.domain,
|
||||||
|
type: "icon",
|
||||||
|
darkOptimized: this.darkOptimizedIcon,
|
||||||
|
})}
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
/>
|
/>
|
||||||
${this.badgeIcon
|
${this.badgeIcon
|
||||||
|
@ -78,6 +78,7 @@ class OnboardingIntegrations extends LitElement {
|
|||||||
.domain=${entry.domain}
|
.domain=${entry.domain}
|
||||||
.title=${title}
|
.title=${title}
|
||||||
badgeIcon="hass:check"
|
badgeIcon="hass:check"
|
||||||
|
.darkOptimizedIcon=${this.hass.selectedTheme?.dark}
|
||||||
></integration-badge>
|
></integration-badge>
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
@ -94,6 +95,7 @@ class OnboardingIntegrations extends LitElement {
|
|||||||
clickable
|
clickable
|
||||||
.domain=${flow.handler}
|
.domain=${flow.handler}
|
||||||
.title=${title}
|
.title=${title}
|
||||||
|
.darkOptimizedIcon=${this.hass.selectedTheme?.dark}
|
||||||
></integration-badge>
|
></integration-badge>
|
||||||
</button>
|
</button>
|
||||||
`,
|
`,
|
||||||
|
@ -241,7 +241,11 @@ export class HaConfigDevicePage extends LitElement {
|
|||||||
integrations.length
|
integrations.length
|
||||||
? html`
|
? html`
|
||||||
<img
|
<img
|
||||||
src=${brandsUrl(integrations[0], "logo")}
|
src=${brandsUrl({
|
||||||
|
domain: integrations[0],
|
||||||
|
type: "logo",
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
@load=${this._onImageLoad}
|
@load=${this._onImageLoad}
|
||||||
@error=${this._onImageError}
|
@error=${this._onImageError}
|
||||||
|
@ -34,6 +34,7 @@ import {
|
|||||||
} from "../../../../dialogs/generic/show-dialog-box";
|
} from "../../../../dialogs/generic/show-dialog-box";
|
||||||
import { haStyle } from "../../../../resources/styles";
|
import { haStyle } from "../../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../../types";
|
import { HomeAssistant } from "../../../../types";
|
||||||
|
import { brandsUrl } from "../../../../util/brands-url";
|
||||||
import { documentationUrl } from "../../../../util/documentation-url";
|
import { documentationUrl } from "../../../../util/documentation-url";
|
||||||
import {
|
import {
|
||||||
showEnergySettingsGridFlowFromDialog,
|
showEnergySettingsGridFlowFromDialog,
|
||||||
@ -152,7 +153,11 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
(entry) => html`<div class="row" .entry=${entry}>
|
(entry) => html`<div class="row" .entry=${entry}>
|
||||||
<img
|
<img
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
src="https://brands.home-assistant.io/co2signal/icon.png"
|
src=${brandsUrl({
|
||||||
|
domain: "co2signal",
|
||||||
|
type: "icon",
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
/>
|
/>
|
||||||
<span class="content">${entry.title}</span>
|
<span class="content">${entry.title}</span>
|
||||||
<a href=${`/config/integrations#config_entry=${entry.entry_id}`}>
|
<a href=${`/config/integrations#config_entry=${entry.entry_id}`}>
|
||||||
@ -170,7 +175,11 @@ export class EnergyGridSettings extends LitElement {
|
|||||||
<div class="row border-bottom">
|
<div class="row border-bottom">
|
||||||
<img
|
<img
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
src="https://brands.home-assistant.io/co2signal/icon.png"
|
src=${brandsUrl({
|
||||||
|
domain: "co2signal",
|
||||||
|
type: "icon",
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
/>
|
/>
|
||||||
<mwc-button @click=${this._addCO2Sensor}>
|
<mwc-button @click=${this._addCO2Sensor}>
|
||||||
Add CO2 signal integration
|
Add CO2 signal integration
|
||||||
|
@ -21,6 +21,7 @@ import "../../../../components/entity/ha-entity-picker";
|
|||||||
import type { HaRadio } from "../../../../components/ha-radio";
|
import type { HaRadio } from "../../../../components/ha-radio";
|
||||||
import { showConfigFlowDialog } from "../../../../dialogs/config-flow/show-dialog-config-flow";
|
import { showConfigFlowDialog } from "../../../../dialogs/config-flow/show-dialog-config-flow";
|
||||||
import { ConfigEntry, getConfigEntries } from "../../../../data/config_entries";
|
import { ConfigEntry, getConfigEntries } from "../../../../data/config_entries";
|
||||||
|
import { brandsUrl } from "../../../../util/brands-url";
|
||||||
|
|
||||||
const energyUnits = ["kWh"];
|
const energyUnits = ["kWh"];
|
||||||
|
|
||||||
@ -117,7 +118,11 @@ export class DialogEnergySolarSettings
|
|||||||
<img
|
<img
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
style="height: 24px; margin-right: 16px;"
|
style="height: 24px; margin-right: 16px;"
|
||||||
src="https://brands.home-assistant.io/forecast_solar/icon.png"
|
src=${brandsUrl({
|
||||||
|
domain: "forecast_solar",
|
||||||
|
type: "icon",
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
/>${entry.title}
|
/>${entry.title}
|
||||||
</div>`}
|
</div>`}
|
||||||
>
|
>
|
||||||
|
@ -94,7 +94,12 @@ class IntegrationsCard extends LitElement {
|
|||||||
<td>
|
<td>
|
||||||
<img
|
<img
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
src=${brandsUrl(domain, "icon", true)}
|
src=${brandsUrl({
|
||||||
|
domain: domain,
|
||||||
|
type: "icon",
|
||||||
|
useFallback: true,
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
/>
|
/>
|
||||||
</td>
|
</td>
|
||||||
|
@ -78,7 +78,11 @@ export class HaIntegrationHeader extends LitElement {
|
|||||||
<slot name="above-header"></slot>
|
<slot name="above-header"></slot>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<img
|
<img
|
||||||
src=${brandsUrl(this.domain, "icon")}
|
src=${brandsUrl({
|
||||||
|
domain: this.domain,
|
||||||
|
type: "icon",
|
||||||
|
darkOptimized: this.hass.selectedTheme?.dark,
|
||||||
|
})}
|
||||||
referrerpolicy="no-referrer"
|
referrerpolicy="no-referrer"
|
||||||
@error=${this._onImageError}
|
@error=${this._onImageError}
|
||||||
@load=${this._onImageLoad}
|
@load=${this._onImageLoad}
|
||||||
|
@ -1,8 +1,11 @@
|
|||||||
export const brandsUrl = (
|
export interface BrandsOptions {
|
||||||
domain: string,
|
domain: string;
|
||||||
type: "icon" | "logo",
|
type: "icon" | "logo" | "icon@2x" | "logo@2x";
|
||||||
useFallback?: boolean
|
useFallback?: boolean;
|
||||||
): string =>
|
darkOptimized?: boolean;
|
||||||
`https://brands.home-assistant.io/${
|
}
|
||||||
useFallback ? "_/" : ""
|
|
||||||
}${domain}/${type}.png`;
|
export const brandsUrl = (options: BrandsOptions): string =>
|
||||||
|
`https://brands.home-assistant.io/${options.useFallback ? "_/" : ""}${
|
||||||
|
options.domain
|
||||||
|
}/${options.darkOptimized ? "dark_" : ""}${options.type}.png`;
|
||||||
|
@ -1,33 +1,41 @@
|
|||||||
import { assert } from "chai";
|
import { assert } from "chai";
|
||||||
import { brandsUrl } from "../../src/util/brands-url";
|
import { brandsUrl } from "../../src/util/brands-url";
|
||||||
|
|
||||||
describe("Generate brands Url", function () {
|
describe("Generate brands Url", () => {
|
||||||
it("Generate logo brands url for cloud component without fallback", function () {
|
it("Generate logo brands url for cloud component without fallback", () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
brandsUrl("cloud", "logo"),
|
brandsUrl({ domain: "cloud", type: "logo" }),
|
||||||
"https://brands.home-assistant.io/cloud/logo.png"
|
"https://brands.home-assistant.io/cloud/logo.png"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("Generate icon brands url for cloud component without fallback", function () {
|
it("Generate icon brands url for cloud component without fallback", () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
brandsUrl("cloud", "icon"),
|
brandsUrl({ domain: "cloud", type: "icon" }),
|
||||||
"https://brands.home-assistant.io/cloud/icon.png"
|
"https://brands.home-assistant.io/cloud/icon.png"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("Generate logo brands url for cloud component with fallback", function () {
|
it("Generate logo brands url for cloud component with fallback", () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
brandsUrl("cloud", "logo", true),
|
brandsUrl({ domain: "cloud", type: "logo", useFallback: true }),
|
||||||
"https://brands.home-assistant.io/_/cloud/logo.png"
|
"https://brands.home-assistant.io/_/cloud/logo.png"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
it("Generate icon brands url for cloud component with fallback", function () {
|
it("Generate icon brands url for cloud component with fallback", () => {
|
||||||
assert.strictEqual(
|
assert.strictEqual(
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
brandsUrl("cloud", "icon", true),
|
brandsUrl({ domain: "cloud", type: "icon", useFallback: true }),
|
||||||
"https://brands.home-assistant.io/_/cloud/icon.png"
|
"https://brands.home-assistant.io/_/cloud/icon.png"
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("Generate dark theme optimized logo brands url for cloud component without fallback", () => {
|
||||||
|
assert.strictEqual(
|
||||||
|
// @ts-ignore
|
||||||
|
brandsUrl({ domain: "cloud", type: "logo", darkOptimized: true }),
|
||||||
|
"https://brands.home-assistant.io/cloud/dark_logo.png"
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user