From 3d0c994b9afd121241d1a4b27a24f836d13627ff Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 19 Jul 2019 15:51:37 -0700 Subject: [PATCH] Sidebar iteration (#3392) * Remove hover effect * Reuse render panel func * Show notification badge on the right in expanded mode --- src/components/ha-sidebar.ts | 149 +++++++++++++---------------------- 1 file changed, 56 insertions(+), 93 deletions(-) diff --git a/src/components/ha-sidebar.ts b/src/components/ha-sidebar.ts index 3f57d25ba9..e813c1e7f0 100644 --- a/src/components/ha-sidebar.ts +++ b/src/components/ha-sidebar.ts @@ -31,8 +31,6 @@ import { classMap } from "lit-html/directives/class-map"; const SHOW_AFTER_SPACER = ["config", "developer-tools"]; -const computeUrl = (urlPath) => `/${urlPath}`; - const SUPPORT_SCROLL_IF_NEEDED = "scrollIntoViewIfNeeded" in document.body; const SORT_VALUE = { @@ -91,22 +89,6 @@ const computePanels = (hass: HomeAssistant): [PanelInfo[], PanelInfo[]] => { return [beforeSpacer, afterSpacer]; }; -const renderPanel = (hass, panel) => html` - - - - - ${hass.localize(`panel.${panel.title}`) || panel.title} - - - -`; - /* * @appliesMixin LocalizeMixin */ @@ -116,13 +98,10 @@ class HaSidebar extends LitElement { @property({ type: Boolean }) public alwaysExpand = false; @property({ type: Boolean, reflect: true }) public expanded = false; - @property({ type: Boolean, reflect: true }) public expandedWidth = false; @property() public _defaultPage?: string = localStorage.defaultPage || DEFAULT_PANEL; @property() private _externalConfig?: ExternalConfig; @property() private _notifications?: PersistentNotification[]; - private _expandTimeout?: number; - private _contractTimeout?: number; protected render() { const hass = this.hass; @@ -156,22 +135,27 @@ class HaSidebar extends LitElement { Home Assistant - - - - ${hass.localize("panel.states")} - - - - ${beforeSpacer.map((panel) => renderPanel(hass, panel))} + ${this._renderPanel( + this._defaultPage, + "hass:apps", + hass.localize("panel.states") + )} + ${beforeSpacer.map((panel) => + this._renderPanel( + panel.url_path, + panel.icon, + hass.localize(`panel.${panel.title}`) || panel.title + ) + )}
- ${afterSpacer.map((panel) => renderPanel(hass, panel))} + ${afterSpacer.map((panel) => + this._renderPanel( + panel.url_path, + panel.icon, + hass.localize(`panel.${panel.title}`) || panel.title + ) + )} ${this._externalConfig && this._externalConfig.hasSettingsScreen ? html` - ${notificationCount > 0 + ${!this.expanded && notificationCount > 0 ? html` ${notificationCount} @@ -213,6 +197,11 @@ class HaSidebar extends LitElement { ${hass.localize("ui.notification_drawer.title")} + ${this.expanded + ? html` + ${notificationCount} + ` + : ""} { - if (this._expandTimeout) { - clearTimeout(this._expandTimeout); - this._expandTimeout = undefined; - } - }); - this.addEventListener("mouseenter", () => { - this._expand(); - }); - this.addEventListener("mouseleave", () => { - this._contract(); - }); subscribeNotifications(this.hass.connection, (notifications) => { this._notifications = notifications; }); @@ -297,9 +270,8 @@ class HaSidebar extends LitElement { protected updated(changedProps) { super.updated(changedProps); - if (changedProps.has("alwaysExpand") && this.alwaysExpand) { - this.expanded = true; - this.expandedWidth = true; + if (changedProps.has("alwaysExpand")) { + this.expanded = this.alwaysExpand; } if (!SUPPORT_SCROLL_IF_NEEDED || !changedProps.has("hass")) { return; @@ -314,33 +286,6 @@ class HaSidebar extends LitElement { } } - private _expand() { - // We debounce it one frame, because on tablets, the mouse-enter and - // click event fire at the same time. - this._expandTimeout = window.setTimeout(() => { - this.expanded = true; - this.expandedWidth = true; - }, 0); - if (this._contractTimeout) { - clearTimeout(this._contractTimeout); - this._contractTimeout = undefined; - } - } - - private _contract() { - if (this._expandTimeout) { - clearTimeout(this._expandTimeout); - this._expandTimeout = undefined; - } - if (this.alwaysExpand) { - return; - } - this.expandedWidth = false; - this._contractTimeout = window.setTimeout(() => { - this.expanded = this.alwaysExpand || false; - }, 400); - } - private _handleShowNotificationDrawer() { fireEvent(this, "hass-show-notifications"); } @@ -356,6 +301,22 @@ class HaSidebar extends LitElement { fireEvent(this, "hass-toggle-menu"); } + private _renderPanel(urlPath, icon, title) { + return html` + + + + ${title} + + + `; + } + static get styles(): CSSResult { return css` :host { @@ -371,12 +332,8 @@ class HaSidebar extends LitElement { var(--primary-background-color) ); width: 64px; - transition: width 0.2s ease-in; - will-change: width; - contain: strict; - transition-delay: 0.2s; } - :host([expandedwidth]) { + :host([expanded]) { width: 256px; } @@ -512,6 +469,9 @@ class HaSidebar extends LitElement { .notifications { cursor: pointer; } + .notifications .item-text { + flex: 1; + } .profile { } .profile paper-icon-item { @@ -522,19 +482,22 @@ class HaSidebar extends LitElement { } .notification-badge { - position: absolute; - font-weight: 400; - bottom: 14px; - left: 26px; + min-width: 20px; + box-sizing: border-box; border-radius: 50%; + font-weight: 400; background-color: var(--primary-color); - height: 20px; line-height: 20px; text-align: center; padding: 0px 6px; - font-size: 0.65em; color: var(--text-primary-color); } + ha-icon + .notification-badge { + position: absolute; + bottom: 14px; + left: 26px; + font-size: 0.65em; + } .spacer { flex: 1;