mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-14 04:46:34 +00:00
Update Media Browser to styling from Mockup (#11424)
Co-authored-by: Paulus Schoutsen <balloob@gmail.com> Co-authored-by: Bram Kragten <mail@bramkragten.nl>
This commit is contained in:
parent
a92100bb0a
commit
7c194d8910
@ -1,9 +1,13 @@
|
|||||||
|
import "../ha-header-bar";
|
||||||
|
import { mdiArrowLeft, mdiClose } from "@mdi/js";
|
||||||
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
import { css, CSSResultGroup, html, LitElement, TemplateResult } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { fireEvent, HASSDomEvent } from "../../common/dom/fire_event";
|
import { fireEvent, HASSDomEvent } from "../../common/dom/fire_event";
|
||||||
|
import { computeRTLDirection } from "../../common/util/compute_rtl";
|
||||||
import type {
|
import type {
|
||||||
MediaPickedEvent,
|
MediaPickedEvent,
|
||||||
MediaPlayerBrowseAction,
|
MediaPlayerBrowseAction,
|
||||||
|
MediaPlayerItem,
|
||||||
} from "../../data/media-player";
|
} from "../../data/media-player";
|
||||||
import { haStyleDialog } from "../../resources/styles";
|
import { haStyleDialog } from "../../resources/styles";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
@ -16,6 +20,8 @@ import { MediaPlayerBrowseDialogParams } from "./show-media-browser-dialog";
|
|||||||
class DialogMediaPlayerBrowse extends LitElement {
|
class DialogMediaPlayerBrowse extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
|
|
||||||
|
@state() private _currentItem?: MediaPlayerItem;
|
||||||
|
|
||||||
@state() private _navigateIds?: MediaPlayerItemId[];
|
@state() private _navigateIds?: MediaPlayerItemId[];
|
||||||
|
|
||||||
@state() private _params?: MediaPlayerBrowseDialogParams;
|
@state() private _params?: MediaPlayerBrowseDialogParams;
|
||||||
@ -33,11 +39,12 @@ class DialogMediaPlayerBrowse extends LitElement {
|
|||||||
public closeDialog() {
|
public closeDialog() {
|
||||||
this._params = undefined;
|
this._params = undefined;
|
||||||
this._navigateIds = undefined;
|
this._navigateIds = undefined;
|
||||||
|
this._currentItem = undefined;
|
||||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
protected render(): TemplateResult {
|
||||||
if (!this._params) {
|
if (!this._params || !this._navigateIds) {
|
||||||
return html``;
|
return html``;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -48,8 +55,36 @@ class DialogMediaPlayerBrowse extends LitElement {
|
|||||||
escapeKeyAction
|
escapeKeyAction
|
||||||
hideActions
|
hideActions
|
||||||
flexContent
|
flexContent
|
||||||
|
.heading=${true}
|
||||||
@closed=${this.closeDialog}
|
@closed=${this.closeDialog}
|
||||||
>
|
>
|
||||||
|
<ha-header-bar slot="heading">
|
||||||
|
${this._navigateIds.length > 1
|
||||||
|
? html`
|
||||||
|
<ha-icon-button
|
||||||
|
slot="navigationIcon"
|
||||||
|
.path=${mdiArrowLeft}
|
||||||
|
@click=${this._goBack}
|
||||||
|
></ha-icon-button>
|
||||||
|
`
|
||||||
|
: ""}
|
||||||
|
<span slot="title">
|
||||||
|
${!this._currentItem
|
||||||
|
? this.hass.localize(
|
||||||
|
"ui.components.media-browser.media-player-browser"
|
||||||
|
)
|
||||||
|
: this._currentItem.title}
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<ha-icon-button
|
||||||
|
.label=${this.hass.localize("ui.dialogs.generic.close")}
|
||||||
|
.path=${mdiClose}
|
||||||
|
dialogAction="close"
|
||||||
|
slot="actionItems"
|
||||||
|
class="header_button"
|
||||||
|
dir=${computeRTLDirection(this.hass)}
|
||||||
|
></ha-icon-button>
|
||||||
|
</ha-header-bar>
|
||||||
<ha-media-player-browse
|
<ha-media-player-browse
|
||||||
dialog
|
dialog
|
||||||
.hass=${this.hass}
|
.hass=${this.hass}
|
||||||
@ -64,8 +99,14 @@ class DialogMediaPlayerBrowse extends LitElement {
|
|||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _mediaBrowsed(ev) {
|
private _goBack() {
|
||||||
|
this._navigateIds = this._navigateIds?.slice(0, -1);
|
||||||
|
this._currentItem = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
private _mediaBrowsed(ev: { detail: HASSDomEvents["media-browsed"] }) {
|
||||||
this._navigateIds = ev.detail.ids;
|
this._navigateIds = ev.detail.ids;
|
||||||
|
this._currentItem = ev.detail.current;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _mediaPicked(ev: HASSDomEvent<MediaPickedEvent>): void {
|
private _mediaPicked(ev: HASSDomEvent<MediaPickedEvent>): void {
|
||||||
@ -89,7 +130,7 @@ class DialogMediaPlayerBrowse extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ha-media-player-browse {
|
ha-media-player-browse {
|
||||||
--media-browser-max-height: 100vh;
|
--media-browser-max-height: calc(100vh - 65px);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (min-width: 800px) {
|
@media (min-width: 800px) {
|
||||||
@ -101,10 +142,17 @@ class DialogMediaPlayerBrowse extends LitElement {
|
|||||||
}
|
}
|
||||||
ha-media-player-browse {
|
ha-media-player-browse {
|
||||||
position: initial;
|
position: initial;
|
||||||
--media-browser-max-height: 100vh - 72px;
|
--media-browser-max-height: 100vh - 137px;
|
||||||
width: 700px;
|
width: 700px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ha-header-bar {
|
||||||
|
--mdc-theme-on-primary: var(--primary-text-color);
|
||||||
|
--mdc-theme-primary: var(--mdc-theme-surface);
|
||||||
|
flex-shrink: 0;
|
||||||
|
border-bottom: 1px solid var(--divider-color, rgba(0, 0, 0, 0.12));
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -88,7 +88,7 @@ export const BROWSER_PLAYER = "browser";
|
|||||||
export type MediaClassBrowserSetting = {
|
export type MediaClassBrowserSetting = {
|
||||||
icon: string;
|
icon: string;
|
||||||
thumbnail_ratio?: string;
|
thumbnail_ratio?: string;
|
||||||
layout?: string;
|
layout?: "grid";
|
||||||
show_list_images?: boolean;
|
show_list_images?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -19,6 +19,7 @@ import {
|
|||||||
TemplateResult,
|
TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
@ -152,7 +153,10 @@ class BarMediaPlayer extends LitElement {
|
|||||||
stateObj.attributes.entity_picture;
|
stateObj.attributes.entity_picture;
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="info">
|
<div
|
||||||
|
class="info ${!isBrowser ? "pointer" : ""}"
|
||||||
|
@click=${this._openMoreInfo}
|
||||||
|
>
|
||||||
${mediaArt ? html`<img src=${this.hass.hassUrl(mediaArt)} />` : ""}
|
${mediaArt ? html`<img src=${this.hass.hassUrl(mediaArt)} />` : ""}
|
||||||
<div class="media-info">
|
<div class="media-info">
|
||||||
<hui-marquee
|
<hui-marquee
|
||||||
@ -309,6 +313,13 @@ class BarMediaPlayer extends LitElement {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _openMoreInfo() {
|
||||||
|
if (this._browserPlayer) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fireEvent(this, "hass-more-info", { entityId: this.entityId });
|
||||||
|
}
|
||||||
|
|
||||||
private get _showProgressBar() {
|
private get _showProgressBar() {
|
||||||
if (!this.hass) {
|
if (!this.hass) {
|
||||||
return false;
|
return false;
|
||||||
@ -418,6 +429,10 @@ class BarMediaPlayer extends LitElement {
|
|||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pointer {
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
|
||||||
.secondary,
|
.secondary,
|
||||||
.progress {
|
.progress {
|
||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { mdiArrowLeft } from "@mdi/js";
|
||||||
import "@polymer/app-layout/app-header/app-header";
|
import "@polymer/app-layout/app-header/app-header";
|
||||||
import "@polymer/app-layout/app-toolbar/app-toolbar";
|
import "@polymer/app-layout/app-toolbar/app-toolbar";
|
||||||
import {
|
import {
|
||||||
@ -13,9 +14,14 @@ import { LocalStorage } from "../../common/decorators/local-storage";
|
|||||||
import { HASSDomEvent } from "../../common/dom/fire_event";
|
import { HASSDomEvent } from "../../common/dom/fire_event";
|
||||||
import { navigate } from "../../common/navigate";
|
import { navigate } from "../../common/navigate";
|
||||||
import "../../components/ha-menu-button";
|
import "../../components/ha-menu-button";
|
||||||
|
import "../../components/ha-icon-button";
|
||||||
import "../../components/media-player/ha-media-player-browse";
|
import "../../components/media-player/ha-media-player-browse";
|
||||||
import type { MediaPlayerItemId } from "../../components/media-player/ha-media-player-browse";
|
import type { MediaPlayerItemId } from "../../components/media-player/ha-media-player-browse";
|
||||||
import { BROWSER_PLAYER, MediaPickedEvent } from "../../data/media-player";
|
import {
|
||||||
|
BROWSER_PLAYER,
|
||||||
|
MediaPickedEvent,
|
||||||
|
MediaPlayerItem,
|
||||||
|
} from "../../data/media-player";
|
||||||
import { resolveMediaSource } from "../../data/media_source";
|
import { resolveMediaSource } from "../../data/media_source";
|
||||||
import "../../layouts/ha-app-layout";
|
import "../../layouts/ha-app-layout";
|
||||||
import { haStyle } from "../../resources/styles";
|
import { haStyle } from "../../resources/styles";
|
||||||
@ -32,6 +38,8 @@ class PanelMediaBrowser extends LitElement {
|
|||||||
|
|
||||||
@property() public route!: Route;
|
@property() public route!: Route;
|
||||||
|
|
||||||
|
@property() _currentItem?: MediaPlayerItem;
|
||||||
|
|
||||||
private _navigateIds: MediaPlayerItemId[] = [
|
private _navigateIds: MediaPlayerItemId[] = [
|
||||||
{
|
{
|
||||||
media_content_id: undefined,
|
media_content_id: undefined,
|
||||||
@ -47,15 +55,26 @@ class PanelMediaBrowser extends LitElement {
|
|||||||
<ha-app-layout>
|
<ha-app-layout>
|
||||||
<app-header fixed slot="header">
|
<app-header fixed slot="header">
|
||||||
<app-toolbar>
|
<app-toolbar>
|
||||||
<ha-menu-button
|
${this._navigateIds.length > 1
|
||||||
.hass=${this.hass}
|
? html`
|
||||||
.narrow=${this.narrow}
|
<ha-icon-button
|
||||||
></ha-menu-button>
|
.path=${mdiArrowLeft}
|
||||||
|
@click=${this._goBack}
|
||||||
|
></ha-icon-button>
|
||||||
|
`
|
||||||
|
: html`
|
||||||
|
<ha-menu-button
|
||||||
|
.hass=${this.hass}
|
||||||
|
.narrow=${this.narrow}
|
||||||
|
></ha-menu-button>
|
||||||
|
`}
|
||||||
<div main-title class="heading">
|
<div main-title class="heading">
|
||||||
<div>
|
<div>
|
||||||
${this.hass.localize(
|
${!this._currentItem
|
||||||
"ui.components.media-browser.media-player-browser"
|
? this.hass.localize(
|
||||||
)}
|
"ui.components.media-browser.media-player-browser"
|
||||||
|
)
|
||||||
|
: this._currentItem.title}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</app-toolbar>
|
</app-toolbar>
|
||||||
@ -110,13 +129,19 @@ class PanelMediaBrowser extends LitElement {
|
|||||||
};
|
};
|
||||||
}),
|
}),
|
||||||
];
|
];
|
||||||
|
this._currentItem = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _mediaBrowsed(ev) {
|
private _goBack() {
|
||||||
if (ev.detail.back) {
|
history.back();
|
||||||
history.back();
|
}
|
||||||
|
|
||||||
|
private _mediaBrowsed(ev: { detail: HASSDomEvents["media-browsed"] }) {
|
||||||
|
if (ev.detail.ids === this._navigateIds) {
|
||||||
|
this._currentItem = ev.detail.current;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let path = "";
|
let path = "";
|
||||||
for (const item of ev.detail.ids.slice(1)) {
|
for (const item of ev.detail.ids.slice(1)) {
|
||||||
path +=
|
path +=
|
||||||
@ -152,6 +177,7 @@ class PanelMediaBrowser extends LitElement {
|
|||||||
sourceUrl: resolvedUrl.url,
|
sourceUrl: resolvedUrl.url,
|
||||||
sourceType: resolvedUrl.mime_type,
|
sourceType: resolvedUrl.mime_type,
|
||||||
title: item.title,
|
title: item.title,
|
||||||
|
can_play: item.can_play,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,6 +4,7 @@ export interface WebBrowserPlayMediaDialogParams {
|
|||||||
sourceUrl: string;
|
sourceUrl: string;
|
||||||
sourceType: string;
|
sourceType: string;
|
||||||
title?: string;
|
title?: string;
|
||||||
|
can_play?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const showWebBrowserPlayMediaDialog = (
|
export const showWebBrowserPlayMediaDialog = (
|
||||||
|
Loading…
x
Reference in New Issue
Block a user