Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/common/entity/domain_icon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { DEFAULT_DOMAIN_ICON } from "../const";
const fixedIcons = {
alert: "hass:alert",
alexa: "hass:amazon-alexa",
automation: "hass:playlist-play",
automation: "hass:robot",
calendar: "hass:calendar",
camera: "hass:video",
climate: "hass:thermostat",
Expand Down Expand Up @@ -36,8 +36,8 @@ const fixedIcons = {
plant: "hass:flower",
proximity: "hass:apple-safari",
remote: "hass:remote",
scene: "hass:google-pages",
script: "hass:file-document",
scene: "hass:palette",
script: "hass:script-text",
sensor: "hass:eye",
simple_alarm: "hass:bell",
sun: "hass:white-balance-sunny",
Expand All @@ -48,7 +48,7 @@ const fixedIcons = {
water_heater: "hass:thermometer",
weather: "hass:weather-cloudy",
weblink: "hass:open-in-new",
zone: "hass:map-marker",
zone: "hass:map-marker-radius",
};

export const domainIcon = (domain: string, state?: string): string => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/ha-menu-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ class HaMenuButton extends LitElement {
top: 5px;
right: 2px;
border-radius: 50%;
border: 2px solid var(--primary-color);
border: 2px solid var(--app-header-background-color);
}
`;
}
Expand Down
5 changes: 5 additions & 0 deletions src/layouts/hass-loading-screen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ class HassLoadingScreen extends LitElement {
return [
haStyle,
css`
:host {
display: block;
height: 100%;
background-color: var(--primary-background-color);
}
.content {
height: calc(100% - 64px);
display: flex;
Expand Down
1 change: 1 addition & 0 deletions src/layouts/hass-subpage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class HassSubpage extends LitElement {
background-color: var(--app-header-background-color);
font-weight: 400;
color: var(--app-header-text-color, white);
border-bottom: var(--app-header-border-bottom, none);
}

ha-menu-button,
Expand Down
239 changes: 239 additions & 0 deletions src/layouts/hass-tabs-subpage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
import {
LitElement,
property,
TemplateResult,
html,
customElement,
css,
CSSResult,
PropertyValues,
} from "lit-element";
import "../components/ha-menu-button";
import "../components/ha-paper-icon-button-arrow-prev";
import { classMap } from "lit-html/directives/class-map";
import { Route, HomeAssistant } from "../types";
import { navigate } from "../common/navigate";
import "@material/mwc-ripple";
import { isComponentLoaded } from "../common/config/is_component_loaded";

export interface PageNavigation {
path: string;
translationKey?: string;
component?: string;
name?: string;
core?: boolean;
exportOnly?: boolean;
icon?: string;
info?: any;
}

@customElement("hass-tabs-subpage")
class HassTabsSubpage extends LitElement {
@property() public hass!: HomeAssistant;
@property({ type: String, attribute: "back-path" }) public backPath?: string;
@property() public backCallback?: () => void;
@property({ type: Boolean }) public hassio = false;
@property({ type: Boolean }) public showAdvanced = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add docstrings to each property. It's not clear to me what this property does.

@property() public route!: Route;
@property() public tabs!: PageNavigation[];
@property({ type: Boolean, reflect: true }) public narrow = false;
@property() private _activeTab: number = -1;

protected updated(changedProperties: PropertyValues) {
super.updated(changedProperties);
if (changedProperties.has("route")) {
this._activeTab = this.tabs.findIndex((tab) =>
this.route.prefix.includes(tab.path)
);
}
}

protected render(): TemplateResult {
return html`
<div class="toolbar">
<ha-paper-icon-button-arrow-prev
aria-label="Back"
.hassio=${this.hassio}
@click=${this._backTapped}
></ha-paper-icon-button-arrow-prev>
<div id="tabbar" class=${classMap({ "bottom-bar": this.narrow })}>
${this.tabs.map((page, index) =>
(!page.component ||
page.core ||
isComponentLoaded(this.hass, page.component)) &&
(!page.exportOnly || this.showAdvanced)
? html`
<div
class="tab ${classMap({
active: index === this._activeTab,
})}"
@click=${this._tabTapped}
.path=${page.path}
>
${this.narrow
? html`
<ha-icon .icon=${page.icon}></ha-icon>
`
: ""}
${!this.narrow || index === this._activeTab
? html`
<span class="name"
>${page.translationKey
? this.hass.localize(page.translationKey)
: name}</span
>
`
: ""}
<mwc-ripple></mwc-ripple>
</div>
`
: ""
)}
</div>

<div id="toolbar-icon">
<slot name="toolbar-icon"></slot>
</div>
</div>
<div class="content">
<slot></slot>
</div>
`;
}

private _tabTapped(ev: MouseEvent): void {
navigate(this, (ev.currentTarget as any).path, true);
}

private _backTapped(): void {
if (this.backPath) {
navigate(this, this.backPath);
return;
}
if (this.backCallback) {
this.backCallback();
return;
}
history.back();
}

static get styles(): CSSResult {
return css`
:host {
display: block;
height: 100%;
background-color: var(--primary-background-color);
}

.toolbar {
display: flex;
align-items: center;
font-size: 20px;
height: 64px;
background-color: var(--sidebar-background-color);
font-weight: 400;
color: var(--sidebar-text-color);
border-bottom: 1px solid var(--divider-color);
padding: 0 16px;
box-sizing: border-box;
}

:host([narrow]) .toolbar {
background-color: var(--primary-background-color);
border-bottom: none;
}

#tabbar {
display: flex;
font-size: 14px;
}

#tabbar.bottom-bar {
position: absolute;
bottom: 0;
left: 0;
padding: 0 16px;
box-sizing: border-box;
background-color: var(--sidebar-background-color);
border-top: 1px solid var(--divider-color);
justify-content: space-between;
z-index: 1;
font-size: 12px;
width: 100%;
}

#tabbar:not(.bottom-bar) {
margin: auto;
left: 50%;
position: absolute;
transform: translate(-50%, 0);
}

.tab {
padding: 0 32px;
display: flex;
flex-direction: column;
text-align: center;
align-items: center;
justify-content: center;
height: 64px;
cursor: pointer;
}

.name {
white-space: nowrap;
}

.tab.active {
color: var(--primary-color);
}

#tabbar:not(.bottom-bar) .tab.active {
border-bottom: 2px solid var(--primary-color);
}

.bottom-bar .tab {
padding: 0 16px;
width: 20%;
min-width: 0;
}

ha-menu-button,
ha-paper-icon-button-arrow-prev,
::slotted([slot="toolbar-icon"]) {
pointer-events: auto;
color: var(--sidebar-icon-color);
}

[main-title] {
margin: 0 0 0 24px;
line-height: 20px;
flex-grow: 1;
}

.content {
position: relative;
width: 100%;
height: calc(100% - 64px);
overflow-y: auto;
overflow: auto;
-webkit-overflow-scrolling: touch;
}

#toolbar-icon {
position: absolute;
right: 16px;
}

:host([narrow]) .content {
height: calc(100% - 128px);
}
`;
}
}

