fix: keep compact trend icons aligned beside room values

This commit is contained in:
jhartworks committed 2026-11-11 12:15:37 +01:00
1 parent cfc77787a0
commit 2bf5f4a60a
10 files changed
+238 -157

No files matched your search

+2 -2
View File
@@ -27,10 +27,10 @@ class NfTrendButton extends LitElement {
if (!loggedEntities(this.hass, this.ids).length) return nothing;
const title = this.label ? `Trend anzeigen: ${this.label}` : "Trend anzeigen";
return html`<button type="button" title=${title} aria-label=${title} aria-haspopup="dialog" ?disabled=${this.busy} @pointerdown=${(e: Event) => e.stopPropagation()} @click=${(e: Event) => void this.open(e)}>
<svg width="15" height="15" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M3 2v15h15M5 13l4-5 4 2 4-6"/></svg>
<svg width="12" height="12" viewBox="0 0 20 20" fill="none" stroke="currentColor" stroke-width="1.5" aria-hidden="true"><path d="M3 2v15h15M5 13l4-5 4 2 4-6"/></svg>
</button>${this.error ? html`<span role="alert">${this.error}</span>` : nothing}`;
}
static styles = css`:host{display:inline-flex;vertical-align:middle;margin-left:4px;font-weight:normal}button{display:inline-flex;align-items:center;justify-content:center;width:25px;height:25px;padding:3px;border:1px solid currentColor;border-radius:6px;background:transparent;color:var(--nf-accent,#40c8ff);opacity:.8;cursor:pointer}button:hover,button:focus-visible{opacity:1;background:#40c8ff18}button:disabled{opacity:.4}span{font:12px system-ui;color:#ff9b9b;max-width:180px}`;
static styles = css`:host{position:relative;display:inline-flex;flex:0 0 18px;width:18px;height:18px;vertical-align:middle;margin-left:3px;font-weight:normal;line-height:0}button{display:inline-flex;align-items:center;justify-content:center;box-sizing:border-box;width:18px;height:18px;padding:2px;border:0;border-radius:3px;background:transparent;color:var(--nf-accent,#40c8ff);opacity:.8;cursor:pointer}svg{display:block;flex-shrink:0}button:hover,button:focus-visible{opacity:1;background:#40c8ff18}button:focus-visible{outline:1px solid currentColor;outline-offset:1px}button:disabled{opacity:.4}span{position:absolute;right:0;top:22px;z-index:10;box-sizing:border-box;width:200px;padding:8px;border:1px solid #ff9b9b50;border-radius:6px;background:var(--nf-chrome-solid,#1c1c1c);font:12px/1.4 system-ui;color:#ff9b9b;white-space:normal}`;
}
if (!customElements.get("nf-trend-button")) customElements.define("nf-trend-button", NfTrendButton);
+25 -6
View File
@@ -21,6 +21,7 @@ import type { PlanPoint } from "../viewer/live-energy.ts";
import type { RoomClimateCard } from "./room-climate-card.ts";
import { fromCelsius, tempUnit } from "../devices.ts";
import { trendButton } from "../components/trend-button.ts";
import { loggedEntities } from "../trend-data.ts";
export interface HouseCard {
kind: "house";
@@ -317,11 +318,12 @@ function heatPumpCard(hass: HomeAssistant | undefined, c: HeatPumpCard, i: numbe
function roomClimateCard(hass: HomeAssistant | undefined, c: RoomClimateCard, i: number): TemplateResult {
const value = (n: number | null, digits: number, unit: string) => n === null ? "–" : `${formatNumber(hass, n, digits)} ${unit}`;
return html`<div class="live-card live-card-roomclimate" data-i=${i} data-room=${c.roomId} role="group" aria-label=${`${c.name || translate(hass, "room")} · ${translate(hass, "climate")}`}>
${c.showTemperature ? html`<div class="live-row live-climate-temperature"><span title=${translate(hass, "climate_temperature")} aria-label=${translate(hass, "climate_temperature")}>🌡</span><b>${value(c.temperature === null ? null : hass ? fromCelsius(hass, c.temperature) : c.temperature, 1, hass ? tempUnit(hass) : "°C")}${trendButton(hass, c.sources?.temperature ?? [], translate(hass, "climate_temperature"))}</b></div>` : nothing}
${c.showHumidity ? html`<div class="live-row live-climate-humidity"><span title=${translate(hass, "climate_humidity")} aria-label=${translate(hass, "climate_humidity")}>💧</span><b>${value(c.humidity, 0, "%")}${trendButton(hass, c.sources?.humidity ?? [], translate(hass, "climate_humidity"))}</b></div>` : nothing}
${c.showCo2 ? html`<div class="live-row live-climate-co2"><span title=${translate(hass, "climate_co2")} aria-label=${translate(hass, "climate_co2")}>☁</span><b>${value(c.co2, 0, "ppm")}${trendButton(hass, c.sources?.co2 ?? [], translate(hass, "climate_co2"))}</b></div>` : nothing}
${c.showIlluminance ? html`<div class="live-row live-climate-illuminance"><span title=${translate(hass, "climate_illuminance")} aria-label=${translate(hass, "climate_illuminance")}>☀</span><b>${value(c.illuminance, 0, "lx")}${trendButton(hass, c.sources?.illuminance ?? [], translate(hass, "climate_illuminance"))}</b></div>` : nothing}
const trends = Object.values(c.sources ?? {}).some((ids) => loggedEntities(hass, ids).length > 0);
return html`<div class="live-card live-card-roomclimate ${trends ? "live-climate-trends" : ""}" data-i=${i} data-room=${c.roomId} role="group" aria-label=${`${c.name || translate(hass, "room")} · ${translate(hass, "climate")}`}>
${c.showTemperature ? html`<div class="live-row live-climate-temperature"><span title=${translate(hass, "climate_temperature")} aria-label=${translate(hass, "climate_temperature")}>🌡</span><b>${value(c.temperature === null ? null : hass ? fromCelsius(hass, c.temperature) : c.temperature, 1, hass ? tempUnit(hass) : "°C")}</b>${trendButton(hass, c.sources?.temperature ?? [], translate(hass, "climate_temperature"))}</div>` : nothing}
${c.showHumidity ? html`<div class="live-row live-climate-humidity"><span title=${translate(hass, "climate_humidity")} aria-label=${translate(hass, "climate_humidity")}>💧</span><b>${value(c.humidity, 0, "%")}</b>${trendButton(hass, c.sources?.humidity ?? [], translate(hass, "climate_humidity"))}</div>` : nothing}
${c.showCo2 ? html`<div class="live-row live-climate-co2"><span title=${translate(hass, "climate_co2")} aria-label=${translate(hass, "climate_co2")}>☁</span><b>${value(c.co2, 0, "ppm")}</b>${trendButton(hass, c.sources?.co2 ?? [], translate(hass, "climate_co2"))}</div>` : nothing}
${c.showIlluminance ? html`<div class="live-row live-climate-illuminance"><span title=${translate(hass, "climate_illuminance")} aria-label=${translate(hass, "climate_illuminance")}>☀</span><b>${value(c.illuminance, 0, "lx")}</b>${trendButton(hass, c.sources?.illuminance ?? [], translate(hass, "climate_illuminance"))}</div>` : nothing}
</div>`;
}
@@ -439,7 +441,24 @@ export const liveCardStyles = css`
box-sizing: border-box;
}
.live-card-roomclimate .live-row {
gap: 12px;
display: grid;
grid-template-columns: 14px minmax(0, 1fr);
align-items: center;
column-gap: 6px;
min-height: 18px;
}
.live-climate-trends .live-row {
grid-template-columns: 14px minmax(0, 1fr) 18px;
}
.live-card-roomclimate .live-row b {
justify-self: end;
white-space: nowrap;
line-height: 18px;
font-variant-numeric: tabular-nums;
}
.live-card-roomclimate nf-trend-button {
grid-column: 3;
margin-left: 0;
}
.live-climate-temperature b { color: color-mix(in srgb, #ffca8a 80%, var(--nf-text)); }
.live-climate-humidity b { color: color-mix(in srgb, #7dd3fc 80%, var(--nf-text)); }
+20
View File
@@ -219,6 +219,25 @@ try {
});
await page.waitForFunction(() => window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate").length === 2);
const text = () => page.evaluate(() => window.climateView.shadowRoot.querySelector(`.live-card[data-room="${window.climateRoomId}"]`).textContent);
await page.evaluate(() => {
window.assertClimateLayout = () => {
for (const card of window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate")) {
const rows = [...card.querySelectorAll(".live-row")], bounds = rows.map((r) => r.getBoundingClientRect());
const values = rows.map((r) => r.querySelector("b").getBoundingClientRect());
if (Math.max(...values.map((r) => r.right)) - Math.min(...values.map((r) => r.right)) > .5) throw new Error("Logged and unlogged values must share the same right edge");
if (Math.max(...bounds.map((r) => r.height)) > 18.5 || Math.max(...bounds.map((r) => r.height)) - Math.min(...bounds.map((r) => r.height)) > .5) throw new Error("A trend icon must not increase a climate row's height");
for (const row of rows) {
const value = row.querySelector("b").getBoundingClientRect(), metric = row.querySelector("span").getBoundingClientRect();
if (metric.right > value.left) throw new Error("The metric symbol must not overlap its value");
const trend = row.querySelector("nf-trend-button");
if (!trend) continue;
const button = trend.shadowRoot.querySelector("button").getBoundingClientRect(), glyph = trend.shadowRoot.querySelector("svg").getBoundingClientRect();
if (button.width > 18.5 || button.height > 18.5 || glyph.width > 12.5 || value.right > button.left) throw new Error("The compact trend symbol must occupy its own column");
}
}
};
});
await page.evaluate(async () => { for (const b of window.climateView.shadowRoot.querySelectorAll("nf-trend-button")) await b.updateComplete; window.assertClimateLayout(); });
assert.match(await text(), /21,5\s*°C/);
assert.match(await text(), /52\s*%/);
assert.match(await text(), /780\s*ppm/);
@@ -322,6 +341,7 @@ try {
await page.setViewport({ width: 390, height: 844 });
await page.evaluate(() => { window.nfPanel.narrow = true; });
await page.waitForFunction(() => [...window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate")].every((c) => { const r = c.getBoundingClientRect(); return r.left >= 0 && r.right <= innerWidth; }));
await page.evaluate(() => window.assertClimateLayout());
await page.screenshot({ path: join(out, "symcon-climate-mobile.png") });
await page.evaluate(() => { const p = window.nfPanel; p._floorId = window.climateFloorId; p._roomId = window.climateRoomId; });
await page.waitForFunction(() => window.climateView.panelOpen && window.climateView.shadowRoot.querySelectorAll(".live-card-roomclimate").length === 1);