mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 03:06:41 +00:00
Adapt more info button layout depending of number of items and screen (#17691)
This commit is contained in:
parent
7483833dcd
commit
6f99a39b55
@ -171,15 +171,12 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
--control-select-menu-background-color: var(--disabled-color);
|
--control-select-menu-background-color: var(--disabled-color);
|
||||||
--control-select-menu-background-opacity: 0.2;
|
--control-select-menu-background-opacity: 0.2;
|
||||||
--control-select-menu-border-radius: 14px;
|
--control-select-menu-border-radius: 14px;
|
||||||
--control-select-menu-min-width: 120px;
|
|
||||||
--control-select-menu-max-width: 200px;
|
|
||||||
--control-select-menu-width: 100%;
|
|
||||||
--mdc-icon-size: 20px;
|
--mdc-icon-size: 20px;
|
||||||
|
width: auto;
|
||||||
color: var(--primary-text-color);
|
color: var(--primary-text-color);
|
||||||
-webkit-tap-highlight-color: transparent;
|
-webkit-tap-highlight-color: transparent;
|
||||||
}
|
}
|
||||||
.select-anchor {
|
.select-anchor {
|
||||||
color: var(--control-select-menu-text-color);
|
|
||||||
height: 48px;
|
height: 48px;
|
||||||
padding: 6px 10px;
|
padding: 6px 10px;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
@ -198,11 +195,8 @@ export class HaControlSelectMenu extends SelectBase {
|
|||||||
z-index: 0;
|
z-index: 0;
|
||||||
font-size: inherit;
|
font-size: inherit;
|
||||||
transition: color 180ms ease-in-out;
|
transition: color 180ms ease-in-out;
|
||||||
color: var(--control-text-icon-color);
|
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
min-width: var(--control-select-menu-min-width);
|
width: 100%;
|
||||||
max-width: var(--control-select-menu-max-width);
|
|
||||||
width: var(--control-select-menu-width);
|
|
||||||
user-select: none;
|
user-select: none;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
|
@ -0,0 +1,79 @@
|
|||||||
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
|
import { customElement } from "lit/decorators";
|
||||||
|
import { classMap } from "lit/directives/class-map";
|
||||||
|
|
||||||
|
@customElement("ha-more-info-control-select-container")
|
||||||
|
export class HaMoreInfoControlSelectContainer extends LitElement {
|
||||||
|
protected render(): TemplateResult {
|
||||||
|
const classname = `items-${this.childElementCount}`;
|
||||||
|
|
||||||
|
return html`
|
||||||
|
<div class="controls">
|
||||||
|
<div
|
||||||
|
class="controls-scroll ${classMap({
|
||||||
|
[classname]: true,
|
||||||
|
multiline: this.childElementCount >= 4,
|
||||||
|
})}"
|
||||||
|
>
|
||||||
|
<slot></slot>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
|
static get styles(): CSSResultGroup {
|
||||||
|
return css`
|
||||||
|
.controls {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
.controls-scroll {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: row;
|
||||||
|
justify-content: flex-start;
|
||||||
|
gap: 12px;
|
||||||
|
margin: auto;
|
||||||
|
overflow: auto;
|
||||||
|
-ms-overflow-style: none; /* IE and Edge */
|
||||||
|
scrollbar-width: none; /* Firefox */
|
||||||
|
margin: 0 -24px;
|
||||||
|
padding: 0 24px;
|
||||||
|
}
|
||||||
|
.controls-scroll::-webkit-scrollbar {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
::slotted(*) {
|
||||||
|
min-width: 120px;
|
||||||
|
max-width: 160px;
|
||||||
|
flex: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media all and (hover: hover),
|
||||||
|
all and (min-width: 600px) and (min-height: 501px) {
|
||||||
|
.controls-scroll {
|
||||||
|
justify-content: center;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 450px;
|
||||||
|
}
|
||||||
|
.controls-scroll.items-4 {
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
||||||
|
.controls-scroll.items-3 ::slotted(*) {
|
||||||
|
max-width: 140px;
|
||||||
|
}
|
||||||
|
.multiline ::slotted(*) {
|
||||||
|
width: 140px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
declare global {
|
||||||
|
interface HTMLElementTagNameMap {
|
||||||
|
"ha-more-info-control-select-container": HaMoreInfoControlSelectContainer;
|
||||||
|
}
|
||||||
|
}
|
@ -22,35 +22,6 @@ export const moreInfoControlStyle = css`
|
|||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.secondary-controls {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: center;
|
|
||||||
}
|
|
||||||
.secondary-controls-scroll {
|
|
||||||
display: flex;
|
|
||||||
flex-direction: row;
|
|
||||||
justify-content: flex-start;
|
|
||||||
gap: 12px;
|
|
||||||
margin: auto;
|
|
||||||
overflow: auto;
|
|
||||||
-ms-overflow-style: none; /* IE and Edge */
|
|
||||||
scrollbar-width: none; /* Firefox */
|
|
||||||
margin: 0 -24px;
|
|
||||||
padding: 0 24px;
|
|
||||||
}
|
|
||||||
.secondary-controls-scroll::-webkit-scrollbar {
|
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Don't use scroll on device without touch support */
|
|
||||||
@media (hover: hover) {
|
|
||||||
.secondary-controls-scroll {
|
|
||||||
justify-content: center;
|
|
||||||
flex-wrap: wrap;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.buttons {
|
.buttons {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@ -38,6 +38,7 @@ import { haOscillating } from "../../../data/icons/haOscillating";
|
|||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import "../components/climate/ha-more-info-climate-humidity";
|
import "../components/climate/ha-more-info-climate-humidity";
|
||||||
import "../components/climate/ha-more-info-climate-temperature";
|
import "../components/climate/ha-more-info-climate-temperature";
|
||||||
|
import "../components/ha-more-info-control-select-container";
|
||||||
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
||||||
|
|
||||||
type MainControl = "temperature" | "humidity";
|
type MainControl = "temperature" | "humidity";
|
||||||
@ -163,8 +164,7 @@ class MoreInfoClimate extends LitElement {
|
|||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
<div class="secondary-controls">
|
<ha-more-info-control-select-container>
|
||||||
<div class="secondary-controls-scroll">
|
|
||||||
<ha-control-select-menu
|
<ha-control-select-menu
|
||||||
.label=${this.hass.formatEntityAttributeName(
|
.label=${this.hass.formatEntityAttributeName(
|
||||||
this.stateObj,
|
this.stateObj,
|
||||||
@ -207,10 +207,7 @@ class MoreInfoClimate extends LitElement {
|
|||||||
@selected=${this._handlePresetmodeChanged}
|
@selected=${this._handlePresetmodeChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
<ha-svg-icon
|
<ha-svg-icon slot="icon" .path=${mdiTuneVariant}></ha-svg-icon>
|
||||||
slot="icon"
|
|
||||||
.path=${mdiTuneVariant}
|
|
||||||
></ha-svg-icon>
|
|
||||||
${stateObj.attributes.preset_modes!.map(
|
${stateObj.attributes.preset_modes!.map(
|
||||||
(mode) => html`
|
(mode) => html`
|
||||||
<ha-list-item .value=${mode} graphic="icon">
|
<ha-list-item .value=${mode} graphic="icon">
|
||||||
@ -295,8 +292,7 @@ class MoreInfoClimate extends LitElement {
|
|||||||
</ha-control-select-menu>
|
</ha-control-select-menu>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</ha-more-info-control-select-container>
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,6 +27,7 @@ import { haOscillating } from "../../../data/icons/haOscillating";
|
|||||||
import { haOscillatingOff } from "../../../data/icons/haOscillatingOff";
|
import { haOscillatingOff } from "../../../data/icons/haOscillatingOff";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
import "../components/fan/ha-more-info-fan-speed";
|
import "../components/fan/ha-more-info-fan-speed";
|
||||||
|
import "../components/ha-more-info-control-select-container";
|
||||||
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
||||||
import "../components/ha-more-info-state-header";
|
import "../components/ha-more-info-state-header";
|
||||||
import "../components/ha-more-info-toggle";
|
import "../components/ha-more-info-toggle";
|
||||||
@ -191,8 +192,7 @@ class MoreInfoFan extends LitElement {
|
|||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
<div class="secondary-controls">
|
<ha-more-info-control-select-container>
|
||||||
<div class="secondary-controls-scroll">
|
|
||||||
${supportsPresetMode && this.stateObj.attributes.preset_modes
|
${supportsPresetMode && this.stateObj.attributes.preset_modes
|
||||||
? html`
|
? html`
|
||||||
<ha-control-select-menu
|
<ha-control-select-menu
|
||||||
@ -207,10 +207,7 @@ class MoreInfoFan extends LitElement {
|
|||||||
@selected=${this._handlePresetMode}
|
@selected=${this._handlePresetMode}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
<ha-svg-icon
|
<ha-svg-icon slot="icon" .path=${mdiTuneVariant}></ha-svg-icon>
|
||||||
slot="icon"
|
|
||||||
.path=${mdiTuneVariant}
|
|
||||||
></ha-svg-icon>
|
|
||||||
${this.stateObj.attributes.preset_modes?.map(
|
${this.stateObj.attributes.preset_modes?.map(
|
||||||
(mode) => html`
|
(mode) => html`
|
||||||
<ha-list-item .value=${mode}>
|
<ha-list-item .value=${mode}>
|
||||||
@ -300,8 +297,7 @@ class MoreInfoFan extends LitElement {
|
|||||||
</ha-control-select-menu>
|
</ha-control-select-menu>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</ha-more-info-control-select-container>
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ import {
|
|||||||
computeHumidiferModeIcon,
|
computeHumidiferModeIcon,
|
||||||
} from "../../../data/humidifier";
|
} from "../../../data/humidifier";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import "../components/ha-more-info-control-select-container";
|
||||||
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
||||||
import "../components/humidifier/ha-more-info-humidifier-humidity";
|
import "../components/humidifier/ha-more-info-humidifier-humidity";
|
||||||
|
|
||||||
@ -91,8 +92,7 @@ class MoreInfoHumidifier extends LitElement {
|
|||||||
></ha-more-info-humidifier-humidity>
|
></ha-more-info-humidifier-humidity>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="secondary-controls">
|
<ha-more-info-control-select-container>
|
||||||
<div class="secondary-controls-scroll">
|
|
||||||
<ha-control-select-menu
|
<ha-control-select-menu
|
||||||
.label=${this.hass.localize("ui.card.humidifier.state")}
|
.label=${this.hass.localize("ui.card.humidifier.state")}
|
||||||
.value=${this.stateObj.state}
|
.value=${this.stateObj.state}
|
||||||
@ -136,10 +136,7 @@ class MoreInfoHumidifier extends LitElement {
|
|||||||
@selected=${this._handleModeChanged}
|
@selected=${this._handleModeChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
<ha-svg-icon
|
<ha-svg-icon slot="icon" .path=${mdiTuneVariant}></ha-svg-icon>
|
||||||
slot="icon"
|
|
||||||
.path=${mdiTuneVariant}
|
|
||||||
></ha-svg-icon>
|
|
||||||
${stateObj.attributes.available_modes!.map(
|
${stateObj.attributes.available_modes!.map(
|
||||||
(mode) => html`
|
(mode) => html`
|
||||||
<ha-list-item .value=${mode} graphic="icon">
|
<ha-list-item .value=${mode} graphic="icon">
|
||||||
@ -162,8 +159,7 @@ class MoreInfoHumidifier extends LitElement {
|
|||||||
</ha-control-select-menu>
|
</ha-control-select-menu>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</ha-more-info-control-select-container>
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,6 +36,7 @@ import {
|
|||||||
lightSupportsFavoriteColors,
|
lightSupportsFavoriteColors,
|
||||||
} from "../../../data/light";
|
} from "../../../data/light";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
import "../components/ha-more-info-control-select-container";
|
||||||
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
||||||
import "../components/ha-more-info-state-header";
|
import "../components/ha-more-info-state-header";
|
||||||
import "../components/ha-more-info-toggle";
|
import "../components/ha-more-info-toggle";
|
||||||
@ -286,8 +287,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<div class="secondary-controls">
|
<ha-more-info-control-select-container>
|
||||||
<div class="secondary-controls-scroll">
|
|
||||||
${supportsEffects && this.stateObj.attributes.effect_list
|
${supportsEffects && this.stateObj.attributes.effect_list
|
||||||
? html`
|
? html`
|
||||||
<ha-control-select-menu
|
<ha-control-select-menu
|
||||||
@ -317,8 +317,7 @@ class MoreInfoLight extends LitElement {
|
|||||||
</ha-control-select-menu>
|
</ha-control-select-menu>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</ha-more-info-control-select-container>
|
||||||
</div>
|
|
||||||
<ha-attributes
|
<ha-attributes
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
.stateObj=${this.stateObj}
|
.stateObj=${this.stateObj}
|
||||||
|
@ -13,6 +13,7 @@ import {
|
|||||||
computeOperationModeIcon,
|
computeOperationModeIcon,
|
||||||
} from "../../../data/water_heater";
|
} from "../../../data/water_heater";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import "../components/ha-more-info-control-select-container";
|
||||||
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
import { moreInfoControlStyle } from "../components/ha-more-info-control-style";
|
||||||
import "../components/water_heater/ha-more-info-water_heater-temperature";
|
import "../components/water_heater/ha-more-info-water_heater-temperature";
|
||||||
|
|
||||||
@ -68,8 +69,7 @@ class MoreInfoWaterHeater extends LitElement {
|
|||||||
.stateObj=${this.stateObj}
|
.stateObj=${this.stateObj}
|
||||||
></ha-more-info-water_heater-temperature>
|
></ha-more-info-water_heater-temperature>
|
||||||
</div>
|
</div>
|
||||||
<div class="secondary-controls">
|
<ha-more-info-control-select-container>
|
||||||
<div class="secondary-controls-scroll">
|
|
||||||
${supportOperationMode && stateObj.attributes.operation_list
|
${supportOperationMode && stateObj.attributes.operation_list
|
||||||
? html`
|
? html`
|
||||||
<ha-control-select-menu
|
<ha-control-select-menu
|
||||||
@ -84,10 +84,7 @@ class MoreInfoWaterHeater extends LitElement {
|
|||||||
@selected=${this._handleOperationModeChanged}
|
@selected=${this._handleOperationModeChanged}
|
||||||
@closed=${stopPropagation}
|
@closed=${stopPropagation}
|
||||||
>
|
>
|
||||||
<ha-svg-icon
|
<ha-svg-icon slot="icon" .path=${mdiWaterBoiler}></ha-svg-icon>
|
||||||
slot="icon"
|
|
||||||
.path=${mdiWaterBoiler}
|
|
||||||
></ha-svg-icon>
|
|
||||||
${stateObj.attributes.operation_list
|
${stateObj.attributes.operation_list
|
||||||
.concat()
|
.concat()
|
||||||
.sort(compareWaterHeaterOperationMode)
|
.sort(compareWaterHeaterOperationMode)
|
||||||
@ -128,17 +125,13 @@ class MoreInfoWaterHeater extends LitElement {
|
|||||||
${this.hass.localize("state.default.on")}
|
${this.hass.localize("state.default.on")}
|
||||||
</ha-list-item>
|
</ha-list-item>
|
||||||
<ha-list-item value="off" graphic="icon">
|
<ha-list-item value="off" graphic="icon">
|
||||||
<ha-svg-icon
|
<ha-svg-icon slot="graphic" .path=${mdiAccount}></ha-svg-icon>
|
||||||
slot="graphic"
|
|
||||||
.path=${mdiAccount}
|
|
||||||
></ha-svg-icon>
|
|
||||||
${this.hass.localize("state.default.off")}
|
${this.hass.localize("state.default.off")}
|
||||||
</ha-list-item>
|
</ha-list-item>
|
||||||
</ha-control-select-menu>
|
</ha-control-select-menu>
|
||||||
`
|
`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>
|
</ha-more-info-control-select-container>
|
||||||
</div>
|
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user