Skip to content
Closed
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
5 changes: 5 additions & 0 deletions gallery/src/pages/components/ha-dropdown.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
title: Dropdown
---

# Dropdown `<ha-dropdown>`
133 changes: 133 additions & 0 deletions gallery/src/pages/components/ha-dropdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
import {
mdiContentCopy,
mdiContentCut,
mdiContentPaste,
mdiDelete,
} from "@mdi/js";
import type { TemplateResult } from "lit";
import { css, html, LitElement } from "lit";
import { customElement } from "lit/decorators";
import "../../../../src/components/ha-button";
import "../../../../src/components/ha-card";
import "../../../../src/components/ha-svg-icon";
import "../../../../src/components/ha-dropdown-item";
import "@home-assistant/webawesome/dist/components/icon/icon";
import "@home-assistant/webawesome/dist/components/button/button";
import "@home-assistant/webawesome/dist/components/dropdown/dropdown";
import "../../../../src/components/ha-dropdown";
import "@home-assistant/webawesome/dist/components/popup/popup";
import { applyThemesOnElement } from "../../../../src/common/dom/apply_themes_on_element";
import "../../../../src/components/ha-icon-button";

@customElement("demo-components-ha-dropdown")
export class DemoHaDropdown extends LitElement {
protected render(): TemplateResult {
return html`
${["light", "dark"].map(
(mode) => html`
<div class=${mode}>
<ha-card header="ha-button in ${mode}">
<div class="card-content">
<ha-dropdown open>
<ha-button slot="trigger" with-caret>Dropdown</ha-button>

<ha-dropdown-item>
<ha-svg-icon
.path=${mdiContentCut}
slot="icon"
></ha-svg-icon>
Cut
</ha-dropdown-item>
<ha-dropdown-item>
<ha-svg-icon
.path=${mdiContentCopy}
slot="icon"
></ha-svg-icon>
Copy
</ha-dropdown-item>
<ha-dropdown-item disabled>
<ha-svg-icon
.path=${mdiContentPaste}
slot="icon"
></ha-svg-icon>
Paste
</ha-dropdown-item>
<ha-dropdown-item>
Show images
<ha-dropdown-item slot="submenu" value="show-all-images"
>Show All Images</ha-dropdown-item
>
<ha-dropdown-item slot="submenu" value="show-thumbnails"
>Show Thumbnails</ha-dropdown-item
>
</ha-dropdown-item>
<ha-dropdown-item type="checkbox" checked
>Emoji Shortcuts</ha-dropdown-item
>
<ha-dropdown-item type="checkbox" checked
>Word Wrap</ha-dropdown-item
>
<ha-dropdown-item variant="danger">
<ha-svg-icon .path=${mdiDelete} slot="icon"></ha-svg-icon>
Delete
</ha-dropdown-item>
</ha-dropdown>
</div>
</ha-card>
</div>
`
)}
`;
}

firstUpdated(changedProps) {
super.firstUpdated(changedProps);
applyThemesOnElement(
this.shadowRoot!.querySelector(".dark"),
{
default_theme: "default",
default_dark_theme: "default",
themes: {},
darkMode: true,
theme: "default",
},
undefined,
undefined,
true
);
}

static styles = css`
:host {
display: flex;
justify-content: center;
}
.dark,
.light {
display: block;
background-color: var(--primary-background-color);
padding: 0 50px;
}
.button {
padding: unset;
}
ha-card {
margin: 24px auto;
}
.card-content {
display: flex;
flex-direction: column;
gap: 24px;
}
.card-content div {
display: flex;
gap: 8px;
}
`;
}

