mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 19:26:36 +00:00
Replace paper-listbox in cast frontend (#19954)
* hc-cast * Update cast/src/launcher/layout/hc-cast.ts Co-authored-by: Bram Kragten <mail@bramkragten.nl> * Update cast/src/launcher/layout/hc-cast.ts Co-authored-by: Bram Kragten <mail@bramkragten.nl> * Update cast/src/launcher/layout/hc-cast.ts Co-authored-by: Bram Kragten <mail@bramkragten.nl> * Fixes --------- Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
f78946447f
commit
2e5cce5409
@ -1,7 +1,6 @@
|
|||||||
import "@material/mwc-button/mwc-button";
|
import "@material/mwc-button/mwc-button";
|
||||||
|
import { ActionDetail } from "@material/mwc-list/mwc-list";
|
||||||
import { mdiCast, mdiCastConnected, mdiViewDashboard } from "@mdi/js";
|
import { mdiCast, mdiCastConnected, mdiViewDashboard } from "@mdi/js";
|
||||||
import "@polymer/paper-item/paper-icon-item";
|
|
||||||
import "@polymer/paper-listbox/paper-listbox";
|
|
||||||
import { Auth, Connection } from "home-assistant-js-websocket";
|
import { Auth, Connection } from "home-assistant-js-websocket";
|
||||||
import { CSSResultGroup, LitElement, TemplateResult, css, html } from "lit";
|
import { CSSResultGroup, LitElement, TemplateResult, css, html } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
@ -28,6 +27,7 @@ import { LovelaceViewConfig } from "../../../../src/data/lovelace/config/view";
|
|||||||
import "../../../../src/layouts/hass-loading-screen";
|
import "../../../../src/layouts/hass-loading-screen";
|
||||||
import { generateDefaultViewConfig } from "../../../../src/panels/lovelace/common/generate-lovelace-config";
|
import { generateDefaultViewConfig } from "../../../../src/panels/lovelace/common/generate-lovelace-config";
|
||||||
import "./hc-layout";
|
import "./hc-layout";
|
||||||
|
import "../../../../src/components/ha-list-item";
|
||||||
|
|
||||||
@customElement("hc-cast")
|
@customElement("hc-cast")
|
||||||
class HcCast extends LitElement {
|
class HcCast extends LitElement {
|
||||||
@ -83,37 +83,37 @@ class HcCast extends LitElement {
|
|||||||
`
|
`
|
||||||
: html`
|
: html`
|
||||||
<div class="section-header">PICK A VIEW</div>
|
<div class="section-header">PICK A VIEW</div>
|
||||||
<paper-listbox
|
<mwc-list @action=${this._handlePickView} activatable>
|
||||||
attr-for-selected="data-path"
|
|
||||||
.selected=${this.castManager.status.lovelacePath || ""}
|
|
||||||
>
|
|
||||||
${(
|
${(
|
||||||
this.lovelaceViews ?? [
|
this.lovelaceViews ?? [
|
||||||
generateDefaultViewConfig({}, {}, {}, {}, () => ""),
|
generateDefaultViewConfig({}, {}, {}, {}, () => ""),
|
||||||
]
|
]
|
||||||
).map(
|
).map(
|
||||||
(view, idx) => html`
|
(view, idx) =>
|
||||||
<paper-icon-item
|
html`<ha-list-item
|
||||||
@click=${this._handlePickView}
|
graphic="avatar"
|
||||||
data-path=${view.path || idx}
|
.activated=${this.castManager.status?.lovelacePath ===
|
||||||
|
(view.path ?? idx)}
|
||||||
|
.selected=${this.castManager.status?.lovelacePath ===
|
||||||
|
(view.path ?? idx)}
|
||||||
>
|
>
|
||||||
|
${view.title || view.path || "Unnamed view"}
|
||||||
${view.icon
|
${view.icon
|
||||||
? html`
|
? html`
|
||||||
<ha-icon
|
<ha-icon
|
||||||
.icon=${view.icon}
|
.icon=${view.icon}
|
||||||
slot="item-icon"
|
slot="graphic"
|
||||||
></ha-icon>
|
></ha-icon>
|
||||||
`
|
`
|
||||||
: html`<ha-svg-icon
|
: html`<ha-svg-icon
|
||||||
slot="item-icon"
|
slot="item-icon"
|
||||||
.path=${mdiViewDashboard}
|
.path=${mdiViewDashboard}
|
||||||
></ha-svg-icon>`}
|
></ha-svg-icon>`}</ha-list-item
|
||||||
${view.title || view.path || "Unnamed view"}
|
> `
|
||||||
</paper-icon-item>
|
)}</mwc-list
|
||||||
`
|
>
|
||||||
)}
|
|
||||||
</paper-listbox>
|
|
||||||
`}
|
`}
|
||||||
|
|
||||||
<div class="card-actions">
|
<div class="card-actions">
|
||||||
${this.castManager.status
|
${this.castManager.status
|
||||||
? html`
|
? html`
|
||||||
@ -185,8 +185,8 @@ class HcCast extends LitElement {
|
|||||||
this.castManager.requestSession();
|
this.castManager.requestSession();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async _handlePickView(ev: Event) {
|
private async _handlePickView(ev: CustomEvent<ActionDetail>) {
|
||||||
const path = (ev.currentTarget as any).getAttribute("data-path");
|
const path = this.lovelaceViews![ev.detail.index].path ?? ev.detail.index;
|
||||||
await ensureConnectedCastSession(this.castManager!, this.auth!);
|
await ensureConnectedCastSession(this.castManager!, this.auth!);
|
||||||
castSendShowLovelaceView(this.castManager, this.auth.data.hassUrl, path);
|
castSendShowLovelaceView(this.castManager, this.auth.data.hassUrl, path);
|
||||||
}
|
}
|
||||||
@ -249,26 +249,14 @@ class HcCast extends LitElement {
|
|||||||
height: 18px;
|
height: 18px;
|
||||||
}
|
}
|
||||||
|
|
||||||
paper-listbox {
|
ha-list-item ha-icon,
|
||||||
padding-top: 0;
|
ha-list-item ha-svg-icon {
|
||||||
}
|
|
||||||
|
|
||||||
paper-listbox ha-icon,
|
|
||||||
paper-listbox ha-svg-icon {
|
|
||||||
padding: 12px;
|
padding: 12px;
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
}
|
}
|
||||||
|
|
||||||
paper-icon-item {
|
:host([hide-icons]) ha-icon {
|
||||||
cursor: pointer;
|
display: none;
|
||||||
}
|
|
||||||
|
|
||||||
paper-icon-item[disabled] {
|
|
||||||
cursor: initial;
|
|
||||||
}
|
|
||||||
|
|
||||||
:host([hide-icons]) paper-icon-item {
|
|
||||||
--paper-item-icon-width: 0px;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.spacer {
|
.spacer {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user