Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update sidebar #16017

Closed
wants to merge 28 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
bfed613
initial sidebar refactoring work, todo: sorting
KTibow Apr 1, 2023
e6f0319
add editing and fix stuff
KTibow Apr 2, 2023
36779f9
rename some stuff and add external config
KTibow Apr 2, 2023
d484b5f
fix focusing the list of items
KTibow Apr 2, 2023
fe5025f
fix rtl (the old sidebar had a rtl bug, fun fact)
KTibow Apr 3, 2023
25ca09d
Merge branch 'dev' into dev
KTibow Apr 5, 2023
4d3bb5f
Merge branch 'dev' into dev
KTibow Jun 2, 2023
45a8797
Fix accessibility and other bugs
KTibow Jun 3, 2023
5846073
Merge branch 'dev' into dev
KTibow Jul 6, 2023
07351e6
use @storage
KTibow Jul 6, 2023
a0f5d4b
improve scrolling
KTibow Aug 2, 2023
364ad1a
Merge branch 'dev' into dev
KTibow Aug 25, 2023
3f1fe22
fix most stuff (TODO: wiggling)
KTibow Aug 25, 2023
586e12f
somewhat improve sorting
KTibow Aug 25, 2023
89482a0
Merge branch 'home-assistant:dev' into dev
KTibow Sep 17, 2023
abb8ca1
Merge remote-tracking branch 'upstream/dev' into dev
KTibow Oct 3, 2023
30b8631
fix a11y
KTibow Oct 3, 2023
c7d72c1
Merge branch 'dev' into dev
KTibow Oct 19, 2023
788eca1
Remove useless slots
KTibow Oct 20, 2023
b38d350
Fix selected
KTibow Oct 21, 2023
6c47aed
Fix RTL
KTibow Oct 21, 2023
471ffef
Merge branch 'dev' into dev
KTibow Oct 21, 2023
fcab8c9
Merge remote-tracking branch 'upstream/dev' into dev
KTibow Oct 31, 2023
5f6d718
format code
KTibow Oct 31, 2023
e154267
Merge remote-tracking branch 'upstream/dev' into dev
KTibow Dec 3, 2023
70ac929
fix formatting
KTibow Dec 3, 2023
74e2f65
address review
KTibow Dec 5, 2023
7de61b9
address review (make keydown/keyup static)
KTibow Dec 5, 2023
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
5 changes: 3 additions & 2 deletions src/components/ha-sidebar-edit-panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ const styles = css`
}
}
`;

@customElement("ha-sidebar-edit-panels")
class HaSidebarEditPanels extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand All @@ -104,8 +105,6 @@ class HaSidebarEditPanels extends LitElement {

@property() public hiddenPanels: any[] = [];

static styles = styles;

private _sortable?: SortableInstance;

protected render() {
Expand Down Expand Up @@ -172,6 +171,8 @@ class HaSidebarEditPanels extends LitElement {
if (!panel) return;
fireEvent(this, "panel-show", panel);
}

static styles = styles;
}

declare global {
Expand Down
15 changes: 10 additions & 5 deletions src/components/ha-sidebar-panel-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@ import { updateCanInstall, UpdateEntity } from "../data/update";
import { haStyleSidebarItem } from "../resources/styles";
import { HomeAssistant } from "../types";
import "./ha-svg-icon";
import { keydown, keyup } from "../resources/button-handlers";
import { createKeydown, createKeyup } from "../resources/button-handlers";

const styles = css`
.item.expanded {
width: 100%;
}
`;

@customElement("ha-sidebar-panel-config")
class HaSidebarPanelConfig extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand All @@ -30,17 +31,19 @@ class HaSidebarPanelConfig extends LitElement {

@state() private _issuesCount = 0;

static styles = [haStyleSidebarItem, styles];

protected render() {
const notices = this._updatesCount + this._issuesCount;
const keydown = createKeydown((e) =>
(e.currentTarget as HTMLElement).click()
);
const keyup = createKeyup((e) => (e.currentTarget as HTMLElement).click());
KTibow marked this conversation as resolved.
Show resolved Hide resolved
return html`<a
href="/config"
aria-label=${this.name}
aria-current=${this.selected ? "page" : "false"}
class="item ${this.expanded ? "expanded" : ""}"
@keydown=${keydown((e) => (e.currentTarget as HTMLElement).click())}
@keyup=${keyup((e) => (e.currentTarget as HTMLElement).click())}
@keydown=${keydown}
@keyup=${keyup}
>
<div class="target"></div>
<span class="icon">
Expand Down Expand Up @@ -80,6 +83,8 @@ class HaSidebarPanelConfig extends LitElement {
]
: [];
}

static styles = [haStyleSidebarItem, styles];
}

declare global {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ha-sidebar-panel-ext-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const styles = css`
width: 100%;
}
`;

@customElement("ha-sidebar-panel-ext-config")
class HaSidebarPanelExtConfig extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand All @@ -20,8 +21,6 @@ class HaSidebarPanelExtConfig extends LitElement {

@property({ type: Boolean }) public expanded = false;

static styles = [haStyleSidebarItem, styles];

protected render() {
return html`<button
class="item ${this.expanded ? "expanded" : ""}"
Expand All @@ -41,6 +40,8 @@ class HaSidebarPanelExtConfig extends LitElement {
type: "config_screen/show",
});
}

static styles = [haStyleSidebarItem, styles];
}

