Skip to content

Commit

Permalink
Clean menu
Browse files Browse the repository at this point in the history
  • Loading branch information
silamon committed Mar 30, 2024
1 parent 85f80ff commit a056b46
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 26 deletions.
37 changes: 37 additions & 0 deletions src/components/ha-menu-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { CSSResult, css } from "lit";
import { MdMenuItem } from "@material/web/menu/menu-item";

@customElement("ha-menu-item")
export class HaMenuItem extends MdMenuItem {
static override styles: CSSResult[] = [
...MdMenuItem.styles,
css`
:host {
--ha-icon-display: block;
--md-sys-color-primary: var(--primary-text-color);
--md-sys-color-on-primary: var(--primary-text-color);
--md-sys-color-secondary: var(--secondary-text-color);
--md-sys-color-surface: var(--card-background-color);
--md-sys-color-on-surface: var(--primary-text-color);
--md-sys-color-on-surface-variant: var(--secondary-text-color);
--md-sys-color-secondary-container: rgba(
var(--rgb-primary-color),
0.15
);
--md-sys-color-on-secondary-container: var(--text-primary-color);
--mdc-icon-size: 16px;
--md-sys-color-on-primary-container: var(--primary-text-color);
--md-sys-color-on-secondary-container: var(--primary-text-color);
}
`,
];
}

declare global {
interface HTMLElementTagNameMap {
"ha-menu-item": HaMenuItem;
}
}
22 changes: 22 additions & 0 deletions src/components/ha-menu.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { customElement } from "lit/decorators";
import "element-internals-polyfill";
import { CSSResult, css } from "lit";
import { MdMenu } from "@material/web/menu/menu";

@customElement("ha-menu")
export class HaMenu extends MdMenu {
static override styles: CSSResult[] = [
...MdMenu.styles,
css`
:host {
--md-sys-color-surface-container: var(--card-background-color);
}
`,
];
}

declare global {
interface HTMLElementTagNameMap {
"ha-menu": HaMenu;
}
}
38 changes: 12 additions & 26 deletions src/layouts/hass-tabs-subpage-data-table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import "@lrnwebcomponents/simple-tooltip/simple-tooltip";
import "@material/mwc-button/mwc-button";
import "@material/web/menu/menu";
import type { MdMenu } from "@material/web/menu/menu";
import "@material/web/menu/menu-item";
import {
mdiArrowDown,
mdiArrowUp,
Expand Down Expand Up @@ -36,6 +35,8 @@ import type {
} from "../components/data-table/ha-data-table";
import "../components/ha-dialog";
import "../components/search-input-outlined";
import "../components/ha-menu";
import "../components/ha-menu-item";
import type { HomeAssistant, Route } from "../types";
import "./hass-tabs-subpage";
import type { PageNavigation } from "./hass-tabs-subpage";
Expand Down Expand Up @@ -409,37 +410,37 @@ export class HaTabsSubpageDataTable extends LitElement {
</ha-data-table>`}
<div slot="fab"><slot name="fab"></slot></div>
</hass-tabs-subpage>
<md-menu anchor="group-by-anchor" id="group-by-menu" positioning="fixed">
<ha-menu anchor="group-by-anchor" id="group-by-menu" positioning="fixed">
${Object.entries(this.columns).map(([id, column]) =>
column.groupable
? html`
<md-menu-item
<ha-menu-item
.value=${id}
@click=${this._handleGroupBy}
.selected=${id === this._groupColumn}
class=${classMap({ selected: id === this._groupColumn })}
>
${column.title || column.label}
</md-menu-item>
</ha-menu-item>
`
: nothing
)}
<li divider role="separator"></li>
<md-menu-item
<ha-menu-item
.value=${undefined}
@click=${this._handleGroupBy}
.selected=${this._groupColumn === undefined}
class=${classMap({ selected: this._groupColumn === undefined })}
>${localize(
"ui.components.subpage-data-table.dont_group_by"
)}</md-menu-item
)}</ha-menu-item
>
</md-menu>
<md-menu anchor="sort-by-anchor" id="sort-by-menu" positioning="fixed">
</ha-menu>
<ha-menu anchor="sort-by-anchor" id="sort-by-menu" positioning="fixed">
${Object.entries(this.columns).map(([id, column]) =>
column.sortable
? html`
<md-menu-item
<ha-menu-item
.value=${id}
@click=${this._handleSortBy}
.selected=${id === this._sortColumn}
Expand All @@ -456,11 +457,11 @@ export class HaTabsSubpageDataTable extends LitElement {
`
: nothing}
${column.title || column.label}
</md-menu-item>
</ha-menu-item>
`
: nothing
)}
</md-menu>
</ha-menu>
`;
}

Expand Down Expand Up @@ -712,21 +713,6 @@ export class HaTabsSubpageDataTable extends LitElement {
display: flex;
flex-direction: column;
}
/* TODO: Migrate to ha-menu and ha-menu-item */
md-menu {
--md-menu-container-color: var(--card-background-color);
}
md-menu-item {
--md-menu-item-label-text-color: var(--primary-text-color);
--mdc-icon-size: 16px;
--md-menu-item-selected-container-color: rgba(
var(--rgb-primary-color),
0.15
);
}
md-menu-item.selected {
--md-menu-item-label-text-color: var(--primary-color);
}
#sort-by-anchor,
#group-by-anchor {
--md-assist-chip-trailing-space: 8px;
Expand Down

0 comments on commit a056b46

Please sign in to comment.