diff --git a/gallery/src/components/demo-card.js b/gallery/src/components/demo-card.js index e52cf02890..921030dee3 100644 --- a/gallery/src/components/demo-card.js +++ b/gallery/src/components/demo-card.js @@ -16,7 +16,8 @@ class DemoCard extends PolymerElement { color: var(--primary-color); } #card { - width: 400px; + max-width: 400px; + width: 100vw; } pre { width: 400px; diff --git a/src/components/entity/state-badge.ts b/src/components/entity/state-badge.ts index c201e50b8c..276ab53580 100644 --- a/src/components/entity/state-badge.ts +++ b/src/components/entity/state-badge.ts @@ -60,6 +60,7 @@ export class StateBadge extends LitElement { const iconStyle: Partial = { color: "", filter: "", + display: "", }; const hostStyle: Partial = { backgroundImage: "", diff --git a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts index 270fb74175..792cdfef7c 100644 --- a/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts +++ b/src/panels/lovelace/entity-rows/hui-media-player-entity-row.ts @@ -12,6 +12,7 @@ import "@polymer/paper-icon-button/paper-icon-button"; import "../components/hui-generic-entity-row"; import "../components/hui-warning"; +import "../../../components/ha-slider"; import { LovelaceRow, EntityConfig } from "./types"; import { HomeAssistant } from "../../../types"; @@ -31,6 +32,7 @@ import { import { hasConfigOrEntityChanged } from "../common/has-changed"; import { computeRTLDirection } from "../../../common/util/compute_rtl"; import { debounce } from "../../../common/util/debounce"; +import { UNAVAILABLE, UNKNOWN } from "../../../data/entity"; @customElement("hui-media-player-entity-row") class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { @@ -41,8 +43,8 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { private _resizeObserver?: ResizeObserver; private _debouncedResizeListener = debounce( () => { - this._narrow = (this.parentElement?.clientWidth || 0) < 350; - this._veryNarrow = (this.parentElement?.clientWidth || 0) < 300; + this._narrow = (this.clientWidth || 0) < 300; + this._veryNarrow = (this.clientWidth || 0) < 225; }, 250, false @@ -82,6 +84,34 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { const stateObj = this.hass.states[this._config.entity]; + const buttons = html` + ${!this._narrow && supportsFeature(stateObj, SUPPORT_PREVIOUS_TRACK) + ? html` + + ` + : ""} + ${stateObj.state !== "playing" && + !supportsFeature(stateObj, SUPPORTS_PLAY) + ? "" + : html` + + `} + ${supportsFeature(stateObj, SUPPORT_NEXT_TRACK) + ? html` + + ` + : ""} + `; + if (!stateObj) { return html` - ${(supportsFeature(stateObj, SUPPORT_TURN_ON) && - (stateObj.state === "off" || stateObj.state === "idle")) || - (supportsFeature(stateObj, SUPPORT_TURN_OFF) && - stateObj.state !== "off") - ? html` - - ` - : ""} - -
-
- ${supportsFeature(stateObj, SUPPORT_VOLUME_MUTE) - ? html` - - ` - : ""} - ${!this._narrow && supportsFeature(stateObj, SUPPORT_VOLUME_SET) - ? html` - - ` - : !this._veryNarrow && - supportsFeature(stateObj, SUPPORT_VOLUME_BUTTONS) - ? html` - - - ` - : ""} -
- ${!this._veryNarrow && - supportsFeature(stateObj, SUPPORT_PREVIOUS_TRACK) + ${supportsFeature(stateObj, SUPPORT_TURN_ON) && + stateObj.state === "off" ? html` ` - : ""} - ${stateObj.state !== "playing" && - !supportsFeature(stateObj, SUPPORTS_PLAY) - ? "" - : html` - - `} - ${supportsFeature(stateObj, SUPPORT_NEXT_TRACK) + : !supportsFeature(stateObj, SUPPORT_VOLUME_SET) && + !supportsFeature(stateObj, SUPPORT_VOLUME_BUTTONS) + ? buttons + : supportsFeature(stateObj, SUPPORT_TURN_OFF) && + stateObj.state !== "off" ? html` ` : ""}
-
- `; - } + + ${(supportsFeature(stateObj, SUPPORT_VOLUME_SET) || + supportsFeature(stateObj, SUPPORT_VOLUME_BUTTONS)) && + ![UNAVAILABLE, UNKNOWN, "off"].includes(stateObj.state) + ? html` +
+
+ ${supportsFeature(stateObj, SUPPORT_VOLUME_MUTE) + ? html` + + ` + : ""} + ${!this._veryNarrow && + supportsFeature(stateObj, SUPPORT_VOLUME_SET) + ? html` + + ` + : !this._veryNarrow && + supportsFeature(stateObj, SUPPORT_VOLUME_BUTTONS) + ? html` + + + ` + : ""} +
- static get styles(): CSSResult { - return css` - :host { - display: block; - } - .flex { - display: flex; - align-items: center; - padding-left: 48px; - justify-content: space-between; - } - .volume { - display: flex; - flex-grow: 2; - flex-shrink: 2; - } - .controls { - white-space: nowrap; - } - ha-slider { - flex-grow: 2; - flex-shrink: 2; - width: 100%; - } +
+ ${buttons} +
+
+ ` + : ""} `; } @@ -317,6 +314,33 @@ class HuiMediaPlayerEntityRow extends LitElement implements LovelaceRow { volume_level: ev.target.value / 100, }); } + + static get styles(): CSSResult { + return css` + :host { + display: block; + } + .flex { + display: flex; + align-items: center; + justify-content: space-between; + } + .volume { + display: flex; + flex-grow: 2; + flex-shrink: 2; + } + .controls { + white-space: nowrap; + } + ha-slider { + flex-grow: 2; + flex-shrink: 2; + width: 100%; + margin: 0 -8px 0 1px; + } + `; + } } declare global {