declare global {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ha-sidebar-panel-notifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const styles = css`
width: 100%;
}
`;

@customElement("ha-sidebar-panel-notifications")
class HaSidebarPanelNotifications extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand All @@ -24,8 +25,6 @@ class HaSidebarPanelNotifications extends LitElement {

@state() private _notifications?: PersistentNotification[];

static styles = [haStyleSidebarItem, styles];

protected render() {
const notificationCount = this._notifications
? this._notifications.length
Expand Down Expand Up @@ -60,6 +59,8 @@ class HaSidebarPanelNotifications extends LitElement {
private _showNotifications() {
fireEvent(this, "hass-show-notifications");
}

static styles = [haStyleSidebarItem, styles];
}

declare global {
Expand Down
15 changes: 10 additions & 5 deletions src/components/ha-sidebar-panel-user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { customElement, property } from "lit/decorators";
import { haStyleSidebarItem } from "../resources/styles";
import { HomeAssistant } from "../types";
import "./user/ha-user-badge";
import { keydown, keyup } from "../resources/button-handlers";
import { createKeydown, createKeyup } from "../resources/button-handlers";

const styles = css`
.icon {
Expand All @@ -18,6 +18,7 @@ const styles = css`
transform: translate(-50%, -50%) scale(0.8);
}
`;

@customElement("ha-sidebar-panel-user")
class HaSidebarPanelUser extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand All @@ -26,15 +27,17 @@ class HaSidebarPanelUser extends LitElement {

@property({ type: Boolean }) public selected = false;

static styles = [haStyleSidebarItem, styles];

protected render() {
const keydown = createKeydown((e) =>
(e.currentTarget as HTMLElement).click()
);
const keyup = createKeyup((e) => (e.currentTarget as HTMLElement).click());
return html`<a
href="/profile"
aria-current=${this.selected ? "page" : "false"}
class="item ${this.expanded ? "expanded" : ""}"
@keydown=${keydown((e) => (e.currentTarget as HTMLElement).click())}
@keyup=${keyup((e) => (e.currentTarget as HTMLElement).click())}
@keydown=${keydown}
@keyup=${keyup}
>
<div class="target"></div>
<span class="icon">
Expand All @@ -48,6 +51,8 @@ class HaSidebarPanelUser extends LitElement {
<span class="name">${this.hass.user ? this.hass.user.name : ""}</span>
</a>`;
}

static styles = [haStyleSidebarItem, styles];
}

declare global {
Expand Down
15 changes: 10 additions & 5 deletions src/components/ha-sidebar-panel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { customElement, property } from "lit/decorators";
import { haStyleSidebarItem } from "../resources/styles";
import "./ha-svg-icon";
import "./ha-icon";
import { keydown, keyup } from "../resources/button-handlers";
import { createKeydown, createKeyup } from "../resources/button-handlers";

const styles = css`
.item.expanded {
Expand All @@ -14,6 +14,7 @@ const styles = css`
margin-left: auto;
}
`;

@customElement("ha-sidebar-panel")
class HaSidebarPanel extends LitElement {
@property() public path = "";
Expand All @@ -28,16 +29,18 @@ class HaSidebarPanel extends LitElement {

@property({ type: Boolean }) public selected = false;

static styles = [haStyleSidebarItem, styles];

protected render() {
const keydown = createKeydown((e) =>
(e.currentTarget as HTMLElement).click()
);
const keyup = createKeyup((e) => (e.currentTarget as HTMLElement).click());
return html`<a
href="/${this.path}"
aria-current=${this.selected ? "page" : "false"}
aria-label=${this.name}
class="item ${this.expanded ? "expanded" : ""}"
@keydown=${keydown((e) => (e.currentTarget as HTMLElement).click())}
@keyup=${keyup((e) => (e.currentTarget as HTMLElement).click())}
@keydown=${keydown}
@keyup=${keyup}
>
<div class="target"></div>
<span class="icon">
Expand All @@ -48,6 +51,8 @@ class HaSidebarPanel extends LitElement {
<span class="name">${this.name}</span>
</a>`;
}

static styles = [haStyleSidebarItem, styles];
}

declare global {
Expand Down
4 changes: 2 additions & 2 deletions src/components/ha-sidebar-panels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ class HaSidebarPanels extends LitElement {

private searchKeysUpdated = 0;

static styles = styles;

constructor() {
super();
const getCurrentFocus = () => {
Expand Down Expand Up @@ -329,6 +327,8 @@ class HaSidebarPanels extends LitElement {
[]
);
}

static styles = styles;
}

declare global {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ha-sidebar-title.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const styles = css`
margin-inline-end: 0;
}
`;

@customElement("ha-sidebar-title")
class HaSidebarTitle extends LitElement {
@property({ attribute: false }) public hass!: HomeAssistant;
Expand All @@ -53,8 +54,6 @@ class HaSidebarTitle extends LitElement {

@property({ type: Boolean }) public editMode = false;

static styles = styles;

protected render() {
const classes = classMap({
menu: true,
Expand Down Expand Up @@ -100,6 +99,8 @@ class HaSidebarTitle extends LitElement {
private _editModeOff() {
fireEvent(this, "hass-edit-sidebar", { editMode: false });
}

static styles = styles;
}

declare global {
Expand Down
5 changes: 3 additions & 2 deletions src/components/ha-sidebar-tooltip.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,14 @@ const styles = css`
display: none;
}
`;

@customElement("ha-sidebar-tooltip")
class HaSidebarTooltip extends LitElement {
static styles = styles;

protected render() {
return html`<div></div>`;
}

static styles = styles;
}

export interface TooltipPosition {
Expand Down
4 changes: 2 additions & 2 deletions src/resources/button-handlers.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const keydown =
export const createKeydown =
(activate: (e: KeyboardEvent) => void) => (e: KeyboardEvent) => {
if (e.key === " ") e.preventDefault();
if (e.key === "Enter") {
e.preventDefault();
activate(e);
}
};
export const keyup =
export const createKeyup =
(activate: (e: KeyboardEvent) => void) => (e: KeyboardEvent) => {
if (e.key === " ") activate(e);
};
Loading