mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
Fix resize observers and update gauge styling (#5949)
This commit is contained in:
parent
28e0384b55
commit
3a453f5843
@ -238,9 +238,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
private async _attachObserver(): Promise<void> {
|
private async _attachObserver(): Promise<void> {
|
||||||
await installResizeObserver();
|
await installResizeObserver();
|
||||||
|
|
||||||
this._resizeObserver = new ResizeObserver(
|
this._resizeObserver = new ResizeObserver(this._debouncedMeasure);
|
||||||
debounce(() => this._measureCard(), 250, false)
|
|
||||||
);
|
|
||||||
|
|
||||||
const card = this.shadowRoot!.querySelector("ha-card");
|
const card = this.shadowRoot!.querySelector("ha-card");
|
||||||
// If we show an error or warning there is no ha-card
|
// If we show an error or warning there is no ha-card
|
||||||
@ -250,6 +248,8 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
this._resizeObserver.observe(card);
|
this._resizeObserver.observe(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _debouncedMeasure = debounce(() => this._measureCard(), 250, true);
|
||||||
|
|
||||||
private _measureCard() {
|
private _measureCard() {
|
||||||
if (!this.isConnected) {
|
if (!this.isConnected) {
|
||||||
return;
|
return;
|
||||||
@ -277,7 +277,7 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
height: 100%;
|
height: 100%;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
padding: 16px 16px 0 16px;
|
padding: 16px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
@ -293,37 +293,39 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
round-slider {
|
round-slider {
|
||||||
max-width: 200px;
|
max-width: 200px;
|
||||||
--round-slider-path-width: 35px;
|
--round-slider-path-width: 35px;
|
||||||
--round-slider-path-color: var(--disabled-text-color);
|
--round-slider-path-color: var(--primary-background-color);
|
||||||
--round-slider-linecap: "butt";
|
--round-slider-linecap: "butt";
|
||||||
}
|
}
|
||||||
|
|
||||||
.gauge-data {
|
.gauge-data {
|
||||||
line-height: 1;
|
|
||||||
text-align: center;
|
text-align: center;
|
||||||
position: relative;
|
line-height: initial;
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
margin-top: -28px;
|
margin-top: -26px;
|
||||||
margin-bottom: 14px;
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gauge-data .percent {
|
.gauge-data .percent {
|
||||||
|
white-space: nowrap;
|
||||||
font-size: 28px;
|
font-size: 28px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.gauge-data .name {
|
.gauge-data .name {
|
||||||
padding-top: 6px;
|
font-size: 15px;
|
||||||
font-size: 14px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ============= NARROW ============= */
|
/* ============= NARROW ============= */
|
||||||
|
|
||||||
|
:host([narrow]) ha-card {
|
||||||
|
padding: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
:host([narrow]) round-slider {
|
:host([narrow]) round-slider {
|
||||||
--round-slider-path-width: 22px;
|
--round-slider-path-width: 22px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([narrow]) .gauge-data {
|
:host([narrow]) .gauge-data {
|
||||||
margin-top: -24px;
|
margin-top: -22px;
|
||||||
margin-bottom: 12px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([narrow]) .gauge-data .percent {
|
:host([narrow]) .gauge-data .percent {
|
||||||
@ -331,30 +333,29 @@ class HuiGaugeCard extends LitElement implements LovelaceCard {
|
|||||||
}
|
}
|
||||||
|
|
||||||
:host([narrow]) .gauge-data .name {
|
:host([narrow]) .gauge-data .name {
|
||||||
font-size: 12px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ============= VERY NARROW ============= */
|
/* ============= VERY NARROW ============= */
|
||||||
|
|
||||||
|
:host([narrow]) ha-card {
|
||||||
|
padding: 4px;
|
||||||
|
}
|
||||||
|
|
||||||
:host([veryNarrow]) round-slider {
|
:host([veryNarrow]) round-slider {
|
||||||
--round-slider-path-width: 15px;
|
--round-slider-path-width: 15px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([veryNarrow]) ha-card {
|
|
||||||
padding-bottom: 16px;
|
|
||||||
}
|
|
||||||
|
|
||||||
:host([veryNarrow]) .gauge-data {
|
:host([veryNarrow]) .gauge-data {
|
||||||
margin-top: 0;
|
margin-top: -16px;
|
||||||
margin-bottom: 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([veryNarrow]) .gauge-data .percent {
|
:host([veryNarrow]) .gauge-data .percent {
|
||||||
font-size: 20px;
|
font-size: 16px;
|
||||||
}
|
}
|
||||||
|
|
||||||
:host([veryNarrow]) .gauge-data .name {
|
:host([veryNarrow]) .gauge-data .name {
|
||||||
font-size: 10px;
|
font-size: 12px;
|
||||||
}
|
}
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
@ -618,6 +618,8 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _debouncedMeasure = debounce(() => this._measureCard(), 250, true);
|
||||||
|
|
||||||
private _measureCard() {
|
private _measureCard() {
|
||||||
const card = this.shadowRoot!.querySelector("ha-card");
|
const card = this.shadowRoot!.querySelector("ha-card");
|
||||||
if (!card) {
|
if (!card) {
|
||||||
@ -630,9 +632,7 @@ export class HuiMediaControlCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
private async _attachObserver(): Promise<void> {
|
private async _attachObserver(): Promise<void> {
|
||||||
await installResizeObserver();
|
await installResizeObserver();
|
||||||
this._resizeObserver = new ResizeObserver(
|
this._resizeObserver = new ResizeObserver(this._debouncedMeasure);
|
||||||
debounce(() => this._measureCard(), 250, false)
|
|
||||||
);
|
|
||||||
|
|
||||||
const card = this.shadowRoot!.querySelector("ha-card");
|
const card = this.shadowRoot!.querySelector("ha-card");
|
||||||
// If we show an error or warning there is no ha-card
|
// If we show an error or warning there is no ha-card
|
||||||
|
@ -290,9 +290,7 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
|||||||
|
|
||||||
private async _attachObserver(): Promise<void> {
|
private async _attachObserver(): Promise<void> {
|
||||||
await installResizeObserver();
|
await installResizeObserver();
|
||||||
this._resizeObserver = new ResizeObserver(
|
this._resizeObserver = new ResizeObserver(this._debouncedMeasure);
|
||||||
debounce(() => this._measureCard(), 250, false)
|
|
||||||
);
|
|
||||||
|
|
||||||
const card = this.shadowRoot!.querySelector("ha-card");
|
const card = this.shadowRoot!.querySelector("ha-card");
|
||||||
// If we show an error or warning there is no ha-card
|
// If we show an error or warning there is no ha-card
|
||||||
@ -302,6 +300,8 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
|||||||
this._resizeObserver.observe(card);
|
this._resizeObserver.observe(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _debouncedMeasure = debounce(() => this._measureCard(), 250, true);
|
||||||
|
|
||||||
private _measureCard() {
|
private _measureCard() {
|
||||||
if (!this.isConnected) {
|
if (!this.isConnected) {
|
||||||
return;
|
return;
|
||||||
|
@ -53,7 +53,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
|||||||
this._veryNarrow = (this.clientWidth || 0) < 225;
|
this._veryNarrow = (this.clientWidth || 0) < 225;
|
||||||
},
|
},
|
||||||
250,
|
250,
|
||||||
false
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
public setConfig(config: EntityConfig): void {
|
public setConfig(config: EntityConfig): void {
|
||||||
@ -216,9 +216,7 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow {
|
|||||||
|
|
||||||
private _attachObserver(): void {
|
private _attachObserver(): void {
|
||||||
installResizeObserver().then(() => {
|
installResizeObserver().then(() => {
|
||||||
this._resizeObserver = new ResizeObserver(() =>
|
this._resizeObserver = new ResizeObserver(this._debouncedResizeListener);
|
||||||
this._debouncedResizeListener()
|
|
||||||
);
|
|
||||||
|
|
||||||
this._resizeObserver.observe(this);
|
this._resizeObserver.observe(this);
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user