declare global {
interface HTMLElementTagNameMap {
"demo-components-ha-dropdown": DemoHaDropdown;
}
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"@fullcalendar/list": "6.1.19",
"@fullcalendar/luxon3": "6.1.19",
"@fullcalendar/timegrid": "6.1.19",
"@home-assistant/webawesome": "3.0.0-beta.6.ha.1",
"@home-assistant/webawesome": "3.0.0-beta.6.ha.2",
"@lezer/highlight": "1.2.1",
"@lit-labs/motion": "1.0.9",
"@lit-labs/observers": "2.0.6",
Expand Down
23 changes: 23 additions & 0 deletions src/components/ha-dropdown-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import DropdownItem from "@home-assistant/webawesome/dist/components/dropdown-item/dropdown-item";
import { css, type CSSResultGroup } from "lit";
import { customElement } from "lit/decorators";

@customElement("ha-dropdown-item")
export class HaDropdownItem extends DropdownItem {
static get styles(): CSSResultGroup {
return [
DropdownItem.styles,
css`
:host {
min-height: 40px;
}
`,
];
}
}

declare global {
interface HTMLElementTagNameMap {
"ha-dropdown-item": HaDropdownItem;
}
}
20 changes: 20 additions & 0 deletions src/components/ha-dropdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import Dropdown from "@home-assistant/webawesome/dist/components/dropdown/dropdown";
import type { CSSResultGroup } from "lit";
import { customElement, property } from "lit/decorators";

@customElement("ha-dropdown")
export class HaDropdown extends Dropdown {
@property({ attribute: false }) dropdownTag = "ha-dropdown";

@property({ attribute: false }) dropdownItemTag = "ha-dropdown-item";

static get styles(): CSSResultGroup {
return [Dropdown.styles];
}
}

declare global {
interface HTMLElementTagNameMap {
"ha-dropdown": HaDropdown;
}
}
27 changes: 12 additions & 15 deletions src/panels/profile/ha-refresh-tokens-card.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import {
} from "../../dialogs/generic/show-dialog-box";
import { haStyle } from "../../resources/styles";
import type { HomeAssistant } from "../../types";
import "../../components/ha-dropdown-item";
import "../../components/ha-dropdown";

// Client ID used by iOS app
const iOSclientId = "https://home-assistant.io/iOS";
Expand Down Expand Up @@ -146,19 +148,18 @@ class HaRefreshTokens extends LitElement {
)}
</div>
<div>
<ha-md-button-menu positioning="popover">
<ha-dropdown>
<ha-icon-button
slot="trigger"
.label=${this.hass.localize("ui.common.menu")}
.path=${mdiDotsVertical}
></ha-icon-button>
<ha-md-menu-item
graphic="icon"
<ha-dropdown-item
@click=${this._toggleTokenExpiration}
.token=${token}
>
<ha-svg-icon
slot="start"
slot="icon"
.path=${token.expire_at
? mdiClockRemoveOutline
: mdiClockCheckOutline}
Expand All @@ -170,24 +171,20 @@ class HaRefreshTokens extends LitElement {
: this.hass.localize(
"ui.panel.profile.refresh_tokens.enable_token_expiration"
)}
</ha-md-menu-item>
<ha-md-menu-item
graphic="icon"
class="warning"
</ha-dropdown-item>
<ha-dropdown-item
variant="danger"
.disabled=${token.is_current}
@click=${this._deleteToken}
.token=${token}
>
<ha-svg-icon
class="warning"
slot="start"
slot="icon"
.path=${mdiDelete}
></ha-svg-icon>
<div slot="headline">
${this.hass.localize("ui.common.delete")}
</div>
</ha-md-menu-item>
</ha-md-button-menu>
${this.hass.localize("ui.common.delete")}
</ha-dropdown-item>
</ha-dropdown>
</div>
</ha-settings-row>
`
Expand Down
3 changes: 3 additions & 0 deletions src/resources/theme/color/wa.globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export const waColorStyles = css`
--wa-color-danger-on-normal: var(--ha-color-on-danger-normal);
--wa-color-danger-on-quiet: var(--ha-color-on-danger-quiet);

--wa-color-text-normal: var(--ha-color-text-primary);
--wa-color-surface-raised: var(--ha-dialog-surface-background, var(--mdc-theme-surface, #fff));

--wa-focus-ring-color: var(--ha-color-neutral-60);
}
`;
10 changes: 9 additions & 1 deletion src/resources/theme/wa.globals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ export const waMainStyles = css`
--wa-font-weight-action: var(--ha-font-weight-medium);
--wa-transition-fast: 75ms;
--wa-transition-easing: ease;
--wa-border-width-l: var(--ha-border-radius-l);
--wa-border-width-s: var(--ha-border-width-sm);
--wa-border-width-m: var(--ha-border-width-md);
--wa-border-width-l: var(--ha-border-width-lg);
--wa-border-radius-s: var(--ha-border-radius-sm);
--wa-border-radius-m: var(--ha-border-radius-md);
--wa-border-radius-l: var(--ha-border-radius-lg);

--wa-line-height-condensed: 1.25;

--wa-space-xl: 32px;
}

Expand Down
10 changes: 5 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1940,9 +1940,9 @@ __metadata:
languageName: node
linkType: hard

"@home-assistant/webawesome@npm:3.0.0-beta.6.ha.1":
version: 3.0.0-beta.6.ha.1
resolution: "@home-assistant/webawesome@npm:3.0.0-beta.6.ha.1"
"@home-assistant/webawesome@npm:3.0.0-beta.6.ha.2":
version: 3.0.0-beta.6.ha.2
resolution: "@home-assistant/webawesome@npm:3.0.0-beta.6.ha.2"
dependencies:
"@ctrl/tinycolor": "npm:4.1.0"
"@floating-ui/dom": "npm:^1.6.13"
Expand All @@ -1953,7 +1953,7 @@ __metadata:
lit: "npm:^3.2.1"
nanoid: "npm:^5.1.5"
qr-creator: "npm:^1.0.0"
checksum: 10/c9510e0c65b682c3868b5cbbf046f62aea30e3c5d969128d9032e0d89a8943faa4c9d78c3500446ec04cffeb0ab1939b870b60d454db657faed2aa0ac6026a3e
checksum: 10/781d3aecc7d11a13307c0be12ae6383774242abdf8ce283167665c1d85d2be8380a8a08cc16d80cfe89bdfbb01fa718c2e43cd095288bbc0ef2d06621b412866
languageName: node
linkType: hard

Expand Down Expand Up @@ -9205,7 +9205,7 @@ __metadata:
"@fullcalendar/list": "npm:6.1.19"
"@fullcalendar/luxon3": "npm:6.1.19"
"@fullcalendar/timegrid": "npm:6.1.19"
"@home-assistant/webawesome": "npm:3.0.0-beta.6.ha.1"
"@home-assistant/webawesome": "npm:3.0.0-beta.6.ha.2"
"@lezer/highlight": "npm:1.2.1"
"@lit-labs/motion": "npm:1.0.9"
"@lit-labs/observers": "npm:2.0.6"
Expand Down
Loading