Add edit sidebar button to profile (#6943)

This commit is contained in:
Bram Kragten 2020-09-12 00:04:25 +02:00 committed by GitHub
parent f01fe65be4
commit 26fbc07cac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 60 additions and 12 deletions

View File

@ -1,3 +1,4 @@
import "@polymer/paper-item/paper-item-body";
import { import {
css, css,
CSSResult, CSSResult,
@ -7,7 +8,6 @@ import {
property, property,
SVGTemplateResult, SVGTemplateResult,
} from "lit-element"; } from "lit-element";
import "@polymer/paper-item/paper-item-body";
@customElement("ha-settings-row") @customElement("ha-settings-row")
export class HaSettingsRow extends LitElement { export class HaSettingsRow extends LitElement {
@ -49,6 +49,9 @@ export class HaSettingsRow extends LitElement {
border-top: 1px solid var(--divider-color); border-top: 1px solid var(--divider-color);
padding-bottom: 8px; padding-bottom: 8px;
} }
::slotted(ha-switch) {
padding: 16px 0;
}
`; `;
} }
} }

View File

@ -165,7 +165,7 @@ let sortStyles: CSSResult;
class HaSidebar extends LitElement { class HaSidebar extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant; @property({ attribute: false }) public hass!: HomeAssistant;
@property() public narrow!: boolean; @property({ type: Boolean, reflect: true }) public narrow!: boolean;
@property({ type: Boolean }) public alwaysExpand = false; @property({ type: Boolean }) public alwaysExpand = false;
@ -259,7 +259,7 @@ class HaSidebar extends LitElement {
<div class="title"> <div class="title">
${this._editMode ${this._editMode
? html`<mwc-button outlined @click=${this._closeEditMode}> ? html`<mwc-button outlined @click=${this._closeEditMode}>
DONE ${hass.localize("ui.sidebar.done")}
</mwc-button>` </mwc-button>`
: "Home Assistant"} : "Home Assistant"}
</div> </div>
@ -447,6 +447,9 @@ class HaSidebar extends LitElement {
subscribeNotifications(this.hass.connection, (notifications) => { subscribeNotifications(this.hass.connection, (notifications) => {
this._notifications = notifications; this._notifications = notifications;
}); });
window.addEventListener("hass-edit-sidebar", () =>
this._activateEditMode()
);
} }
protected updated(changedProps) { protected updated(changedProps) {
@ -479,11 +482,15 @@ class HaSidebar extends LitElement {
return this.shadowRoot!.querySelector(".tooltip")! as HTMLDivElement; return this.shadowRoot!.querySelector(".tooltip")! as HTMLDivElement;
} }
private async _handleAction(ev: CustomEvent<ActionHandlerDetail>) { private _handleAction(ev: CustomEvent<ActionHandlerDetail>) {
if (ev.detail.action !== "hold") { if (ev.detail.action !== "hold") {
return; return;
} }
this._activateEditMode();
}
private async _activateEditMode() {
if (!Sortable) { if (!Sortable) {
const [sortableImport, sortStylesImport] = await Promise.all([ const [sortableImport, sortStylesImport] = await Promise.all([
import("sortablejs/modular/sortable.core.esm"), import("sortablejs/modular/sortable.core.esm"),
@ -498,9 +505,7 @@ class HaSidebar extends LitElement {
} }
this._editMode = true; this._editMode = true;
if (!this.expanded) { fireEvent(this, "hass-open-menu");
fireEvent(this, "hass-toggle-menu");
}
await this.updateComplete; await this.updateComplete;
@ -761,6 +766,9 @@ class HaSidebar extends LitElement {
width: 100%; width: 100%;
display: none; display: none;
} }
:host([narrow]) .title {
padding: 0 16px;
}
:host([expanded]) .title { :host([expanded]) .title {
display: initial; display: initial;
} }

View File

@ -24,6 +24,7 @@ const NON_SWIPABLE_PANELS = ["map"];
declare global { declare global {
// for fire event // for fire event
interface HASSDomEvents { interface HASSDomEvents {
"hass-open-menu": undefined;
"hass-toggle-menu": undefined; "hass-toggle-menu": undefined;
"hass-show-notifications": undefined; "hass-show-notifications": undefined;
} }
@ -92,6 +93,17 @@ class HomeAssistantMain extends LitElement {
protected firstUpdated() { protected firstUpdated() {
import(/* webpackChunkName: "ha-sidebar" */ "../components/ha-sidebar"); import(/* webpackChunkName: "ha-sidebar" */ "../components/ha-sidebar");
this.addEventListener("hass-open-menu", () => {
if (this._sidebarNarrow) {
this.drawer.open();
} else {
fireEvent(this, "hass-dock-sidebar", {
dock: "docked",
});
setTimeout(() => this.appLayout.resetLayout());
}
});
this.addEventListener("hass-toggle-menu", () => { this.addEventListener("hass-toggle-menu", () => {
if (this._sidebarNarrow) { if (this._sidebarNarrow) {
if (this.drawer.opened) { if (this.drawer.opened) {

View File

@ -107,6 +107,23 @@ class HaPanelProfile extends LitElement {
.narrow=${this.narrow} .narrow=${this.narrow}
.hass=${this.hass} .hass=${this.hass}
></ha-pick-dashboard-row> ></ha-pick-dashboard-row>
<ha-settings-row .narrow=${this.narrow}>
<span slot="heading">
${this.hass.localize(
"ui.panel.profile.customize_sidebar.header"
)}
</span>
<span slot="description">
${this.hass.localize(
"ui.panel.profile.customize_sidebar.description"
)}
</span>
<mwc-button @click=${this._customizeSidebar}>
${this.hass.localize(
"ui.panel.profile.customize_sidebar.button"
)}
</mwc-button>
</ha-settings-row>
${this.hass.dockedSidebar !== "auto" || !this.narrow ${this.hass.dockedSidebar !== "auto" || !this.narrow
? html` ? html`
<ha-force-narrow-row <ha-force-narrow-row
@ -183,6 +200,10 @@ class HaPanelProfile extends LitElement {
`; `;
} }
private _customizeSidebar() {
fireEvent(this, "hass-edit-sidebar");
}
private async _refreshRefreshTokens() { private async _refreshRefreshTokens() {
this._refreshTokens = await this.hass.callWS({ this._refreshTokens = await this.hass.callWS({
type: "auth/refresh_tokens", type: "auth/refresh_tokens",

View File

@ -15,16 +15,14 @@ declare global {
// for fire event // for fire event
interface HASSDomEvents { interface HASSDomEvents {
"hass-dock-sidebar": DockSidebarParams; "hass-dock-sidebar": DockSidebarParams;
}
interface HASSDomEvents {
"hass-default-panel": DefaultPanelParams; "hass-default-panel": DefaultPanelParams;
"hass-edit-sidebar": undefined;
} }
// for add event listener // for add event listener
interface HTMLElementEventMap { interface HTMLElementEventMap {
"hass-dock-sidebar": HASSDomEvent<DockSidebarParams>; "hass-dock-sidebar": HASSDomEvent<DockSidebarParams>;
}
interface HTMLElementEventMap {
"hass-default-panel": HASSDomEvent<DefaultPanelParams>; "hass-default-panel": HASSDomEvent<DefaultPanelParams>;
"hass-edit-sidebar": undefined;
} }
} }

View File

@ -585,7 +585,8 @@
}, },
"sidebar": { "sidebar": {
"external_app_configuration": "App Configuration", "external_app_configuration": "App Configuration",
"sidebar_toggle": "Sidebar Toggle" "sidebar_toggle": "Sidebar Toggle",
"done": "Done"
}, },
"panel": { "panel": {
"calendar": { "calendar": {
@ -2431,6 +2432,11 @@
"header": "Always hide the sidebar", "header": "Always hide the sidebar",
"description": "This will hide the sidebar by default, similar to the mobile experience." "description": "This will hide the sidebar by default, similar to the mobile experience."
}, },
"customize_sidebar": {
"header": "Change the order and hide items from the sidebar",
"description": "You can also press and hold the header of the sidebar to activate edit mode.",
"button": "Edit"
},
"vibrate": { "vibrate": {
"header": "Vibrate", "header": "Vibrate",
"description": "Enable or disable vibration on this device when controlling devices." "description": "Enable or disable vibration on this device when controlling devices."