declare global {
interface HTMLElementTagNameMap {
"hass-tabs-subpage": HassTabsSubpage;
}
}
27 changes: 20 additions & 7 deletions src/panels/config/areas/ha-config-areas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import "@polymer/paper-item/paper-item";
import "@polymer/paper-item/paper-item-body";

import { HomeAssistant } from "../../../types";
import { HomeAssistant, Route } from "../../../types";
import {
AreaRegistryEntry,
updateAreaRegistryEntry,
Expand All @@ -20,7 +20,7 @@ import {
} from "../../../data/area_registry";
import "../../../components/ha-card";
import "../../../components/ha-fab";
import "../../../layouts/hass-subpage";
import "../../../layouts/hass-tabs-subpage";
import "../../../layouts/hass-loading-screen";
import "../ha-config-section";
import {
Expand All @@ -30,11 +30,14 @@ import {
import { classMap } from "lit-html/directives/class-map";
import { computeRTL } from "../../../common/util/compute_rtl";
import { UnsubscribeFunc } from "home-assistant-js-websocket";
import { configSections } from "../ha-panel-config";

@customElement("ha-config-areas")
export class HaConfigAreas extends LitElement {
@property() public hass!: HomeAssistant;
@property() public isWide?: boolean;
@property() public narrow!: boolean;
@property() public route!: Route;
@property() private _areas?: AreaRegistryEntry[];
private _unsubAreas?: UnsubscribeFunc;

Expand All @@ -52,9 +55,12 @@ export class HaConfigAreas extends LitElement {
`;
}
return html`
<hass-subpage
.header="${this.hass.localize("ui.panel.config.areas.caption")}"
.showBackButton=${!this.isWide}
<hass-tabs-subpage
.hass=${this.hass}
.narrow=${this.narrow}
back-path="/config"
.route=${this.route}
.tabs=${configSections.persons}
>
<ha-config-section .isWide=${this.isWide}>
<span slot="header">
Expand Down Expand Up @@ -95,10 +101,11 @@ export class HaConfigAreas extends LitElement {
: html``}
</ha-card>
</ha-config-section>
</hass-subpage>
</hass-tabs-subpage>

<ha-fab
?is-wide=${this.isWide}
?narrow=${this.narrow}
icon="hass:plus"
title="${this.hass.localize("ui.panel.config.areas.create_area")}"
@click=${this._createArea}
Expand Down Expand Up @@ -162,6 +169,10 @@ All devices in this area will become unassigned.`)

static get styles(): CSSResult {
return css`
hass-loading-screen {
--app-header-background-color: var(--sidebar-background-color);
--app-header-text-color: var(--sidebar-text-color);
}
a {
color: var(--primary-color);
}
Expand Down Expand Up @@ -189,7 +200,9 @@ All devices in this area will become unassigned.`)
bottom: 24px;
right: 24px;
}

ha-fab[narrow] {
bottom: 84px;
}
ha-fab.rtl {
right: auto;
left: 16px;
Expand Down
Loading