fix: keep compact trend icons aligned beside room values
This commit is contained in:
1 parent
cfc77787a0
commit
2bf5f4a60a
10 files changed
+238
-157
No files matched your search
@@ -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);
|
||||
|
||||
|
||||
@@ -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)); }
|
||||
|
||||
Reference in new issue
Block a user