From 8a93284bb36ef238f8fd0f2810663befc298efcf Mon Sep 17 00:00:00 2001 From: Paul Bottein Date: Mon, 4 Dec 2023 14:16:10 +0100 Subject: [PATCH] Use resize-controller instead of container queries (#18885) --- src/components/ha-control-number-buttons.ts | 13 ++- src/panels/calendar/ha-panel-calendar.ts | 3 +- src/panels/todo/ha-panel-todo.ts | 3 +- .../ha-state-control-climate-humidity.ts | 16 +++- .../ha-state-control-climate-temperature.ts | 32 ++++--- .../ha-state-control-humidifier-humidity.ts | 16 +++- .../state-control-circular-slider-style.ts | 90 ++++++++++++------- ...-state-control-water_heater-temperature.ts | 16 +++- 8 files changed, 132 insertions(+), 57 deletions(-) diff --git a/src/components/ha-control-number-buttons.ts b/src/components/ha-control-number-buttons.ts index c68ddd9754..1311b244b3 100644 --- a/src/components/ha-control-number-buttons.ts +++ b/src/components/ha-control-number-buttons.ts @@ -1,3 +1,4 @@ +import { ResizeController } from "@lit-labs/observers/resize-controller"; import { mdiMinus, mdiPlus } from "@mdi/js"; import { CSSResultGroup, @@ -49,6 +50,13 @@ export class HaControlNumberButton extends LitElement { @query("#input") _input!: HTMLDivElement; + private _hideUnit = new ResizeController(this, { + callback: (entries) => { + const width = entries[0]?.contentRect.width; + return width < 100; + }, + }); + private boundedValue(value: number) { const clamped = conditionalClamp(value, this.min, this.max); return Math.round(clamped / this._step) * this._step; @@ -145,7 +153,10 @@ export class HaControlNumberButton extends LitElement { ?disabled=${this.disabled} @keydown=${this._handleKeyDown} > - ${value} ${unit ? html`${unit}` : nothing} + ${value} + ${unit && !this._hideUnit.value + ? html`${unit}` + : nothing}